/** * Возвращает актуальное объявление * @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]; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BlockCode::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'platform_id' => $this->platform_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'hash_block', $this->hash_block]); return $dataProvider; }
/** * Finds the BlockCode model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return BlockCode the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BlockCode::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBlockcode() { return $this->hasOne(BlockCode::className(), ['id' => 'blockcode_id']); }