当前位置: 首页>>代码示例>>PHP>>正文


PHP Doctrine_Record类代码示例

本文整理汇总了PHP中Doctrine_Record的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Record类的具体用法?PHP Doctrine_Record怎么用?PHP Doctrine_Record使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Doctrine_Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doPreSave

 protected function doPreSave(Doctrine_Record $record, sfForm $form)
 {
     // loop through relations
     if ($relations = $form->getOption('dynamic_relations')) {
         foreach ($relations as $field => $config) {
             $collection = $record->get($config['relation']->getAlias());
             // collect form objects for comparison
             $search = array();
             foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) {
                 $search[] = $embed->getObject();
             }
             foreach ($collection as $i => $object) {
                 if (false === ($pos = array_search($object, $search, true))) {
                     // if a related object exists in the record but isn't represented
                     // in the form, the reference has been removed
                     $collection->remove($i);
                     // if the foreign column is a notnull columns, delete the object
                     $column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
                     if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
                         $object->delete();
                     }
                 }
             }
         }
     }
 }
开发者ID:rschumacher,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:26,代码来源:sfDoctrineDynamicFormRelationsListener.class.php

示例2: fetchRelatedValues

 public function fetchRelatedValues(Doctrine_Record $record, $property)
 {
     $values = array();
     $skipDirectPropertyGet = false;
     // Record available translations of property, if available
     if ($record->hasRelation('Translation')) {
         if (!is_null($this->cacheUriCulture) && $this->hasTranslation($record, $this->cacheUriCulture)) {
             $translations = array($record->Translation[$this->cacheUriCulture]);
             $skipDirectPropertyGet = true;
         } else {
             $translations = $record->Translation;
         }
         foreach ($translations as $translation) {
             if (isset($translation[$property]) && $translation[$property]) {
                 $values[] = $translation[$property];
             }
         }
     }
     // Standard property get
     if (false === $skipDirectPropertyGet) {
         try {
             if ($value = (string) $record->{$property}) {
                 $values[] = $value;
             }
         } catch (Exception $e) {
         }
     }
     return array_unique($values);
 }
开发者ID:jeremyb,项目名称:akDoctrineTemplateCacheInvaliderPlugin,代码行数:29,代码来源:akDoctrineCacheUriResolver.class.php

示例3: __construct

 /**
  * contructor, creates node with reference to record and any options
  *
  * @param object $record                    instance of Doctrine_Record
  * @param array $options                    options
  */
 public function __construct(Doctrine_Record $record, $options)
 {
     $this->record = $record;
     $this->options = $options;
     // Make sure that the tree object of the root class is used in the case
     // of column aggregation inheritance (single table inheritance).
     $class = $record->getTable()->getComponentName();
     $thisTable = $record->getTable();
     $table = $thisTable;
     if ($thisTable->getOption('inheritanceMap')) {
         // Move up the hierarchy until we find the "subclasses" option. This option
         // MUST be set on the root class of the user's hierarchy that uses STI.
         while (!($subclasses = $table->getOption('subclasses'))) {
             $class = get_parent_class($class);
             $reflectionClass = new ReflectionClass($class);
             if ($reflectionClass->isAbstract()) {
                 continue;
             }
             if ($class == 'Doctrine_Record') {
                 throw new Doctrine_Node_Exception("No subclasses specified. You are " . "using Single Table Inheritance with NestedSet but you have " . "not specified the subclasses correctly. Make sure you use " . "setSubclasses() in the root class of your hierarchy.");
             }
             $table = $table->getConnection()->getTable($class);
         }
     }
     if ($thisTable !== $table) {
         $this->_tree = $table->getTree();
     } else {
         $this->_tree = $thisTable->getTree();
     }
 }
开发者ID:sensorsix,项目名称:app,代码行数:36,代码来源:Node.php

示例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)
    {
        $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;
    }
开发者ID:nationalfield,项目名称:symfony,代码行数:39,代码来源:LocalKey.php

示例5: fetchRelatedFor

    public function fetchRelatedFor(Doctrine_Record $record)
    {
        $id      = $record->getIncremented();

        $q = new Doctrine_RawSql();

        $assocTable = $this->getAssociationFactory()->getTableName();
        $tableName  = $record->getTable()->getTableName();
        $identifierColumnNames = $record->getTable()->getIdentifierColumnNames();
        $identifier = array_pop($identifierColumnNames);

        $sub     = 'SELECT '.$this->getForeign().
                   ' FROM '.$assocTable.
                   ' WHERE '.$this->getLocal().
                   ' = ?';

        $sub2   = 'SELECT '.$this->getLocal().
                  ' FROM '.$assocTable.
                  ' WHERE '.$this->getForeign().
                  ' = ?';

        $q->select('{'.$tableName.'.*}, {'.$assocTable.'.*}')
          ->from($tableName . ' INNER JOIN '.$assocTable.' ON '.
                 $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocal() . ' OR ' .
                 $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeign()
                 )
          ->where($tableName.'.'.$identifier.' IN ('.$sub.') OR '.
                  $tableName.'.'.$identifier.' IN ('.$sub2.')'
                );
        $q->addComponent($tableName,  $record->getTable()->getComponentName());
        $q->addComponent($assocTable, $record->getTable()->getComponentName(). '.' . $this->getAssociationFactory()->getComponentName());
        $q->orderBy($this->getOrderByStatement($tableName, true));

        return $q->execute(array($id, $id));
    }
开发者ID:nationalfield,项目名称:symfony,代码行数:35,代码来源:Self.php

示例6: 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 = array();
     $localTable = $record->getTable();
     foreach ((array) $this->definition['local'] as $local) {
         $value = $record->get($localTable->getFieldName($local));
         if (isset($value)) {
             $id[] = $value;
         }
     }
     if ($this->isOneToOne()) {
         if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
             $related = $this->getTable()->create();
         } else {
             $dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition();
             $coll = $this->getTable()->getConnection()->query($dql, $id);
             $related = $coll[0];
         }
         $related->set($related->getTable()->getFieldName($this->definition['foreign']), $record, false);
     } else {
         if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
             $related = Doctrine_Collection::create($this->getTable());
         } else {
             $query = $this->getRelationDql(1);
             $related = $this->getTable()->getConnection()->query($query, $id);
         }
         $related->setReference($record, $this);
     }
     return $related;
 }
开发者ID:swk,项目名称:bluebox,代码行数:38,代码来源:ForeignKey.php

示例7: fetchRelatedFor

 public function fetchRelatedFor(Doctrine_Record $record)
 {
     $id = $record->getIncremented();
     if (empty($id) || !$this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
         return Doctrine_Collection::create($this->getTable());
     } else {
         $q = new Doctrine_RawSql($this->getTable()->getConnection());
         $assocTable = $this->getAssociationFactory()->getTableName();
         $tableName = $record->getTable()->getTableName();
         $identifierColumnNames = $record->getTable()->getIdentifierColumnNames();
         $identifier = array_pop($identifierColumnNames);
         $sub = 'SELECT ' . $this->getForeignRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocalRefColumnName() . ' = ?';
         $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub . ')';
         $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeignRefColumnName();
         if ($this->definition['equal']) {
             $sub2 = 'SELECT ' . $this->getLocalRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeignRefColumnName() . ' = ?';
             $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub2 . ')';
             $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocalRefColumnName();
         }
         $q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . implode(' OR ', $joinCondition))->where(implode(' OR ', $condition))->orderBy($tableName . '.' . $identifier . ' ASC');
         if ($orderBy = $this->getOrderByStatement($tableName, true)) {
             $q->addOrderBy($orderBy);
         }
         $q->addComponent($tableName, $this->getClass());
         $path = $this->getClass() . '.' . $this->getAssociationFactory()->getComponentName();
         if ($this->definition['refClassRelationAlias']) {
             $path = $this->getClass() . '.' . $this->definition['refClassRelationAlias'];
         }
         $q->addComponent($assocTable, $path);
         $params = $this->definition['equal'] ? array($id, $id) : array($id);
         $res = $q->execute($params);
         return $res;
     }
 }
开发者ID:tests1,项目名称:zendcasts,代码行数:34,代码来源:Nest.php

示例8: fetchRelatedFor

 /**
 public function fetchRelatedFor(Doctrine_Record $record)
 {
     $id = $record->getIncremented();
 
     if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
         return new Doctrine_Collection($this->getTable());
     } else {
         $q = new Doctrine_Query();
         
         $c  = $this->getTable()->getComponentName();
         $a  = substr($c, 0, 1);
         $c2 = $this->getAssociationTable()->getComponentName();
         $a2 = substr($c2, 0, 1);
 
         $q->from($c)
           ->innerJoin($c . '.' . $c2)
 
         $sub = 'SELECT ' . $this->getForeign() 
              . ' FROM '  . $c2
              . ' WHERE ' . $this->getLocal() 
              . ' = ?';
     }
 }
 */
 public function fetchRelatedFor(Doctrine_Record $record)
 {
     $id = $record->getIncremented();
     if (empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
         return new Doctrine_Collection($this->getTable());
     } else {
         $q = new Doctrine_RawSql();
         $assocTable = $this->getAssociationFactory()->getTableName();
         $tableName = $record->getTable()->getTableName();
         $identifier = $record->getTable()->getIdentifier();
         $sub = 'SELECT ' . $this->getForeign() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocal() . ' = ?';
         $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub . ')';
         $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeign();
         if ($this->definition['equal']) {
             $sub2 = 'SELECT ' . $this->getLocal() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeign() . ' = ?';
             $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub2 . ')';
             $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocal();
         }
         $q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . implode(' OR ', $joinCondition))->where(implode(' OR ', $condition));
         $q->addComponent($tableName, $record->getTable()->getComponentName());
         $q->addComponent($assocTable, $record->getTable()->getComponentName() . '.' . $this->getAssociationFactory()->getComponentName());
         $params = $this->definition['equal'] ? array($id, $id) : array($id);
         return $q->execute($params);
     }
 }
开发者ID:kirvin,项目名称:the-nerdery,代码行数:50,代码来源:Nest.php

示例9: doPreSave

 protected function doPreSave(Doctrine_Record $record, sfForm $form)
 {
     // loop through relations
     if ($relations = $form->getOption('dynamic_relations')) {
         foreach ($relations as $field => $config) {
             $collection = $record->get($config['relation']->getAlias());
             // collect form objects for comparison
             $search = array();
             try {
                 foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) {
                     $search[] = $embed->getObject();
                 }
             } catch (InvalidArgumentException $e) {
                 // previously embedded form was removed at the end of form.filter_values as there were no values for it.
                 // @see sfDoctrineDynamicFormRelations::correctValidators()
             }
             foreach ($collection as $i => $object) {
                 $pos = array_search($object, $search, true);
                 if (false === $pos && $this->filterObject($object, $config['arguments'])) {
                     // if a related object exists in the record but isn't represented
                     // in the form, the reference has been removed
                     $collection->remove($i);
                     // if the foreign column is a notnull columns, delete the object
                     $column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
                     if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
                         $object->delete();
                     }
                 }
             }
         }
     }
 }
开发者ID:AUTOPLANNING,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:32,代码来源:sfDoctrineDynamicFormRelationsListener.class.php

示例10: setObject

 public function setObject(Doctrine_Record $record)
 {
     if (!$record->exists()) {
         throw new Exception("Can't set ObjectTag's object to new object");
     }
     $this->object_model = get_class($record);
     $this->object_id = $record->id;
 }
开发者ID:silky,项目名称:littlesis,代码行数:8,代码来源:ObjectTag.class.php

示例11: updatedAtBy

function updatedAtBy(Doctrine_Record $record)
{
    $user = $record->get('UpdatedBy');
    if ($user && $user->isNew()) {
        $user = null;
    }
    return format_date($record->get('updated_at'), 'f') . ($user ? ' - ' . $user : '');
}
开发者ID:Regmaya,项目名称:diem-project,代码行数:8,代码来源:MyAdminHelper.php

示例12: getValue

 /**
  * Extract the value of the field from a record.
  * @param Doctrine_Record $record
  * @return mixed
  */
 public function getValue($record)
 {
     if (!$this->getField()) {
         throw new IllegalStateException('Not field defined por relation ' . $this->getName());
     }
     $getter = 'get' . ucfirst($this->getName());
     return $this->getField()->getValue($record->__call($getter, array()));
 }
开发者ID:BGCX261,项目名称:zoorestaurant-svn-to-git,代码行数:13,代码来源:AsyncSearchRelationField.class.php

示例13: _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);
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:8,代码来源:TrimmableListener.class.php

示例14: getByModelAndObjectQuery

 static function getByModelAndObjectQuery($model, Doctrine_Record $object)
 {
     if (!$object->exists()) {
         throw new Exception("Can't get " . LsString::pluralize($model) . " by new object");
     }
     $alias = substr(strtolower($model), 0, 1);
     return LsDoctrineQuery::create()->from($model . ' ' . $alias)->where($alias . '.object_model = ? AND ' . $alias . '.object_id = ?', array(get_class($object), $object->id));
 }
开发者ID:silky,项目名称:littlesis,代码行数:8,代码来源:Objectable.class.php

示例15: filterGet

 /**
  * filterGet
  * defines an implementation for filtering the get() method of Doctrine_Record
  *
  * @param mixed $name                       name of the property or related component
  */
 public function filterGet(Doctrine_Record $record, $name)
 {
     // fields are mapped directly in the dmDoctrineRecord class
     // for performance reasons, but relations are mapped here.
     if ($this->getTable()->hasI18n() && $this->getTable()->getI18nTable()->hasRelation($name)) {
         return $record->getCurrentTranslation()->get($name);
     }
     throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
 }
开发者ID:theolymp,项目名称:diem,代码行数:15,代码来源:dmDoctrineRecordI18nFilter.class.php


注:本文中的Doctrine_Record类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。