/** * Возвращает актуальное объявление * @param $hash_block * @param $host * @return array advertisment */ public function getImgUrl($hash_block, $host) { $block_code = BlockCode::find()->where(['hash_block' => $hash_block])->one(); $param['blockcode_id'] = $block_code['id']; $param['platform_id'] = $block_code['platform_id']; $param['type_id'] = $block_code['adstype_id']; $platform = Platforms::find()->where(['id' => $param['platform_id'], 'status' => Platforms::STATUS_ACTIVE])->one(); if (!empty($platform)) { if ($this->getHost($platform['url']) != $this->getHost($host)) { return array('name' => 'Exception403'); } } $categories_id = CodeblocksAdscategories::find()->where(['blockcode_id' => $param['blockcode_id']])->all(); if (is_array($categories_id)) { foreach ($categories_id as $category_id) { $categories[] = $category_id['adscategory_id']; } } $ads = Ads::find()->where(['status' => Ads::STATUS_ACTIVE, 'type_id' => $param['type_id'], 'category_id' => $categories])->all(); foreach ($ads as $advertisement) { $views = $advertisement->getView()->all(); $sortAds[$advertisement->id] = count($views); $ads_type = $advertisement->getAdsType()->One(); $adsArray[$advertisement->id]['picture'] = $advertisement->picture; $adsArray[$advertisement->id]['id'] = $advertisement->id; $adsArray[$advertisement->id]['action_url'] = $advertisement->action_url; $adsArray[$advertisement->id]['height'] = $ads_type->height; $adsArray[$advertisement->id]['width'] = $ads_type->width; } asort($sortAds); $currentAds = key($sortAds); // $adsView = new AdsViews(); // $adsView->actionView($currentAds,$param['platform_id']); return $adsArray[$currentAds]; }
public function actionEvent() { $event = new AdsEvents(); $platform = Platforms::find()->where(['like', 'url', Yii::$app->request->post('domain')])->one(); if ($event->checkUniqueEvent(Yii::$app->request->post('ipAddress'), Yii::$app->request->post('ads_id'), $platform->id)) { $event->setEvent(Yii::$app->request->post('ipAddress'), Yii::$app->request->post('ads_id'), $platform->id, 1); } }
/** * Updates an existing BlockCode model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'platforms' => Platforms::find()->where(['status' => 2])->all(), 'categories' => Adscategory::find()->all(), 'adstype' => Adstype::find()->all()]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Platforms::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => Yii::$app->getUser()->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
/** * Finds the Platforms model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Platforms the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Platforms::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }