Пример #1
0
Файл: user.php Проект: anqh/anqh
 /**
  * Controller default action
  */
 public function action_index()
 {
     $user = $this->_get_user();
     // Helper variables
     $owner = Visitor::$user && Visitor::$user->id == $user->id;
     // Comments section
     if (Permission::has($user, Model_User::PERMISSION_COMMENTS)) {
         $errors = array();
         $values = array();
         // Handle comment
         if (Permission::has($user, Model_User::PERMISSION_COMMENT) && $_POST) {
             try {
                 $comment = Model_User_Comment::factory()->add(Visitor::$user->id, $user->id, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private'));
                 // Receiver
                 $user->comment_count++;
                 if (!$owner) {
                     $user->new_comment_count++;
                 }
                 $user->save();
                 // Sender
                 Visitor::$user->left_comment_count++;
                 Visitor::$user->save();
                 if ($this->_request_type !== Controller::REQUEST_AJAX) {
                     $this->request->redirect(Route::url('user', array('username' => urlencode($user->username))));
                     return;
                 }
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validation');
                 $values = $comment;
             }
         }
         // Mark own comments read
         if ($owner) {
             $user->mark_comments_read();
         }
         $section_comments = $this->section_comments($user, 'user_comment');
         $section_comments->errors = $errors;
         $section_comments->values = $values;
     } else {
         if (!Visitor::$user) {
             // Teaser for guests
             $section_comments = $this->section_comments_teaser($user->comment_count);
         }
     }
     if (isset($section_comments) && $this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->body($section_comments);
         return;
     }
     // Build page
     $this->view = self::_set_page($user);
     $this->view->tab = 'profile';
     // Newsfeed
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_newsfeed($user));
     // Comments
     if (isset($section_comments)) {
         $this->view->add(View_Page::COLUMN_CENTER, $section_comments);
     }
     // Portrait
     $this->view->add(View_Page::COLUMN_RIGHT, $this->section_carousel($user));
     // Info
     $this->view->add(View_Page::COLUMN_RIGHT, $this->section_info($user));
 }
Пример #2
0
Файл: user.php Проект: anqh/core
 /**
  * Controller default action
  */
 public function action_index()
 {
     $user = $this->_get_user();
     // Helper variables
     $owner = self::$user && self::$user->id == $user->id;
     // Comments section
     if (Permission::has($user, Model_User::PERMISSION_COMMENTS, self::$user)) {
         $errors = array();
         $values = array();
         // Handle comment
         if (Permission::has($user, Model_User::PERMISSION_COMMENT, self::$user) && $_POST) {
             try {
                 $comment = Model_User_Comment::factory()->add(self::$user->id, $user->id, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private'));
                 // Receiver
                 $user->comment_count++;
                 if (!$owner) {
                     $user->new_comment_count++;
                 }
                 $user->save();
                 // Sender
                 self::$user->left_comment_count++;
                 self::$user->save();
                 if ($this->_request_type !== Controller::REQUEST_AJAX) {
                     $this->request->redirect(Route::url('user', array('username' => urlencode($user->username))));
                     return;
                 }
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validation');
                 $values = $comment;
             }
         }
         // Mark own comments read
         if ($owner) {
             $user->mark_comments_read();
         }
         $section_comments = $this->section_comments($user, 'user_comment');
         $section_comments->errors = $errors;
         $section_comments->values = $values;
     } else {
         if (!self::$user) {
             // Teaser for guests
             $section_comments = $this->section_comments_teaser($user->comment_count);
         }
     }
     if (isset($section_comments) && $this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->body($section_comments);
         return;
     }
     // Build page
     $this->_set_page($user);
     $this->view->tab = 'profile';
     // Owner / admin actions
     if (Permission::has($user, Model_User::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => URL::user($user, 'image'), 'text' => '<i class="icon-picture icon-white"></i> ' . __('Add image'));
     }
     // Newsfeed
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_newsfeed($user));
     // Comments
     $this->view->add(View_Page::COLUMN_MAIN, $section_comments);
     // Portrait
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_carousel($user));
     // Info
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_info($user));
 }
Пример #3
0
Файл: user.php Проект: anqh/anqh
 /**
  * Get image comments
  *
  * @param   Model_User  $viewer
  * @param   View_Generic_Pagination  $pagination
  * @return  Model_User_Comment[]
  */
 public function comments(Model_User $viewer = null, View_Generic_Pagination $pagination = null)
 {
     $query = Model_Comment::query_viewer(DB::select_array(Model_User_Comment::factory()->fields()), $viewer)->order_by('id', 'DESC');
     if ($pagination) {
         $query = $query->offset($pagination->offset)->limit($pagination->items_per_page);
     }
     return $this->find_related('user_comments', $query);
 }