Commit cd976a8ddeda0ac7a96f62ca1777e1579ed28b16
0 parents
add event to composer
Showing
14 changed files
with
986 additions
and
0 deletions
Show diff stats
| 1 | +++ a/composer.json | |
| 1 | +{ | |
| 2 | + "name": "artweb/artbox-event", | |
| 3 | + "description": "Yii2 light-weight CMS", | |
| 4 | + "license": "BSD-3-Clause", | |
| 5 | + "minimum-stability": "dev", | |
| 6 | + "type": "yii2-extension", | |
| 7 | + "require": { | |
| 8 | + "php": ">=5.4", | |
| 9 | + "yiisoft/yii2": "*", | |
| 10 | + "developeruz/yii2-db-rbac": "*", | |
| 11 | + "artweb/artbox": "dev-master", | |
| 12 | + "artweb/artbox-language": "dev-master" | |
| 13 | + }, | |
| 14 | + "autoload": { | |
| 15 | + "psr-4": { | |
| 16 | + "artweb\\artbox\\event\\": "" | |
| 17 | + } | |
| 18 | + } | |
| 19 | +} | |
| 0 | 20 | \ No newline at end of file | ... | ... |
| 1 | +++ a/controllers/EventController.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace artweb\artbox\event\controllers; | |
| 4 | + | |
| 5 | + | |
| 6 | +use Yii; | |
| 7 | +use artweb\artbox\event\models\Event; | |
| 8 | +use artweb\artbox\event\models\EventSearch; | |
| 9 | +use yii\web\Controller; | |
| 10 | +use yii\web\NotFoundHttpException; | |
| 11 | +use yii\filters\VerbFilter; | |
| 12 | +use developeruz\db_rbac\behaviors\AccessBehavior; | |
| 13 | +use yii\web\UploadedFile; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * EventController implements the CRUD actions for Event model. | |
| 17 | + */ | |
| 18 | +class EventController extends Controller | |
| 19 | +{ | |
| 20 | + /** | |
| 21 | + * @inheritdoc | |
| 22 | + */ | |
| 23 | + public function behaviors() | |
| 24 | + { | |
| 25 | + return [ | |
| 26 | + 'access'=>[ | |
| 27 | + 'class' => AccessBehavior::className(), | |
| 28 | + 'rules' => | |
| 29 | + ['site' => | |
| 30 | + [ | |
| 31 | + [ | |
| 32 | + 'actions' => ['login', 'error'], | |
| 33 | + 'allow' => true, | |
| 34 | + ] | |
| 35 | + ] | |
| 36 | + ] | |
| 37 | + ], | |
| 38 | + 'verbs' => [ | |
| 39 | + 'class' => VerbFilter::className(), | |
| 40 | + 'actions' => [ | |
| 41 | + 'delete' => ['POST'], | |
| 42 | + ], | |
| 43 | + ], | |
| 44 | + ]; | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Lists all Event models. | |
| 49 | + * @return mixed | |
| 50 | + */ | |
| 51 | + public function actionIndex() | |
| 52 | + { | |
| 53 | + $searchModel = new EventSearch(); | |
| 54 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| 55 | + | |
| 56 | + return $this->render('index', [ | |
| 57 | + 'searchModel' => $searchModel, | |
| 58 | + 'dataProvider' => $dataProvider, | |
| 59 | + ]); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Displays a single Event model. | |
| 64 | + * @param integer $id | |
| 65 | + * @return mixed | |
| 66 | + */ | |
| 67 | + public function actionView($id) | |
| 68 | + { | |
| 69 | + return $this->render('view', [ | |
| 70 | + 'model' => $this->findModel($id), | |
| 71 | + ]); | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Creates a new Event model. | |
| 76 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 77 | + * @return mixed | |
| 78 | + */ | |
| 79 | + public function actionCreate() | |
| 80 | + { | |
| 81 | + $model = new Event(); | |
| 82 | + $model->generateLangs(); | |
| 83 | + if ($model->load(Yii::$app->request->post())) { | |
| 84 | + $model->loadLangs(\Yii::$app->request); | |
| 85 | + if ($model->save() && $model->transactionStatus) { | |
| 86 | + return $this->redirect([ | |
| 87 | + 'view', | |
| 88 | + 'id' => $model->id, | |
| 89 | + ]); | |
| 90 | + } | |
| 91 | + | |
| 92 | + } | |
| 93 | + return $this->render('create', [ | |
| 94 | + 'model' => $model, | |
| 95 | + 'modelLangs' => $model->modelLangs, | |
| 96 | + ]); | |
| 97 | + | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Updates an existing Event model. | |
| 102 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 103 | + * @param integer $id | |
| 104 | + * @return mixed | |
| 105 | + */ | |
| 106 | + public function actionUpdate($id) | |
| 107 | + { | |
| 108 | + $model = $this->findModel($id); | |
| 109 | + $model->generateLangs(); | |
| 110 | + if ($model->load(Yii::$app->request->post())) { | |
| 111 | + $model->loadLangs(\Yii::$app->request); | |
| 112 | + if ($model->save() && $model->transactionStatus) { | |
| 113 | + | |
| 114 | + if ( ($file = UploadedFile::getInstance($model, 'products_file')) ) { | |
| 115 | + if(!empty($file)){ | |
| 116 | + $file->saveAs(Yii::getAlias('@uploadDir/' . $file->name)); | |
| 117 | + $model->goEvent(Yii::getAlias('@uploadDir/' . $file->name)); | |
| 118 | + } | |
| 119 | + | |
| 120 | + } | |
| 121 | + | |
| 122 | + return $this->redirect([ | |
| 123 | + 'view', | |
| 124 | + 'id' => $model->id, | |
| 125 | + ]); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + | |
| 129 | + return $this->render('update', [ | |
| 130 | + 'model' => $model, | |
| 131 | + 'modelLangs' => $model->modelLangs, | |
| 132 | + ]); | |
| 133 | + | |
| 134 | + } | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * Deletes an existing Event model. | |
| 138 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 139 | + * @param integer $id | |
| 140 | + * @return mixed | |
| 141 | + */ | |
| 142 | + public function actionDelete($id) | |
| 143 | + { | |
| 144 | + $this->findModel($id)->delete(); | |
| 145 | + | |
| 146 | + return $this->redirect(['index']); | |
| 147 | + } | |
| 148 | + | |
| 149 | + public function actionDelimg($id,$field){ | |
| 150 | + $model = $this->findModel($id); | |
| 151 | + $model->detachBehavior('img'); | |
| 152 | + $model->$field = ''; | |
| 153 | + $model->save(); | |
| 154 | + return true; | |
| 155 | + } | |
| 156 | + | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * Finds the Event model based on its primary key value. | |
| 160 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 161 | + * @param integer $id | |
| 162 | + * @return Event the loaded model | |
| 163 | + * @throws NotFoundHttpException if the model cannot be found | |
| 164 | + */ | |
| 165 | + protected function findModel($id) | |
| 166 | + { | |
| 167 | + if (($model = Event::findOne($id)) !== null) { | |
| 168 | + return $model; | |
| 169 | + } else { | |
| 170 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 171 | + } | |
| 172 | + } | |
| 173 | +} | ... | ... |
| 1 | +++ a/models/Event.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace artweb\artbox\event\models; | |
| 4 | + | |
| 5 | +use artweb\artbox\behaviors\SaveImgBehavior; | |
| 6 | +use artweb\artbox\ecommerce\models\Product; | |
| 7 | +use artweb\artbox\ecommerce\models\ProductVariant; | |
| 8 | +use artweb\artbox\language\behaviors\LanguageBehavior; | |
| 9 | +use Yii; | |
| 10 | +use yii\behaviors\TimestampBehavior; | |
| 11 | +use yii\helpers\ArrayHelper; | |
| 12 | +use yii\db\ActiveQuery; | |
| 13 | +use yii\web\Request; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * This is the model class for table "event". | |
| 17 | + * | |
| 18 | + * @property integer $id | |
| 19 | + * @property string $name | |
| 20 | + * @property string $alias | |
| 21 | + * @property string $body | |
| 22 | + * @property string $image | |
| 23 | + * @property string $meta_title | |
| 24 | + * @property string $description | |
| 25 | + * @property string $h1 | |
| 26 | + * @property string $seo_text | |
| 27 | + * @property integer $created_at | |
| 28 | + * @property integer $updated_at | |
| 29 | + * @property integer $end_at | |
| 30 | + * @property integer $status | |
| 31 | + * @property integer $banner | |
| 32 | + * * From language behavior * | |
| 33 | + * @property EventLang $lang | |
| 34 | + * @property EventLang[] $langs | |
| 35 | + * @property EventLang $objectLang | |
| 36 | + * @property string $ownerKey | |
| 37 | + * @property string $langKey | |
| 38 | + * @property EventLang[] $modelLangs | |
| 39 | + * @property bool $transactionStatus | |
| 40 | + * @method string getOwnerKey() | |
| 41 | + * @method void setOwnerKey( string $value ) | |
| 42 | + * @method string getLangKey() | |
| 43 | + * @method void setLangKey( string $value ) | |
| 44 | + * @method ActiveQuery getLangs() | |
| 45 | + * @method ActiveQuery getLang( integer $language_id ) | |
| 46 | + * @method EventLang[] generateLangs() | |
| 47 | + * @method void loadLangs( Request $request ) | |
| 48 | + * @method bool linkLangs() | |
| 49 | + * @method bool saveLangs() | |
| 50 | + * @method bool getTransactionStatus() | |
| 51 | + * * End language behavior * | |
| 52 | + * * From SaveImgBehavior | |
| 53 | + * @property string|null $imageFile | |
| 54 | + * @property string|null $imageUrl | |
| 55 | + * @method string|null getImageFile( int $field ) | |
| 56 | + * @method string|null getImageUrl( int $field ) | |
| 57 | + * * End SaveImgBehavior | |
| 58 | + * | |
| 59 | + */ | |
| 60 | +class Event extends \yii\db\ActiveRecord | |
| 61 | +{ | |
| 62 | + public $imageUpload; | |
| 63 | + public $products_file; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * @inheritdoc | |
| 67 | + */ | |
| 68 | + public static function tableName() | |
| 69 | + { | |
| 70 | + return 'event'; | |
| 71 | + } | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * @inheritdoc | |
| 78 | + */ | |
| 79 | + public function behaviors() | |
| 80 | + { | |
| 81 | + return [ | |
| 82 | + 'img'=>[ | |
| 83 | + 'class' => SaveImgBehavior::className(), | |
| 84 | + 'fields' => [ | |
| 85 | + ['name'=>'image','directory' => 'event' ], | |
| 86 | + ['name'=>'banner','directory' => 'event' ], | |
| 87 | + ] | |
| 88 | + ], | |
| 89 | + TimestampBehavior::className(), | |
| 90 | + 'language' => [ | |
| 91 | + 'class' => LanguageBehavior::className(), | |
| 92 | + 'objectLang' => EventLang::className() | |
| 93 | + ], | |
| 94 | + ]; | |
| 95 | + } | |
| 96 | + | |
| 97 | + | |
| 98 | + public function beforeSave($insert) | |
| 99 | + { | |
| 100 | + if (parent::beforeSave($insert)) { | |
| 101 | + | |
| 102 | + $this->end_at = !empty($this->end_at) ? (string)strtotime($this->end_at) : ''; | |
| 103 | + return true; | |
| 104 | + } | |
| 105 | + return false; | |
| 106 | + | |
| 107 | + } | |
| 108 | + | |
| 109 | + public function afterFind(){ | |
| 110 | + $this->end_at = !empty($this->end_at) ? date("Y-m-d", $this->end_at) : ''; | |
| 111 | + } | |
| 112 | + | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * @inheritdoc | |
| 116 | + */ | |
| 117 | + public function rules() | |
| 118 | + { | |
| 119 | + return [ | |
| 120 | + [['created_at', 'updated_at','percent','status','sale','is_event','percent' ], 'integer'], | |
| 121 | + [['image', 'end_at','banner'], 'string', 'max' => 255], | |
| 122 | + [['imageUpload','sale','is_event'], 'safe'], | |
| 123 | + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], | |
| 124 | + [['products_file'], 'file'], | |
| 125 | + ]; | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * @inheritdoc | |
| 130 | + */ | |
| 131 | + public function attributeLabels() | |
| 132 | + { | |
| 133 | + return [ | |
| 134 | + 'id' => Yii::t('app', 'ID акции'), | |
| 135 | + 'name' => Yii::t('app', 'name'), | |
| 136 | + 'alias' => Yii::t('app', 'alias'), | |
| 137 | + 'body' => Yii::t('app', 'body'), | |
| 138 | + 'image' => Yii::t('app', 'image'), | |
| 139 | + 'meta_title' => Yii::t('app', 'meta_title'), | |
| 140 | + 'description' => Yii::t('app', 'description'), | |
| 141 | + 'h1' => Yii::t('app', 'h1'), | |
| 142 | + 'seo_text' => Yii::t('app', 'seo_text'), | |
| 143 | + 'created_at' => Yii::t('app', 'created_at'), | |
| 144 | + 'updated_at' => Yii::t('app', 'updated_at'), | |
| 145 | + 'end_at' => Yii::t('app', 'end_at'), | |
| 146 | + 'status' => Yii::t('app', 'Статус акции'), | |
| 147 | + 'products_file' => Yii::t('app', 'Загрузка файла'), | |
| 148 | + 'sale' => Yii::t('app', 'Распродажа'), | |
| 149 | + 'percent' => Yii::t('app', 'Процент'), | |
| 150 | + 'is_event' => Yii::t('app', 'Акция'), | |
| 151 | + ]; | |
| 152 | + } | |
| 153 | + | |
| 154 | + | |
| 155 | + public function isActive(){ | |
| 156 | + if($this->status){ | |
| 157 | + | |
| 158 | + if(!empty($this->end_at) && (strtotime($this->end_at) <= strtotime(date("Y-m-d")))){ | |
| 159 | + return false; | |
| 160 | + } | |
| 161 | + return true; | |
| 162 | + } | |
| 163 | + return false; | |
| 164 | + } | |
| 165 | + | |
| 166 | + | |
| 167 | + public function goEvent($file) { | |
| 168 | + | |
| 169 | + set_time_limit(0); | |
| 170 | + | |
| 171 | + | |
| 172 | + $handle = fopen($file, 'r'); | |
| 173 | + | |
| 174 | + | |
| 175 | + while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { | |
| 176 | + if(isset($data[0]) && isset($data[1])){ | |
| 177 | + $product = ProductVariant::find()->where(['sku' => $data[1]])->joinWith('product')->one(); | |
| 178 | + if($product instanceof ProductVariant){ | |
| 179 | + $model= EventsToProducts::find()->where(['event_id' =>$data[0], 'product_id' => $product->product->id ])->one(); | |
| 180 | + if(!$model instanceof EventsToProducts){ | |
| 181 | + $model = new EventsToProducts; | |
| 182 | + $model->event_id = $data[0]; | |
| 183 | + $model->product_id = $product->product->id; | |
| 184 | + $model->save(); | |
| 185 | + } | |
| 186 | + } | |
| 187 | + } | |
| 188 | + | |
| 189 | + } | |
| 190 | + fclose($handle); | |
| 191 | + unlink($file); | |
| 192 | + | |
| 193 | + } | |
| 194 | + | |
| 195 | + public function getProducts(){ | |
| 196 | + return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['id' => 'event_id']); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public static function getSaleEvents(){ | |
| 200 | + return ArrayHelper::toArray(self::find()->select('percent')->distinct('percent')->where('sale=true AND percent IS NOT NULL')->orderBy('percent')->all()); | |
| 201 | + } | |
| 202 | + | |
| 203 | +} | ... | ... |
| 1 | +++ a/models/EventLang.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace artweb\artbox\event\models; | |
| 4 | + | |
| 5 | +use artweb\artbox\language\models\Language; | |
| 6 | +use Yii; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * This is the model class for table "event_lang". | |
| 10 | + * | |
| 11 | + * @property integer $event_id | |
| 12 | + * @property integer $language_id | |
| 13 | + * @property string $title | |
| 14 | + * @property string $body | |
| 15 | + * @property string $meta_title | |
| 16 | + * @property string $meta_description | |
| 17 | + * @property string $seo_text | |
| 18 | + * @property string $h1 | |
| 19 | + * @property string $alias | |
| 20 | + * | |
| 21 | + * @property Event $event | |
| 22 | + * @property Language $language | |
| 23 | + */ | |
| 24 | +class EventLang extends \yii\db\ActiveRecord | |
| 25 | +{ | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public static function tableName() | |
| 30 | + { | |
| 31 | + return 'event_lang'; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public function behaviors() | |
| 35 | + { | |
| 36 | + return [ | |
| 37 | + 'slug' => [ | |
| 38 | + 'class' => 'artweb\artbox\behaviors\Slug', | |
| 39 | + ], | |
| 40 | + ]; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @inheritdoc | |
| 45 | + */ | |
| 46 | + public function rules() | |
| 47 | + { | |
| 48 | + return [ | |
| 49 | + [['event_id', 'language_id', 'title', 'body'], 'required'], | |
| 50 | + [['event_id', 'language_id'], 'integer'], | |
| 51 | + [['body', 'seo_text'], 'string'], | |
| 52 | + [['title', 'meta_title', 'meta_description', 'h1', 'alias'], 'string', 'max' => 255], | |
| 53 | + [['alias'], 'unique'], | |
| 54 | + [['event_id', 'language_id'], 'unique', 'targetAttribute' => ['event_id', 'language_id'], 'message' => 'The combination of Event ID and Language ID has already been taken.'], | |
| 55 | + [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => Event::className(), 'targetAttribute' => ['event_id' => 'id']], | |
| 56 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | |
| 57 | + ]; | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * @inheritdoc | |
| 62 | + */ | |
| 63 | + public function attributeLabels() | |
| 64 | + { | |
| 65 | + return [ | |
| 66 | + 'event_id' => 'Event ID', | |
| 67 | + 'language_id' => 'Language ID', | |
| 68 | + 'title' => 'Title', | |
| 69 | + 'body' => 'Body', | |
| 70 | + 'meta_title' => 'Meta Title', | |
| 71 | + 'meta_description' => 'Meta Description', | |
| 72 | + 'seo_text' => 'Seo Text', | |
| 73 | + 'h1' => 'H1', | |
| 74 | + 'alias' => 'Alias', | |
| 75 | + ]; | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @return \yii\db\ActiveQuery | |
| 80 | + */ | |
| 81 | + public function getEvent() | |
| 82 | + { | |
| 83 | + return $this->hasOne(Event::className(), ['id' => 'event_id']); | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @return \yii\db\ActiveQuery | |
| 88 | + */ | |
| 89 | + public function getLanguage() | |
| 90 | + { | |
| 91 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
| 92 | + } | |
| 93 | +} | ... | ... |
| 1 | +++ a/models/EventSearch.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace artweb\artbox\event\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | +use yii\base\Model; | |
| 7 | +use yii\data\ActiveDataProvider; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * EventSearch represents the model behind the search form about `common\models\Event`. | |
| 11 | + */ | |
| 12 | +class EventSearch extends Event | |
| 13 | +{ | |
| 14 | + /** | |
| 15 | + * @inheritdoc | |
| 16 | + */ | |
| 17 | + public function rules() | |
| 18 | + { | |
| 19 | + return [ | |
| 20 | + [['id', 'created_at', 'updated_at', 'end_at'], 'integer'], | |
| 21 | + [['name', 'alias', 'body', 'image', 'meta_title', 'description', 'h1', 'seo_text'], 'safe'], | |
| 22 | + ]; | |
| 23 | + } | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @inheritdoc | |
| 29 | + */ | |
| 30 | + public function scenarios() | |
| 31 | + { | |
| 32 | + // bypass scenarios() implementation in the parent class | |
| 33 | + return Model::scenarios(); | |
| 34 | + } | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Creates data provider instance with search query applied | |
| 38 | + * | |
| 39 | + * @param array $params | |
| 40 | + * | |
| 41 | + * @return ActiveDataProvider | |
| 42 | + */ | |
| 43 | + public function search($params) | |
| 44 | + { | |
| 45 | + | |
| 46 | + | |
| 47 | + $query = Event::find(); | |
| 48 | + | |
| 49 | + // add conditions that should always apply here | |
| 50 | + | |
| 51 | + $dataProvider = new ActiveDataProvider([ | |
| 52 | + 'query' => $query, | |
| 53 | + ]); | |
| 54 | + | |
| 55 | + $this->load($params); | |
| 56 | + | |
| 57 | + if (!$this->validate()) { | |
| 58 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 59 | + // $query->where('0=1'); | |
| 60 | + return $dataProvider; | |
| 61 | + } | |
| 62 | + | |
| 63 | + $query->joinWith('lang'); | |
| 64 | + // grid filtering conditions | |
| 65 | + $query->andFilterWhere([ | |
| 66 | + 'id' => $this->id, | |
| 67 | + 'created_at' => $this->created_at, | |
| 68 | + 'updated_at' => $this->updated_at, | |
| 69 | + 'end_at' => $this->end_at, | |
| 70 | + ]); | |
| 71 | + | |
| 72 | + if($this->lang !== null){ | |
| 73 | + $query->andFilterWhere(['like', 'title', $this->lang->title]) | |
| 74 | + ->andFilterWhere(['like', 'alias', $this->lang->alias]) | |
| 75 | + ->andFilterWhere(['like', 'body', $this->lang->body]) | |
| 76 | + ->andFilterWhere(['like', 'image', $this->image]) | |
| 77 | + ->andFilterWhere(['like', 'meta_title', $this->lang->meta_title]) | |
| 78 | + ->andFilterWhere(['like', 'description', $this->lang->meta_description]) | |
| 79 | + ->andFilterWhere(['like', 'h1', $this->lang->h1]) | |
| 80 | + ->andFilterWhere(['like', 'seo_text', $this->lang->seo_text]); | |
| 81 | + } | |
| 82 | + | |
| 83 | + | |
| 84 | + return $dataProvider; | |
| 85 | + } | |
| 86 | +} | ... | ... |
| 1 | +++ a/models/EventsToProducts.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace artweb\artbox\event\models; | |
| 4 | + | |
| 5 | +use artweb\artbox\ecommerce\models\Product; | |
| 6 | +use Yii; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * This is the model class for table "events_to_products". | |
| 10 | + * | |
| 11 | + * @property integer $events_to_products_id | |
| 12 | + * @property integer $event_id | |
| 13 | + * @property integer $product_id | |
| 14 | + * | |
| 15 | + * @property Event $event | |
| 16 | + * @property Product $product | |
| 17 | + */ | |
| 18 | +class EventsToProducts extends \yii\db\ActiveRecord | |
| 19 | +{ | |
| 20 | + /** | |
| 21 | + * @inheritdoc | |
| 22 | + */ | |
| 23 | + public static function tableName() | |
| 24 | + { | |
| 25 | + return 'events_to_products'; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @inheritdoc | |
| 30 | + */ | |
| 31 | + public function rules() | |
| 32 | + { | |
| 33 | + return [ | |
| 34 | + [['event_id', 'product_id'], 'required'], | |
| 35 | + [['event_id', 'product_id'], 'integer'], | |
| 36 | + [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => Event::className(), 'targetAttribute' => ['event_id' => 'event_id']], | |
| 37 | + [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], | |
| 38 | + ]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @inheritdoc | |
| 43 | + */ | |
| 44 | + public function attributeLabels() | |
| 45 | + { | |
| 46 | + return [ | |
| 47 | + 'events_to_products_id' => 'Events To Products ID', | |
| 48 | + 'event_id' => 'Event ID', | |
| 49 | + 'product_id' => 'Product ID', | |
| 50 | + ]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @return \yii\db\ActiveQuery | |
| 55 | + */ | |
| 56 | + public function getEvent() | |
| 57 | + { | |
| 58 | + return $this->hasOne(Event::className(), ['event_id' => 'event_id']); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @return \yii\db\ActiveQuery | |
| 63 | + */ | |
| 64 | + public function getProduct() | |
| 65 | + { | |
| 66 | + return $this->hasOne(Product::className(), ['product_id' => 'product_id']); | |
| 67 | + } | |
| 68 | +} | ... | ... |
| 1 | +++ a/views/event/_form.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use artweb\artbox\components\artboximage\ArtboxImageHelper; | |
| 4 | +use artweb\artbox\event\models\Event; | |
| 5 | +use artweb\artbox\event\models\EventLang; | |
| 6 | +use artweb\artbox\language\widgets\LanguageForm; | |
| 7 | +use kartik\date\DatePicker; | |
| 8 | +use yii\helpers\Html; | |
| 9 | +use yii\widgets\ActiveForm; | |
| 10 | + | |
| 11 | +/* @var $this yii\web\View */ | |
| 12 | +/* @var $model Event */ | |
| 13 | +/* @var $modelLangs EventLang */ | |
| 14 | +/* @var $form yii\widgets\ActiveForm */ | |
| 15 | +?> | |
| 16 | + | |
| 17 | +<div class="event-form"> | |
| 18 | + | |
| 19 | + <?php $form = ActiveForm::begin([ | |
| 20 | + 'enableClientValidation' => false, | |
| 21 | + 'options' => ['enctype' => 'multipart/form-data'] | |
| 22 | + ]); ?> | |
| 23 | + | |
| 24 | + <?= $form->field($model, 'id')->textInput(['maxlength' => true, 'disabled'=>true]) ?> | |
| 25 | + | |
| 26 | + <?= $form->field($model, 'end_at') | |
| 27 | + ->widget(DatePicker::className(), [ | |
| 28 | + 'pluginOptions' => [ | |
| 29 | + 'todayHighlight' => true, | |
| 30 | + 'format' => 'yyyy-mm-dd', | |
| 31 | + ]]) ?> | |
| 32 | + | |
| 33 | + <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ | |
| 34 | + 'language' => 'ru', | |
| 35 | + 'options' => [ | |
| 36 | + 'accept' => 'image/*', | |
| 37 | + 'multiple' => false, | |
| 38 | + ], | |
| 39 | + 'pluginOptions' => [ | |
| 40 | + 'allowedFileExtensions' => ['jpg', 'gif', 'png'], | |
| 41 | + 'initialPreview' => !empty($model->imageUrl) ? ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', | |
| 42 | + 'deleteUrl' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $model->primaryKey]), | |
| 43 | + 'initialPreviewConfig' => $model->getImagesConfig(), | |
| 44 | + 'overwriteInitial' => true, | |
| 45 | + 'showUpload' => false, | |
| 46 | + 'previewFileType' => 'image', | |
| 47 | + ], | |
| 48 | + ]); ?> | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + <?= $form->field($model, 'banner')->widget(\kartik\file\FileInput::classname(), [ | |
| 54 | + 'language' => 'ru', | |
| 55 | + 'options' => [ | |
| 56 | + 'accept' => 'image/*', | |
| 57 | + 'multiple' => false, | |
| 58 | + ], | |
| 59 | + 'pluginOptions' => [ | |
| 60 | + 'allowedFileExtensions' => ['jpg', 'gif', 'png'], | |
| 61 | + 'initialPreview' => !empty($model->getImageUrl(1)) ? ArtboxImageHelper::getImage($model->getImageUrl(1), 'list') : '', | |
| 62 | + 'deleteUrl' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $model->primaryKey]), | |
| 63 | + 'initialPreviewConfig' => $model->getImagesConfig('banner'), | |
| 64 | + 'overwriteInitial' => true, | |
| 65 | + 'showUpload' => false, | |
| 66 | + 'previewFileType' => 'image', | |
| 67 | + ], | |
| 68 | + ]); ?> | |
| 69 | + | |
| 70 | + | |
| 71 | + <?= $form->field($model, 'products_file')->widget(\kartik\file\FileInput::classname(), [ | |
| 72 | + 'language' => 'ru' | |
| 73 | + ]); ?> | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + <?= $form->field($model, 'status')->checkbox() ?> | |
| 78 | + | |
| 79 | + <?= $form->field($model, 'sale')->checkbox() ?> | |
| 80 | + | |
| 81 | + <?= $form->field($model, 'is_event')->checkbox() ?> | |
| 82 | + | |
| 83 | + <?= $form->field($model, 'percent')->textInput() ?> | |
| 84 | + | |
| 85 | + <?= LanguageForm::widget([ | |
| 86 | + 'modelLangs' => $modelLangs, | |
| 87 | + 'formView' => '@artweb/artbox/event/views/event/_form_language', | |
| 88 | + 'form' => $form, | |
| 89 | + ]) ?> | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + <div class="form-group"> | |
| 98 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
| 99 | + </div> | |
| 100 | + | |
| 101 | + <?php ActiveForm::end(); ?> | |
| 102 | + | |
| 103 | +</div> | ... | ... |
| 1 | +++ a/views/event/_form_language.php | |
| 1 | +<?php | |
| 2 | + use artweb\artbox\language\models\Language; | |
| 3 | + use common\models\EventLang; | |
| 4 | + use mihaildev\ckeditor\CKEditor; | |
| 5 | + use mihaildev\elfinder\ElFinder; | |
| 6 | + use yii\web\View; | |
| 7 | + use yii\widgets\ActiveForm; | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * @var EventLang $model_lang | |
| 11 | + * @var Language $language | |
| 12 | + * @var ActiveForm $form | |
| 13 | + * @var View $this | |
| 14 | + */ | |
| 15 | + | |
| 16 | + | |
| 17 | +?> | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | +<?= $form->field($model_lang, '[' . $language->id . ']title')->textInput(['maxlength' => true]) ?> | |
| 24 | + | |
| 25 | +<?= $form->field($model_lang, '[' . $language->id . ']alias')->textInput(['maxlength' => true]) ?> | |
| 26 | + | |
| 27 | +<?= $form->field($model_lang, '[' . $language->id . ']body')->widget(CKEditor::className(), | |
| 28 | + [ | |
| 29 | + 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ | |
| 30 | + 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать | |
| 31 | + 'inline' => false, //по умолчанию false]), | |
| 32 | + 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') | |
| 33 | + ] | |
| 34 | + ) | |
| 35 | + ]) ?> | |
| 36 | + | |
| 37 | +<?= $form->field($model_lang, '[' . $language->id . ']meta_title')->textInput(['maxlength' => true]) ?> | |
| 38 | + | |
| 39 | +<?= $form->field($model_lang, '[' . $language->id . ']meta_description')->textInput(['maxlength' => true]) ?> | |
| 40 | + | |
| 41 | +<?= $form->field($model_lang, '[' . $language->id . ']h1')->textInput(['maxlength' => true]) ?> | |
| 42 | + | |
| 43 | +<?= $form->field($model_lang, '[' . $language->id . ']seo_text')->textarea(['rows' => 6]) ?> | |
| 44 | + | |
| 45 | + | |
| 46 | + | ... | ... |
| 1 | +++ a/views/event/_search.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\widgets\ActiveForm; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\models\EventSearch */ | |
| 8 | +/* @var $form yii\widgets\ActiveForm */ | |
| 9 | +?> | |
| 10 | + | |
| 11 | +<div class="event-search"> | |
| 12 | + | |
| 13 | + <?php $form = ActiveForm::begin([ | |
| 14 | + 'action' => ['index'], | |
| 15 | + 'method' => 'get', | |
| 16 | + ]); ?> | |
| 17 | + | |
| 18 | + <?= $form->field($model, 'event_id') ?> | |
| 19 | + | |
| 20 | + <?= $form->field($model, 'name') ?> | |
| 21 | + | |
| 22 | + <?= $form->field($model, 'alias') ?> | |
| 23 | + | |
| 24 | + <?= $form->field($model, 'body') ?> | |
| 25 | + | |
| 26 | + <?= $form->field($model, 'image') ?> | |
| 27 | + | |
| 28 | + <?php // echo $form->field($model, 'meta_title') ?> | |
| 29 | + | |
| 30 | + <?php // echo $form->field($model, 'description') ?> | |
| 31 | + | |
| 32 | + <?php // echo $form->field($model, 'h1') ?> | |
| 33 | + | |
| 34 | + <?php // echo $form->field($model, 'seo_text') ?> | |
| 35 | + | |
| 36 | + <?php // echo $form->field($model, 'created_at') ?> | |
| 37 | + | |
| 38 | + <?php // echo $form->field($model, 'updated_at') ?> | |
| 39 | + | |
| 40 | + <?php // echo $form->field($model, 'end_at') ?> | |
| 41 | + | |
| 42 | + <div class="form-group"> | |
| 43 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | |
| 44 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | |
| 45 | + </div> | |
| 46 | + | |
| 47 | + <?php ActiveForm::end(); ?> | |
| 48 | + | |
| 49 | +</div> | ... | ... |
| 1 | +++ a/views/event/create.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use common\models\EventLang; | |
| 5 | +/** | |
| 6 | + * @var $this yii\web\View | |
| 7 | + * @var $model common\models\Event | |
| 8 | + * @var EventLang[] $modelLangs | |
| 9 | + */ | |
| 10 | + | |
| 11 | +$this->title = Yii::t('app', 'Create Event'); | |
| 12 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Events'), 'url' => ['index']]; | |
| 13 | +$this->params['breadcrumbs'][] = $this->title; | |
| 14 | +?> | |
| 15 | +<div class="event-create"> | |
| 16 | + | |
| 17 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 18 | + | |
| 19 | + <?= $this->render('_form', [ | |
| 20 | + 'model' => $model, | |
| 21 | + 'modelLangs' => $modelLangs | |
| 22 | + ]) ?> | |
| 23 | + | |
| 24 | +</div> | ... | ... |
| 1 | +++ a/views/event/index.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\grid\GridView; | |
| 5 | +use artweb\artbox\event\models\EventSearch; | |
| 6 | +/** | |
| 7 | +* @var $this yii\web\View | |
| 8 | +* @var $searchModel EventSearch | |
| 9 | +* @var $dataProvider yii\data\ActiveDataProvider | |
| 10 | + * */ | |
| 11 | + | |
| 12 | +$this->title = Yii::t('app', 'Events'); | |
| 13 | +$this->params['breadcrumbs'][] = $this->title; | |
| 14 | +?> | |
| 15 | +<div class="event-index"> | |
| 16 | + | |
| 17 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 18 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
| 19 | + | |
| 20 | + <p> | |
| 21 | + <?= Html::a(Yii::t('app', 'Create Event'), ['create'], ['class' => 'btn btn-success']) ?> | |
| 22 | + </p> | |
| 23 | + <?= GridView::widget([ | |
| 24 | + 'dataProvider' => $dataProvider, | |
| 25 | + 'filterModel' => $searchModel, | |
| 26 | + 'columns' => [ | |
| 27 | + ['class' => 'yii\grid\SerialColumn'], | |
| 28 | + | |
| 29 | + 'id', | |
| 30 | + 'lang.title', | |
| 31 | + 'lang.alias', | |
| 32 | + 'imageUrl:image', | |
| 33 | + // 'meta_title', | |
| 34 | + // 'description', | |
| 35 | + // 'h1', | |
| 36 | + // 'seo_text:ntext', | |
| 37 | + // 'created_at', | |
| 38 | + // 'updated_at', | |
| 39 | + // 'end_at', | |
| 40 | + | |
| 41 | + ['class' => 'yii\grid\ActionColumn'], | |
| 42 | + ], | |
| 43 | + ]); ?> | |
| 44 | +</div> | ... | ... |
| 1 | +++ a/views/event/update.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use common\models\EventLang; | |
| 5 | +/** | |
| 6 | + * @var $this yii\web\View | |
| 7 | + * @var $model common\models\Event | |
| 8 | + * @var EventLang[] $modelLangs | |
| 9 | + */ | |
| 10 | +$this->title = Yii::t('app', 'Update {modelClass}: ', [ | |
| 11 | + 'modelClass' => 'Event', | |
| 12 | +]) . $model->lang->title; | |
| 13 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Events'), 'url' => ['index']]; | |
| 14 | +$this->params['breadcrumbs'][] = ['label' => $model->lang->title, 'url' => ['view', 'id' => $model->id]]; | |
| 15 | +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | |
| 16 | +?> | |
| 17 | +<div class="event-update"> | |
| 18 | + | |
| 19 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 20 | + | |
| 21 | + <?= $this->render('_form', [ | |
| 22 | + 'model' => $model, | |
| 23 | + 'modelLangs' => $modelLangs | |
| 24 | + ]) ?> | |
| 25 | + | |
| 26 | +</div> | ... | ... |
| 1 | +++ a/views/event/view.php | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\widgets\DetailView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\models\Event */ | |
| 8 | + | |
| 9 | +$this->title = $model->lang->title; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Events'), 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="event-view"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <p> | |
| 18 | + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
| 19 | + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ | |
| 20 | + 'class' => 'btn btn-danger', | |
| 21 | + 'data' => [ | |
| 22 | + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), | |
| 23 | + 'method' => 'post', | |
| 24 | + ], | |
| 25 | + ]) ?> | |
| 26 | + </p> | |
| 27 | + | |
| 28 | + <?= DetailView::widget([ | |
| 29 | + 'model' => $model, | |
| 30 | + 'attributes' => [ | |
| 31 | + 'id', | |
| 32 | + 'lang.title', | |
| 33 | + 'lang.alias', | |
| 34 | + 'lang.meta_title', | |
| 35 | + 'lang.meta_description', | |
| 36 | + 'lang.h1', | |
| 37 | + ], | |
| 38 | + ]) ?> | |
| 39 | + | |
| 40 | +</div> | ... | ... |