/**
  * Page Acceuil
  */
 public function dashboard()
 {
     // $redirectUrl = $response->links[1]->href;
     $nbacteurs = Actors::count();
     $nbcommentaires = Comments::count();
     $nbmovies = Movies::count();
     $nbseances = Sessions::count();
     $actor = new Actors();
     // Je récpere mon modèle
     $comment = new Comments();
     // Je récpere mon modèle
     $movie = new Movies();
     // Je récpere mon modèle
     $session = new Sessions();
     // Je récpere mon modèle
     $user = new User();
     // Je récpere mon modèle
     $avgacteurs = $actor->getAvgActors();
     $avgnotecommentaire = $comment->getAvgNote();
     $avgnotepresse = $movie->getAvgNotePresse();
     $avghour = $session->getAvgHourDate();
     $seances = $session->getNextSession();
     $users = $user->getLastUsers();
     /*
      $seances = Sessions::where("date_session",  ">", DB::raw("NOW()"))
     ->take(15)->get();
     */
     return view('Main/dashboard', ['avgnotecommentaire' => $avgnotecommentaire->avgnote, 'avgnotepresse' => $avgnotepresse->avgpress, 'avgacteurs' => $avgacteurs->age, 'avghour' => $avghour->avghour, 'nbacteurs' => $nbacteurs, 'nbcommentaires' => $nbcommentaires, 'nbmovies' => $nbmovies, 'nbseances' => $nbseances, 'seances' => $seances, 'users' => $users]);
 }
 /**
  * retourne les données de comments
  */
 public function comments()
 {
     $tab = [];
     $comment = new Comments();
     $comments = $comment->commentsRepartition();
     foreach ($comments as $comment) {
         $tab[] = [['name' => $comment->name], ['valeur' => $comment->nb]];
     }
     return $tab;
 }
 /**
  * action favori enregistré en session
  * stockage temporel
  */
 public function favori($id, $action)
 {
     //recuperation du commentaire concerné
     $comment = Comments::find($id);
     //recuperation de la variable favori en session
     //et fixation d'un tableau par defaut
     //si rien en session favori
     $favoris = session("favoris", []);
     //si l'action est 'favori'
     if ($action == "favori") {
         //j'ajoute le commentaire dans le tableau des favoris
         //en créant une clé qui a la valeur de l'id du commentaire
         //pour pouvoir le retrouver
         $favoris[$id] = $comment->id;
         Session::flash('warning', "Le commentaire {$comment->id} est désormais en favori");
     } else {
         //suppression du favori dans le tableau
         unset($favoris[$id]);
         Session::flash('warning', "Le commentaire {$comment->id} n'est désormais plus en favori");
     }
     //enregistrement en session du nouveau tableau des favoris
     Session::put("favoris", $favoris);
     //redirection
     return Redirect::route('comments_index');
 }
 /**
  * Page Dashboard.
  */
 public function dashboard()
 {
     $nbacteurs = Actors::count();
     $nbcommentaires = Comments::count();
     $nbmovies = Movies::count();
     $nbseances = Sessions::count();
     $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
     $collection = new \MongoDB\Collection($manager, 'laravel', 'videos');
     $videos = collect($collection->find()->toArray())->shuffle();
     $collection = new \MongoDB\Collection($manager, 'laravel', 'stats');
     $youtubeinfo = collect($collection->find(['origin' => 'Youtube'])->toArray())->first();
     $collection = new \MongoDB\Collection($manager, 'laravel', 'stats');
     $tweeterinfo = collect($collection->find(['origin' => 'Twitter', 'type' => 'infos'])->toArray())->first();
     $actor = new Actors();
     // Je récpere mon modèle
     $comment = new Comments();
     // Je récpere mon modèle
     $movie = new Movies();
     // Je récpere mon modèle
     $session = new Sessions();
     // Je récpere mon modèle
     $user = new User();
     // Je récpere mon modèle
     $avgacteurs = $actor->getAvgActors();
     $avgnotecommentaire = $comment->getAvgNote();
     $avgnotepresse = $movie->getAvgNotePresse();
     $avghour = $session->getAvgHourDate();
     $seances = $session->getNextSession();
     $users = $user->getLastUsers();
     return view('Main/dashboard', ['avgnotecommentaire' => $avgnotecommentaire->avgnote, 'avgnotepresse' => $avgnotepresse->avgpress, 'avgacteurs' => $avgacteurs->age, 'videos' => $videos, 'video' => $videos[0], 'youtubeinfo' => $youtubeinfo->data, 'tweeterinfo' => $tweeterinfo['data'][0], 'youtubeinfodateupdated' => $youtubeinfo->created, 'tweeterinfodateupdated' => $tweeterinfo['created_at'], 'avghour' => $avghour->avghour, 'nbacteurs' => $nbacteurs, 'nbcommentaires' => $nbcommentaires, 'nbmovies' => $nbmovies, 'nbseances' => $nbseances, 'seances' => $seances, 'users' => $users]);
 }
 /**
  *
  */
 public function update(Request $request)
 {
     $field = 'content';
     $id = $request->id;
     $value = $request->value;
     $comment = Comments::find($id);
     $comment->update([$field => $value]);
     //        Session::flash('success', "Le commentaire a bien été mis à jour");
     //        return Redirect::route('comments.index');
 }
 public function dashboard()
 {
     //compter les objets Actors
     $nbacteurs = Actors::count();
     //compter les objets Comments
     $nbcommentaires = Comments::count();
     //compter les objets Movies
     $nbfilms = Movies::count();
     //compter les objets Session
     $nbseances = Sessions::count();
     //compter les objets User
     $nbusers = User::count();
     //compter les objets Categories
     $nbcategories = Categories::count();
     //compter les objets Directors
     $nbdirectors = Directors::count();
     //compter les objets Medias
     $nbmedias = Medias::count();
     //moyenne d'age des Actors
     $actor = new Actors();
     $moyenne_acteurs = $actor->getAvgActors();
     //moyenne des Comments
     $comment = new Comments();
     $moyenne_commentaires = $comment->getAvgComments();
     //moyenne des Movies
     $movie = new Movies();
     $moyenne_presse = $movie->getAvgMovies();
     //moyenne des Sessions
     $session = new Sessions();
     $moyenne_seance = $session->getAvgSessions();
     //liste des 24 derniers Users
     $user = new User();
     $liste_users = $user->getLastUsers(24);
     //Pourcentage des films par distributeurs
     $movies_distributeur = $movie->getMoviesDistributeur();
     //liste des 15 prochaines Sessions
     $session = new Sessions();
     $liste_sessions = $session->getNextSessions(15);
     //pour utilisation de la 3ème méthode
     //qui retourne un timestamp
     $moyenne_acteurs = \Carbon\Carbon::createFromTimestamp($moyenne_acteurs);
     return view("Main/dashboard", ['nbacteurs' => $nbacteurs, 'moyenne_acteurs' => $moyenne_acteurs->diffInYears(), 'nbcommentaires' => $nbcommentaires, 'nbfilms' => $nbfilms, 'moyenne_commentaires' => round($moyenne_commentaires), 'moyenne_presse' => round($moyenne_presse), 'nbseances' => $nbseances, 'moyenne_seance' => round($moyenne_seance->moyenne), 'nbusers' => $nbusers, 'liste_users' => $liste_users, 'liste_sessions' => $liste_sessions, 'nbcategories' => $nbcategories, 'nbdirectors' => $nbdirectors, 'nbmedias' => $nbmedias, 'movies_distributeur' => $movies_distributeur]);
 }
 /**
  * Page Acceuil
  */
 public function dashboard()
 {
     $nbacteurs = Actors::count();
     $nbcommentaires = Comments::count();
     $nbmovies = Movies::count();
     $nbseances = Sessions::count();
     $actor = new Actors();
     // Je récpere mon modèle
     $comment = new Comments();
     // Je récpere mon modèle
     $movie = new Movies();
     // Je récpere mon modèle
     $session = new Sessions();
     // Je récpere mon modèle
     $user = new User();
     // Je récpere mon modèle
     $avgacteurs = $actor->getAvgActors();
     $avgnotecommentaire = $comment->getAvgNote();
     $avgnotepresse = $movie->getAvgNotePresse();
     $avghour = $session->getAvgHourDate();
     $seances = $session->getNextSession();
     $users = $user->getLastUsers();
     return view('Main/dashboard', ['avgnotecommentaire' => $avgnotecommentaire->avgnote, 'avgnotepresse' => $avgnotepresse->avgpress, 'avgacteurs' => $avgacteurs->age, 'avghour' => $avghour->avghour, 'nbacteurs' => $nbacteurs, 'nbcommentaires' => $nbcommentaires, 'nbmovies' => $nbmovies, 'nbseances' => $nbseances, 'seances' => $seances, 'users' => $users]);
 }
Beispiel #8
0
 /**
  * View Checkin by Id
  * route: /checkins/view/{id}
  *
  * @param @id
  * @return Response
  */
 public function viewAction($id)
 {
     $json_return = array();
     $checkin = CheckIns::find($id);
     if (!$checkin) {
         return showErrorResponse('Checkin not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_CHECKIN_MISSING);
     }
     $restaurant = Restaurants::find($checkin->restaurant_id);
     if (!$restaurant) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     $user = Users::find($checkin->user_id);
     $photos = Photos::getByType(CONSTANTS::CHECKIN, $checkin->id);
     $photos_array = Photos::convertPhotosToArray($photos);
     $comments = Comments::getByType(CONSTANTS::REVIEW, $checkin->id);
     $comments_array = array();
     if ($comments) {
         foreach ($comments as $comment) {
             $comments_array[] = ModelFormatter::commentFormat($comment);
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::checkin => ModelFormatter::checkinFormat($checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
     return response()->json($json_return);
 }
Beispiel #9
0
 /**
  * Send push notification through GCM server
  *
  * @param Array $registration_ids = device_ids
  * @return result
  *
  */
 private function sendToGCM($registration_ids)
 {
     $user_notification_count = $this->getNotificationByUserTo($this->user_id_to, CONSTANTS::NOTIFICATION_STATUS_NEW, true);
     $type = $this->type;
     $activities = array();
     $user_count = 0;
     $username_array = array();
     $activity_type = 0;
     //Time Interval for notification groupings = 1 Day (86400 seconds)
     $date_range = array(KeyParser::date_from => date('Y-m-d H:i:s', time() - CONSTANTS::DAY_SECOND_VALUE), KeyParser::date_to => date('Y-m-d H:i:s'));
     //Build usernames_from array()
     if (strpos($type, 'photo')) {
         $activity_type = 5;
     } elseif (strpos($type, 'checkin')) {
         $activity_type = 2;
     } elseif (strpos($type, 'review')) {
         $activity_type = 1;
     }
     if ($type == CONSTANTS::NOTIFICATION_TYPE_LIKE_CHECKIN || $type == CONSTANTS::NOTIFICATION_TYPE_LIKE_REVIEW || $type == CONSTANTS::NOTIFICATION_TYPE_LIKE_PHOTO) {
         $activities = Like::getLikerList($activity_type, $this->type_id, false, $date_range);
     } else {
         if ($type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_CHECKIN || $type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_REVIEW || $type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_PHOTO) {
             $activities = Comments::getByType($activity_type, $this->type_id, $date_range);
         } else {
             $user_from = Users::find($this->user_id_from);
             $username_array[] = $user_from->getUserFullName();
         }
     }
     foreach ($activities as $activity) {
         if ($activity->user_id == $this->user_id_to) {
             continue;
         }
         $user_count++;
         $user_fullname = Users::getFullNameById($activity->user_id);
         if ($user_count <= CONSTANTS::NOTIFICATION_USER_GROUP_LIMIT && !in_array($user_fullname, $username_array)) {
             $username_array[] = $user_fullname;
         }
     }
     // Build payload
     $payload = array(KeyParser::id => $this->id, KeyParser::usernames_from => $username_array, KeyParser::count => $user_notification_count, KeyParser::type => $this->type, KeyParser::type_id => $this->type_id, KeyParser::restaurant_id => $this->restaurant_id, KeyParser::user_id_from => $this->user_id_from, KeyParser::user_id_to => $this->user_id_to, 'typeid' => '0', 'useridfrom' => '0', 'useridto' => '0', 'restaurantid' => '0', 'message' => $this->buildMessage());
     $restaurant_name = Restaurants::getRestaurantNameById($this->restaurant_id);
     if ($restaurant_name) {
         $payload[KeyParser::restaurant_name] = $restaurant_name;
     }
     $fields = array(KeyParser::registration_ids => $registration_ids, KeyParser::data => $payload);
     $headers = array('Authorization: key=' . GCM_API_KEY, 'Content-Type: application/json');
     //Prepare cURL
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, GCM_API_URL);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
     $result = curl_exec($ch);
     curl_close($ch);
     return $result;
 }
Beispiel #10
0
function checkTypeId($type, $type_id)
{
    switch ($type) {
        case CONSTANTS::REVIEW:
            $object = Reviews::find($type_id);
            $message = "Review does not exist";
            $error_code = CONSTANTS::ERROR_CODE_REVIEW_MISSING;
            break;
        case CONSTANTS::CHECKIN:
            $object = CheckIns::find($type_id);
            $message = "Checkin does not exist";
            $error_code = CONSTANTS::ERROR_CODE_CHECKIN_MISSING;
            break;
        case CONSTANTS::BOOKMARK:
            $object = Bookmarks::find($type_id);
            $message = "Bookmark does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::COMMENT:
            $object = Comments::find($type_id);
            $message = "Comment does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::PHOTO:
            $object = Photos::find($type_id);
            $message = "Photo does not exist";
            $error_code = CONSTANTS::ERROR_CODE_PHOTO_MISSING;
            break;
        case CONSTANTS::RESTAURANT:
            $object = Restaurants::find($type_id);
            $message = "Restaurant does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case 'user':
            $object = Users::find($type_id);
            $message = "User does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        default:
            return showErrorResponse('Invalid type', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_INVALID_TYPE);
    }
    if (!$object) {
        return showErrorResponse($message, HTTP_ACCEPTED, $error_code);
    }
    return false;
}
Beispiel #11
0
 /**
  * Delete Review
  * @param $id
  * @throws $e
  */
 public function deleteReview($id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $review = Reviews::find($id);
         if ($review) {
             //delete review
             $review->delete();
             //delete activities
             $activities = new Activities();
             $activities->deleteActivity(CONSTANTS::REVIEW, $id);
             //delete comments
             $comments = new Comments();
             $comments->deleteCommentByType(CONSTANTS::REVIEW, $id);
             //delete likes
             $like = new Like();
             $like->deleteLikes(CONSTANTS::REVIEW, $id);
         } else {
             throw new \Exception('No review found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Beispiel #12
0
 /**
  * Delete Checkin
  * @param $id
  * @throws $e
  */
 public function deleteCheckin($id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $checkin = CheckIns::find($id);
         if ($checkin) {
             //delete checkin
             $checkin->delete();
             //delete activities
             $activities = new Activities();
             $activities->deleteActivity(CONSTANTS::CHECKIN, $id);
             //delete comments
             $comments = new Comments();
             $comments->deleteCommentByType(CONSTANTS::CHECKIN, $id);
             //delete likes
             $like = new Like();
             $like->deleteLikes(CONSTANTS::CHECKIN, $id);
         } else {
             throw new \Exception('No checkin found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Beispiel #13
0
 /**
  * Delete comment
  *
  * @param $id
  * @return Response
  */
 public function deleteCommentAction($id)
 {
     $comment = Comments::find($id);
     if (!$comment) {
         return showErrorResponse('Comment not found');
     }
     $comment_type = $comment->type;
     $comment_type_id = $comment->type_id;
     try {
         $comment->deleteComment();
         $json_return[KeyParser::data] = array(KeyParser::id => $id, KeyParser::is_success => CONSTANTS::DELETE_SUCCESS);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     $comments = Comments::getByTypePaginate($comment_type, $comment_type_id);
     foreach ($comments as $comment) {
         $user = Users::find($comment->user_id);
         $json_return[KeyParser::comments][] = array(KeyParser::comment => ModelFormatter::commentFormat($comment), KeyParser::user => ModelFormatter::userFormat($user));
     }
     $json_return[KeyParser::comment_count] = Comments::getCountByType($comment_type, $comment_type_id);
     $json_return[KeyParser::page] = array(KeyParser::current => $comments->currentPage(), KeyParser::number => $comments->lastPage());
     return response()->json($json_return);
 }
Beispiel #14
0
 /**
  * Returns an array of photo data
  *
  * @param Photos $data
  * @return array
  */
 public static function photosFormat(Photos $data)
 {
     $viewer_id = Input::get('viewer_id');
     $short_photo_url = route('short_photo_view', ['id' => $data->id]);
     $arr = array();
     $arr[KeyParser::id] = $data->id;
     $arr[KeyParser::short_url] = $short_photo_url;
     $arr[KeyParser::restaurant_id] = $data->restaurant_id;
     $arr[KeyParser::type] = $data->type;
     $arr[KeyParser::type_id] = $data->type_id;
     $arr[KeyParser::user_id] = $data->user_id;
     $arr[KeyParser::text] = $data->text;
     $arr[KeyParser::url] = $data->url;
     $arr[KeyParser::date_uploaded] = elapsedTime($data->date_uploaded);
     $arr[KeyParser::status] = $data->status;
     $arr[KeyParser::comment_count] = Comments::getCountByType(CONSTANTS::PHOTO, $data->id);
     $arr[KeyParser::like_count] = Like::getCount(CONSTANTS::PHOTO, $data->id);
     if ($viewer_id) {
         $arr[KeyParser::is_liked] = Like::isLiked($viewer_id, CONSTANTS::PHOTO, $data->id);
     }
     return $arr;
 }
Beispiel #15
0
 /**
  * Delete a Photo
  * route: /photos/delete{id}
  *
  * @param Request $request
  * @return Response
  */
 public function photoDeleteAction(Request $request)
 {
     $path = API_UPLOAD_DIR . '/';
     $data = $request->json()->get('Photo');
     $failed_ids = array();
     $succeeded_ids = array();
     foreach ($data['id'] as $photo_id) {
         $photo = Photos::find($photo_id);
         if (!$photo || $photo->user_id != $data['user_id']) {
             $failed_ids[] = $photo_id;
             continue;
         }
         $filename = $photo->url;
         $fullpath = $path . $filename;
         try {
             DB::beginTransaction();
             if (FILE::exists($fullpath)) {
                 // Delete an array of files
                 //$files = array($file1, $file2);
                 FILE::delete($fullpath);
             }
             // end if Exists
             $comment = new Comments();
             $comment->deleteCommentByType(CONSTANTS::PHOTO, $photo->id);
             $like = new Like();
             $like->deleteLikes(CONSTANTS::PHOTO, $photo->id);
             $activity = new Activities();
             $activity->deleteActivity(CONSTANTS::PHOTO_UPLOAD_RESTAURANT, $photo->id);
             $photo->delete();
             DB::commit();
             $succeeded_ids[] = $photo_id;
         } catch (\Exception $e) {
             DB::rollback();
             return showErrorResponse('Error deleting photo');
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::success => $succeeded_ids, KeyParser::failed => $failed_ids);
     return response()->json($json_return);
 }
Beispiel #16
0
 /**
  * Delete comment/s and likes of the comment/s by type
  *
  * @param $type
  * @param $type_id
  * @return mixed
  * @throws \Exception
  */
 public function deleteCommentByType($type, $type_id)
 {
     try {
         $connection = $this->getConnection();
         $connection->beginTransaction();
         $comments = Comments::where('type', $type)->where('type_id', $type_id);
         if ($comments) {
             // TODO: Delete associated notification
             foreach ($comments as $comment) {
                 $like = new Like();
                 $like->deleteLikes(CONSTANTS::COMMENT, $comment->id);
                 $comment->delete();
             }
         } else {
             throw new \Exception('No comments found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Beispiel #17
0
 /**
  * Get the review, checkin, bookmark, follow, photos, comments, and notification data of a user
  *
  * @param $id
  * @param $viewer_id
  * @return array
  */
 public static function getStatistics($id, $viewer_id = false)
 {
     $user = self::find($id);
     if (!$user) {
         return array();
     }
     $user_array = ModelFormatter::userLongFormat($user);
     $user_array[KeyParser::review_count] = Reviews::getCountByUserId($id);
     $user_array[KeyParser::checkin_count] = CheckIns::getCountByUserId($id);
     $user_array[KeyParser::bookmark_count] = Bookmarks::getCountByUserId($id);
     $user_array[KeyParser::following_count] = Follow::getCountByUserId($id, CONSTANTS::FOLLOW_FOLLOWED);
     $user_array[KeyParser::follower_count] = Follow::getCountByUserId($id, CONSTANTS::FOLLOW_FOLLOWER);
     $user_array[KeyParser::photo_count] = Photos::getCountByUserId($id);
     $user_array[KeyParser::comment_count] = Comments::getCountByUserId($id);
     $user_array[KeyParser::unread_notification_count] = Notification::getNotificationByUserToCustomPaginate(CONSTANTS::NOTIFICATION_STATUS_UNREAD, CONSTANTS::ORDER_DESC, $id, null, true);
     $user_array[KeyParser::new_notification_count] = Notification::getNotificationByUserToCustomPaginate(CONSTANTS::NOTIFICATION_STATUS_NEW, CONSTANTS::ORDER_DESC, $id, null, true);
     if ($viewer_id) {
         $user_array[KeyParser::is_followed_by_viewer] = Follow::isFollowed($viewer_id, $id);
     }
     return $user_array;
 }
 public function getAvgComments()
 {
     // peut s'utiliser directement dans le Controller
     return Comments::avg('note');
 }