Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     //var_dump($params['id']);die;
     $id = isset($params['id']) ? $params['id'] : Yii::$app->user->id;
     $query = Journal::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere('user_id=' . $id)->orderBy('id DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 10]]);
     //\yii\helpers\VarDumper::dump($query->all(), 1100, true);die;
     $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, 'user_id' => $this->user_id, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'entry', $this->entry])->andFilterWhere(['like', 'shared_with', $this->shared_with]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $filter)
 {
     $query = Journal::find();
     $query->joinWith(['company', 'kind', 'type']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['N_year' => SORT_ASC]]]);
     // Add extended sorts for related tables
     $dataProvider->sort->attributes['company.nazva'] = ['asc' => [Leshoz::tableName() . '.nazva' => SORT_ASC], 'desc' => [Leshoz::tableName() . '.nazva' => SORT_DESC]];
     $dataProvider->sort->attributes['kind.nazva_short'] = ['asc' => [Poroda::tableName() . '.nazva_short' => SORT_ASC], 'desc' => [Poroda::tableName() . '.nazva_short' => SORT_DESC]];
     $dataProvider->sort->attributes['type.type'] = ['asc' => [TestType::tableName() . '.type' => SORT_ASC], 'desc' => [TestType::tableName() . '.type' => 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, 'N_total' => $this->N_total, 'N_year' => $this->N_year, 'id_leshoz' => $this->id_leshoz, 'id_poroda' => $this->id_poroda, 'date_start' => $this->date_start, 'date_end' => $this->date_end, 'date_pasport' => $this->date_pasport, 'masa' => $this->masa, 'masa_zrazka' => $this->masa_zrazka, 'energy' => $this->energy, 'shozh' => $this->shozh, 'chistota' => $this->chistota, 'masa_1000' => $this->masa_1000, 'klass' => $this->klass, 'date_doc' => $this->date_doc, 'id_type' => $this->id_type, 'N_prev' => $this->N_prev, 'v_rahunok' => $this->v_rahunok, 'id_bill' => $this->id_bill, 'id_koef' => $this->id_koef]);
     $query->andFilterWhere(['like', 'N_pasport', $this->N_pasport])->andFilterWhere(['like', 'zagotiv', $this->zagotiv]);
     if (empty($params['date_start']) && isset($filter['year'])) {
         $query->andFilterWhere(['between', 'date_start', $filter['year'] . '-01-01', $filter['year'] . '-12-31']);
     }
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * Display user dashboard
  */
 public function actionDashboard()
 {
     //$model = Yii::$app->user->identity;
     $journals = new ActiveDataProvider(['query' => Journal::find()->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
     $events = new ActiveDataProvider(['query' => \app\models\Event::find()->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
     $photos = \app\models\Photos::find()->orderBy(['id' => SORT_DESC])->limit(5)->all();
     $wishlists = new ActiveDataProvider(['query' => \app\models\Wishlist::find()->where(['status' => 0])->orderBy('id')->limit(5), 'pagination' => false]);
     $DataProvider = new ActiveDataProvider(['query' => User::find()->where('level !=0 AND parent_id=0')->orderBy('id')]);
     $RegisteredMembers = count(User::find()->where('level > :level', [':level' => 3])->orWhere('level > :level', [':level' => 2])->orWhere('level > :level', [':level' => 1])->all());
     $famillies = User::find()->where(['level' => '1'])->count();
     $orders = count(\app\models\Payment::find()->all());
     $payments = Payment::getPaymentsCount();
     $months = Payment::getMonths();
     $epercent = Payment::earningPercentage();
     $earning = Payment::getMonthlyEarning();
     $revenue = Payment::totalRevenue();
     $rpercent = payment::revenuePercentage();
     $mearning = Payment::getPaymentsMonth();
     return $this->render('dashboard', ['dataProvider' => $DataProvider, 'events' => $events, 'journals' => $journals, 'photos' => $photos, 'wishlists' => $wishlists, 'RegisteredMembers' => $RegisteredMembers, 'orders' => $orders, 'payments' => $payments, 'months' => $months, 'epercent' => $epercent, 'earning' => $earning, 'revenue' => $revenue, 'rpercent' => $rpercent, 'mearning' => $mearning, 'famillies' => $famillies]);
 }
Exemplo n.º 4
0
 /**
  * Display user dashboard
  * @param integer $id User ID
  */
 public function actionDashboard($id = null)
 {
     //Check user level & existence of $id
     $id = Yii::$app->user->identity->level == 0 && $id != null ? $id : Yii::$app->user->id;
     $model = User::findOne($id);
     $photos = \app\models\Photos::getItems();
     $journals = new ActiveDataProvider(['query' => Journal::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
     if ($model->level == 3) {
         //if the user is child
         $moods = new ActiveDataProvider(['query' => Mood::find()->select('mood')->where(['user_id' => $id])->orderBy(['date' => SORT_DESC, 'time' => SORT_DESC])->limit(1), 'pagination' => false]);
         $DataProvider = new ActiveDataProvider(['query' => $model->findParents(), 'pagination' => ['pageSize' => 20]]);
         return $this->render('childdashboard', ['dataProvider' => $DataProvider, 'journalProvider' => $journals, 'moodsProvider' => $moods, 'moods' => new Mood(), 'model' => $model, 'photos' => $photos]);
     } else {
         //if the user is parent
         $events = new ActiveDataProvider(['query' => \app\models\Event::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
         $wishlists = new ActiveDataProvider(['query' => \app\models\Wishlist::find()->where(['assigned_to' => $id, 'status' => 0])->orderBy('id')->limit(5), 'pagination' => false]);
         $DataProvider = new ActiveDataProvider(['query' => $model->findFamily()]);
         $activity = new ActiveDataProvider(['query' => \app\models\Activity::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->limit(4), 'pagination' => false]);
         return $this->render('dashboard', ['dataProvider' => $DataProvider, 'activity' => $activity, 'events' => $events, 'journals' => $journals, 'photos' => $photos, 'wishlists' => $wishlists]);
     }
 }
Exemplo n.º 5
0
 /**
  * @return newsfeed generations array- DTR
  */
 public function getNews()
 {
     $user = Yii::$app->user->id;
     $notification = Notification::find()->where(['shared_id' => $user])->orderBy(['date' => SORT_DESC])->all();
     foreach ($notification as $news) {
         if ($news->type == 'event') {
             return Event::find()->where(['id' => $news->type_id]);
         } elseif ($news->type == 'activity') {
             return Activity::find()->where(['id' => $news->type_id]);
         } elseif ($news->type == 'journal') {
             return Journal::find()->where(['id' => $news->type_id]);
         } elseif ($news->type == 'wishlist') {
             return Wishlist::find()->where(['id' => $news->type_id]);
         } else {
             return Photos::find()->where(['id' => $news->type_id]);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * get latest journal entry by DTR
  */
 public function latestJournal($user_id)
 {
     $journal = Journal::find()->where(['user_id' => $user_id])->orderBy(['date' => SORT_DESC])->limit(3);
     return $journal;
 }
Exemplo n.º 7
0
 /**
  * Join for newsfeed
  */
 public function newsFeed($news)
 {
     $events = Event::find()->joinWith('user')->orderBy(['date' => SORT_DESC])->all();
     $journals = Journal::find()->joinWith('user')->orderBy(['date' => SORT_DESC])->all();
     //$activities = Activity::find()->joinWith('user')->orderBy('date')->all();
     if ($news == 'events') {
         return $events;
     } else {
         if ($news == 'journals') {
             // if($news == 'journals'){
             return $journals;
         }
     }
     //else{
     // return $activities;
     //}
 }
Exemplo n.º 8
0
 /**
  * Synchronizes new samples from another source.
  * In this case synchronizes with production server. Check configuration in config/params.php
  *
  * This is esay version of one table replication, for advanced synchronization check database
  * replication manuals for your DB.
  */
 public function actionSync()
 {
     /**
      * Find max id and load all new records in current journal
      */
     $lastModel = Journal::find()->orderBy(['id' => SORT_DESC])->one();
     $syncData = file_get_contents(Yii::$app->params['journalSyncUrl'] . $lastModel->id);
     if (!empty($syncData)) {
         $syncData = json_decode($syncData, true);
         foreach ($syncData as $row) {
             $newModel = new Journal();
             $newModel->load(['Journal' => $row]);
             $newModel->save();
         }
     }
     return $this->redirect(['index']);
 }