/**
  * 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);
     }
 }
Exemple #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();
 }
Exemple #3
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();
 }
Exemple #4
0
 /**
  * Mark this section as the default for this offering
  *
  * @return  boolean
  */
 public function makeDefault()
 {
     if (!$this->exists() || !$this->get('offering_id')) {
         return true;
     }
     $sections = $this->_tbl->find(array('offering_id' => $this->get('offering_id')));
     foreach ($sections as $section) {
         $section = new Section($section);
         $section->set('is_default', 0);
         $section->store(false);
     }
     $this->set('is_default', 1);
     return $this->store(false);
 }
 /**
  * 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();
 }
Exemple #6
0
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=registrations.csv");
header("Pragma: no-cache");
header("Expires: 0");
foreach ($this->rows as $row) {
    $section = \Components\Courses\Models\Section::getInstance($row->get('section_id'));
    echo encodeCSVField($row->get('user_id'));
    echo ',';
    echo encodeCSVField($row->get('name'));
    echo ',';
    echo encodeCSVField($row->get('email'));
    echo ',';
    echo encodeCSVField($section->exists()) ? $this->escape(stripslashes($section->get('title'))) : Lang::txt('COM_COURSES_NONE');
    echo ',';
    if ($row->get('enrolled') && $row->get('enrolled') != '0000-00-00 00:00:00') {
        echo encodeCSVField(Date::of($row->get('enrolled'))->toLocal(Lang::txt('DATE_FORMAT_HZ1')));
    } else {
        echo encodeCSVField(Lang::txt('COM_COURSES_UNKNOWN'));
    }
    echo "\n";
}
 /**
  * Set the state of a course
  *
  * @return void
  */
 public function stateTask($state = 0)
 {
     // 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
             $section = \Components\Courses\Models\Section::getInstance($id);
             // Ensure we found the course info
             if (!$section->exists()) {
                 continue;
             }
             //set the course to be published and update
             $section->set('state', $state);
             if (!$section->store()) {
                 $this->setError(Lang::txt('COM_COURSES_ERROR_UNABLE_TO_SET_STATE', $id));
                 continue;
             }
             $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 . '&offering=' . Request::getInt('offering', 0), false), $state ? Lang::txt('COM_COURSES_ITEMS_PUBLISHED', $num) : Lang::txt('COM_COURSES_ITEMS_UNPUBLISHED', $num));
     }
 }
Exemple #8
0
 /**
  * Cancel a task (redirects to default task)
  *
  * @return  void
  */
 public function optionsTask()
 {
     $section = Request::getInt('section', 0);
     $this->view->section = \Components\Courses\Models\Section::getInstance($section);
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
 /**
  * Create a section linked to this offering
  *
  * @param   boolean $validate Validate data?
  * @return  boolean True on success, False on error
  */
 public function makeSection($alias = '__default', $is_default = 1)
 {
     $section = new Section();
     $section->set('offering_id', $this->get('id'));
     $section->set('alias', $alias);
     $section->set('title', Lang::txt('Default'));
     $section->set('state', 1);
     $section->set('is_default', $is_default);
     $section->set('enrollment', $this->config('default_enrollment', 0));
     $section->set('start_date', $this->get('start_date'));
     $section->set('end_date', $this->get('end_date'));
     $section->set('publish_up', $this->get('publish_up'));
     $section->set('publish_down', $this->get('publish_down'));
     if (!$section->store()) {
         $this->setError($section->getError());
         return false;
     }
     $this->_sections = null;
     return true;
 }