Exemplo n.º 1
0
 /**
  * Возвращает актуальное объявление
  * @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];
 }
Exemplo n.º 2
0
 /**
  * Creates a new BlockCode model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new BlockCode();
     if ($model->load(Yii::$app->request->post())) {
         $post = Yii::$app->request->post();
         $categories = $post['BlockCode']['categories'];
         $model->hash_block = md5($post['BlockCode']['name'] . $post['BlockCode']['platform_id'] . rand('100', '1000'));
         if ($model->save()) {
             foreach ($categories as $category) {
                 $block_cat = new CodeblocksAdscategories();
                 $block_cat->adscategory_id = $category;
                 $block_cat->blockcode_id = $model->id;
                 $block_cat->save(false);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'platforms' => Platforms::find()->where(['status' => 2])->all(), 'categories' => Adscategory::find()->all(), 'adstype' => Adstype::find()->all()]);
     }
 }