Exemplo n.º 1
0
 public function get(array $where = [])
 {
     $this->isNew = false;
     $condition = DbModel::buildWhere($where);
     $query = "SELECT * FROM {$this->tableName} " . ($condition != null ? 'WHERE ' . $condition : "");
     $datastore = new DbModelStore();
     $itr = 0;
     $stmt = DbConnection::getDefault()->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $classname = get_class($this);
         $model = new $classname();
         foreach ($this->tableMap as $prop) {
             $setter = "set" . ucfirst($prop->getModelPropertyName());
             $model->{$setter}($row[$prop->getDbPropertyName()]);
         }
         $model->isNew = false;
         $datastore->Add($itr++, $model);
     }
     return $datastore;
 }