public function actionUpdateContacts() { /* @var $contacts LuxContactInfo */ /* @var $contactsLng LuxContactInfoLng */ $id = Yii::app()->request->getParam('id', null); $label = Yii::app()->request->getParam('label', null); $email_1 = Yii::app()->request->getParam('email_1', null); $phone_1 = Yii::app()->request->getParam('phone_1', null); $phone_2 = Yii::app()->request->getParam('phone_2', null); $email_admin = Yii::app()->request->getParam('email_admin', null); $map_link = Yii::app()->request->getParam('map_link', null); $small_text_lng = Yii::app()->request->getParam('info', array()); $subject_lng = Yii::app()->request->getParam('subject', array()); $title_lng = Yii::app()->request->getParam('title', array()); $contacts = LuxContactInfo::model()->findByPk($id); if ($contacts == null) { $contacts = new LuxContactInfo(); } $contacts->email_1 = $email_1; $contacts->phone_1 = $phone_1; $contacts->phone_2 = $phone_2; $contacts->administrator_email = $email_admin; $contacts->map_link = $map_link; $contacts->label = $label; $old_f_name = $contacts->map_image; $new_f_name = DwHelper::uploadPicAndGetPath($_FILES, 'map_img', $old_f_name); if ($new_f_name != "") { $contacts->map_image = $new_f_name; } if ($contacts->isNewRecord) { $contacts->save(); } else { $contacts->update(); } foreach (Constants::GetLngArray() as $lng) { $contactsLng = $contacts->getLngObject($lng); $contactsLng->small_text = $small_text_lng[$lng]; $contactsLng->feedback_subject = $subject_lng[$lng]; $contactsLng->text = $title_lng[$lng]; if ($contactsLng->isNewRecord) { $contactsLng->save(); } else { $contactsLng->update(); } } $this->redirect($this->createUrl('/admin/inlux/contacts')); }
public function actionUpdatePage() { /* @var $item LmtContentUnit */ //get parameters from request $id = Yii::app()->request->getParam('id', null); $label = Yii::app()->request->getParam('label', ''); $status = Yii::app()->request->getParam('status', Constants::STATUS_HIDDEN); $tree_id = Yii::app()->request->getParam('tree_id', ''); //get multi-language arrays $titles = Yii::app()->request->getParam('title', array()); $texts = Yii::app()->request->getParam('text', array()); //try find by id $item = LmtContentUnit::model()->findByPk($id); //if not found - that means we need create if ($item == null) { $item = new LmtContentUnit(); } //changed category or not $changed = false; if (!$item->getIsNewRecord() && $item->tree_id != $tree_id) { $changed = true; } //set main params $item->label = $label; $item->status = $status; $item->type = Constants::TYPE_TEXT_BLOCK; $item->tree_id = $tree_id; //upload thumbnail $old_f_name = $item->thumb; $new_f_name = DwHelper::uploadPicAndGetPath($_FILES, 'thumbnail', $old_f_name); if ($new_f_name != "") { $item->thumb = $new_f_name; } //if this is creation if ($item->getIsNewRecord()) { //set new priority considering category if ($tree_id != '') { $item->priority = DwHelper::getNextPriorityComplex("LmtContentUnit", $tree_id, "tree_id"); } else { $item->priority = DwHelper::getNextPriority("LmtContentUnit"); } //set dates $item->date_created = time(); $item->date_changed = time(); //save $item->save(); } else { //if changed category - get next priority in category if ($changed) { $item->priority = DwHelper::getNextPriorityComplex("LmtContentUnit", $tree_id, "tree_id"); } //set date of changing $item->date_changed = time(); //update $item->update(); } //get language objects foreach (Constants::GetLngArray() as $lng) { //get lng object $itemLng = $item->getLngObject($lng); //set data $itemLng->title = $titles[$lng]; $itemLng->text = $texts[$lng]; //update or create if not exist if ($itemLng->getIsNewRecord()) { $itemLng->save(); } else { $itemLng->update(); } } //prefix for category in url $prefixRedirect = ""; //if have category - set url prefix if ($tree_id != '') { $prefixRedirect = "/cat/" . $tree_id; } //back to list $this->redirect($this->createUrl('/admin/lmt/pageslist' . $prefixRedirect)); }