Ejemplo n.º 1
0
 /**
  * Save in cache
  *
  * @return void
  */
 private function _saveInCache(Zend_Cache_Core $cache)
 {
     $cacheData = array();
     $cacheData['tableName'] = $this->_dbData->getTable()->getComponentName();
     $cacheData['dataArray'] = $this->_dbData->toArray(self::SERIALIZATION_DEEP);
     $cache->save($cacheData, $this->_cacheKey);
 }
 public function testInsertMultiple()
 {
     $count = count($this->dbh);
     $listener = new Transaction_TestLogger();
     $users = new Doctrine_Collection('User');
     $users->getTable()->getConnection()->setListener($listener);
     $this->connection->beginTransaction();
     $users[0]->name = 'Arnold';
     $users[1]->name = 'Vincent';
     $users[0]->save();
     $users[1]->save();
     $this->assertEqual($listener->pop(), 'onSave');
     $this->assertEqual($listener->pop(), 'onInsert');
     $this->assertEqual($listener->pop(), 'onPreInsert');
     $this->assertEqual($listener->pop(), 'onPreSave');
     $this->assertEqual($listener->pop(), 'onSave');
     $this->assertEqual($listener->pop(), 'onInsert');
     $this->assertEqual($listener->pop(), 'onPreInsert');
     $this->assertEqual($listener->pop(), 'onPreSave');
     $this->assertEqual($users[0]->id, 2);
     $this->assertEqual($users[1]->id, 3);
     $this->assertTrue($count < count($this->dbh));
     $this->connection->commit();
     $this->assertEqual($listener->pop(), 'onTransactionCommit');
     $this->assertEqual($listener->pop(), 'onPreTransactionCommit');
 }
Ejemplo n.º 3
0
 public function getObjects()
 {
     $objects = parent::getObjects();
     if ($objects instanceof Doctrine_Record) {
         $objects = new Doctrine_Collection($objects->getTable());
     }
     return $objects;
 }
 /**
  * Remaps a doctrine collection so that the keys of the colleciton "array"
  * are the ids of the underlying objects. This makes the collection
  * easier to deal with then replacing objects
  * 
  * @return Doctrine_Collection
  */
 protected static function _buildObjects(Doctrine_Collection $collection)
 {
     $objects = new Doctrine_Collection($collection->getTable());
     foreach ($collection as $key => $value) {
         $objects[$value->slug] = $value;
     }
     return $objects;
 }
Ejemplo n.º 5
0
 /**
  * @param Doctrine_Record|Doctrine_Collection|Array $data
  * @param null|Doctrine_Table $table
  * @return Kebab_Validate_Doctrine_Table
  */
 protected function _setTable($data, $table = null)
 {
     if (is_null($table) && $data instanceof Doctrine_Record) {
         $this->_table = $data->getTable();
     }
     if (!is_null($table) && $table instanceof Doctrine_Table) {
         $this->_table = $table;
     }
     if (is_string($table) && !$table instanceof Doctrine_Table) {
         $this->_table = Doctrine_Core::getTable($table);
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Merges collection into $this and returns merged collection
  * 
  * @param Doctrine_Collection $coll
  * @return Doctrine_Collection
  */
 public function merge(Doctrine_Collection $coll)
 {
     $localBase = $this->getTable()->getComponentName();
     $otherBase = $coll->getTable()->getComponentName();
     if ($otherBase != $localBase && !is_subclass_of($otherBase, $localBase)) {
         throw new Doctrine_Collection_Exception("Can't merge collections with incompatible record types");
     }
     foreach ($coll->getData() as $record) {
         $this->add($record);
     }
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Return an collection of records as XML. 
  * 
  * @see getRecordAsXml for options to set in the record class to control this.
  *
  * @param Doctrine_Collection $collection
  * @param SimpleXMLElement $xml
  * @return string Xml as string 
  */
 public static function getCollectionAsXml(Doctrine_Collection $collection, SimpleXMLElement $incomming_xml = null)
 {
     $collectionName = Doctrine_Lib::plurelize($collection->getTable()->tableName);
     if ($collection->count != 0) {
         $record = $collection[0];
         $xml_options = $record->option("xml");
         if (isset($xml_options["collection_name"])) {
             $collectionName = $xml_options["collection_name"];
         }
     }
     if (!isset($incomming_xml)) {
         $new_xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><" . $collectionName . "></" . $collectionName . ">";
         $xml = new SimpleXMLElement($new_xml_string);
     } else {
         $xml = $incomming_xml->addChild($collectionName);
     }
     foreach ($collection as $key => $record) {
         Doctrine_Lib::getRecordAsXml($record, $xml);
     }
     return $xml->asXML();
 }