コード例 #1
0
 /**
  * Get the relation reference count.
  *
  * @param ForeignKey $fkey   The foreign key
  * @param int        $max    The maximum count
  * @return int
  */
 protected function getRelationReferenceCount($fkey, $max = null)
 {
     $count = 0;
     $tablename = $fkey->getOwningTable()->getRawTableName();
     foreach ($this->getTable()->getManyToManyRelations() as $relation) {
         // $relation key => reference (ForeignKey), refTable (Table)
         if ($this->checkReferenceTableName($relation['refTable'], $tablename)) {
             $count++;
         }
         if ($max && $count == $max) {
             break;
         }
     }
     return $count;
 }
コード例 #2
0
 /**
  * Inject relation.
  *
  * @param \MwbExporter\Model\ForeignKey $foreignKey
  */
 public function injectRelation(ForeignKey $foreignKey)
 {
     foreach ($this->relations as $_relation) {
         if ($_relation->getId() === $foreignKey->getId()) {
             return;
         }
     }
     $this->relations[] = $foreignKey;
 }
コード例 #3
0
 /**
  * Get foreign key join annotation. If foreign key is composite
  * JoinColumns returned, otherwise JoinColumn returned.
  *
  * @param \MwbExporter\Model\ForeignKey $fkey  Foreign key
  * @param boolean $owningSide  Is join for owning side or vice versa
  * @return \MwbExporter\Object\Annotation
  */
 protected function getJoins(ForeignKey $fkey, $owningSide = true)
 {
     $joins = array();
     $lcols = $owningSide ? $fkey->getForeigns() : $fkey->getLocals();
     $fcols = $owningSide ? $fkey->getLocals() : $fkey->getForeigns();
     $onDelete = $this->getFormatter()->getDeleteRule($fkey->getParameters()->get('deleteRule'));
     for ($i = 0; $i < count($lcols); $i++) {
         $joins[] = $this->getAnnotation('JoinColumn', array('name' => $this->quoteIdentifier($lcols[$i]->getColumnName()), 'referencedColumnName' => $this->quoteIdentifier($fcols[$i]->getColumnName()), 'nullable' => $lcols[$i]->getNullableValue(), 'onDelete' => $onDelete));
     }
     return count($joins) > 1 ? $this->getAnnotation('JoinColumns', array($joins), array('multiline' => true, 'wrapper' => ' * %s')) : $joins[0];
 }
コード例 #4
0
 /**
  * Check if foreign key owner tablename matched.
  *
  * @param \MwbExporter\Model\ForeignKey $foreign    The foreign key
  * @param string     $tablename  The table name
  * @return bool
  */
 protected function checkForeignKeyOwnerTableName($foreign, $tablename)
 {
     return $this->checkReferenceTableName($foreign ? $foreign->getReferencedTable() : null, $tablename);
 }
コード例 #5
0
 /**
  * Get foreign key join descriptor.
  *
  * @param \MwbExporter\Model\ForeignKey $fkey  Foreign key
  * @param string $owningSide  Is join for owning side or vice versa
  * @return array
  */
 protected function getJoins(ForeignKey $fkey, $owningSide = true)
 {
     $joins = array();
     $lcols = $owningSide ? $fkey->getForeigns() : $fkey->getLocals();
     $fcols = $owningSide ? $fkey->getLocals() : $fkey->getForeigns();
     $onDelete = $this->getFormatter()->getDeleteRule($fkey->getParameters()->get('deleteRule'));
     for ($i = 0; $i < count($lcols); $i++) {
         $joins[] = array('name' => $lcols[$i]->getColumnName(), 'referencedColumnName' => $fcols[$i]->getColumnName(), 'nullable' => $lcols[$i]->isNotNull() ? false : null, 'onDelete' => $onDelete);
     }
     return count($joins) > 1 ? array('joinColumns' => $this->convertJoinColumns($joins)) : array('joinColumn' => $joins[0]);
 }
コード例 #6
0
 /**
  * Add foreign key reference.
  *
  * @param \MwbExporter\Model\ForeignKey $foreign
  */
 public function markAsForeignReference(ForeignKey $foreign)
 {
     $this->foreigns[$foreign->getId()] = $foreign;
 }