Example #1
0
 public function action_index()
 {
     $sort = $this->request->param('sort', 'name');
     $order = $this->request->param('order', 'ASC');
     Session::instance()->delete('course_id');
     $criteria = array('user' => Acl::instance()->relevant_user(), 'filters' => array('name' => $this->request->param('filter_name'), 'access_code' => $this->request->param('filter_access_code'), 'start_date' => $this->request->param('filter_start_date'), 'end_date' => $this->request->param('filter_end_date')));
     $total = Model_Course::courses_total($criteria);
     $pagination = Pagination::factory(array('total_items' => $total, 'items_per_page' => 5));
     $criteria = array_merge($criteria, array('sort' => $sort, 'order' => $order, 'limit' => $pagination->items_per_page, 'offset' => $pagination->offset));
     $courses = Model_Course::courses($criteria);
     $sorting = new Sort(array('Course' => 'name', 'Access Code' => 'access_code', 'Start Date' => 'start_date', 'End Date' => 'end_date', 'Actions' => ''));
     $url = 'course/index';
     if ($this->request->param('filter_name')) {
         $url .= '/filter_name/' . $this->request->param('filter_name');
         $filter = $this->request->param('filter_name');
         $filter_select = 'filter_name';
     }
     if ($this->request->param('filter_access_code')) {
         $url .= '/filter_access_code/' . $this->request->param('filter_access_code');
         $filter = $this->request->param('filter_access_code');
         $filter_select = 'filter_access_code';
     }
     if ($this->request->param('filter_start_date')) {
         $url .= '/filter_start_date/' . $this->request->param('filter_start_date');
         $filter = $this->request->param('filter_start_date');
         $filter_select = 'filter_start_date';
     }
     if ($this->request->param('filter_end_date')) {
         $url .= '/filter_end_date/' . $this->request->param('filter_end_date');
         $filter = $this->request->param('filter_end_date');
         $filter_select = 'filter_end_date';
     }
     $sorting->set_link($url);
     $sorting->set_order($order);
     $sorting->set_sort($sort);
     $heading = $sorting->render();
     // Render the pagination links
     $pagination = $pagination->render();
     $links = array('add' => Html::anchor('/course/add/', 'Create a course', array('class' => 'createButton l')), 'delete' => URL::site('/course/delete/'), 'join' => Html::anchor('/course/join/', 'Join Course', array('class' => 'pageAction c')));
     $table = array('heading' => $heading, 'data' => $courses);
     $filter_name = $this->request->param('filter_name');
     $filter_access_code = $this->request->param('filter_access_code');
     $filter_start_date = $this->request->param('filter_start_date');
     $filter_end_date = $this->request->param('filter_end_date');
     $filter_url = URL::site('course/index');
     $success = Session::instance()->get('success');
     Session::instance()->delete('success');
     $view = View::factory('course/list')->bind('table', $table)->bind('count', $total)->bind('links', $links)->bind('pagination', $pagination)->bind('filter', $filter)->bind('filter_select', $filter_select)->bind('filter_url', $filter_url)->bind('success', $success);
     Breadcrumbs::add(array('Courses', Url::site('course')));
     $this->content = $view;
 }
Example #2
0
 public function action_upload()
 {
     $submitted = FALSE;
     if ($this->request->method() === 'POST' && $this->request->post()) {
         if (Arr::get($this->request->post(), 'save') !== null) {
             $submitted = TRUE;
             $document = ORM::factory('document');
             $validator = $document->validator(array_merge($this->request->post(), $_FILES));
             $validator->bind(':files', $_FILES['name']);
             if ($validator->check()) {
                 $filename = Upload::save($_FILES['name'], NULL, UPLOAD_PATH);
                 $document = ORM::factory('document');
                 $document->values($this->request->post());
                 $document->name = basename($filename);
                 $document->time = time();
                 $document->save();
                 $document->add('courses', $this->request->post('course_id'));
                 $document->add('roles', $this->request->post('role'));
                 foreach ($this->request->post('course_id') as $course_id) {
                     $feed = new Feed_Document();
                     $feed->set_action('add');
                     $feed->set_course_id($course_id);
                     $feed->set_respective_id($document->id);
                     $feed->set_actor_id(Auth::instance()->get_user()->id);
                     $stream_data = array('course_id' => $course_id, 'role_id' => $this->request->post('role'));
                     $feed->streams($stream_data);
                     $feed->save();
                 }
                 Request::current()->redirect('document');
             } else {
                 $this->_errors = $validator->errors('document');
             }
         }
     }
     $courses = Model_Course::courses()->as_array('id', 'name');
     $course_id = Session::instance()->get('course_id');
     //remove the current course from the list
     unset($courses[$course_id]);
     $form = new Stickyform('document/upload', array('enctype' => "multipart/form-data"), $submitted ? $this->_errors : array());
     $form->default_data = array('title' => '', 'user_id' => Auth::instance()->get_user()->id, 'course_id' => 0, 'role' => 0);
     $form->posted_data = $submitted ? $this->request->post() : array();
     $form->append('Title', 'title', 'text');
     $form->append('Access To', 'role', 'text');
     $form->append('User', 'user_id', 'hidden');
     $form->append('File', 'name', 'file');
     $form->append('Also add to', 'course_id', 'select', array('options' => $courses, 'attributes' => array('multiple' => 'multiple', 'name' => 'course_id[]')));
     $form->append('Upload', 'save', 'submit', array('attributes' => array('class' => 'button')));
     $form->process();
     $course = ORM::factory('course', $course_id);
     $roles = ORM::factory('role')->find_all()->as_array('id', 'name');
     $view = View::factory('document/form')->bind('form', $form)->bind('course', $course)->bind('roles', $roles);
     Breadcrumbs::add(array('Courses', Url::site('course')));
     Breadcrumbs::add(array('Documents', Url::site('document')));
     Breadcrumbs::add(array('Upload', Url::site('document/upload')));
     $this->content = $view;
 }