コード例 #1
0
ファイル: Group.php プロジェクト: Godefroy/iseplive
 /**
  * Show the profile of a group
  */
 public function view($params)
 {
     $this->setView('view.php');
     try {
         $group = $this->model->getInfoByName($params['group']);
         $this->set('group', $group);
     } catch (Exception $e) {
         throw new ActionException('Page', 'error404');
     }
     $this->setTitle(__('GROUP_TITLE', array('group' => htmlspecialchars($group['name']))));
     $is_logged = isset(User_Model::$auth_data);
     $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     $category = isset($params['category']) ? $params['category'] : null;
     $category_model = new Category_Model();
     $post_model = new Post_Model();
     $this->set(array('is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin, 'categories' => $category_model->getAll(), 'current_category' => $category, 'posts' => $post_model->getPosts(array('restricted' => true, 'group_id' => (int) $group['id'], 'category_name' => $category, 'official' => $is_logged ? null : true, 'show_private' => $is_student), Config::POST_DISPLAYED)));
     // Events
     $event_model = new Event_Model();
     $this->set(array('events' => $event_model->getByMonth((int) date('Y'), (int) date('n'), array('group_id' => (int) $group['id'], 'official' => $is_logged ? null : true, 'show_private' => $is_student)), 'calendar_month' => (int) date('n'), 'calendar_year' => (int) date('Y')));
     // If the user is logged
     if ($is_logged) {
         $this->set(array('username' => User_Model::$auth_data['username'], 'groups_auth' => Group_Model::getAuth()));
     }
     if ($is_student) {
         $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
     }
 }
コード例 #2
0
ファイル: Student.php プロジェクト: Godefroy/iseplive
 /**
  * Show the profile of a student
  */
 public function view($params)
 {
     $this->setView('view.php');
     $is_logged = isset(User_Model::$auth_data);
     $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // If the user isn't logged in
     if (!$is_logged) {
         throw new ActionException('User', 'signin', array('redirect' => $_SERVER['REQUEST_URI']));
     }
     try {
         $student = $this->model->getInfo($params['username']);
         $post_model = new Post_Model();
         $this->setTitle(htmlspecialchars($student['firstname'] . ' ' . $student['lastname']));
         $this->set(array('student' => $student, 'groups' => isset($student['id']) ? Group_Model::getAuth((int) $student['id']) : array(), 'is_owner' => User_Model::$auth_data['username'] == $student['username'], 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin, 'username' => User_Model::$auth_data['username']));
         if ($is_student) {
             $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
         }
         // If the student is a user, we show their posts
         if (isset($student['id'])) {
             $category = isset($params['category']) ? $params['category'] : null;
             $category_model = new Category_Model();
             $this->set(array('posts' => $post_model->getPosts(array('restricted' => true, 'user_id' => (int) $student['id'], 'category_name' => $category, 'official' => false, 'show_private' => $is_student), Config::POST_DISPLAYED), 'categories' => $category_model->getAll(), 'current_category' => $category));
         }
     } catch (Exception $e) {
         throw new ActionException('Page', 'error404');
     }
 }
コード例 #3
0
ファイル: Search.php プロジェクト: hugonicolas/Site
 /**
  * Search posts, groups, and students
  */
 public function index($params)
 {
     $this->setView('index.php');
     $is_logged = isset(User_Model::$auth_data);
     $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     if (!isset($_GET['q'])) {
         throw new ActionException('Page', 'error404');
     }
     $limit = 100;
     $results = $this->model->search($_GET['q'], null, $limit, !$is_logged, $is_student);
     $posts_ids = array();
     $students_usernames = array();
     $groups_ids = array();
     foreach ($results as &$result) {
         switch ($result['_type']) {
             case 'student':
                 $students_usernames[] = $result['_id'];
                 break;
             case 'group':
                 $groups_ids[] = (int) $result['_id'];
                 break;
             case 'post':
                 $posts_ids[] = (int) $result['_id'];
                 break;
         }
     }
     $post_model = new Post_Model();
     $this->setTitle(__('SEARCH_TITLE', array('query' => htmlspecialchars($_GET['q']))));
     $this->set(array('query' => $_GET['q'], 'posts' => $post_model->getPosts(array('restricted' => true, 'ids' => $posts_ids, 'show_private' => $is_student), $limit), 'students' => Student_Model::getInfoByUsernames($students_usernames), 'groups' => Group_Model::getInfoByIds($groups_ids), 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin));
     if ($is_logged) {
         $this->set(array('username' => User_Model::$auth_data['username']));
     }
     if ($is_student) {
         $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
     }
 }
コード例 #4
0
ファイル: android.php プロジェクト: hugonicolas/Site
 // Lecture des posts demandés et
 $model = new Post_Model();
 // Parametres de base :
 $postParam = array('restricted' => true, 'show_private' => true);
 if (isset($_GET['id']) && $_GET['id'] != "-1") {
     $postParam['id'] = $_GET['id'];
 }
 if (isset($_GET['official']) && $_GET['official'] == "true") {
     $postParam['official'] = true;
 } elseif (isset($_GET['official']) && $_GET['official'] == "false") {
     $postParam['official'] = false;
 }
 if (isset($_GET['category']) && $_GET['category'] != "") {
     $postParam['category_id'] = $_GET['category'];
 }
 $posts = $model->getPosts($postParam, 5);
 foreach ($posts as $post) {
     $postXml = $xml->createElement('post');
     $node = $xml->createElement('group', $post['group_name']);
     $postXml->appendChild($node);
     $node = $xml->createElement('user', $post['username']);
     $postXml->appendChild($node);
     try {
         $message = $post['message'];
     } catch (Exception $e) {
         $message = "";
     }
     $node = $xml->createElement('message', $message);
     $postXml->appendChild($node);
     $node = $xml->createElement('id', $post['id']);
     $postXml->appendChild($node);