Example #1
0
 protected function buildAssociativeRelationSql(Doctrine_Relation $relation, $assocAlias, $foreignAlias, $localAlias)
 {
     $table = $relation->getTable();
     $queryPart = ' ON ';
     if ($relation->isEqual()) {
         $queryPart .= '(';
     }
     $localIdentifier = $table->getColumnName($table->getIdentifier());
     $queryPart .= $this->_conn->quoteIdentifier($foreignAlias . '.' . $localIdentifier) . ' = ' . $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getForeignRefColumnName());
     if ($relation->isEqual()) {
         $queryPart .= ' OR ' . $this->_conn->quoteIdentifier($foreignAlias . '.' . $localIdentifier) . ' = ' . $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getLocalRefColumnName()) . ') AND ' . $this->_conn->quoteIdentifier($foreignAlias . '.' . $localIdentifier) . ' != ' . $this->_conn->quoteIdentifier($localAlias . '.' . $localIdentifier);
     }
     return $queryPart;
 }
Example #2
0
 /**
  * Get/generate a unique foreign key name for a relationship
  *
  * @param  Doctrine_Relation $relation  Relation object to generate the foreign key name for
  * @return string $fkName
  */
 public function generateUniqueRelationForeignKeyName(Doctrine_Relation $relation)
 {
     $parts = array($relation['localTable']->getTableName(), $relation->getLocalColumnName(), $relation['table']->getTableName(), $relation->getForeignColumnName());
     $key = implode('_', array_merge($parts, array($relation['onDelete']), array($relation['onUpdate'])));
     $format = $this->getAttribute(Doctrine_Core::ATTR_FKNAME_FORMAT);
     return $this->_generateUniqueName('foreign_keys', $parts, $key, $format, $this->getAttribute(Doctrine_Core::ATTR_MAX_IDENTIFIER_LENGTH));
 }
Example #3
0
 /**
  * Sets a reference pointer
  *
  * @return void
  */
 public function setReference(Doctrine_Record $record, Doctrine_Relation $relation)
 {
     $this->reference = $record;
     $this->relation = $relation;
     if ($relation instanceof Doctrine_Relation_ForeignKey || $relation instanceof Doctrine_Relation_LocalKey) {
         $this->referenceField = $relation->getForeignFieldName();
         $value = $record->get($relation->getLocalFieldName());
         foreach ($this->data as $record) {
             if ($value !== null) {
                 $record->set($this->referenceField, $value, false);
             } else {
                 $record->set($this->referenceField, $this->reference, false);
             }
         }
     } elseif ($relation instanceof Doctrine_Relation_Association) {
     }
 }
 /**
  * Returns Doctrine Record object prepared for form given the relation
  * @param string $relationName
  * @param Doctrine_Relation $relation
  * @return Doctrine_Record
  */
 private function embeddedFormObjectFactory($relationName, Doctrine_Relation $relation)
 {
     if (!$relation->isOneToOne()) {
         $newFormObjectClass = $relation->getClass();
         $newFormObject = new $newFormObjectClass();
         $newFormObject[$this->getRelationAliasByObject($newFormObject)] = $this->getObject();
     } else {
         $newFormObject = $this->getObject()->{$relationName};
     }
     return $newFormObject;
 }
Example #5
0
 /**
  * Get/generate a unique foreign key name for a relationship
  *
  * @param  Doctrine_Relation $relation  Relation object to generate the foreign key name for
  * @return string $fkName
  */
 public function generateUniqueRelationForeignKeyName(Doctrine_Relation $relation)
 {
     $parts = array($relation['localTable']->getTableName(), $relation->getLocalColumnName(), $relation['table']->getTableName(), $relation->getForeignColumnName());
     $key = implode('_', array_merge($parts, array($relation['onDelete']), array($relation['onUpdate'])));
     $format = $this->getAttribute(Doctrine::ATTR_FKNAME_FORMAT);
     return $this->_generateUniqueName('foreign_keys', $parts, $key, $format, $this->properties['max_identifier_length']);
 }
Example #6
0
 protected function renderRelatedRecord(Doctrine_Record $record, Doctrine_Relation $relation)
 {
     $value = $record->get($relation->getLocal());
     $cacheKey = md5(implode('|', array($this->versionModel, $relation->getClass(), $value)));
     if (isset($this->relatedRecordCache[$cacheKey])) {
         return $this->relatedRecordCache[$cacheKey];
     }
     try {
         if ('DmMedia' === $relation->getClass()) {
             $relatedRecord = $relation->getTable()->findOneByIdWithFolder($value);
             if ($relatedRecord && $relatedRecord->isImage()) {
                 $return = $this->helper->media($relatedRecord)->size($this->getOption('media_width'), $this->getOption('media_height'))->render();
             } else {
                 $return = $relatedRecord;
             }
         } else {
             $return = $relation->getTable()->findOneById($value);
         }
     } catch (Exception $e) {
         $return = get_class($relation->getClass()) . ' #' . $value;
     }
     return $this->relatedRecordCache[$cacheKey] = $return;
 }
Example #7
0
 protected function _createElementForRelation($relationName, Doctrine_Relation $relation)
 {
     switch ($relation->getType()) {
         case Doctrine_Relation::ONE:
             return new Zend_Form_Element_Select($relationName);
         case Doctrine_Relation::MANY:
             return new Zend_Form_Element_Multiselect($relationName);
         default:
             throw new ZendX_Form_Doctrine_Exception('Relation type not supported ("' . $relation->getType() . '"). ' . 'Consider extending ' . __CLASS__ . ' and overriding ' . __METHOD__ . '() to support it.');
     }
 }