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
|
<?php
/**
*
*
* @author Filip Zamboj (fzamboj@netbeans.org)
*/
class Application_Model_PropertyMapper {
/**
*
* @global String
*/
protected $_dbTable;
/**
*
* @param type $dbTable
* @return Application_Model_PropertyMapper
*/
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;
}
/**
*
* @return Application_Model_DbTable_Property
*/
public function getDbTable() {
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Property');
}
return $this->_dbTable;
}
/**
*
* @param Application_Model_Property $property
* @return type
*/
public function save(Application_Model_Property $property) {
$data = array(
'reference_no' => $property->getReference_no(),
'title_en' => $property->getTitle_en(),
'text_en' => $property->getText_en(),
'disposition_id' => $property->getDisposition_id(),
'area' => $property->getArea(),
'floor' => $property->getFloor(),
'lift' => $property->getLift(),
'cellar' => $property->getCellar(),
'balcony' => $property->getBalcony(),
'location_id' => $property->getLocation_id(),
'price' => $property->getPrice(),
'created_on' => date('Y-m-d H-i-s'),
'street' => $property->getStreet(),
'property_build_id' => $property->getProperty_build_id(),
'terace' => $property->getTerace(),
'loggia' => $property->getLoggia(),
'garden' => $property->getGarden(),
'garage' => $property->getGarage(),
'parking_place' => $property->getParking_place(),
);
if (null === ($id = $property->getId())) {
unset($data['id']);
return $this->getDbTable()->insert($data);
} else {
$this->getDbTable()->update($data, array('id = ?' => $id));
return $id;
}
}
/**
*
* @param type $id
* @param Application_Model_Property $property
* @return type
*/
public function find($id, Application_Model_Property $property) {
$result = $this->getDbTable()->find($id);
if (0 == count($result)) {
return;
}
$row = $result->current();
$property->setId($row->id)
->setTitle_en($row->title_en)
->setText_en($row->text_en)
->setDisposition_id($row->diposition_id)
->setArea($row->area)
->setFloor($row->floor)
->setLift($row->lift)
->setCellar($row->cellar)
->setBalcony($row->balcony)
->setProperty_type_id($row->property_type_id)
->setLocation_id($row->location_id)
->setPrice($row->price)
->setCreated_on($row->created_on)
->setDisabled($row->disabled)
->setStreet($row->street);
}
/**
*
* @param type $resultSet
* @return Application_Model_Property
*/
private function processResultSet($resultSet) {
$entries = array();
foreach ($resultSet as $row) {
$entry = new Application_Model_Property();
$entry->setId($row->id);
$entry->setReference_no($row->reference_no);
$entry->setTitle_en($row->title_en);
$entry->setText_en($row->text_en);
$entry->setDisposition_id($row->disposition_id);
$entry->setArea($row->area);
$entry->setFloor($row->floor);
$entry->setLift($row->lift);
$entry->setCellar($row->cellar);
$entry->setBalcony($row->balcony);
$entry->setLocation_id($row->location_id);
$entry->setPrice($row->price);
$entry->setCreated_on($row->created_on);
$entry->setStreet($row->street);
$entry->setProperty_build_id($row->property_build_id);
$entry->setTerace($row->terace);
$entry->setLoggia($row->loggia);
$entry->setGarden($row->garden);
$entry->setGarage($row->garage);
$entry->setParking_place($row->parking_place);
$entries[] = $entry;
}
return $entries;
}
/**
*
* @return type
*/
public function fetchAll($query = NULL) {
if ($query === NULL) {
$resultSet = $this->getDbTable()->fetchAll();
} else {
$table = $this->getDbTable();
$select = $table->select();
$select->from($table)
->where($query);
$resultSet = $this->getDbTable()->fetchAll($select);
}
return $this->processResultSet($resultSet);
}
}
?>
|