예제 #1
0
 /**
  * Set the state of a course
  *
  * @return  void
  */
 public function stateTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     $state = $this->_task == 'publish' ? 1 : 0;
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Do we have any IDs?
     $num = 0;
     if (!empty($ids)) {
         //foreach course id passed in
         foreach ($ids as $id) {
             // Load the course page
             $model = new \Components\Courses\Models\Page($id);
             // Ensure we found the course info
             if (!$model->exists()) {
                 continue;
             }
             //set the course to be published and update
             $model->set('active', $state);
             if (!$model->store()) {
                 $this->setError(Lang::txt('COM_COURSES_ERROR_UNABLE_TO_SET_STATE', $id));
                 continue;
             }
             // Log the course approval
             $model->log($model->get('id'), 'page', $state ? 'published' : 'unpublished');
             $num++;
         }
     }
     if ($this->getErrors()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), implode('<br />', $this->getErrors()), 'error');
     } else {
         // Output messsage and redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $state ? Lang::txt('COM_COURSES_ITEMS_PUBLISHED', $num) : Lang::txt('COM_COURSES_ITEMS_UNPUBLISHED', $num));
     }
 }
예제 #2
0
 /**
  * Display a list of files
  *
  * @return  void
  */
 public function _fileList()
 {
     $page = new \Components\Courses\Models\Page(Request::getInt('page', 0));
     if (!$page->exists()) {
         $page->set('offering_id', $this->view->offering->get('id'));
         $page->set('section_id', Request::getInt('section_id', 0));
     }
     $path = $this->_path($page);
     $folders = array();
     $docs = array();
     if (is_dir($path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new DirectoryIterator($path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             if ($file->isDir()) {
                 $name = $file->getFilename();
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 $name = $file->getFilename();
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->docs = $docs;
     $this->view->folders = $folders;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setLayout('list');
 }