public function actionChain() { \yii::$app->user->setIdentity(\common\models\User::findByUsername('admin')); $usersData = \yii::$app->oldcmsdb->createCommand("SELECT * FROM tc_est_groups")->query(); while ($row = $usersData->read()) { $attributes = array('Id' => $row['est_grp_id'], 'name' => htmlspecialchars_decode($row['est_grp_name'], ENT_QUOTES), 'description' => htmlspecialchars_decode($row['est_grp_desc'], ENT_QUOTES), 'guid' => $row['est_grp_url'], 'status' => $row['status'], 'ip' => $row['IP'], 'createdOn' => $row['insertdate'], 'updatedOn' => $row['insertdate'], 'createdBy' => 40, 'updatedBy' => 40); if (($brand = Brands::findOne($attributes['Id'])) !== null) { } else { $brand = new Brands(); } $attributes['logo'] = $this->importimagefromstr($row['logo'], $brand->logoPath, 'chainLogo'); $chainImage = \yii::$app->oldcmsdb->createCommand("select * from tc_est_media where est_flag = 'chainMainImage' and est_id='" . $row['est_grp_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 = 'chainMainMenu' and est_id='" . $row['est_grp_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)) { echo "Chain Id:" . $attributes['Id'] . " name:" . $attributes['name'] . ": imported\n"; } else { echo "Chain Id:" . $attributes['Id'] . " name:" . $attributes['name'] . ": not imported\n"; } } }
/** * Finds the Brands model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Brands the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Brands::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Brands::find()->where('status=0'); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['Id' => $this->Id, 'createdBy' => $this->createdBy, 'updatedBy' => $this->updatedBy, 'createdOn' => $this->createdOn, 'updatedOn' => $this->updatedOn, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'guid', $this->guid])->andFilterWhere(['like', 'logo', $this->logo])->andFilterWhere(['like', 'ip', $this->ip]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Brands::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['BrandId' => $this->BrandId, 'IsLogoVisible' => $this->IsLogoVisible, 'created_by' => $this->created_by, 'LastUpdatedBy' => $this->LastUpdatedBy, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at]); $query->andFilterWhere(['like', 'Name', $this->Name])->andFilterWhere(['like', 'Description', $this->Description])->andFilterWhere(['like', 'Website', $this->Website])->andFilterWhere(['like', 'LogoUrl', $this->LogoUrl])->andFilterWhere(['like', 'Comment', $this->Comment]); return $dataProvider; }
//use yii\adminUi\assetsBundle\AdminUIMultiselect; use yii\adminUi\widget\Multiselect; use common\modules\media\widgets\MediaUpload; //AdminUIMultiselect::register($this); /* @var $this yii\web\View */ /* @var $model common\models\BrandsCityMap */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="brands-city-map-form"> <?php $form = ActiveForm::begin(['validationUrl' => ['validate']]); ?> <?php echo $form->field($model, 'chainId', ['enableAjaxValidation' => true])->dropDownList(ArrayHelper::merge(['' => 'Select'], ArrayHelper::map(\common\models\Brands::find()->andWhere(['status' => 1])->orderBy('name')->All(), 'Id', 'name'))); ?> <?php echo $form->field($model, 'cityId', ['enableAjaxValidation' => true])->dropDownList(ArrayHelper::merge(['' => 'Select'], ArrayHelper::map(\common\models\City::find()->andWhere(['status' => 1])->All(), 'Id', 'name'))); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => 225]); ?> <?php echo $form->field($modelBrandsCityField, 'name')->checkbox(['label' => 'Lock']);
<?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; use common\models\Suppliers; use common\models\Brands; use common\models\Producttypes; use common\models\Productcategories; /* @var $this yii\web\View */ /* @var $model common\models\Products */ /* @var $form yii\bootstrap\ActiveForm */ $dataProductCategory = ArrayHelper::map(Productcategories::find()->asArray()->all(), 'ProductCategoryId', 'Name'); $dataSuppliers = ArrayHelper::map(Suppliers::find()->asArray()->all(), 'SupplierId', 'Name'); $dataBrands = ArrayHelper::map(Brands::find()->asArray()->all(), 'BrandId', 'Name'); $dataProducttypes = ArrayHelper::map(Producttypes::find()->asArray()->all(), 'ProducttypeId', 'Name'); ?> <div class="products-form"> <?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?> <?php echo $form->field($model, 'Name', ['horizontalCssClasses' => ['wrapper' => 'col-sm-4']])->textInput(['maxlength' => 500]); ?> <?php echo $form->field($model, 'ProductCategoryId', ['horizontalCssClasses' => ['wrapper' => 'col-sm-3']])->dropDownList($dataProductCategory, ['prompt' => '----------Choose a Category----------']); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getBrand() { return $this->hasOne(Brands::className(), ['BrandId' => 'BrandId']); }
/** * @return \yii\db\ActiveQuery */ public function getChain() { return $this->hasOne(Brands::className(), ['Id' => 'chainId'])->via('chainCity'); }
/** * @return \yii\db\ActiveQuery */ public function getChain() { // die('in chian'); return $this->hasOne(Brands::className(), ['Id' => 'chainId']); }