/** * Reads a from the table * * @param string $table * @param string $model * @param string $condition * @param string $order * @return mixed */ public function read($table, $model, $condition = '', $order = '', $limit = '') { $query = 'select * from ' . $table; if ($condition !== '') { $query .= ' where ' . $condition; } if ($order !== '') { $query .= ' order by ' . $order; } if ($limit !== '') { $query .= ' limit ' . $limit; } $query .= ';'; $result = $this->query($query, PDO::FETCH_ASSOC); if ($result->rowCount() == 1) { $result = new $model($result->fetch()); } elseif ($result->rowCount() > 1) { $collection = new ModelCollection(); foreach ($result as $row) { $collection->add(new $model($row)); } $result = $collection; } else { return false; } return $result; }
/** * Renvoie une collection d'objet Models, à partir d'une requête en BDD. * * @param string $sSQL Requête SQL de type SELECT. * @return \Aouka\ORM\ModelCollection */ public static function getAll($sSQL) { $oEmptyInstance = new static(); $aResults = $oEmptyInstance->getDB()->getArray($sSQL); $oCollection = new ModelCollection(self::UPDATE); if ($aResults) { foreach ($aResults as $aResult) { $oCollection->add(static::init($aResult)); } $oCollection->end(); } return $oCollection; }