Пример #1
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;
     }
 }
Пример #2
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;
     }
 }