Пример #1
0
 /**
  * @param AbstractLink $link
  * @return $this
  */
 public function addLink(AbstractLink $link)
 {
     $this->_linkList[$link->getName()] = $link;
     return $this;
 }
Пример #2
0
 /**
  * @param Column $localColumn
  * @param Column $foreignColumn
  * @param null   $ruleUpdate
  * @param null   $ruleDelete
  * @return ManyToOne|OneToMany|OneToOne|null
  */
 protected function getLinkByColumns(Column $localColumn, Column $foreignColumn, $ruleUpdate = null, $ruleDelete = null)
 {
     return \Model\Cluster\Schema\Table\Link\AbstractLink::factory($localColumn, $foreignColumn, $ruleUpdate, $ruleDelete);
 }
Пример #3
0
    /**
     * @param AbstractLink $link
     * @return MethodGenerator
     */
    protected function getDeleteLinkMethodWithoutLinkTable(AbstractLink $link)
    {
        $localEntity = $link->getLocalEntity();
        $localEntityAsVar = $link->getLocalEntityAsVar();
        $localEntityAsCamelCase = $link->getLocalEntityAsCamelCase();
        $foreignTableAsCamelCase = $link->getForeignTable()->getNameAsCamelCase();
        $foreignEntity = $link->getForeignEntity();
        $foreignEntityAsVar = $link->getForeignEntityAsVar();
        $foreignEntityAsCamelCase = $link->getForeignEntityAsCamelCase();
        $localColumn = $link->getLocalColumn()->getName();
        $foreignColumn = $link->getForeignColumn()->getName();
        $tags = array(array('name' => 'param', 'description' => 'mixed $' . $localEntityAsVar), array('name' => 'param', 'description' => 'mixed $' . $foreignEntityAsVar), array('name' => 'return', 'description' => '\\Model\\Result\\Result'));
        $docblock = new DocBlockGenerator('Отвязать ' . $localEntityAsCamelCase . ' от ' . $foreignEntityAsCamelCase);
        $docblock->setTags($tags);
        $nullValue = new ValueGenerator('array()', ValueGenerator::TYPE_CONSTANT);
        $method = new MethodGenerator();
        $method->setName('deleteLink' . $localEntityAsCamelCase . 'To' . $foreignEntityAsCamelCase);
        $method->setParameter(new ParameterGenerator($localEntityAsVar, 'mixed', $nullValue));
        $method->setParameter(new ParameterGenerator($foreignEntityAsVar, 'mixed', $nullValue));
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setDocBlock($docblock);
        if ($link->isDirect()) {
            $method->setBody(<<<EOS
\${$localEntityAsVar}Ids = array_unique(\$this->getIdsFromMixed(\${$localEntityAsVar}));
\${$foreignEntityAsVar}Ids = array_unique({$foreignTableAsCamelCase}Model::getInstance()->getIdsFromMixed(\${$foreignEntityAsVar}));

\$result = new Result();
\$result->setResult(true);

if (count(\${$localEntityAsVar}Ids) == 0 && count(\${$foreignEntityAsVar}Ids) == 0) {
    return \$result;
}

\$cond = array();
if (count(\${$localEntityAsVar}Ids) != 0) {
    \$cond['{$foreignColumn}'] = \${$localEntityAsVar}Ids;
}

if (count(\${$foreignEntityAsVar}Ids) != 0) {
    \$cond['{$localColumn}'] = \${$foreignEntityAsVar}Ids;
}

try {
    \$this->getDb()->update(\$this->getRawName(), array('{$localColumn}' => null), \$cond);
} catch (\\Exception \$e) {
    \$result->setResult(false);
    \$result->addError("Delete link {$localEntity} to {$foreignEntity} failed", 'delete_link_failed');
}

return \$result;
EOS
);
        } else {
            $method->setBody(<<<EOS
return {$foreignTableAsCamelCase}Model::getInstance()->deleteLink{$foreignEntityAsCamelCase}To{$localEntityAsCamelCase}(\${$foreignEntityAsVar}, \${$localEntityAsVar});
EOS
);
        }
        return $method;
    }