<?php

define('INTERNAL', 1);
define('PUBLIC', 1);
define('JSON', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
safe_require('artefact', 'courses');
$filter = param_alpha('filter', 'all');
$query = param_variable('query', '');
$eschool_param = param_integer('eschool', 0);
$category_param = param_variable('category', 0);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if ($eschool_param == 0) {
    $available_eschools = $CFG->current_app->getMnetEschools();
    $courselist = ArtefactTypeCourses::get_courses($filter, $query, $limit, $offset, $available_eschools, 0);
} else {
    $eschools = array();
    array_push($eschools, Doctrine::getTable('GcrEschool')->findOneById($eschool_param));
    $courselist = ArtefactTypeCourses::get_courses($filter, $query, $limit, $offset, $eschools, $category_param);
}
$data = ArtefactTypeCourses::build_courselist_html($courselist, 'index', $eschool_param, $category_param);
json_reply(false, array('data' => $data));
Ejemplo n.º 2
0
function course_create_submit(Pieform $form, $values)
{
    global $CFG;
    $mhr_user = $CFG->current_app->getCurrentUser();
    try {
        $new_category = ArtefactTypeCourses::create_category($values);
        $results = ArtefactTypeCourses::create_course($values, $new_category);
        if (!$results) {
            $CFG->current_app->gcError('Course creation error', 'gcdatabaseerror');
        } else {
            foreach ($results as $course_data) {
                $eschool = Doctrine::getTable('GcrEschool')->findOneById($values['eschool']);
                $mdl_course = $eschool->getCourse($course_data['id']);
                if (isset($values['password'])) {
                    $eschool->alterGcrEnrollmentByName($mdl_course, 'password', $values['password']);
                }
                if ($values['cost'] > 0) {
                    $eschool->alterGcrEnrollmentByName($mdl_course, 'cost', $values['cost']);
                }
                $mdl_user = $mhr_user->getUserOnEschool($eschool, true);
                $mdl_user->enrolUserinCourse($mdl_course, $eschool, '3');
                if ($mhr_user->hasEclassroom()) {
                    if ($mdl_role = $eschool->selectFromMdlTable('role', 'shortname', 'eclassroomcourseowner', true)) {
                        $mdl_user->enrolUserinCourse($mdl_course, $eschool, $mdl_role->id);
                    }
                }
            }
            redirect($eschool->getAppUrl() . "/course/view.php?id=" . $course_data['id'] . "&transfer=" . $CFG->current_app->getShortName());
        }
    } catch (Exception $e) {
        $CFG->current_app->gcError('Problem with create course submission: ' . $e, 'gcdatabaseerror');
    }
}