Example #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getResMaps()
 {
     return $this->hasMany(ResMap::className(), ['serviceId' => 'Id']);
 }
Example #2
0
 public function alocateChain($chain, $validation = true)
 {
     $this->chainId = $chain->Id;
     //$chain->refresh();
     if ($chain->chainFieldStatusMaps->name == 1) {
         \yii::trace('chain Name is Locked', __METHOD__);
         $this->name = $chain->name;
     } else {
         if ($this->name === null || $this->name == '') {
             \yii::trace('chain Name not Locked. but in db it is:' . $this->name . "with type" . var_export($this->name, true), __METHOD__);
             $this->name = $chain->name;
         }
     }
     if ($chain->chainFieldStatusMaps->website == 1) {
         \yii::trace('chain Website is Locked', __METHOD__);
         $this->website = $chain->website;
     } else {
         if ($this->website === null || $this->website == '') {
             \yii::trace('chain Website not Locked. but in db it is:' . $this->website . "with type" . var_export($this->website, true), __METHOD__);
             $this->website = $chain->website;
         }
     }
     if ($chain->chainFieldStatusMaps->pricefortwo == 1) {
         \yii::trace('chain Price for 2 is Locked', __METHOD__);
         $this->priceForTwo = $chain->pricefortwo;
     } else {
         if ($this->priceForTwo === null || $this->priceForTwo == '' || $this->priceForTwo == 0) {
             \yii::trace('chain Price for 2 not Locked. but in db it is:' . $this->priceForTwo . "with type" . var_export($this->priceForTwo, true), __METHOD__);
             $this->priceForTwo = $chain->pricefortwo;
         }
     }
     if ($chain->chainFieldStatusMaps->specilities == 1) {
         \yii::trace('chain Specilities is Locked', __METHOD__);
         $this->famousFor = $chain->specilities;
     } else {
         if ($this->famousFor === null || $this->famousFor == '') {
             \yii::trace('chain Price for 2 not Locked. but in db it is:' . $this->famousFor . "with type" . var_export($this->famousFor, true), __METHOD__);
             $this->famousFor = $chain->specilities;
         }
     }
     if ($chain->chainFieldStatusMaps->whichType == 1) {
         \yii::trace('chain whichtype is Locked', __METHOD__);
         $this->entityType = $chain->whichType;
     } else {
         if ($this->entityType === null || $this->entityType == '' || $this->entityType == 0) {
             \yii::trace('chain which type not Locked. but in db it is:' . $this->entityType . "with type" . var_export($this->entityType, true), __METHOD__);
             $this->entityType = $chain->whichType;
         }
     }
     if ($chain->chainFieldStatusMaps->facebookUrl == 1) {
         \yii::trace('chain facebook is Locked', __METHOD__);
         $this->facebook = $chain->facebookUrl;
     } else {
         if ($this->facebook === null || $this->facebook == '') {
             \yii::trace('chain facebook not Locked. but in db it is:' . $this->facebook . "with type" . var_export($this->facebook, true), __METHOD__);
             $this->facebook = $chain->facebookUrl;
         }
     }
     $this->update($validation);
     $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'];
     $length = 0;
     $data = [];
     if ($chain->chainFieldStatusMaps->cusinies == 1) {
         \yii::trace('chain cuisine is Locked', __METHOD__);
         $data['cuisines'] = explode(',', $chain->cusinies);
     }
     if ($chain->chainFieldStatusMaps->type == 1) {
         \yii::trace('chain type is Locked', __METHOD__);
         $data['types'] = explode(',', $chain->type);
     }
     foreach ($data as $key => $arval) {
         if (is_array($arval) && ($ar_count = count($arval))) {
             if ($ar_count > $length) {
                 $length = $ar_count;
             }
         }
     }
     if ($length) {
         $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]));
                 if (isset($data[$key][$check_start]) && $data[$key][$check_start] !== null && $data[$key][$check_start] != "") {
                     $doc[$mapkey] = $data[$key][$check_start];
                 }
             }
             if ($ar_count > 0 && isset($mapAR[$check_start])) {
                 //need to update
                 $armodel = $mapAR[$check_start];
             } else {
                 //create new record
                 $armodel = new ResMap();
                 $armodel->loadDefaultValues();
             }
             //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++) {
                 $candelete = true;
                 foreach ($map as $key => $mapkey) {
                     if (in_array($mapkey, ['typesId', 'cuisineId'])) {
                         continue;
                     }
                     if ($mapAR[$length]->{$mapkey} != 0) {
                         $candelete = false;
                     }
                 }
                 if ($candelete) {
                     Yii::info("doc resterror load  :" . $candelete);
                     \yii::trace(print_r($mapAR[$length], true), __METHOD__);
                     $mapAR[$length]->delete();
                 } else {
                     $mapAR[$length]->typesId = 0;
                     $mapAR[$length]->cuisineId = 0;
                     $mapAR[$length]->update();
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getResMaps()
 {
     return $this->hasMany(ResMap::className(), ['categoryId' => 'Id']);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getResMaps()
 {
     return $this->hasMany(ResMap::className(), ['specialityId' => 'Id']);
 }