public function actionUpdateTree() { /* @var $tree LuxTree */ //get params from request $id = Yii::app()->request->getParam('id', null); $label = Yii::app()->request->getParam('label', ''); $status = Yii::app()->request->getParam('status', Constants::STATUS_HIDDEN); $type = Yii::app()->request->getParam('type', Constants::TYPE_TEXT_PAGE_1_ARRINGTON); $names = Yii::app()->request->getParam('name', array()); //try to find by pk $tree = LuxTree::model()->findByPk($id); //if not found by pk - that means that id not found ind request, need to create new if ($tree == null) { $tree = new LuxTree(); } //set main parameters $tree->status = $status; $tree->type = $type; $tree->label = $label; //if this is creation if ($tree->getIsNewRecord()) { //set priority $tree->priority = DwHelper::getNextPriority("LuxTree"); //creation date $tree->date_created = time(); //last change date $tree->date_changed = time(); //save new record in db $tree->save(); } else { //last change date $tree->date_changed = time(); //update $tree->update(); } //get all lng objects by active languages on site foreach (Constants::GetLngArray() as $lng) { //get object $treeLng = $tree->getLngObject($lng); //set name using multi-language array given from request $treeLng->name = $names[$lng]; //update or create if not exist if ($treeLng->getIsNewRecord()) { $treeLng->save(); } else { $treeLng->update(); } } //back to list $this->redirect($this->createUrl('/admin/inlux/treelist')); }