public function bootstrap($app) { Event::on(ActiveRecord::classname(), AppActiveRecord::EVENT_AFTER_TRANCINSERT, function ($event) { TcEventAction::EventActionAfterTrancInsert($event); }); Event::on(ActiveRecord::classname(), AppActiveRecord::EVENT_AFTER_TRANCUPDATE, function ($event) { TcEventAction::EventActionAfterTrancUpdate($event); }); Event::on(ActiveRecord::classname(), BaseActiveRecord::EVENT_AFTER_INSERT, function ($event) { TcEventAction::EventActionCreate($event); }); Event::on(ActiveRecord::classname(), BaseActiveRecord::EVENT_AFTER_UPDATE, function ($event) { TcEventAction::EventActionUpdate($event); }); Event::on(ActiveRecord::classname(), AppActiveRecord::EVENT_BEFORE_PUBLISH, function ($event) { TcEventAction::EventActionBeforePublish($event); }); Event::on(ActiveRecord::classname(), AppActiveRecord::EVENT_AFTER_PUBLISH, function ($event) { TcEventAction::EventActionAfterPublish($event); }); Event::on(AppActiveRecord::classname(), AppActiveRecord::EVENT_AFTER_SOFTDELETE, function ($event) { TcEventAction::EventActionSoftDelete($event); }); Event::on(AppActiveRecord::classname(), AppActiveRecord::EVENT_AFTER_UNPUBLISH, function ($event) { TcEventAction::EventActionUnpublish($event); }); }
/** * * @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; } }
/** * * @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; } }
/** * * @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; } }
public function addPageMeta() { $content = array('page_url', 'title', 'meta', 'content', 'related', 'leading', 'footer'); $chain_name = $this->name; $chain_name_clean = \common\component\AppActiveRecord::urlFilter($chain_name); $city_name = $this->cityname; $city_name_clean = \common\component\AppActiveRecord::seftxt(trim($city_name)); $cuisine_name = $this->primarycuisine; $cuisine_name_clean = \common\component\AppActiveRecord::seftxt(trim($cuisine_name)); $leading = $related = array(); array_push($leading, $chain_name . " " . $city_name); array_push($leading, $chain_name . " menu"); array_push($leading, $chain_name . " order online"); array_push($leading, $chain_name . " price list"); array_push($related, array(\yii::$app->params['weburl'] . $city_name_clean . "/restaurant/" . $cuisine_name_clean => $cuisine_name . " restaurants")); array_push($related, array(\yii::$app->params['weburl'] . $city_name_clean . "/restaurants" => "Restaurants in " . $city_name)); array_push($related, array(\yii::$app->params['weburl'] . $city_name_clean . "/restaurant/newly-open/" => "Newly opened")); $page_url = $this->guid; $content_array = array('page_url' => $page_url, 'leading' => $leading, 'related' => $related); $content = json_encode($content_array); $sql = "SELECT id FROM tc_pages WHERE page_url = '{$page_url}' AND type = '1' AND status = '1'"; $pagaData = \yii::$app->oldcmsdb->createCommand($sql)->query(); $record_found = $pagaData->getRowCount(); if ($record_found > 0) { $page_id = $pagaData->read(); \yii::$app->oldcmsdb->createCommand()->update('tc_pages', ['content' => $content], ['id' => $page_id['id']])->execute(); } else { \yii::$app->oldcmsdb->createCommand()->insert('tc_pages', ['page_url' => $page_url, 'filters' => '', 'content' => $content, 'type' => 1, 'status' => 1, 'created_time' => new Expression('NOW()')])->execute(); } }
/** * * @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; } }