/**
  * Constructor
  *
  * @param      integer $id  Resource ID
  * @param      integer $sid Section ID
  * @return     void
  */
 public function __construct($oid, $sid = null)
 {
     $this->_db = \App::get('db');
     $this->_tbl = new $this->_tbl_name($this->_db);
     if (is_numeric($oid)) {
         // Check if this is the default section
         if (!is_null($sid)) {
             $section = new Section($sid);
             if (!$section->get('is_default')) {
                 $config = Component::params('com_courses');
                 $canEdit = $config->get('section_grade_policy', true);
                 if (!$canEdit) {
                     // We need to find the default section and use that grade policy
                     $offering = new Offering($section->get('offering_id'));
                     $default = $offering->section('!!default!!');
                     $oid = $default->get('grade_policy_id');
                 }
             }
         }
         $this->_tbl->load($oid);
     }
 }
示例#2
0
 /**
  * Execute a task
  *
  * @return     void
  */
 public function execute()
 {
     if ($section_id = Request::getInt('section', 0, 'get')) {
         $section = Models\Section::getInstance($section_id);
         if ($section->exists()) {
             $offering = Models\Offering::getInstance($section->get('offering_id'));
             $offering->section($section->get('alias'));
             App::redirect(Route::url($offering->link('overview')));
         }
     }
     $this->registerTask('__default', 'intro');
     $this->_authorize('course');
     parent::execute();
 }
示例#3
0
 /**
  * Constructor
  *
  * @param   integer  $scope_id  Scope ID (group, course, etc.)
  * @return  void
  */
 public function __construct($scope_id = 0)
 {
     $this->set('scope_id', $scope_id);
     include_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'courses.php';
     $offering = \Components\Courses\Models\Offering::getInstance($this->get('scope_id'));
     $course = \Components\Courses\Models\Course::getInstance($offering->get('course_id'));
     $this->_segments['gid'] = $course->get('alias');
     $this->_segments['offering'] = $offering->alias();
     $this->_segments['active'] = 'discussions';
     if (Request::getVar('active') == 'outline') {
         $this->_segments['active'] = 'outline';
     }
     $this->_name = String::truncate($course->get('alias'), 50) . ': ' . String::truncate($offering->get('alias'), 50);
 }
示例#4
0
 /**
  * Get items reported as abusive
  *
  * @param   integer  $refid     Comment ID
  * @param   string   $category  Item type (kb)
  * @param   integer  $parent    Parent ID
  * @return  array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if ($category != 'forum') {
         return null;
     }
     $query = "SELECT rc.id, rc.comment as `text`, rc.parent, rc.created_by as author, rc.created, rc.title as subject, rc.anonymous as anon, 'forum' AS parent_category,\n\t\t\t\t\ts.alias AS section, c.alias AS category, rc.scope, rc.scope_id, rc.object_id, rc.thread\n\t\t\t\t\tFROM `#__forum_posts` AS rc\n\t\t\t\t\tLEFT JOIN `#__forum_categories` AS c ON c.id = rc.category_id\n\t\t\t\t\tLEFT JOIN `#__forum_sections` AS s ON s.id = c.section_id\n\t\t\t\t\tWHERE rc.id=" . $refid;
     $database = App::get('db');
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'models' . DS . 'manager.php';
         foreach ($rows as $key => $row) {
             /*$thread = $row->id;
             		if ($row->parent)
             		{
             			$thread = $this->_getThread($row->parent);
             		}*/
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             switch ($row->scope) {
                 case 'course':
                     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'course.php';
                     $offering = \Components\Courses\Models\Offering::getInstance($row->scope_id);
                     $course = \Components\Courses\Models\Course::getInstance($offering->get('course_id'));
                     $url = 'index.php?option=com_courses&gid=' . $course->get('alias') . '&controller=offering&offering=' . $offering->get('alias') . '&active=discussions&thread=' . $row->thread;
                     break;
                 case 'group':
                     $group = \Hubzero\User\Group::getInstance($row->scope_id);
                     $url = 'index.php?option=com_groups&cn=' . $group->get('cn') . '&active=forum&scope=' . $row->section . '/' . $row->category . '/' . $parent;
                     break;
                 case 'site':
                 default:
                     $url = 'index.php?option=com_forum&section=' . $row->section . '&category=' . $row->category . '&thread=' . $parent;
                     break;
             }
             $rows[$key]->href = Route::url($url);
         }
     }
     return $rows;
 }
示例#5
0
 /**
  * Get the state of the entry as either text or numerical value
  *
  * @param      string  $as      Format to return state in [text, number]
  * @param      integer $shorten Number of characters to shorten text to
  * @return     mixed String or Integer
  */
 public function content($as = 'parsed', $shorten = 0)
 {
     $as = strtolower($as);
     $options = array();
     switch ($as) {
         case 'parsed':
             $content = $this->get('content_parsed', null);
             if ($content === null) {
                 $config = array('option' => Request::getCmd('option', 'com_courses'), 'scope' => Request::getVar('gid', ''), 'pagename' => $this->get('url'), 'pageid' => '', 'filepath' => DS . ltrim($this->config()->get('uploadpath', '/site/courses'), DS) . DS . $this->get('course_id') . DS . 'pagefiles' . ($this->get('offering_id') ? DS . $this->get('offering_id') : ''), 'domain' => $this->get('course_id'));
                 if ($this->get('offering_id')) {
                     $config['scope'] = Course::getInstance($this->get('course_id'))->get('alias') . DS . Offering::getInstance($this->get('offering_id'))->get('alias') . DS . 'pages';
                 }
                 if ($this->get('section_id')) {
                     $config['filepath'] = DS . trim($this->config()->get('uploadpath', '/site/courses'), DS) . DS . $this->get('course_id') . DS . 'sections' . DS . $this->get('section_id') . DS . 'pagefiles';
                 }
                 $content = $this->get('content');
                 $this->importPlugin('content')->trigger('onContentPrepare', array($this->_context, &$this, &$config));
                 $this->set('content_parsed', (string) $this->get('content'));
                 $this->set('content', $content);
                 return $this->content($as, $shorten);
             }
             $options['html'] = true;
             break;
         case 'clean':
             $content = strip_tags($this->content('parsed'));
             break;
         case 'raw':
         default:
             $content = $this->get('content');
             $content = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $content);
             $content = html_entity_decode($content);
             break;
     }
     if ($shorten) {
         $content = String::truncate($content, $shorten, $options);
     }
     return $content;
 }
示例#6
0
 /**
  * Displays a list of codes
  *
  * @return  void
  */
 public function displayTask()
 {
     // Incoming
     $this->view->filters = array('section' => Request::getState($this->_option . '.' . $this->_controller . '.section', 'section', 0), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'redeemed' => Request::getState($this->_option . '.' . $this->_controller . '.redeemed', 'redeemed', '-1'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $this->view->section = \Components\Courses\Models\Section::getInstance($this->view->filters['section']);
     if (!$this->view->section->exists()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=courses', false));
         return;
     }
     $this->view->offering = \Components\Courses\Models\Offering::getInstance($this->view->section->get('offering_id'));
     $this->view->course = \Components\Courses\Models\Course::getInstance($this->view->offering->get('course_id'));
     // In case limit has been changed, adjust limitstart accordingly
     $this->view->filters['start'] = $this->view->filters['limit'] != 0 ? floor($this->view->filters['start'] / $this->view->filters['limit']) * $this->view->filters['limit'] : 0;
     $this->view->filters['count'] = true;
     $this->view->total = $this->view->section->codes($this->view->filters);
     $this->view->filters['count'] = false;
     $this->view->rows = $this->view->section->codes($this->view->filters);
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
示例#7
0
 /**
  * Get the section logo
  *
  * @param      string $rtrn Property to return
  * @return     string
  */
 public function logo($rtrn = '')
 {
     $rtrn = strtolower(trim($rtrn));
     // Return just the file name
     if ($rtrn == 'file') {
         return $this->params('logo');
     }
     // We need the course ID
     if (!$this->get('course_id')) {
         $offering = Offering::getInstance($this->get('offering_id'));
         $this->set('course_id', $offering->get('course_id'));
     }
     // Build the path
     $path = '/' . trim($this->config('uploadpath', '/site/courses'), '/') . '/' . $this->get('course_id') . '/sections/' . $this->get('id');
     // Return just the upload path?
     if ($rtrn == 'path') {
         return $path;
     }
     // Do we have a logo set?
     if ($file = $this->params('logo')) {
         // Return the web path to the image
         $path .= '/' . $file;
         if (file_exists(PATH_APP . $path)) {
             $path = str_replace('/administrator', '', \Request::base(true)) . $path;
         }
         if ($rtrn == 'url') {
             $offering = Offering::getInstance($this->get('offering_id'));
             return $offering->link() . '&active=logo';
         }
         return $path;
     }
     return '';
 }
示例#8
0
 /**
  * Display a list of 'manager' for a specific section
  *
  * @param   object  $model  \Components\Courses\Models\Offering
  * @return  void
  */
 public function displayTask($model = null)
 {
     // Incoming
     if (!$model instanceof \Components\Courses\Models\Offering) {
         $model = \Components\Courses\Models\Offering::getInstance(Request::getInt('offering', 0, 'get'));
         if ($section = Request::getInt('section', 0)) {
             $model->section($section);
         }
     }
     $this->view->model = $model;
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->setLayout('display')->display();
 }
示例#9
0
 /**
  * Display an offering asset
  *
  * @return     void
  */
 public function enrollTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_COURSES_ENROLLMENT_REQUIRES_LOGIN'));
         return;
     }
     $offering = $this->course->offering();
     // Is the user a manager or student?
     if ($offering->isManager() || $offering->isStudent()) {
         // Yes! Already enrolled
         // Redirect back to the course page
         App::redirect(Route::url($offering->link()), Lang::txt('COM_COURSES_ALREADY_ENROLLED'));
         return;
     }
     $this->view->course = $this->course;
     // Build the title
     $this->_buildTitle();
     // Build pathway
     $this->_buildPathway();
     // Can the user enroll?
     if (!$offering->section()->canEnroll()) {
         $this->view->setLayout('enroll_closed');
         $this->view->display();
         return;
     }
     $enrolled = false;
     // If enrollment is open OR a coupon code was posted
     if (!$offering->section()->get('enrollment') || ($code = Request::getVar('code', ''))) {
         $section_id = $offering->section()->get('id');
         // If a coupon code was posted
         if (isset($code)) {
             // Get the coupon
             $coupon = $offering->section()->code($code);
             // Is it a valid code?
             if (!$coupon->exists()) {
                 $this->setError(Lang::txt('COM_COURSES_ERROR_CODE_INVALID', $code));
             }
             // Has it already been redeemed?
             if ($coupon->isRedeemed()) {
                 $this->setError(Lang::txt('COM_COURSES_ERROR_CODE_ALREADY_REDEEMED', $code));
             } else {
                 // Has it expired?
                 if ($coupon->isExpired()) {
                     $this->setError(Lang::txt('COM_COURSES_ERROR_CODE_EXPIRED', $code));
                 }
             }
             if (!$this->getError()) {
                 // Is this a coupon for a different section?
                 if ($offering->section()->get('id') != $coupon->get('section_id')) {
                     $section = \Components\Courses\Models\Section::getInstance($coupon->get('section_id'));
                     if ($section->exists() && $section->get('offering_id') != $offering->get('id')) {
                         $offering = \Components\Courses\Models\Offering::getInstance($section->get('offering_id'));
                         if ($offering->exists() && $offering->get('course_id') != $this->course->get('id')) {
                             $this->course = \Components\Courses\Models\Course::getInstance($offering->get('course_id'));
                         }
                     }
                     App::redirect(Route::url($offering->link() . '&task=enroll&code=' . $code));
                     return;
                 }
                 // Redeem the code
                 $coupon->redeem(User::get('id'));
                 // set('redeemed_by', User::get('id'));
                 //$coupon->store();
             }
         }
         // If no errors
         if (!$this->getError()) {
             // Add the user to the course
             $model = new \Components\Courses\Models\Member(0);
             //::getInstance(User::get('id'), $offering->get('id'));
             $model->set('user_id', User::get('id'));
             $model->set('course_id', $this->course->get('id'));
             $model->set('offering_id', $offering->get('id'));
             $model->set('section_id', $offering->section()->get('id'));
             if ($roles = $offering->roles()) {
                 foreach ($roles as $role) {
                     if ($role->alias == 'student') {
                         $model->set('role_id', $role->id);
                         break;
                     }
                 }
             }
             $model->set('student', 1);
             if ($model->store(true)) {
                 $enrolled = true;
             } else {
                 $this->setError($model->getError());
             }
         }
     }
     if ($enrolled) {
         $link = $offering->link();
         $data = Event::trigger('courses.onCourseEnrolled', array($this->course, $offering, $offering->section()));
         if ($data && count($data) > 0) {
             $link = implode('', $data);
         }
         App::redirect(Route::url($link));
         return;
     }
     // If enrollment is srestricted and the user isn't enrolled yet
     if ($offering->section()->get('enrollment') == 1 && !$enrolled) {
         // Show a form for entering a coupon code
         $this->view->setLayout('enroll_restricted');
     }
     if ($this->getError()) {
         \Notify::error($this->getError(), 'courses');
     }
     $this->view->notifications = \Notify::messages('courses');
     $this->view->display();
 }
示例#10
0
 /**
  * Displays an edit form
  *
  * @return  void
  */
 public function editTask($model = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!is_object($model)) {
         // Incoming
         $id = Request::getVar('id', array(0));
         // Get the single ID we're working with
         if (is_array($id)) {
             $id = !empty($id) ? $id[0] : '';
         }
         $model = new \Components\Courses\Models\Assetgroup($id);
     }
     $this->view->row = $model;
     if (!$this->view->row->get('unit_id')) {
         $this->view->row->set('unit_id', Request::getInt('unit', 0));
     }
     $this->view->unit = \Components\Courses\Models\Unit::getInstance($this->view->row->get('unit_id'));
     $this->view->offering = \Components\Courses\Models\Offering::getInstance($this->view->unit->get('offering_id'));
     $rows = $this->view->unit->assetgroups();
     // establish the hierarchy of the menu
     $children = array(0 => array());
     $levellimit = 500;
     // first pass - collect children
     foreach ($rows as $v) {
         $children[0][] = $v;
         $children[$v->get('id')] = $v->children();
     }
     // second pass - get an indent list of the items
     $this->view->assetgroups = $this->treeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
     // Set any errors
     foreach ($this->getErrors() as $error) {
         \Notify::error($error);
     }
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }
示例#11
0
 /**
  * Edit a course page
  *
  * @return void
  */
 public function editTask($model = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!is_object($model)) {
         // Incoming
         $id = Request::getVar('id', array(0));
         // Get the single ID we're working with
         if (is_array($id)) {
             $id = !empty($id) ? $id[0] : 0;
         }
         $model = new \Components\Courses\Models\Page($id);
     }
     $this->view->row = $model;
     if (!$this->view->row->get('course_id')) {
         $this->view->row->set('course_id', Request::getInt('course', 0));
     }
     if (!$this->view->row->get('offering_id')) {
         $this->view->row->set('offering_id', Request::getInt('offering', 0));
     }
     if (!$this->view->row->exists()) {
         $this->view->row->set('active', 1);
     }
     $this->view->course = \Components\Courses\Models\Course::getInstance($this->view->row->get('course_id'));
     $this->view->offering = \Components\Courses\Models\Offering::getInstance($this->view->row->get('offering_id'));
     // Set any errors
     foreach ($this->getErrors() as $error) {
         \Notify::error($error);
     }
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }
示例#12
0
 /**
  * Set and get a specific offering
  *
  * @return     void
  */
 public function offering($id = null)
 {
     // If the current offering isn't set
     //    OR the ID passed doesn't equal the current offering's ID or alias
     if (!isset($this->_offering) || $id !== null && (int) $this->_offering->get('id') != $id && (string) $this->_offering->get('alias') != $id) {
         // Reset current offering
         $this->_offering = null;
         // If the list of all offerings is available ...
         if (isset($this->_offerings)) {
             // Find an offering in the list that matches the ID passed
             foreach ($this->offerings() as $key => $offering) {
                 if ((int) $offering->get('id') == $id || (string) $offering->get('alias') == $id) {
                     // Set current offering
                     $this->_offering = $offering;
                     break;
                 }
             }
         }
         if (is_null($this->_offering)) {
             // Get current offering
             $this->_offering = Offering::getInstance($id, $this->get('id'));
         }
     }
     // Return current offering
     return $this->_offering;
 }
示例#13
0
 /**
  * Show a form for editing a course
  *
  * @return     void
  */
 public function saveofferingTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_COURSES_NOT_LOGGEDIN'));
         return;
     }
     $data = Request::getVar('offering', array(), 'post', 'none', 2);
     $no_html = Request::getInt('no_html', 0);
     $course = Models\Course::getInstance($data['course_id']);
     $offering = Models\Offering::getInstance($data['id']);
     // Is this a new entry or updating?
     $isNew = false;
     if (!$offering->exists()) {
         $isNew = true;
     }
     $response = new stdClass();
     $response->success = true;
     // Push back into edit mode if any errors
     if (!$offering->bind($data)) {
         if ($no_html) {
             $response->message = $offering->getError();
             echo json_encode($response);
         } else {
             Notify::error($offering->getError(), 'courses');
             $this->newofferingTask($offering);
         }
         return;
     }
     // Push back into edit mode if any errors
     if (!$offering->store(true)) {
         if ($no_html) {
             $response->message = $offering->getError();
         } else {
             Notify::error($offering->getError(), 'courses');
             $this->newTask($offering);
         }
         return;
     }
     $response->message = Lang::txt('COM_COURSES_OFFERING_SAVED');
     if ($no_html) {
         echo json_encode($response);
     } else {
         // Redirect back to the course page
         App::redirect(Route::url($course->link()), $response->message);
     }
 }
示例#14
0
 /**
  * Reorder entries
  *
  * @return  void
  */
 public function orderTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $id = Request::getVar('id', array(0), 'post', 'array');
     \Hubzero\Utility\Arr::toInteger($id, array(0));
     $uid = $id[0];
     $inc = $this->_task == 'orderup' ? -1 : 1;
     $row = new Tables\Unit($this->database);
     $row->load($uid);
     $row->move($inc, 'offering_id=' . $this->database->Quote($row->offering_id));
     $offering = \Components\Courses\Models\Offering::getInstance(Request::getInt('offering', 0));
     foreach ($offering->units() as $unit) {
         $unit->store();
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . Request::getInt('offering', 0), false));
 }
示例#15
0
 /**
  * Removes a course and all associated information
  *
  * @return	void
  */
 public function deleteTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $offering_id = Request::getInt('offering', 0);
     $num = 0;
     // Do we have any IDs?
     if (!empty($ids)) {
         $offering_id = 0;
         foreach ($ids as $id) {
             // Load the course page
             $model = \Components\Courses\Models\Section::getInstance($id);
             // Ensure we found the course info
             if (!$model->exists()) {
                 continue;
             }
             $offering_id = $model->get('offering_id');
             // Delete course
             if (!$model->delete()) {
                 throw new Exception(Lang::txt('COM_COURSES_ERROR_UNABLE_TO_REMOVE_ENTRY'), 500);
             }
             $num++;
         }
         if ($num && $offering_id) {
             $filters = array('count' => true, 'offering_id' => $offering_id, 'is_default' => 1);
             $offering = \Components\Courses\Models\Offering::getInstance($filters['offering_id']);
             if (!$offering->sections($filters)) {
                 $sections = $offering->sections(array('count' => false, 'sort' => 'id', 'sort_Dir' => 'ASC', 'limit' => 1, 'start' => 0));
                 foreach ($sections as $section) {
                     $section->makeDefault();
                 }
             }
         }
     }
     // Redirect back to the courses page
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . $offering_id, false), Lang::txt('COM_COURSES_ITEMS_REMOVED', $num));
 }
示例#16
0
    foreach ($this->threads as $thread) {
        $view = $this->view('_thread');
        $view->set('option', $this->option)->set('course', $this->course)->set('unit', $this->unit)->set('lecture', $this->lecture)->set('config', $this->config)->set('thread', $thread)->set('cls', $cls)->set('base', $this->base)->set('search', $this->search)->set('active', isset($this->active) ? $this->active : '');
        if (!$thread->scope_sub_id) {
            $subs[] = $thread->id;
        }
        if (isset($this->instructors)) {
            $view->set('instructors', $this->instructors);
        }
        if (isset($this->prfx)) {
            $view->set('prfx', $this->prfx);
        }
        $view->display();
    }
    if (count($subs) > 0) {
        $offering = \Components\Courses\Models\Offering::getInstance(Request::getVar('offering', ''));
        if ($offering->exists()) {
            $database = App::get('db');
            $database->setQuery("UPDATE `#__forum_posts` SET scope_sub_id=" . $offering->section()->get('id') . " WHERE scope='course' AND scope_sub_id=0 AND id IN(" . implode(",", $subs) . ")");
            if (!$database->query()) {
                echo '<!-- Failed to update data -->';
            }
        }
    }
} else {
    ?>
	<li class="comments-none">
		<p><?php 
    echo Lang::txt('PLG_COURSES_DISCUSSIONS_NO_TOPICS_FOUND');
    ?>
</p>
示例#17
0
 /**
  * Display a file and its info
  *
  * @param   string   $file  File name
  * @param   integer  $id    User ID
  * @return  void
  */
 public function displayTask($file = '', $id = 0)
 {
     // Load the component config
     $this->view->config = $this->config;
     // Incoming
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     $this->view->id = $id;
     $this->view->type = strtolower(Request::getWord('type', ''));
     // Build the file path
     $this->view->dir = $id;
     $this->view->path = $this->_path($this->view->type, $id);
     switch ($this->view->type) {
         case 'section':
             $model = \Components\Courses\Models\Section::getInstance($id);
             $this->view->file = $model->params('logo');
             break;
         case 'offering':
             $model = \Components\Courses\Models\Offering::getInstance($id);
             $this->view->file = $model->params('logo');
             break;
         case 'course':
             $model = \Components\Courses\Models\Course::getInstance($id);
             $this->view->file = $model->get('logo');
             break;
         default:
             $this->setError(Lang::txt('COM_COURSES_ERROR_INVALID_TYPE'));
             return;
             break;
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->setLayout('display')->display();
 }
示例#18
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 = \Components\Courses\Models\Offering::getInstance($id);
             // Ensure we found the course info
             if (!$model->exists()) {
                 continue;
             }
             //set the course to be published and update
             $model->set('state', $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'), 'offering', $state ? 'published' : 'unpublished');
             $num++;
         }
     }
     if ($this->getErrors()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&course=' . Request::getInt('course', 0), false), implode('<br />', $this->getErrors()), 'error');
     } else {
         // Output messsage and redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&course=' . Request::getInt('course', 0), false), $state ? Lang::txt('COM_COURSES_ITEMS_PUBLISHED', $num) : Lang::txt('COM_COURSES_ITEMS_UNPUBLISHED', $num));
     }
 }
示例#19
0
 /**
  * Event call to return data for a specific member
  *
  * @param      object  $user   User
  * @param      object  $member MembersProfile
  * @param      string  $option Component name
  * @param      string  $areas  Plugins to return data
  * @return     array   Return array of html
  */
 public function onMembers($user, $member, $option, $areas)
 {
     $returnhtml = true;
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onMembersAreas($user, $member)) && !array_intersect($areas, array_keys($this->onMembersAreas($user, $member)))) {
             $returnhtml = false;
         }
     }
     $arr = array('html' => '', 'metadata' => array('count' => 0));
     $this->database = App::get('db');
     $this->member = $member;
     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'offering.php';
     $model = \Components\Courses\Models\Offering::getInstance();
     $roles = $model->roles();
     $hasRoles = 0;
     if ($roles) {
         foreach ($roles as $i => $role) {
             $roles[$i]->total = $this->_getData('count', $role->alias);
             if ($roles[$i]->total > 0) {
                 $hasRoles++;
             }
             $arr['metadata']['count'] += $roles[$i]->total;
         }
     }
     // Build the HTML
     if ($returnhtml) {
         $view = $this->view('default', 'display');
         $view->option = $option;
         $view->member = $member;
         $view->roles = $roles;
         $view->hasRoles = $hasRoles;
         $view->filters = array();
         $view->filters['limit'] = Request::getState($option . '.plugin.courses.limit', 'limit', Config::get('list_limit'), 'int');
         $view->filters['start'] = Request::getState($option . '.plugin.courses.limitstart', 'limitstart', 0, 'int');
         $view->filters['task'] = strtolower(Request::getVar('action', ''));
         $view->filters['sort'] = strtolower(Request::getWord('sort', 'enrolled'));
         if (!in_array($view->filters['sort'], array('enrolled', 'title'))) {
             $view->filters['sort'] = 'enrolled';
         }
         $view->total = 0;
         $view->results = null;
         $view->active = null;
         $view->results = null;
         if ($view->hasRoles >= 1) {
             $found = false;
             if ($view->filters['task']) {
                 foreach ($roles as $i => $role) {
                     if ($view->filters['task'] == $role->alias && $role->total > 0) {
                         $found = true;
                     }
                 }
             }
             if (!$found) {
                 foreach ($roles as $i => $role) {
                     if ($role->total > 0) {
                         $view->filters['task'] = $role->alias;
                         break;
                     }
                 }
             }
         }
         foreach ($view->roles as $i => $role) {
             if ($view->filters['task'] == $role->alias) {
                 $view->active = $view->roles[$i];
                 $view->total = $view->roles[$i]->total;
             }
         }
         if (!is_null($view->active)) {
             $view->results = $this->_getData('list', $view->active->alias, $view->filters);
         }
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         $arr['html'] = $view->loadTemplate();
     }
     return $arr;
 }
示例#20
0
 /**
  * Save students info as CSV file
  *
  * @return  void
  */
 public function csvTask()
 {
     $this->view->filters = array('offering' => Request::getState($this->_option . '.' . $this->_controller . '.offering', 'offering', 0), 'section_id' => Request::getState($this->_option . '.' . $this->_controller . '.section', 'section', 0));
     $this->view->offering = \Components\Courses\Models\Offering::getInstance($this->view->filters['offering']);
     $this->view->filters['offering_id'] = $this->view->filters['offering'];
     $this->view->course = \Components\Courses\Models\Course::getInstance($this->view->offering->get('course_id'));
     if (!$this->view->filters['offering_id']) {
         $this->view->filters['offering_id'] = null;
     }
     if (!$this->view->filters['section_id']) {
         $this->view->filters['section_id'] = null;
     }
     $this->view->filters['student'] = 1;
     $tbl = new Tables\Member($this->database);
     $this->view->rows = $tbl->find($this->view->filters);
     //$this->view->offering->students($this->view->filters);
     if ($this->view->rows) {
         foreach ($this->view->rows as $key => $row) {
             $this->view->rows[$key] = new \Components\Courses\Models\Student($row);
         }
     }
     // Output the CSV
     $this->view->display();
 }