public function actionGet_ajax()
 {
     if (Yii::$app->request->isAjax) {
         $data = Yii::$app->request->post();
         $min = strtotime($data['analytics'][0]);
         $max = strtotime($data['analytics'][1]);
         /*ссылки на клиентские кампании*/
         $id_user = Yii::$app->user->identity->id;
         $links = Campaigns::Get_links($id_user);
         $summary = $max - $min;
         $summary = $summary / 3600 / 24;
         for ($i = 0; $i < count($links); $i++) {
             for ($j = 0; $j < $summary; $j++) {
                 $massive = Analytics::Get_info($links[$i]->id, date('Ymd', $min + $j * 3600 * 24));
                 $rows[$links[$i]->id][] = $massive;
             }
         }
         for ($i = 0; $i < count($links); $i++) {
             for ($j = 0; $j < count($rows[$links[$i]->id]); $j++) {
                 if (count($rows[$links[$i]->id][$j]) == 0) {
                     $mass[$i][] = ['data' => ($min + $j * 3600 * 24) * 1000, 'count' => 0, 'id' => $links[$i]->id, 'link' => '/campaigns?id=' . $links[$i]->id];
                 } else {
                     $result = Detail::Get_count($rows[$links[$i]->id][$j][0]->id);
                     $mass[$i][] = ['data' => strtotime($rows[$links[$i]->id][$j][0]->date) * 1000, 'count' => (int) $result, 'id' => $rows[$links[$i]->id][$j][0]->id_campaigns, 'link' => $rows[$links[$i]->id][$j][0]->link];
                 }
             }
         }
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return ['data' => $mass, 'counts' => count($rows), 'summary' => $summary, 'max' => $max, 'min' => $min];
     }
 }
 public function unique_projects()
 {
     $name = Yii::$app->request->post();
     $id_project = Yii::$app->request->post();
     $password = Campaigns::find()->where(['name' => $name['Campaigns']['name'], 'id_project' => $id_project['Campaigns']['id_project'], 'id_user' => Yii::$app->user->identity['id']])->one();
     return $password->id_project;
 }
 public function search_view($params)
 {
     //->where(['id_project' => $params['id']] // выборка по проэкту
     /*Campaigns::find()->with('author')->where(['id_project' => $params['id']])*/
     $query = Campaigns::find();
     $query->joinWith(['spheres']);
     $query->where(['id_project' => $params['id']]);
     $query->orderBy("date_post DESC");
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // Important: here is how we set up the sorting
     // The key is the attribute name on our "TourSearch" instance
     $dataProvider->sort->attributes['spheres'] = ['asc' => ['spheres.name' => SORT_ASC], 'desc' => ['spheres.name' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date_post' => $this->date_post, 'date_end' => $this->date_end, 'date_begin' => $this->date_begin, 'date_update' => $this->date_update, 'id_project' => $this->id_project, 'id_user' => $this->id_user, 'id_sphere' => $this->id_sphere]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'about', $this->about])->andFilterWhere(['like', 'unique_link', $this->unique_link])->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'spheres.name', $this->spheres]);
     return $dataProvider;
 }
 /**
  * Finds the Campaigns model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Campaigns the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Campaigns::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function Get_date($id)
 {
     $counts = Campaigns::Get_count($id);
     if ($counts > 0) {
         /*Последняя запись*/
         $links = Campaigns::Get_max_date_link($id);
         /*первая запись аналитики по последней кампании*/
         $min = Analytics::Get_min_date_id($links->id);
         if (!empty($min)) {
             $result['check'] = 1;
             $result['min'] = $min;
             return $result;
         } else {
             $result['check'] = 2;
             $result['min'] = '';
             return $result;
         }
     } else {
         $result['check'] = 0;
         $result['min'] = '';
         return $result;
     }
 }