public function setAttributesForFutureParent(Tree $parent)
{
//Родитель должен быть уже сохранен
if ($parent->isNewRecord) {
throw new Exception('Родитель дольжен быть сохранен');
}
if ($this->id == $parent->id) {
throw new Exception('Родитель не может быть вложен в родителя');
}
$newPids = $parent->pids;
$newPids[] = $parent->primaryKey;
$this->setAttribute("level", $parent->level + 1);
$this->setAttribute('pid', $parent->primaryKey);
$this->setAttribute("pids", $newPids);
if (!$this->name) {
$this->generateName();
}
if (!$this->code) {
//Просто генерируем pageName
$this->generateCode();
}
if ($parent->dir) {
$this->setAttribute("dir", $parent->dir . Tree::PIDS_DELIMETR . $this->code);
} else {
$this->setAttribute("dir", $this->code);
}
return $this;
}