if ($this->isNewRecord) {
if(!empty($this->parent_id)) {
if (some condition) $success = true;
}
else {
if (some condition) $success = true;
}
}
else {
if(!empty($this->parent_id)) {
if (some condition) $success = true;
}
else {
if (some condition) $success = true;
}
}
if (@$success) {
$this->message = "OK!";
}
if ($this->isNewRecord && !empty($this->parent_id)) {
if (some condition) $success = true;
}
elseif ($this->isNewRecord && empty($this->parent_id)) {
if (some condition) $success = true;
}
elseif (!$this->isNewRecord && !empty($this->parent_id)) {
if (some condition) $success = true;
}
else {
if (some condition) $success = true;
}
if (@$success) {
$this->message = "OK!";
}
if (some condition1 || some condition2 || some conditio3 || some condition4) {
$success = true;
}
$condition1 = ($this->isNewRecord && !empty($this->parent_id) && some condition1);
$condition1 = ($this->isNewRecord && empty($this->parent_id) && some condition2);
$condition1 = (!$this->isNewRecord && !empty($this->parent_id) && some condition3);
$condition1 = (!$this->isNewRecord && empty($this->parent_id) && some condition4);
if (!empty($category->pid)) {
$rootCategory = Categories::model()->findByPk($category->pid);
$categorySaved = ($category->isNewRecord ?
$category->appendTo($rootCategory) :
$category->moveAsFirst($rootCategory)
) && $category->saveNode());
} else {
$categorySaved = ($category->isNewRecord || !$category->isRoot() && $category->moveAsRoot()
) && $category->saveNode();
}
int to0123(bool a, bool b)
{
return ((int)(a == true) << 1) + (int)(b == true);
}
conditions = {f1, f2, f3, f4};
, где fx функции, которые проверяют ваши some conditions,idx = to0123($this->isNewRecord, empty($this->parent_id));
if (conditions[idx])
success = true
if ($category->isNewRecord && empty($category->pid)) {
if ($category->saveNode()) $categorySaved = true;
}
elseif ($category->isNewRecord && !empty($category->pid)) {
$rootCategory = Categories::model()->findByPk($category->pid);
if ($category->appendTo($rootCategory) && $category->saveNode()) $categorySaved = true;
}
elseif (!$category->isNewRecord && empty($category->pid) && !$category->isRoot()) {
if ($category->moveAsRoot() && $category->saveNode()) $categorySaved = true;
}
elseif (!$category->isNewRecord && !empty($category->pid)) {
$rootCategory = Categories::model()->findByPk($category->pid);
if ($category->moveAsFirst($rootCategory) && $category->saveNode()) $categorySaved = true;
}
$categorySaved = true;
if (!empty($category->pid)) {
$rootCategory = Categories::model()->findByPk($category->pid);
$categorySaved = $category->isNewRecord ?
$category->appendTo($rootCategory) : $category->moveAsFirst($rootCategory);
} else if ($category->isNewRecord && !$category->isRoot()) {
$categorySaved = $category->moveAsRoot();
}
$categorySaved = $categorySaved && $category->saveNode();