/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate()
 {
     if ($this->catalog) {
         $catalog = ucwords($this->catalog);
         $id = (int) Yii::app()->request->getParam("id", 0);
         if (!empty($id)) {
             $model = $catalog::fetch($id);
         } else {
             $model = new $catalog();
         }
         $message = "";
         // Сохрание полей
         if (isset($_POST[$catalog])) {
             $model->setAttributesFromArray($_POST[$catalog]);
             if ($model->description) {
                 $model->description = str_replace("../../../../", Yii::app()->params["baseUrl"], $model->description);
             }
             if (!empty($_FILES[$catalog])) {
                 foreach ($_FILES[$catalog]["name"] as $key => $field) {
                     if (property_exists($model, $key)) {
                         $model->{$key} = $field;
                     }
                 }
             }
             if ($model->saveWithRelation()) {
                 $message = "Данные успешно сохраненны";
                 //$this->redirect(array('view','id'=>$model->id));
             }
         }
         // Сохранение TITLE галереи
         if (!empty($_POST["image_submit"]) && !empty($_POST["image"])) {
             foreach ($_POST["image"] as $value) {
                 if ($value["id"] > 0) {
                     $imageModel = CatGallery::fetch($value["id"]);
                     if ($imageModel->id > 0) {
                         $imageModel->name = $value["name"];
                         $imageModel->pos = $value["pos"];
                         $imageModel->type = $value["type"];
                         $imageModel->save();
                     }
                 }
             }
             $message = "Галерея успешно сохраненна";
         }
         // Добвление картинки
         $addGallery = new CatGallery();
         if (!empty($_POST["submit_add_gallery"]) && !empty($id)) {
             $addGallery->setAttributesFromArray($_POST["CatGallery"]);
             $addGallery->image = $_FILES["CatGallery"]["name"]["image"];
             $addGallery->catalog = $model->tableName();
             $addGallery->item_id = $id;
             $addGallery->save();
             // "", false
             $addGallery = new CatGallery();
         }
         if ($model->id > 0) {
             $listImage = CatGallery::findByAttributes(array("catalog" => $model->tableName(), "item_id" => $model->id));
         } else {
             $listImage = array();
         }
         $this->render('edit', array('arrayParams' => $this->arrayParams, 'form' => $model, 'catalog' => $this->catalog, 'listImage' => $listImage, 'message' => $message, 'addGallery' => $addGallery));
     }
 }
Example #2
0
 public function actionSetPublish()
 {
     $id = (int) Yii::app()->request->getParam("id", 0);
     $catalog = Yii::app()->request->getParam("catalog");
     if ($id > 0 && !empty($catalog)) {
         $newCatalog = new $catalog();
         $modelClass = SiteHelper::getCamelCase($newCatalog->tableName());
         $model = $modelClass::fetch($id);
         $listImages = CatGallery::findByAttributes(array("catalog" => $newCatalog->tableName(), "item_id" => $id));
         $imagesMin = SiteHelper::getConfig("publish_min_images");
         $sizeofImages = sizeof($listImages);
         if ($model->image) {
             $sizeofImages++;
         }
         // Для CatalogFirmsBannersAdd не должно влиять ограичение перед публиацией по количесву картинок
         if ($sizeofImages >= $imagesMin || $catalog == "CatalogFirmsBannersAdd" || $catalog == "CatalogFirmsBanners") {
             $error = false;
             $commentModel = $catalog::fetch($id);
             if (($catalog == "CatalogFirmsBannersAdd" || $catalog == "CatalogFirmsBanners") && !$commentModel->file) {
                 $error = true;
             }
             if ($commentModel->user_id->id != Yii::app()->user->getId() && $commentModel->firm_id->user_id->id != Yii::app()->user->getId()) {
                 $error = true;
             }
             if (!$error) {
                 if ($commentModel->user_id && $commentModel->user_id->id > 0) {
                     $id = $commentModel->user_id->id;
                 } else {
                     $id = $commentModel->firm_id->user_id->id;
                 }
                 if ($commentModel->id > 0 && $id == Yii::app()->user->getId()) {
                     if ($commentModel->active == 0) {
                         $commentModel->active = 1;
                         $action = "publish";
                     } else {
                         $commentModel->active = 0;
                         $action = "nopublish";
                     }
                     SiteHelper::setLog($newCatalog->tableName(), $action, $commentModel->user_id->id, Yii::app()->user->getId());
                     if ($commentModel->save()) {
                         echo 1;
                     } else {
                         print_r($commentModel->getErrors());
                     }
                     return;
                 }
             }
         } else {
             echo 3;
             return;
         }
     }
     echo 0;
     return;
 }