Exemple #1
0
 public function index($type = NULL)
 {
     //Event::add('system.post_controller', 'foo');
     if ($this->access->allowed('papers', 'read')) {
         $filtered = in_array($type, array('standard', 'digital', 'sticky'));
         $total = ORM::factory('paper')->where('status != ', 'deleted');
         if ($filtered) {
             $total->where('type', $type);
         }
         $total = $total->count_all();
         $paging = new Pagination(array('total_items' => $total));
         $view = new view(url::routes_area() . 'index');
         $list = new view(url::routes_area() . 'index_list');
         $list_papers = ORM::factory('paper')->orderby('name', 'asc')->where('status != ', 'deleted');
         if ($filtered) {
             $list_papers->where('type', $type);
         }
         $list->papers = $list_papers->find_all($paging->items_per_page, $paging->sql_offset);
         if (request::is_ajax()) {
             // ajax request return all the data the index will require to repopulate
             $this->ajax['list'] = $list->__toString();
             $this->ajax['page_number'] = $paging->page_number()->__toString();
             $this->ajax['pagination'] = $paging->render();
         } else {
             if ($filtered) {
                 // replace the last bread crumb
                 $this->breadcrumbs->add()->url(url::location())->title(ucwords($type));
             }
             $view->pagination = $paging->render();
             $view->page_number = $paging->page_number();
             $view->list = $list;
             $this->template->content = $view;
             $this->template->title = $filtered ? ucwords($type) . ' Papers' : 'Papers';
         }
     } else {
         Kohana::log('debug', 'User failed constructor security check');
         url::failed();
     }
 }
Exemple #2
0
 /**
  * Method for displaying a users lightboxes, the only people who should have access to this page are
  * user of the system.
  *
  * @todo add notification for fails
  */
 public function index()
 {
     // get the current user.
     $user = Security::instance()->get_user();
     // sanity check
     if ($user && $user->loaded) {
         if ($this->access->allowed('lightboxes', 'index')) {
             $paging = new Pagination(array('total_items' => ORM::factory('lightbox')->where('creator_id', $user->id)->count_all()));
             $view = new view(url::routes_area() . 'index');
             $view->breadcrumbs = $this->breadcrumbs->get();
             $this->breadcrumbs->delete();
             $list = new view(url::routes_area() . 'index_list');
             $list->lightboxes = ORM::factory('lightbox')->orderby('updated', 'desc')->where('creator_id', $user->id)->find_all($paging->items_per_page, $paging->sql_offset);
             if (request::is_ajax()) {
                 // ajax request return all the data the index will require to repopulate
                 $this->ajax['list'] = $list->__toString();
                 $this->ajax['page_number'] = $paging->page_number()->__toString();
                 $this->ajax['pagination'] = $paging->render();
             } else {
                 $view->pagination = $paging->render();
                 $view->page_number = $paging->page_number();
                 $view->list = $list;
                 $this->template->content = $view;
                 $this->template->title = 'Papers';
             }
         } else {
             // they are logged in, but dont have access to the page.
             // you cant go to an index of a lightbox with out being logged into an account.
             Kohana::log('debug', 'User failed constructor security check');
             url::failed();
         }
     } else {
         // instead of the generic message, instead give them a nice messgae, or redirect to login page.
         Kohana::log('debug', 'User failed constructor security check');
         url::failed(url::current());
     }
 }