public static function add($doc_id, $user_id) { $model = Wishlist::find()->where(['doc_id' => $doc_id, 'user_id' => $user_id])->one(); if (!$model) { $model = new Wishlist(); } $model->user_id = $user_id; $model->doc_id = $doc_id; $model->created_at = time(); $model->updated_at = time(); if ($model->save(FALSE)) { return true; } return false; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Wishlist::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC]); $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, 'user_id' => $this->user_id, 'date' => $this->date]); $query->andFilterWhere(['like', 'emoji', $this->emoji])->andFilterWhere(['like', 'assigned_to', $this->assigned_to]); return $dataProvider; }
public function search($input) { $query = Wishlist::query(); $columns = Schema::getColumnListing('wishlists'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }
/** * Finds the Wishlist model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Wishlist the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Wishlist::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 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]); }
/** * 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]); } }
public function getLastWish($id) { return Wishlist::find()->where(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(1); }
/** * @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]); } } }
public function WishlistView($username) { $getUsers = User::where('username', '=', $username)->select('username')->get(); //foreach ($getUsers as $getUser => $value) {if($username != $getUser->username){return redirect('http://localhost/sites/Running-shoes/public/Login');}} $wishlist = Wishlist::all(); dd($wishlist); return View('Runningshoes.pages.wishlist.Wishlist'); }
/** * Run the database seeds. * * @return void */ public function run() { Wishlist::create(['user_id' => 1, 'giving_circle_id' => 1]); }
public function actionAddWishlist() { $request = Yii::$app->request; try { $doc_id = $request->post('doc_id', ''); $user_id = Yii::$app->session['user_id']; $check_doc = Documents::find()->where(['id' => $doc_id])->count(); if ($check_doc == 0) { return json_encode(Util::arrayError('Không tồn tại tài liệu này', '')); } if (empty($user_id)) { return json_encode(Util::arrayError('Bạn chưa đăng nhập', '')); } $result = Wishlist::add($doc_id, $user_id); return json_encode(Util::arraySuccess('Thành công', $result)); } catch (Exception $ex) { } }
public function getWishlists() { return $this->hasMany(Wishlist::className(), ['user_id' => 'id'])->orderBy(['id' => SORT_DESC]); }