public function actionUpdatePage()
 {
     /* @var $item LuxContentUnit */
     //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 = LuxContentUnit::model()->findByPk($id);
     //if not found - that means we need create
     if ($item == null) {
         $item = new LuxContentUnit();
     }
     //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("LuxContentUnit", $tree_id, "tree_id");
         } else {
             $item->priority = DwHelper::getNextPriority("LuxContentUnit");
         }
         //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("LuxContentUnit", $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/inlux/pageslist' . $prefixRedirect));
 }
示例#2
0
            </select>
        </div>
        <div class="hr"></div>

        <?php 
foreach (Constants::GetLngArray() as $label => $lng) {
    ?>
        <label class="top-field-label">Название <?php 
    echo $label;
    ?>
:</label>
        <div class="field-container-long"><input type="text" name="title[<?php 
    echo $lng;
    ?>
]" class="input-main float-left" value="<?php 
    echo $item->getLngObject($lng)->title;
    ?>
"></div>
        <?php 
}
?>
        <div class="hr"></div>

        <?php 
foreach (Constants::GetLngArray() as $label => $lng) {
    ?>
            <label class="top-field-label">Текст <?php 
    echo $label;
    ?>
:</label>
            <div class="field-container-height">