/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Call::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]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
 public static function badgeAllCount($modelName)
 {
     $count = 0;
     switch ($modelName) {
         case 'Order':
             $count = Order::find()->count();
             break;
         case 'Call':
             $count = Call::find()->count();
             break;
         case 'Review':
             $count = Review::find()->count();
             break;
         default:
             $count = 0;
             break;
     }
     $options = ['class' => 'badge'];
     if ($count) {
         return Html::tag('span', $count, $options);
     }
     return Html::tag('span', $count, $options);
 }
 public static function badges($modelName)
 {
     $count = 0;
     switch ($modelName) {
         case 'Order':
             $count = Order::find()->where(['status' => Order::STATUS_NEW])->count();
             break;
         case 'Call':
             $count = Call::find()->where(['status' => Call::STATUS_NEW])->count();
             break;
         case 'Review':
             $count = Review::find()->where(['status' => Review::STATUS_NEW])->count();
             break;
         default:
             $count = 0;
             break;
     }
     $options = ['class' => 'label-danger label-as-badge'];
     if ($count) {
         return Html::tag('span', $count, $options);
     }
     $options = ['class' => 'label-info label-as-badge'];
     return Html::tag('span', $count, $options);
 }
 /**
  * Finds the Call model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Call the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Call::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionCallCreate()
 {
     $model = new Call();
     $products = Product::find()->where(['top' => Product::STATUS_TOP, 'category_id' => 1])->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->addFlash('success', 'Спасибо! Мы перезвоним Вам в ближайшее время.');
         $model->sendEmail('Новый Заказать Звонок', 'call');
         return $this->goHome();
     } else {
         return $this->render('index', ['call' => $model, 'products' => $products]);
     }
 }