/**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $query = FLanguecenter::find()->where(['is_show' => 1])->orderBy('ordinal_view ASC');
     $limit_Lang_home = FConfigParam::find()->where(['name' => 'NUMBER_LANGUE_IN_HOME'])->one();
     $count = $query->count();
     $pagination = new Pagination(['defaultPageSize' => $limit_Lang_home->value, 'totalCount' => $count]);
     $models = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['models' => $models, 'pagination' => $pagination]);
 }
Example #2
0
 public function run()
 {
     parent::run();
     $limit_Lang_most = FConfigParam::find()->where(['name' => 'NUMBER_LANGUE_IN_MOST'])->one();
     if ($limit_Lang_most) {
         $limit = $limit_Lang_most->value;
     } else {
         $limit = 10;
     }
     $query = FLanguecenter::find()->where(['is_show' => 1])->orderBy('number DESC');
     $mostViewlangs = $query->limit($limit)->all();
     return $this->render('@frontend/views/widgets/mostView', ['mostViewlangs' => $mostViewlangs]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = FLanguecenter::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(['ID' => $this->ID, 'open_at' => $this->open_at, 'rate' => $this->rate, 'ordinal_view' => $this->ordinal_view]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'decription', $this->decription])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'url', $this->url]);
     return $dataProvider;
 }
 public function actionRate()
 {
     if (isset($_POST['rate']) && isset($_POST['idlang'])) {
         $new_rate = intval($_POST['rate']);
         $idlang = intval($_POST['idlang']);
         if (!Yii::$app->session->isActive) {
             Yii::$app->session->open();
         }
         $user_id = Yii::$app->session->getId();
         $model = FRateCenter::find()->where(['user_session' => $user_id, 'id_center' => $idlang])->one();
         if ($model === null) {
             /// So no old recorde
             $rate = new FRateCenter();
             $rate->id_center = $idlang;
             $rate->user_session = $user_id;
             $rate->value = $new_rate;
             $rate->rate_at = time();
             $rate->rate_at = formatTime::convert($rate->rate_at, 'datetime');
             $rate->save();
             $query = FRateCenter::find()->where(['id_center' => $idlang]);
             $total = $query->count();
             $ratecenters = $query->all();
             $sum_rate = 0;
             foreach ($ratecenters as $ratecenter) {
                 $sum_rate = $sum_rate + $ratecenter->value;
             }
             $langue = FLanguecenter::find()->where(['ID' => $idlang])->one();
             $langue->rate = $sum_rate / $total;
             $langue->save();
             Yii::$app->session->setFlash('success-rate', Yii::t('frontend', 'You rated success {0}. Thank you for your rating!', $rate->value));
         } else {
             Yii::$app->session->setFlash('error-rate', Yii::t('frontend', 'You used to rate {0} star. Thank you for your rating!', $model->value));
         }
         //return $this->run('view', ['id'=>$idlang]);
         $this->redirect(\Yii::$app->request->getReferrer());
     }
 }