/** * Finds the BrandsCityMap model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return BrandsCityMap the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BrandsCityMap::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionCitychain() { \yii::$app->user->setIdentity(\common\models\User::findByUsername('admin')); $usersData = \yii::$app->oldcmsdb->createCommand("SELECT * \n FROM \n tc_group_city_mapping")->query(); while ($row = $usersData->read()) { $attributes = array('Id' => $row['id'], 'chainId' => $row['chain_id'], 'cityId' => $row['city_id'], 'name' => htmlspecialchars_decode($row['establishment_name'], ENT_QUOTES), 'website' => $row['establishment_website'], 'pricefortwo' => $row['price_for_two'], 'cusinies' => $row['cusinies'], 'specilities' => $row['specilities'], 'whichType' => $row['est_which_type'], 'crowd' => $row['crowd'], 'type' => $row['establishment_type'], 'facebookUrl' => $row['facebook_url'], 'serves' => $row['serves'], 'guid' => $row['guid'], 'createdBy' => 40, 'updatedBy' => 40, 'createdOn' => $row['insert_date'], 'updatedOn' => $row['modified_date'], 'status' => $row['status']); if (($brand = BrandsCityMap::findOne($attributes['Id'])) !== null) { } else { $brand = new BrandsCityMap(); } $chainImage = \yii::$app->oldcmsdb->createCommand("select * from tc_est_media where est_flag = 'chainCityMapp' and est_id='" . $row['id'] . "' and status=1 order by est_priority")->query(); $images = []; while ($img = $chainImage->read()) { $images[] = ['media_id' => $img['est_media_id'], 'media_name' => $img['est_media_name'], 'media_caption' => $img['est_media_caption'], 'flag' => $img['est_flag'], 'created_by' => $img['created_by'], 'insertdate' => $img['insertdate'], 'IP' => $img['IP'], 'priority' => $img['est_priority']]; } $attributes['media'] = Import::importMediaData($images, $brand->imagePath); $chainmenu = \yii::$app->oldcmsdb->createCommand("select * from tc_est_media where est_flag = 'chainmenu' and est_id='" . $row['id'] . "' and status=1 order by est_priority")->query(); $images = []; while ($img = $chainmenu->read()) { $images[] = ['media_id' => $img['est_media_id'], 'media_name' => $img['est_media_name'], 'media_caption' => $img['est_media_caption'], 'flag' => $img['est_flag'], 'created_by' => $img['created_by'], 'insertdate' => $img['insertdate'], 'IP' => $img['IP'], 'priority' => $img['est_priority']]; } $attributes['menu'] = Import::importMediaData($images, $brand->menuimagePath); $brand->detachBehavior('timestamp'); $brand->detachBehavior('user'); $brand->setAttributes($attributes); $brand->Id = $attributes['Id']; if ($brand->save(false, null, $attributes, false)) { echo "Map Id:" . $attributes['Id'] . ": imported\n"; } else { echo "Map Id:" . $attributes['Id'] . ": not imported\n"; } } }
/** * Validate Chain City Map * @return mixed */ public function actionValidate($id = 0) { if ($id) { if (($model = BrandsCityMap::findOne($id)) !== null) { } else { throw new NotFoundHttpException('The requested page does not exist.'); } } else { $model = new BrandsCityMap(); } if ($model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } }