public function actionDict() { $userId = Auth::getUser()['id']; $favors = FavoritesModel::model()->where("`user_id`='{$userId}'")->findAll(); $in = "("; foreach ($favors as $favor) { $in .= "'{$favor->video_id}'" . ", "; } $in = substr($in, 0, -2); $in .= ")"; if ($in == ")") { $movies = array(); } else { $movies = MoviesModel::model()->where("`id` IN {$in}")->findAll(); } $movies_count = MoviesModel::model()->where("`id` IN {$in}")->countAll(); $dicts = DictModel::model()->where("`user_id`='" . Auth::getUser()['id'] . "'")->countAll(); //echo $dicts; $dict_groups = DictGroupsModel::model()->where("`user_id`='" . Auth::getUser()['id'] . "'")->findAll(); $this->view("profile/dict", array("dicts" => $dicts, "groups" => $dict_groups, "movies_count" => $movies_count), false); }
public static function isFavorited($id, $type) { $userId = Auth::getUser()['id']; return FavoritesModel::model()->where("`user_id`='{$userId}' AND `video_id`='{$id}' AND `type`='{$type}'")->findRow(); }
public static function newSeries($serial, $series) { $users = FavoritesModel::model()->where("`video_id`='{$serial->id}'")->findAll(); $to = ""; if (!$users) { return False; } foreach ($users as $user) { $model = UsersModel::model()->where("`id`='{$user->user_id}'")->findRow(); if ($model->email) { $to .= $model->email . ", "; } } $to = trim($to, ", "); $mail = new self(); $mail->to = $to; $mail->nameTo = "Everybody"; $mail->subject = "Новая серия " . $serial->en_name; $mail->text = $mail->loadTemplate("new_series", array("serial_name" => $serial->en_name, "href" => "http://" . $_SERVER['HTTP_HOST'] . "/serials/" . $serial->seo_url, "series_name" => $series->name)); $mail->send(); }
public function actionFavorites($type, $id) { if (!Auth::isLogged()) { Error::httpError(403); } $userId = Auth::getUser()['id']; $model = new FavoritesModel(); $model->user_id = $userId; $model->video_id = (int) $id; $model->type = (int) $type; if ($model->exists()) { FavoritesModel::model()->where("`user_id`='{$model->user_id}' AND `video_id`='{$model->video_id}' AND `type`='{$model->type}'")->delete(); echo "/assets/images/plus_fav.png"; } else { $model->save(); echo "/assets/images/minus_fav.png"; } }