Exemplo n.º 1
0
 public static function find($parameters = null)
 {
     //Create an unique key based on the parameters
     $key = self::_createKey($parameters);
     if (!isset(self::$_cache[$key])) {
         //Store the result in the memory cache
         self::$_cache[$key] = parent::find($parameters);
     }
     //Return the result in the cache
     return self::$_cache[$key];
 }
Exemplo n.º 2
0
 public static function find($parameters = null)
 {
     //Convert the parameters to an array
     if (!is_array($parameters)) {
         $parameters = array($parameters);
     }
     //Check if a cache key wasn't passed
     //and create the cache parameters
     if (!isset($parameters['cache'])) {
         $parameters['cache'] = array("key" => self::_createKey($parameters), "lifetime" => 300);
     }
     return parent::find($parameters);
 }
Exemplo n.º 3
0
 public function getMessages()
 {
     $messages = array();
     foreach (parent::getMessages() as $message) {
         switch ($message->getType()) {
             case 'InvalidCreateAttempt':
                 $messages[] = 'The record cannot be created because it already exists';
                 break;
             case 'InvalidUpdateAttempt':
                 $messages[] = 'The record cannot be updated because it already exists';
                 break;
             case 'PresenceOf':
                 $messages[] = 'The field ' . $message->getField() . ' is mandatory';
                 break;
         }
     }
     return $messages;
 }
Exemplo n.º 4
0
 public static function find($parameters = null)
 {
     //Create a unique key
     $key = self::_createKey($parameters);
     //Check if there are data in the cache
     $results = self::_getCache($key);
     // Valid data is an object
     if (is_object($results)) {
         return $results;
     }
     $results = array();
     $invoices = parent::find($parameters);
     foreach ($invoices as $invoice) {
         //Query the related customer
         $customer = $invoice->customer;
         //Assign it to the record
         $invoice->customer = $customer;
         $results[] = $invoice;
     }
     //Store the invoices in the cache + their customers
     self::_setCache($key, $results);
     return $results;
 }
Exemplo n.º 5
0
 protected function issue886($di)
 {
     $this->_prepareDb($di->getShared('db'));
     Phalcon\Mvc\Model::setup(array('phqlLiterals' => false));
     $people = People::findFirst();
     $this->assertTrue(is_object($people));
     $this->assertEquals(get_class($people), 'People');
 }
Exemplo n.º 6
0
 protected function _executeTestsNormalComplexCastHydrate($di)
 {
     Phalcon\Mvc\Model::setup(['castOnHydrate' => true]);
     $result = $di->get('modelsManager')->executeQuery('SELECT id FROM Robots');
     //Scalar complex query
     foreach ($result as $row) {
         $this->assertEquals(get_class($row), 'Phalcon\\Mvc\\Model\\Row');
         $this->assertTrue(is_numeric($row->id));
     }
     $result->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_RECORDS);
     foreach ($result as $row) {
         $this->assertEquals(get_class($row), 'Phalcon\\Mvc\\Model\\Row');
         $this->assertTrue(is_numeric($row->id));
     }
     $result->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);
     foreach ($result as $row) {
         $this->assertTrue(is_array($row));
         $this->assertTrue(is_numeric($row['id']));
     }
     $result->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);
     foreach ($result as $row) {
         $this->assertEquals(get_class($row), 'stdClass');
         $this->assertTrue(is_numeric($row->id));
     }
     //Complex resultset including scalars and complete objects
     $result = $di->get('modelsManager')->executeQuery('SELECT Robots.id, Robots.*, RobotsParts.* FROM Robots JOIN RobotsParts');
     foreach ($result as $row) {
         $this->assertEquals(get_class($row), 'Phalcon\\Mvc\\Model\\Row');
         $this->assertTrue(is_numeric($row->id));
         $this->assertEquals(gettype($row->robots), 'object');
         $this->assertEquals(get_class($row->robots), 'Robots');
         $this->assertEquals(gettype($row->robotsParts), 'object');
         $this->assertEquals(get_class($row->robotsParts), 'RobotsParts');
     }
     $result->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_RECORDS);
     foreach ($result as $row) {
         $this->assertEquals(get_class($row), 'Phalcon\\Mvc\\Model\\Row');
         $this->assertTrue(is_numeric($row->id));
         $this->assertEquals(gettype($row->robots), 'object');
         $this->assertEquals(get_class($row->robots), 'Robots');
         $this->assertEquals(gettype($row->robotsParts), 'object');
         $this->assertEquals(get_class($row->robotsParts), 'RobotsParts');
     }
     $result->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);
     foreach ($result as $row) {
         $this->assertTrue(is_array($row));
         $this->assertTrue(is_numeric($row['id']));
         $this->assertEquals(gettype($row['robots']), 'array');
         $this->assertEquals(count($row['robots']), 7);
         $this->assertEquals(gettype($row['robotsParts']), 'array');
         $this->assertEquals(count($row['robotsParts']), 3);
     }
     $result->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);
     foreach ($result as $row) {
         $this->assertEquals(get_class($row), 'stdClass');
         $this->assertTrue(is_numeric($row->id));
         $this->assertEquals(gettype($row->robots), 'object');
         $this->assertEquals(get_class($row->robots), 'stdClass');
         $this->assertEquals(gettype($row->robotsParts), 'object');
         $this->assertEquals(get_class($row->robotsParts), 'stdClass');
     }
     Phalcon\Mvc\Model::setup(['castOnHydrate' => false]);
 }
Exemplo n.º 7
0
<?php

Phalcon\Mvc\Model::setup(array('phqlLiterals' => false));
Exemplo n.º 8
0
 public static function findFirst($parameters = null)
 {
     return parent::findFirst($parameters);
 }
<?php

$robot = Phalcon\Mvc\Model::cloneResult(new Robots(), array('type' => 'mechanical', 'name' => 'Astro Boy', 'year' => 1952));
Exemplo n.º 10
0
 protected function issue1801($di)
 {
     Phalcon\Mvc\Model::setup(array('columnRenaming' => false));
     $robot = Robots::findFirst(1);
     $di->get('modelsMetadata')->reset();
     $robot = Robots::findFirst(1);
     $this->assertTrue(true);
 }