本文整理汇总了PHP中Doctrine_Record::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Record::set方法的具体用法?PHP Doctrine_Record::set怎么用?PHP Doctrine_Record::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Record
的用法示例。
在下文中一共展示了Doctrine_Record::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchRelatedFor
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public function fetchRelatedFor(Doctrine_Record $record)
{
$localFieldName = $record->getTable()->getFieldName($this->definition['local']);
$id = $record->get($localFieldName);
if (is_null($id) || ! $this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
// Ticket #1131 Patch.
if ( ! is_null($id)) {
$related->assignIdentifier($id);
$related->state(Doctrine_Record::STATE_PROXY);
}
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()
. ' WHERE ' . $this->getCondition() . $this->getOrderBy(null, false);
$related = $this->getTable()
->getConnection()
->query($dql, array($id))
->getFirst();
if ( ! $related || empty($related)) {
$related = $this->getTable()->create();
}
}
$record->set($localFieldName, $id, false);
return $related;
}
示例2: _trim
private function _trim(Doctrine_Record $record)
{
foreach ($this->_options['fields'] as $field) {
if ($record->rawGet($field) != trim($record->rawGet($field))) {
$record->set($field, trim($record->rawGet($field)), false);
}
}
}
示例3: set
public function set($name, $value, $load = true)
{
if ($col = $this->getTable()->getColumnDefinition($name)) {
if ($col["type"] == 'blob') {
$value = base64_encode($value);
}
}
parent::set($name, $value, $load);
}
示例4: fetchRelatedFor
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public function fetchRelatedFor(Doctrine_Record $record)
{
$id = $record->get($this->definition['local']);
if (empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
} else {
$related = $this->getTable()->find($id);
if (!$related) {
$related = $this->getTable()->create();
}
}
$record->set($this->definition['local'], $related, false);
return $related;
}
示例5: fetchRelatedFor
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public function fetchRelatedFor(Doctrine_Record $record)
{
$id = $record->get($this->definition['local']);
if (empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition();
$related = $this->getTable()->getConnection()->query($dql, array($id))->getFirst();
if (!$related || empty($related)) {
$related = $this->getTable()->create();
}
}
$record->set($this->definition['local'], $related, false);
return $related;
}
示例6: add
/**
* Adds a record to collection
*
* @param Doctrine_Record $record record to be added
* @param string $key optional key for the record
* @return boolean
*/
public function add($record, $key = null)
{
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);
}
$relations = $this->relation['table']->getRelations();
foreach ($relations as $relation) {
if ($this->relation['class'] == $relation['localTable']->getOption('name') && $relation->getLocal() == $this->relation->getForeignFieldName()) {
$record->{$relation}['alias'] = $this->reference;
break;
}
}
}
/**
* for some weird reason in_array cannot be used here (php bug ?)
*
* if used it results in fatal error : [ nesting level too deep ]
*/
foreach ($this->data as $val) {
if ($val === $record) {
return false;
}
}
if (isset($key)) {
if (isset($this->data[$key])) {
return false;
}
$this->data[$key] = $record;
return true;
}
if (isset($this->keyColumn)) {
$value = $record->get($this->keyColumn);
if ($value === null) {
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '" . $this->keyColumn . "' was null.");
}
$this->data[$value] = $record;
} else {
$this->data[] = $record;
}
return true;
}
示例7: saveRelatedLocalKeys
/**
* saveRelatedLocalKeys
* saves all related (through LocalKey) records to $record
*
* @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record
*/
public function saveRelatedLocalKeys(Doctrine_Record $record)
{
$state = $record->state();
$record->state($record->exists() ? Doctrine_Record::STATE_LOCKED : Doctrine_Record::STATE_TLOCKED);
foreach ($record->getReferences() as $k => $v) {
$rel = $record->getTable()->getRelation($k);
$local = $rel->getLocal();
$foreign = $rel->getForeign();
if ($rel instanceof Doctrine_Relation_LocalKey) {
// ONE-TO-ONE relationship
$obj = $record->get($rel->getAlias());
// Protection against infinite function recursion before attempting to save
if ($obj instanceof Doctrine_Record && $obj->isModified()) {
$obj->save($this->conn);
$id = array_values($obj->identifier());
if (!empty($id)) {
foreach ((array) $rel->getLocal() as $k => $columnName) {
$field = $record->getTable()->getFieldName($columnName);
if (isset($id[$k]) && $id[$k] && $record->getTable()->hasField($field)) {
$record->set($field, $id[$k]);
}
}
}
}
}
}
$record->state($state);
}
示例8: set
public function set($fieldName, $value, $load = true)
{
parent::set($fieldName, $value, $load);
}
示例9: saveRelated
/**
* saveRelated
* saves all related records to $record
*
* @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record
*/
public function saveRelated(Doctrine_Record $record)
{
$saveLater = array();
foreach ($record->getReferences() as $k => $v) {
$rel = $record->getTable()->getRelation($k);
$local = $rel->getLocal();
$foreign = $rel->getForeign();
if ($rel instanceof Doctrine_Relation_ForeignKey) {
$saveLater[$k] = $rel;
} else {
if ($rel instanceof Doctrine_Relation_LocalKey) {
// ONE-TO-ONE relationship
$obj = $record->get($rel->getAlias());
// Protection against infinite function recursion before attempting to save
if ($obj instanceof Doctrine_Record && $obj->isModified()) {
$obj->save($this->conn);
$id = array_values($obj->identifier());
if (!empty($id)) {
foreach ((array) $rel->getLocal() as $k => $field) {
if (isset($id[$k]) && $id[$k] && $record->getTable()->hasField($k)) {
$record->set($field, $id[$k]);
}
}
}
}
}
}
}
return $saveLater;
}
示例10: add
/**
* adds a record to collection
* @param Doctrine_Record $record record to be added
* @param string $key optional key for the record
* @return boolean
*/
public function add(Doctrine_Record $record, $key = null)
{
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);
}
}
/**
* for some weird reason in_array cannot be used here (php bug ?)
*
* if used it results in fatal error : [ nesting level too deep ]
*/
foreach ($this->data as $val) {
if ($val === $record) {
return false;
}
}
if (isset($key)) {
if (isset($this->data[$key])) {
return false;
}
$this->data[$key] = $record;
return true;
}
if (isset($this->keyColumn)) {
$value = $record->get($this->keyColumn);
if ($value === null) {
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '" . $this->keyColumn . "' was null.");
}
$this->data[$value] = $record;
} else {
$this->data[] = $record;
}
return true;
}
示例11: rawSet
/**
* Use inside of overriden Doctrine accessors
*
* @param string $name
* @param string $value
* @return void
*/
public function rawSet($name, $value)
{
parent::set($name, $value);
}
示例12: copyDoctrineFields
public static function copyDoctrineFields(Doctrine_Record $a, Doctrine_Record $b, array $fields)
{
foreach ($fields as $field) {
$b->set($field, $a->get($field));
}
}
示例13: refreshPosition
/**
* Refreshs the position of the object
*
* @param Doctrine_Record $object
*/
private function refreshPosition(Doctrine_Record $object)
{
$identifiers = $object->getTable()->getIdentifierColumnNames();
$query = $object->getTable()->createQuery()->select($this->_options['name']);
foreach ($identifiers as $identifier) {
$query->andWhere($identifier . ' = ?', $object->get($identifier));
}
$position = $query->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
$object->set($this->_options['name'], $position['position'], false);
}
示例14: update
/**
* update
* updates the given record
*
* @param Doctrine_Record $record record to be updated
* @return boolean whether or not the update was successful
*/
public function update(Doctrine_Record $record)
{
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_UPDATE);
$record->preUpdate($event);
if (!$event->skipOperation) {
$array = $record->getPrepared();
if (empty($array)) {
return false;
}
$set = array();
foreach ($array as $name => $value) {
if ($value instanceof Doctrine_Expression) {
$set[] = $value->getSql();
unset($array[$name]);
} else {
$set[] = $name . ' = ?';
if ($value instanceof Doctrine_Record) {
if (!$value->exists()) {
$record->save($this->conn);
}
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
}
}
}
$params = array_values($array);
$id = $record->identifier();
if (!is_array($id)) {
$id = array($id);
}
$id = array_values($id);
$params = array_merge($params, $id);
$sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName()) . ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys()) . ' = ?';
$stmt = $this->conn->getDbh()->prepare($sql);
$stmt->execute($params);
$record->assignIdentifier(true);
}
$record->postUpdate($event);
return true;
}
示例15: rawSet
function rawSet($name, $value, $load = true)
{
return parent::set($name, $value, $load);
}