1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of DispositionMapper
*
* @author Filip Zamboj (fzamboj@netbeans.org)
*/
class Application_Model_DispositionMapper {
protected $_dbTable;
public function setDbTable($dbTable) {
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable() {
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Disposition');
}
return $this->_dbTable;
}
public function save(Application_Model_Disposition $disposition) {
$data = array(
'text_en' => $disposition->getText_en()
);
if (null === ($id = $disposition->getId())) {
unset($data['id']);
$this->getDbTable()->insert($data);
} else {
$this->getDbTable()->update($data, array('id = ?' => $id));
}
}
public function find($id, Application_Model_Content $content) {
$result = $this->getDbTable()->find($id);
if (0 == count($result)) {
return;
}
$row = $result->current();
$content->setId($row->id)
->setText_en($row->text_en);
}
public function fetchAllUsed($city, $cp, $pType, $offer_id, $cityMatch) {
$locationQuery = "";
if ($cityMatch == true) {
if (count($cp) > 0) {
foreach ($cp as $v) {
if (strlen($locationQuery) > 0)
$locationQuery .= " or ";
$locationQuery .= " location_id = " . $v . " ";
}
} else {
$lm = new Application_Model_PropertyLocationMapper();
$lmr = $lm->fetchUsedLocationsParts($city);
foreach ($lmr as $v) {
if (strlen($locationQuery) > 0)
$locationQuery .= " or ";
$locationQuery .= " location_id = " . $v->getId() . " ";
}
}
}
$pm = new Application_Model_PropertyMapper();
$dQuery = "";
if (strlen($locationQuery) > 0 && !($pType == null))
$fpQuery = " ($locationQuery) and property_type_id = $pType";
else if (strlen($locationQuery) == 0 && !($pType == null))
$fpQuery = " property_type_id = $pType";
else if (strlen($locationQuery) > 0 && ($pType == null))
$fpQuery = " $locationQuery ";
else
$fpQuery = "";
if (strlen($fpQuery) > 0)
$fpQuery .= " and offer_id = $offer_id";
else
$fpQuery = "offer_id = $offer_id";
// var_dump($fpQuery);
foreach ($pm->fetchAll($fpQuery. " and disabled = 0") as $v) {
if (strlen($dQuery) > 0)
$dQuery .= " or ";
$dQuery .= " id = " . $v->getDisposition_id() . " ";
}
if (strlen($dQuery) == 0)
return null;
$table = $this->getDbTable();
$select = $table->select();
$select->from($table)
->where($dQuery)
->group("id");
$final = $this->fetchAll($dQuery);
return $final;
}
public function fetchAll($query = null) {
$table = $this->getDbTable();
$select = $table->select();
$select->from($table)
->order("text_en asc");
if (!($query == null)) {
$select->where($query);
}
$select->order("id asc");
$resultSet = $table->fetchAll($select);
return $this->processResultSet($resultSet);
}
private function processResultSet($resultSet) {
$entries = array();
foreach ($resultSet as $row) {
$entry = new Application_Model_Disposition();
$entry->setId($row->id);
$entry->setText_en($row->text_en);
$entries[] = $entry;
}
return $entries;
}
public function getCount() {
$table = $this->getDbTable();
$select = $table->select();
$select->from($table, array("count(id) as sum"));
$resultSet = $table->fetchAll($select);
$array = $resultSet->toArray();
return $array[0]['sum'];
}
public function fetchAllFilterToArray($query) {
$table = $this->getDbTable();
$select = $table->select();
$select->from($table)
->where($query);
$resultSet = $table->fetchAll($select);
$toArray = $resultSet->toArray();
return $toArray[0];
}
public function delete($id) {
$table = $this->getDbTable();
$table->delete("id = $id");
}
}
?>
|