Esempio n. 1
0
 /**
  * @param $from
  * @param $to
  * @return \mtoolkit\evolution\model\evolution\Evolution[]
  * @throws GetEvolutionsException
  * @throws \Exception
  */
 public function getEvolutions($from, $to)
 {
     $connection = $this->getConnection();
     $stmt = $connection->prepare("SELECT id, up, down, inserted, executed\n            FROM mt_evolutions\n            WHERE ( id>=? OR ? IS NULL )\n                AND ( id<=? OR ? IS NULL )\n            ORDER BY id ASC;");
     if ($stmt === false) {
         $errorMessage = sprintf("%s: %s", ErrorNumber::EN_002, $connection->error);
         throw new \Exception($errorMessage, $connection->errno);
     }
     $stmt->bind_param('iiii', $from, $from, $to, $to);
     $result = $stmt->execute();
     if ($result === false) {
         throw new GetEvolutionsException();
     }
     $toReturn = array();
     $stmt->bind_result($id, $up, $down, $inserted, $executed);
     while ($stmt->fetch()) {
         $evolution = new Evolution();
         $evolution->setId($id)->setUp($up)->setDown($down);
         if ($executed != null) {
             $evolution->setExecuted(new \DateTime($executed));
         }
         if ($inserted != null) {
             $evolution->setInserted(new \DateTime($inserted));
         }
         $toReturn[] = $evolution;
     }
     $stmt->free_result();
     $stmt->close();
     return $toReturn;
 }