Exemplo n.º 1
0
 public function actionSingle()
 {
     $model = new CommentForm();
     $blog = Blog::getInstance();
     $uri = \Yii::$app->request->get('uri');
     $article = Articles::findOne(['id' => \Yii::$app->request->get('id')]);
     if (!$article) {
         \Yii::$app->session->setFlash('articleNotFound', 'warning');
         // Look at UrlManager configurations
         // Real address is['/blog/category?uri=' . $uri]
         return $this->redirect(['/category/' . $uri], 302);
     }
     $articleCatUri = $article->category->uri;
     $articleId = $article->id;
     if ($articleCatUri != $uri) {
         // Look at UrlManager configurations
         // Real address is ['/blog/single?uri=' . $articleCatUri . '&id=' . $articleId]
         return $this->redirect(['/category/' . $articleCatUri . '/' . $articleId], 302);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         $model->article_id = $articleId;
         $answer = $model->addComment() ? ['name' => 'commentSuccessSending', 'type' => 'success'] : ['name' => 'commentWarningSending', 'type' => 'error'];
         \Yii::$app->session->setFlash($answer['name'], $answer['type']);
         return $this->refresh();
     }
     $data = $blog->getComments($articleId);
     return $this->render('single', ['article' => $article, 'model' => $model, 'data' => $data]);
 }
Exemplo n.º 2
0
 /**
  * Finds the Blog model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Blog the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Blog::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
0
 public function actionIndex()
 {
     $blog = Blog::getInstance();
     if (!($data = $blog->getArticlesPage())) {
         return $this->render('@note', ['msg' => 'noBlogData']);
     }
     return $this->render('index', ['data' => $data]);
 }
Exemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Blog::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['blog_id' => $this->blog_id, 'user_id' => $this->user_id, 'category_id' => $this->category_id, 'date_create' => $this->date_create]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Exemplo n.º 5
0
 public function actionIndex()
 {
     $mregional = new Regional();
     $mcustomer = new Customer();
     $session = new Session();
     $company = $session->get('company');
     $facebook = Facebook::find()->asArray()->count();
     $twitter = Twitter::find()->asArray()->count();
     $blog = Blog::find()->asArray()->count();
     $instagram = Instagram::find()->asArray()->count();
     $customer = Customer::find()->asArray()->count();
     $customer_countall = $mcustomer->find()->limit(7)->count();
     $regional = $mregional->find()->limit(7)->all();
     $speedo = "";
     foreach ($regional as $key => $rows) {
         $customer_count = $mcustomer->find()->where(['FIELD7' => $rows->FIELD1])->andWhere(['FIELD9' => $company])->limit(7)->count();
         $no = $key + 1;
         $percentage = $customer_count / $customer_countall * 100;
         $agree = number_format($percentage, 0, '.', '.');
         $speedo .= "<div class='wrapp-spedo'>\n            <div id='speedo" . $no . "'>\n              " . $agree . "\n            </div>\n            <h4 align='center'>REGIONAL " . $no . "</h4>\n          </div>";
     }
     return $this->render('index', ['speedo' => $speedo, 'facebook' => $facebook, 'twitter' => $twitter, 'blog' => $blog, 'instagram' => $instagram, 'customer' => $customer]);
 }