/**
  * 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($id)
 {
     $model = Horoscope::model()->with(array('post' => array('with' => array('portfolio' => array('with' => 'photos')))))->findByPk($id);
     $portfolio = $model->post->portfolio;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Horoscope'])) {
         $model->attributes = $_POST['Horoscope'];
         if (empty($_POST['Horoscope']['publication_date'])) {
             $model->publication_date = Yii::app()->dateFormatter->format('yyyy-MM-dd hh:mm:ss', time());
         }
         Yii::import('application.modules.portfolio.widgets.PhotoPortfolio.PhotoPortfolioWidget');
         $portfolioWidget = new PhotoPortfolioWidget();
         $galleries = $portfolioWidget->validatePortfolio($_POST);
         if ($model->saveHoroscope($galleries)) {
             $strMessage = Yii::t('main', 'Horoscope was saved successfully');
             Yii::app()->user->setFlash('success', $strMessage);
             //show flash message
             Yii::app()->request->redirect(Yii::app()->createAbsoluteUrl('/horoscope/default/index'));
             Yii::app()->end();
         } else {
             $portfolio = $galleries[0];
             //returns portfolio with errors to form
         }
     }
     if (empty($portfolio)) {
         $portfolio = new Portfolio();
     }
     $this->render('update', array('model' => $model, 'portfolio' => $portfolio));
 }
 /**
  * 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($id)
 {
     $model = Partners::model()->with(array('portfolio' => array('with' => 'photos')))->findByPk($id);
     $portfolio = $model->portfolio;
     $portfolio->gallery_type = 1;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Partners'])) {
         $model->attributes = $_POST['Partners'];
         Yii::import('application.modules.portfolio.widgets.PhotoPortfolio.PhotoPortfolioWidget');
         $portfolioWidget = new PhotoPortfolioWidget();
         $galleries = $portfolioWidget->validatePortfolio($_POST);
         if ($model->savePartners($galleries)) {
             $strMessage = Yii::t('main', 'Partners was saved successfully');
             Yii::app()->user->setFlash('success', $strMessage);
             //show flash message
             Yii::app()->request->redirect(Yii::app()->createAbsoluteUrl('/partners/default/index'));
         } else {
             $portfolio = $galleries[0];
             //returns portfolio with errors to form
         }
     }
     if (empty($portfolio)) {
         $portfolio = new Portfolio();
     }
     $this->render('form', array('model' => $model, 'portfolio' => $portfolio));
 }
 public function actionUploadMagazine()
 {
     if (Yii::app()->request->isAjaxRequest) {
         Yii::import('application.modules.portfolio.widgets.PhotoPortfolio.PhotoPortfolioWidget');
         $portfolioWidget = new PhotoPortfolioWidget();
         $portfolioWidget->checkBoxClass = 'hide';
         $portfolioWidget->radiobuttonClass = 'hide';
         $portfolioWidget->uploadPhoto();
     }
 }
示例#4
0
 public function saveBanners(&$galleries)
 {
     $isErrorsBanners = false;
     $isErrorsPortfolio = false;
     $isGalSaved = false;
     $isBanSaved = false;
     $isErrorsBanners = !$this->validate();
     $isErrorsPortfolio = PhotoPortfolioWidget::checkForErrors($galleries);
     if (!$isErrorsPortfolio && !$isErrorsBanners) {
         $transaction = Yii::app()->db->beginTransaction();
         //saving portfolio
         if (is_array($galleries)) {
             foreach ($galleries as $portfolio) {
                 $isGalSaved = $portfolio->savePortfolio();
                 break;
             }
             $this->gallery_id = $portfolio->gallery_id;
             $isBanSaved = $this->save(false);
         }
         if ($isGalSaved && $isBanSaved) {
             $transaction->commit();
             return true;
         } else {
             $transaction->rollback();
             return false;
         }
     } else {
         return false;
     }
 }
示例#5
0
 public function savePartners(&$galleries)
 {
     $isErrorsPartners = false;
     $isErrorsPortfolio = false;
     $isGalSaved = false;
     $isParSaved = false;
     $isErrorsPartners = !$this->validate();
     $isErrorsPortfolio = PhotoPortfolioWidget::checkForErrors($galleries);
     if (!$isErrorsPortfolio && !$isErrorsPartners) {
         $transaction = Yii::app()->db->beginTransaction();
         //saving portfolio
         if (is_array($galleries)) {
             foreach ($galleries as &$portfolio) {
                 if (count($portfolio->photos) != 2) {
                     $portfolio->addError('count_photos', Yii::t('main', 'Minimum number of photos is 2'));
                     $transaction->rollback();
                     return false;
                 }
                 $isGalSaved = $portfolio->savePortfolio();
                 break;
             }
             $this->gallery_id = $portfolio->gallery_id;
             $isParSaved = $this->save(false);
         }
         if ($isGalSaved && $isParSaved) {
             $transaction->commit();
             return true;
         } else {
             $transaction->rollback();
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * action for update
  * 
  * @param mixed $id
  */
 public function actionUpdate($id = null)
 {
     Yii::import('application.modules.portfolio.widgets.PhotoPortfolio.PhotoPortfolioWidget');
     $news = $this->loadModel($this->_modelclass, $id);
     $post = isset($news->post) ? $news->post : new Posting();
     if ($post->scenario == 'insert') {
         $this->setPostType($post);
         if (empty($news->publication_date)) {
             $news->publication_date = CTimestamp::formatDate('Y-m-d H:i:s');
         }
     }
     $portfolio = isset($news->post->portfolio) ? $news->post->portfolio : new Portfolio();
     $portfolio->gallery_type = 1;
     if (!empty($_POST[$this->_modelclass])) {
         $post->attributes = $_POST['Posting'];
         //set attributes
         $news->attributes = $_POST[$this->_modelclass];
         $posttitle = $post->title;
         //save name of posting to buffer
         $portfolioWidget = new PhotoPortfolioWidget();
         $galleries = $portfolioWidget->validatePortfolio($_POST);
         if (!empty($galleries)) {
             $portfolio = $galleries[0];
         }
         $post->validate();
         $news->validate();
         $success = !$post->hasErrors() && !$news->hasErrors() && is_object($portfolio) && !$portfolio->hasErrors();
         if ($success && isset($post->tags)) {
             //search for deleted tags
             foreach ($post->tags as $tag) {
                 if (!in_array($tag->tag_id, $post->postedTags)) {
                     $post->deletedTags[] = $tag;
                 }
             }
         }
         $strMessage = ($post->isNewRecord ? Yii::t('main', 'New article was created successfully') : Yii::t('main', 'Article was saved successfully')) . ' (' . Yii::t('main', 'Title') . ': ' . $posttitle . ')';
         if ($success) {
             $transaction = Yii::app()->db->beginTransaction();
             if ($success = $portfolio->savePortfolio()) {
                 $post->gallery_id = $portfolio->gallery_id;
                 if ($success = $post->save()) {
                     $news->post_id = $post->post_id;
                     if ($success = $news->save()) {
                         //if exists deleted tags - process its
                         foreach ($post->deletedTags as $tag) {
                             $countDeleted = Tagpost::model()->deleteAll('tag_id = :tag_id AND post_id = :post_id', array(':tag_id' => $tag->tag_id, ':post_id' => $post->post_id));
                             if (!($success = $countDeleted > 0)) {
                                 break;
                             }
                         }
                         foreach ($post->postedTags as $tag) {
                             $exists = Tagpost::model()->exists('tag_id = :tag_id AND post_id = :post_id', array(':tag_id' => $tag, ':post_id' => $post->post_id));
                             if (!$exists) {
                                 $tagpost = new Tagpost();
                                 $tagpost->tag_id = $tag;
                                 $tagpost->post_id = $post->post_id;
                                 $tagpost->save();
                             }
                         }
                     }
                 }
             }
             if ($success) {
                 $transaction->commit();
                 $resultMode = $success ? 'success' : 'error';
                 Yii::app()->user->setFlash($resultMode, $strMessage);
                 //show flash message
                 $this->redirect($this->createUrl('index'));
             } else {
                 $transaction->rollback();
             }
         }
     }
     $this->render('application.modules.news.views.default.form', array('news' => $news, 'post' => $post, 'portfolio' => $portfolio));
 }