Exemple #1
0
 public function action_new()
 {
     if (Auth::instance()->logged_in()) {
         $view = View::factory('topic/new');
         $category = new Model_Category();
         $category_id = $this->request->param('id');
         $view->categories = $category->find_all();
         $user_id = Auth::instance()->get_user()->pk();
         $view->role_id = ORM::factory('Roles_User')->get_last_role_id($user_id);
         $user_id = Auth::instance()->get_user()->pk();
         $users = ORM::factory('User')->get_data($user_id);
         $this->template->content = $view->render();
         if ($this->request->method() === Request::POST) {
             if (!Security::check($this->request->param('id'))) {
                 throw new Exception("Bad token!");
             }
             $title = $this->request->post('title');
             $category_id = $this->request->post('category_id');
             $author = $user_id;
             $content = $this->request->post('content');
             if (empty($title) or empty($category_id) or empty($author) or empty($content)) {
                 throw new Exception("Fields cannot be empty!");
             }
             $data = array('title' => $title, 'category_id' => $category_id, 'author_id' => $author, 'content' => $content, 'published' => time());
             $topic = new Model_Topic();
             $publish_topic = $topic->publish($data);
             if (!$publish_topic) {
                 throw new Exception("Cannot publish your topic!");
             }
             $this->request->redirect('category/index/' . $category_id);
         }
     } else {
         $this->redirect('');
     }
 }
 public function action_index()
 {
     $cat = new Model_Category();
     $list_cat = $cat->find_all();
     // get all to print at sidebar view
     $loc = new Model_Location();
     $list_loc = $loc->find_all();
     // get all to print at sidebar view
     $user = Auth::instance()->get_user();
     $ads = new Model_Ad();
     Controller::$full_width = TRUE;
     $my_adverts = $ads->where('id_user', '=', $user->id_user);
     $res_count = $my_adverts->count_all();
     if ($res_count > 0) {
         $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $res_count, 'items_per_page' => core::config('advertisement.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My ads'))->set_url(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index'))));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(sprintf(__("Page %d"), $pagination->current_page)));
         $ads = $my_adverts->order_by('published', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
         $this->template->content = View::factory('oc-panel/profile/ads', array('ads' => $ads, 'pagination' => $pagination, 'category' => $list_cat, 'location' => $list_loc, 'user' => $user));
     } else {
         $this->template->content = View::factory('oc-panel/profile/ads', array('ads' => $ads, 'pagination' => NULL, 'category' => NULL, 'location' => NULL, 'user' => $user));
     }
 }