/** * Returns the course id. * * @return int */ public static function get_c_id() { $result = Request::get(self::PARAM_C_ID, 0); $result = intval($result); $result = $result ? $result : api_get_real_course_id(); $result = $result ? $result : 0; return $result; }
/** * Room constructor. */ public function __construct() { $this->table = \Database::get_main_table('plugin_openmeetings'); $this->name = 'C' . api_get_real_course_id() . '-' . api_get_session_id(); $accessUrl = api_get_access_url(api_get_current_access_url_id()); $this->externalRoomType = substr($accessUrl['url'], strpos($accessUrl['url'], '://') + 3, -1); if (strcmp($this->externalRoomType, 'localhost') == 0) { $this->externalRoomType = substr(api_get_path(WEB_PATH), strpos(api_get_path(WEB_PATH), '://') + 3, -1); } $this->externalRoomType = 'chamilolms.' . $this->externalRoomType; }
/** * Create a group for every class subscribed to the current course * @param int $category_id The category in which the groups should be created * @return array */ public static function create_class_groups($category_id) { $options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id()); $obj = new UserGroup(); $classes = $obj->get_usergroup_in_course($options); $group_ids = array(); foreach ($classes as $class) { $users_ids = $obj->get_users_by_usergroup($class['id']); $group_id = self::create_group($class['name'], $category_id, 0, count($users_ids)); self::subscribe_users($users_ids, $group_id); $group_ids[] = $group_id; } return $group_ids; }
/** * Insert a row like history inside track_e_item_property table * first you must set description_type, title, content, progress and * session_id properties with the object CourseDescription * @param int description type * @return int affected rows */ public function insert_stats($description_type) { $tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY); $description_id = $this->get_id_by_description_type($description_type); $course_id = api_get_real_course_id(); $course_code = api_get_course_id(); $item_property_id = api_get_item_property_id($course_code, TOOL_COURSE_DESCRIPTION, $description_id); $params = ['c_id' => api_get_course_int_id(), 'course_id' => $course_id, 'item_property_id' => $item_property_id, 'title' => $this->title, 'content' => $this->content, 'progress' => $this->progress, 'lastedit_date' => api_get_utc_datetime(), 'lastedit_user_id' => api_get_user_id(), 'session_id' => $this->session_id]; Database::insert($tbl_stats_item_property, $params); return 1; }
/** * @param string $tool * @param int $ref * @return array|resource */ function api_get_track_item_property_history($tool, $ref) { $tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY); $course_id = api_get_real_course_id(); //numeric $course_code = api_get_course_id(); //alphanumeric $item_property_id = api_get_item_property_id($course_code, $tool, $ref); $sql = "SELECT * FROM {$tbl_stats_item_property}\n WHERE item_property_id = {$item_property_id} AND course_id = {$course_id}\n ORDER BY lastedit_date DESC"; $result = Database::query($sql); $result = Database::store_result($result, 'ASSOC'); return $result; }
$group_el[] = $create_subgroups_form->createElement('static', null, null, get_lang('CreateNumberOfGroups')); $group_el[] = $create_subgroups_form->createElement('text', 'number_of_groups', null, array('size' => 3)); $group_el[] = $create_subgroups_form->createElement('static', null, null, get_lang('WithUsersFrom')); $group_el[] = $create_subgroups_form->createElement('select', 'base_group', null, $base_group_options); $group_el[] = $create_subgroups_form->createElement('button', 'submit', get_lang('Ok')); $create_subgroups_form->addGroup($group_el, 'create_groups', null, ' ', false); $defaults = array(); $defaults['action'] = 'create_subgroups'; $create_subgroups_form->setDefaults($defaults); $create_subgroups_form->display(); } } /* * Show form to generate groups from classes subscribed to the course */ $options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id()); $obj = new UserGroup(); $classes = $obj->get_usergroup_in_course($options); if (count($classes) > 0) { echo '<b>' . get_lang('GroupsFromClasses') . '</b>'; echo '<blockquote>'; echo '<p>' . get_lang('GroupsFromClassesInfo') . '</p>'; echo '<ul>'; foreach ($classes as $index => $class) { $number_of_users = count($obj->get_users_by_usergroup($class['id'])); echo '<li>'; echo $class['name']; echo ' (' . $number_of_users . ' ' . get_lang('Users') . ')'; echo '</li>'; } echo '</ul>';
/** * Insert a row like history inside track_e_item_property table * first you must set description_type, title, content, progress and session_id properties with the object CourseDescription * @param int description type * @return int affected rows */ public function insert_stats($description_type) { $tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY); $description_id = $this->get_id_by_description_type($description_type); $course_id = api_get_real_course_id(); $course_code = api_get_course_id(); $item_property_id = api_get_item_property_id($course_code, TOOL_COURSE_DESCRIPTION, $description_id); $sql = "INSERT IGNORE INTO {$tbl_stats_item_property} SET\n\t\t\t\tc_id\t\t\t\t= " . api_get_course_int_id() . ",\n\t\t\t\tcourse_id \t\t\t= '{$course_id}',\n\t\t\t \titem_property_id \t= '{$item_property_id}',\n\t\t\t \ttitle \t\t\t\t= '" . Database::escape_string($this->title) . "',\n\t\t\t \tcontent \t\t\t= '" . Database::escape_string($this->content) . "',\n\t\t\t \tprogress \t\t\t= '" . intval($this->progress) . "',\n\t\t\t \tlastedit_date \t\t= '" . date('Y-m-d H:i:s') . "',\n\t\t\t \tlastedit_user_id \t= '" . api_get_user_id() . "',\n\t\t\t \tsession_id\t\t\t= '" . intval($this->session_id) . "'"; $result = Database::query($sql); $affected_rows = Database::affected_rows($result); return $affected_rows; }
/** * Generates an HTML Certificate and fills the path_certificate field in the DB **/ public function generate($params = array()) { // The user directory should be set if (empty($this->certification_user_path) && $this->force_certificate_generation == false) { return false; } $params['hide_print_button'] = isset($params['hide_print_button']) ? true : false; $my_category = Category::load($this->certificate_data['cat_id']); if (isset($my_category[0]) && $my_category[0]->is_certificate_available($this->user_id)) { $user = api_get_user_info($this->user_id); $scoredisplay = ScoreDisplay::instance(); $scorecourse = $my_category[0]->calc_score($this->user_id); $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'); // Prepare all necessary variables: $organization_name = api_get_setting('platform.institution'); //$portal_name = api_get_setting('platform.site_name'); $stud_fn = $user['firstname']; $stud_ln = $user['lastname']; //@todo this code is not needed $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn . ' ' . $stud_ln, $my_category[0]->get_name(), $scorecourse_display); $certif_text = str_replace("\\n", "\n", $certif_text); //If the gradebook is related to skills we added the skills to the user $courseId = api_get_real_course_id(); $sessionId = api_get_session_id(); $skill = new Skill(); $skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id'], $courseId, $sessionId); if (is_dir($this->certification_user_path)) { if (!empty($this->certificate_data)) { $new_content_html = GradebookUtils::get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), $my_category[0]->get_session_id(), false, $params['hide_print_button']); if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) { $name = $this->certificate_data['path_certificate']; $my_path_certificate = $this->certification_user_path . basename($name); if (file_exists($my_path_certificate) && !empty($name) && !is_dir($my_path_certificate) && $this->force_certificate_generation == false) { //Seems that the file was already generated return true; } else { // Creating new name $name = md5($this->user_id . $this->certificate_data['cat_id']) . '.html'; $my_path_certificate = $this->certification_user_path . $name; $path_certificate = '/' . $name; //Getting QR filename $file_info = pathinfo($path_certificate); $qr_code_filename = $this->certification_user_path . $file_info['filename'] . '_qr.png'; $my_new_content_html = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path . $file_info['filename'] . '_qr.png', 'QR'), $new_content_html['content']); $my_new_content_html = mb_convert_encoding($my_new_content_html, 'UTF-8', api_get_system_encoding()); $result = @file_put_contents($my_path_certificate, $my_new_content_html); if ($result) { //Updating the path self::update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate); $this->certificate_data['path_certificate'] = $path_certificate; if ($this->html_file_is_generated()) { if (!empty($file_info)) { $text = $this->parse_certificate_variables($new_content_html['variables']); $this->generate_qr($text, $qr_code_filename); } } } return $result; } } } } } return false; }