Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new GroupProduct();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['GroupProduct'])) {
         $model->attributes = $_POST['GroupProduct'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #2
0
 public function actionCreateGroupProduct($mode = GroupProduct::BOOK, $preselected_event_id = 0)
 {
     $user = User::model()->findByPk(Yii::app()->user->id);
     $OwnedGroups = $user->OwnedGroup;
     if (count($OwnedGroups) == 0) {
         $this->render('noOwnedGroup');
         return;
     }
     /* validate all query string param */
     $model = new GroupProduct('create');
     $model->categorize($mode);
     //this will throw new CHttpException(404,'test');
     /*define the required variable for the controller base on the query string param */
     $fileModel = new FileUploadFormModel();
     $view;
     $subValidationScen;
     if ($model->product_catagory_enum == GroupProduct::BOOK) {
         $view = 'createBook';
         $subValidationScen = GroupProduct::BOOK_CAT_TITLE;
     } else {
         if ($model->product_catagory_enum == GroupProduct::GIFT) {
             $view = 'createGift';
             $subValidationScen = GroupProduct::GIFT_CAT_TITLE;
         } else {
             $view = 'createElect';
             $subValidationScen = GroupProduct::ELECT_CAT_TITLE;
         }
     }
     if (isset($_POST['GroupProduct'])) {
         $model->setAttributes($_POST['GroupProduct']);
         //$fileHandler->LoadUploadedeImageToModel();
         //$model->photos = $fileHandler->photos;
         //$model->photos = CUploadedFile::getInstancesByName(BSMultiFileUploadWidget::fieldName);
         if ($model->validate()) {
             $model->setScenario($subValidationScen);
             $model->setAttributes($_POST['GroupProduct']);
             if ($model->validate()) {
                 $fileModel->LoadUploadedeImage();
                 $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_MULTI);
                 if ($fileModel->validate()) {
                     if ($model->save()) {
                         $model->addJoinEvents($model->event_arr_id);
                         //$SavedFileRelativePaths = $fileModel->processImage(get_class($model),$model->group->id,$model->id);
                         $ips = new ImageProcessService($fileModel, get_class($model), $model->group->id, $model->id);
                         $ips->saveImage(150, 150);
                         $SavedFileRelativePaths = $ips->getOriginalImageVirtualPath();
                         $SavedThumbnailFileRelativePaths = $ips->getThumbnailImageVirtualPath();
                         $model->save_img_src($SavedFileRelativePaths, $SavedThumbnailFileRelativePaths);
                         Yii::app()->user->setFlash(FlashMsg::SUCCESS, "投稿販賣情報成功");
                         $this->redirect(SeoHelper::groupProductViewSEORouteArray($model));
                     } else {
                         Yii::app()->user->setFlash(FlashMsg::ERROR, "投稿販賣情報失敗");
                     }
                 }
             }
         }
     }
     $this->render($view, array('model' => $model, 'fileModel' => $fileModel, 'preselected_event_id' => $preselected_event_id));
 }