當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。