/** * Gets a record for given key * * There are two special cases: * * 1. if null is given as a key a new record is created and attached * at the end of the collection * * 2. if given key does not exist, then a new record is create and attached * to the given key * * Collection also maps referential information to newly created records * * @param mixed $key the key of the element * @return Doctrine_Record return a specified record */ public function get($key) { if (!isset($this->data[$key])) { $record = $this->_table->create(); if (isset($this->referenceField)) { $value = $this->reference->get($this->relation->getLocalFieldName()); if ($value !== null) { $record->set($this->referenceField, $value, false); } else { $record->set($this->referenceField, $this->reference, false); } } if ($key === null) { $this->data[] = $record; } else { $this->data[$key] = $record; } $this->oids[$record->oid()] = true; if (isset($this->keyColumn)) { $record->set($this->keyColumn, $key); } return $record; } return $this->data[$key]; }
/** * Write Event to database * * @param array $event */ public function _write($event) { $entry = $this->_table->create(array()); foreach ($this->_columnMap as $eventIndex => $tableColumn) { $entry->{$tableColumn} = $event[$eventIndex]; } $entry->save(); }
/** * Create a new lab * @param <type> $name * @return <type> */ public function create($name) { if ($name == "") { throw new Exception(self::ERROR_INVALID_NAME); } $code_generator = new App_Value_Code(); do { $code = $code_generator->get(); } while ($this->db->findByCode($code)->count() != 0); $lab = $this->db->create(); $lab->name = $name; $lab->code = $code; if ($lab->isValid()) { try { $lab->save(); } catch (Exception $e) { throw new Exception(self::ERROR_NOT_SAVED); } } else { throw new Exception(self::ERROR_NOT_VALID . $lab->getErrorStackAsString()); } return $lab->toArray(); }
/** * Write a message to the log. * * @param array $event event data * @return void */ protected function _write($event) { if ($this->_table === null) { throw new Zym_Log_Exception('Database adapter instance has been removed by shutdown'); } if (!$this->_columnMap) { $dataToInsert = $event; } else { $dataToInsert = array(); foreach ($this->_columnMap as $columnName => $fieldKey) { $dataToInsert[$columnName] = $event[$fieldKey]; } } $record = $this->_table->create($dataToInsert); $record->save(); }
/** * get * returns a record for given key * * There are two special cases: * * 1. if null is given as a key a new record is created and attached * at the end of the collection * * 2. if given key does not exist, then a new record is create and attached * to the given key * * Collection also maps referential information to newly created records * * @param mixed $key the key of the element * @return Doctrine_Record return a specified record */ public function get($key) { if ($key === null || !isset($this->data[$key])) { $record = $this->_table->create(); if (isset($this->referenceField)) { $value = $this->reference->get($this->relation->getLocal()); if ($value !== null) { $record->set($this->referenceField, $value, false); } else { $record->set($this->referenceField, $this->reference, false); } } $this->data[] = $record; return $record; } return $this->data[$key]; }
/** * * @param Doctrine_Table $table * @param array $data */ public function create(Doctrine_Table $table, $data) { foreach ($data as $row) { $table->create($row)->save(); } }