예제 #1
0
 /**
  * 
  * @param boolean $runValidation whether to perform validation before saving the record.
  * If the validation fails, the record will not be saved to database.
  * @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param array $data Data Array
  * @return boolean whether the saving succeeds
  */
 public function save($runValidation = true, $attributeNames = null, $data = [])
 {
     if (!$this->beforeTrancSave()) {
         return false;
     }
     $db = static::getDb();
     $transaction = $db->beginTransaction();
     try {
         $this->loadDefaultValues();
         $result = parent::save($runValidation, $attributeNames);
         if (!$result) {
             $transaction->rollBack();
             return false;
         }
         $length = 0;
         $datakey = ['phone', 'mobile'];
         $map = ['phone' => 'phone', 'mobile' => 'mobile'];
         if (count($data) < 1) {
             $req = Yii::$app->getRequest()->getBodyParams();
             $postdata = isset($req[$this->formName()]) ? $req[$this->formName()] : $req;
             \Yii::trace(print_r($postdata, true), __METHOD__);
             $data = [];
             foreach ($datakey as $key) {
                 if (isset($postdata[$key])) {
                     $data[$key] = $postdata[$key];
                 }
             }
         }
         foreach ($data as $key => $arval) {
             if (is_array($arval) && ($ar_count = count($arval))) {
                 if ($ar_count > $length) {
                     $length = $ar_count;
                 }
             }
         }
         $mapAR = $this->theaterMap;
         //it will provide relational AR Array if there is any record. else it will be none.
         $ar_count = count($mapAR);
         for ($check_start = 0; $check_start < $length; $check_start++) {
             foreach ($map as $key => $mapkey) {
                 //Yii::info("data for".$key.':'.  var_dump($data[$key][$check_start]));
                 $doc[$mapkey] = isset($data[$key][$check_start]) && $data[$key][$check_start] !== null && $data[$key][$check_start] != "" ? $data[$key][$check_start] : 0;
             }
             $isdata = false;
             foreach ($doc as $doc_data) {
                 if ($doc_data) {
                     $isdata = true;
                     break;
                 }
             }
             if (!$isdata) {
                 continue;
             }
             $doc['order'] = $check_start + 1;
             if ($ar_count > 0 && isset($mapAR[$check_start])) {
                 //need to update
                 $armodel = $mapAR[$check_start];
             } else {
                 //create new record
                 $armodel = new TheatreMap();
             }
             //Yii::info("doc after load:".print_r($doc,true));
             $armodel->load($doc, '');
             $armodel->save($runValidation);
             $this->link('theaterMap', $armodel);
         }
         if ($ar_count > $length) {
             for ($length; $length < $ar_count; $length++) {
                 $mapAR[$length]->delete();
             }
         }
         //$assetDataar = ['media' => $this->ClassSortNeme().'_image_'.  $this->Id,];
         //$this->saveAsset($assetDataar, $data,$runValidation);
         //$this->saveTags($data['tag'],$runValidation);
         $this->saveUrl($runValidation);
         $transaction->commit();
         $this->afterTrancSave();
         return true;
     } catch (\yii\base\ErrorException $e) {
         Yii::info($e, __METHOD__);
         $transaction->rollBack();
         return false;
     }
 }
예제 #2
0
 /**
  * 
  * @param boolean $runValidation whether to perform validation before saving the record.
  * If the validation fails, the record will not be saved to database.
  * @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param array $data Data Array
  * @return boolean whether the saving succeeds
  */
 public function save($runValidation = true, $attributeNames = null, $data = [])
 {
     if (!$this->beforeTrancSave()) {
         return false;
     }
     $db = static::getDb();
     $transaction = $db->beginTransaction();
     try {
         $this->loadDefaultValues();
         $result = parent::save($runValidation, $attributeNames);
         if (!$result) {
             $transaction->rollBack();
             return false;
         }
         $length = 0;
         $datakey = ['category', 'phone', 'mobile', 'media', 'video', 'tag', 'venue'];
         $map = [['relation' => 'eventMap', 'classname' => 'common\\models\\EventMap', 'dataarray' => true, 'map' => ['category' => 'categoryId', 'phone' => 'phone', 'mobile' => 'mobile']], ['relation' => 'eventVenueMap', 'classname' => 'common\\models\\EventVenueMap', 'dataarray' => false, 'datakey' => 'venue', 'map' => ['venueId' => 'mapId', 'venuetype' => 'mapType']]];
         if (count($data) < 1) {
             $req = Yii::$app->getRequest()->getBodyParams();
             $postdata = isset($req[$this->formName()]) ? $req[$this->formName()] : $req;
             $data = [];
             foreach ($datakey as $key) {
                 if (isset($postdata[$key])) {
                     $data[$key] = $postdata[$key];
                 }
             }
         }
         /**
          *  ReIndexing Venue Map data so that it can be in required array format
          * chnaged by Atul on 26-09-2014
          */
         if (!empty($data['venue'])) {
             foreach ($data['venue'] as $venueKey => $venueValues) {
                 $data['mapData'][] = $venueValues;
             }
             $data['venue'] = array();
             $data['venue'] = $data['mapData'];
         }
         Yii::info($data, __METHOD__);
         foreach ($map as $config) {
             if (isset($config['datakey'])) {
                 $length = count($data[$config['datakey']]);
             } else {
                 foreach ($data as $key => $arval) {
                     if (is_array($arval) && ($ar_count = count($arval))) {
                         if ($ar_count > $length) {
                             $length = $ar_count;
                         }
                     }
                 }
             }
             $relvar = $config['relation'];
             $mapAR = $this->{$relvar};
             $ar_count = count($mapAR);
             //checking length
             for ($check_start = 0; $check_start < $length; $check_start++) {
                 $doc = array();
                 foreach ($config['map'] as $key => $mapkey) {
                     if ($config['dataarray']) {
                         Yii::info("data for" . $key . ' with ' . $config['relation'] . ':' . $data[$key][$check_start]);
                         Yii::info("data for" . $key . ' with ' . $config['relation'] . ':' . print_r($data[$key], true));
                         $doc[$mapkey] = isset($data[$key][$check_start]) && $data[$key][$check_start] !== null && $data[$key][$check_start] != "" ? $data[$key][$check_start] : 0;
                     } else {
                         Yii::info("data for" . $key . ' with ' . $config['relation'] . ':' . $data[$config['datakey']][$check_start][$key]);
                         Yii::info("data for" . $key . ' with ' . $config['relation'] . ':' . print_r($data, true));
                         $doc[$mapkey] = isset($data[$config['datakey']][$check_start][$key]) && $data[$config['datakey']][$check_start][$key] !== null && $data[$config['datakey']][$check_start][$key] != "" ? $data[$config['datakey']][$check_start][$key] : 0;
                     }
                 }
                 $isdoc = false;
                 foreach ($config['map'] as $key => $mapkey) {
                     if ($doc[$mapkey] != 0) {
                         $isdoc = true;
                         break;
                     }
                 }
                 //Yii::info("doc for ".$config['relation'].':'.  var_dump($doc));
                 if (!$isdoc) {
                     continue;
                 }
                 $doc['order'] = $check_start + 1;
                 if ($ar_count > 0 && isset($mapAR[$check_start])) {
                     //need to update
                     $armodel = $mapAR[$check_start];
                 } else {
                     //create new record
                     $armodel = new $config['classname']();
                 }
                 Yii::info("doc after load:" . print_r($doc, true));
                 $armodel->load($doc, '');
                 //$armodel->save();
                 $this->link($config['relation'], $armodel);
             }
             if ($ar_count > $length) {
                 for ($length; $length < $ar_count; $length++) {
                     $mapAR[$length]->delete();
                 }
             }
         }
         $assetDataar = ['media' => $this->ClassSortNeme() . '_image_' . $this->Id, 'video' => $this->ClassSortNeme() . '_video_' . $this->Id];
         $this->saveAsset($assetDataar, $data);
         //$this->saveUrl();
         $this->saveTags($data['tag']);
         $this->saveUrl($runValidation);
         $transaction->commit();
         $this->afterTrancSave();
         return true;
     } catch (\yii\base\ErrorException $e) {
         Yii::info(print_r($e, true), __METHOD__);
         $transaction->rollBack();
         return false;
     }
 }
예제 #3
0
 /**
  * 
  * @param boolean $runValidation whether to perform validation before saving the record.
  * If the validation fails, the record will not be saved to database.
  * @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param array $data Data Array
  * @return boolean whether the saving succeeds
  */
 public function save($runValidation = true, $attributeNames = null, $data = [], $chainupdate = true)
 {
     if (!$this->beforeTrancSave()) {
         return false;
     }
     $db = static::getDb();
     $transaction = $db->beginTransaction();
     try {
         $this->loadDefaultValues();
         $result = parent::save($runValidation, $attributeNames);
         if (!$result) {
             $transaction->rollBack();
             return false;
         }
         $datakey = ['media', 'menu'];
         if (count($data) < 1) {
             $req = Yii::$app->getRequest()->getBodyParams();
             $postdata = isset($req[$this->formName()]) ? $req[$this->formName()] : $req;
             $data = [];
             foreach ($datakey as $key) {
                 if (isset($postdata[$key])) {
                     $data[$key] = $postdata[$key];
                 }
             }
         }
         $assetDataar = ['media' => $this->ClassSortNeme() . '_image_' . $this->Id, 'menu' => $this->ClassSortNeme() . '_menu_' . $this->Id];
         $this->saveAsset($assetDataar, $data, $runValidation);
         \yii::trace('save media', 'save');
         \yii::trace('update restaurant', 'save');
         $transaction->commit();
         if ($chainupdate) {
             $this->addPageMeta();
         }
         $this->afterTrancSave();
         if ($chainupdate && is_array($this->restaurants)) {
             \yii::trace('update restaurant Save and publish', 'save');
             $this->UpdateRestaurants($this->restaurants);
             /*foreach($this->restaurants as $model){
                   $model->published();
               }
                * 
                */
         }
         return true;
     } catch (\Exception $e) {
         \yii::trace($e->getMessage(), 'saveerror');
         \yii::trace($e->getTraceAsString(), 'saveerror');
         $transaction->rollBack();
         return false;
     }
 }
예제 #4
0
 /**
  * 
  * @param boolean $runValidation whether to perform validation before saving the record.
  * If the validation fails, the record will not be saved to database.
  * @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param array $data Data Array
  * @return boolean whether the saving succeeds
  */
 public function save($runValidation = true, $attributeNames = null, $data = [])
 {
     if (!$this->beforeTrancSave()) {
         return false;
     }
     $db = static::getDb();
     $transaction = $db->beginTransaction();
     try {
         $this->loadDefaultValues();
         $result = parent::save($runValidation, $attributeNames);
         if (!$result) {
             $transaction->rollBack();
             return false;
         }
         $length = 0;
         $datakey = ['types', 'feature', 'cuisines', 'payment', 'category', 'crowd', 'feature', 'music', 'usp', 'phone', 'mobile', 'media', 'menu', 'video', 'tag', 'logo'];
         $map = ['types' => 'typesId', 'feature' => 'featureId', 'cuisines' => 'cuisineId', 'payment' => 'paymentId', 'category' => 'categoryId', 'crowd' => 'crowdId', 'feature' => 'featureId', 'music' => 'musicId', 'usp' => 'uspId', 'phone' => 'phone', 'mobile' => 'mobile'];
         if (count($data) < 1) {
             $req = Yii::$app->getRequest()->getBodyParams();
             $postdata = isset($req[$this->formName()]) ? $req[$this->formName()] : $req;
             $data = [];
             foreach ($datakey as $key) {
                 if (isset($postdata[$key])) {
                     $data[$key] = $postdata[$key];
                 }
             }
         }
         foreach ($data as $key => $arval) {
             if (is_array($arval) && ($ar_count = count($arval))) {
                 if ($ar_count > $length) {
                     $length = $ar_count;
                 }
             }
         }
         $mapAR = $this->resMaps;
         //it will provide relational AR Array if there is any record. else it will be none.
         $ar_count = count($mapAR);
         for ($check_start = 0; $check_start < $length; $check_start++) {
             foreach ($map as $key => $mapkey) {
                 //Yii::info("data for".$key.':'.  var_dump($data[$key][$check_start]));
                 $doc[$mapkey] = isset($data[$key][$check_start]) && $data[$key][$check_start] !== null && $data[$key][$check_start] != "" ? $data[$key][$check_start] : 0;
             }
             $doc['order'] = $check_start + 1;
             if ($ar_count > 0 && isset($mapAR[$check_start])) {
                 //need to update
                 $armodel = $mapAR[$check_start];
             } else {
                 //create new record
                 $armodel = new ResMap();
             }
             //Yii::info("doc after load:".print_r($doc,true));
             $armodel->load($doc, '');
             $armodel->save($runValidation);
             $this->link('resMaps', $armodel);
         }
         if ($ar_count > $length) {
             for ($length; $length < $ar_count; $length++) {
                 $mapAR[$length]->delete();
             }
         }
         $assetDataar = ['media' => $this->ClassSortNeme() . '_image_' . $this->Id, 'menu' => $this->ClassSortNeme() . '_menu_' . $this->Id, 'video' => $this->ClassSortNeme() . '_video_' . $this->Id, 'logo' => $this->ClassSortNeme() . '_logo_' . $this->Id];
         $this->saveAsset($assetDataar, $data, $runValidation);
         $this->saveTags($data['tag']);
         $transaction->commit();
         $this->afterTrancSave();
         return true;
     } catch (\Exception $e) {
         Yii::info(print_r($e, true), __METHOD__);
         //\yii::trace($e->getMessage());
         $transaction->rollBack();
         return false;
     }
 }
예제 #5
0
 /**
  * 
  * @param boolean $runValidation whether to perform validation before saving the record.
  * If the validation fails, the record will not be saved to database.
  * @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param array $data Data Array
  * @return boolean whether the saving succeeds
  */
 public function save($runValidation = true, $attributeNames = null, $data = [])
 {
     if (!$this->beforeTrancSave()) {
         return false;
     }
     $db = static::getDb();
     $transaction = $db->beginTransaction();
     try {
         $this->loadDefaultValues();
         $result = parent::save($runValidation, $attributeNames);
         if (!$result) {
             $transaction->rollBack();
             return false;
         }
         $datakey = ['media', 'menu', 'logo'];
         if (count($data) < 1) {
             $req = Yii::$app->getRequest()->getBodyParams();
             $postdata = isset($req[$this->formName()]) ? $req[$this->formName()] : $req;
             $data = [];
             foreach ($datakey as $key) {
                 if (isset($postdata[$key])) {
                     $data[$key] = $postdata[$key];
                 }
             }
         }
         $assetDataar = ['media' => $this->ClassSortNeme() . '_image_' . $this->Id, 'menu' => $this->ClassSortNeme() . '_menu_' . $this->Id, 'logo' => $this->ClassSortNeme() . '_logo_' . $this->Id];
         $this->saveAsset($assetDataar, $data, $runValidation);
         $transaction->commit();
         $this->afterTrancSave();
         return true;
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
 }