/** * @param array $options * @param int $type * * @return array|bool */ public function getUserGroupNotInCourse($options = array(), $type = -1) { $course_id = null; if (isset($options['course_id'])) { $course_id = intval($options['course_id']); unset($options['course_id']); } if (empty($course_id)) { return false; } $typeCondition = ''; if ($type != -1) { $type = intval($type); $typeCondition = " AND group_type = {$type} "; } if ($this->useMultipleUrl) { $urlId = api_get_current_access_url_id(); $sql = "SELECT DISTINCT u.*\n FROM {$this->table} u\n INNER JOIN {$this->access_url_rel_usergroup} a\n ON (a.usergroup_id = u.id)\n LEFT OUTER JOIN {$this->usergroup_rel_course_table} urc\n ON (u.id = urc.usergroup_id AND course_id = {$course_id})\n "; } else { $sql = "SELECT DISTINCT u.*\n FROM {$this->table} u\n LEFT OUTER JOIN {$this->usergroup_rel_course_table} urc\n ON (u.id = urc.usergroup_id AND course_id = {$course_id})\n "; } $conditions = Database::parse_conditions($options); if (empty($conditions)) { $conditions .= "WHERE 1 = 1 {$typeCondition} "; } else { $conditions .= " {$typeCondition} "; } $sql .= $conditions; if ($this->useMultipleUrl) { $sql .= " AND access_url_id = {$urlId}"; } if (isset($options['LIMIT'])) { $limits = explode(',', $options['LIMIT']); $limits = array_map('intval', $limits); if (isset($limits[0]) && isset($limits[1])) { $sql .= " LIMIT " . $limits[0] . ', ' . $limits[1]; } } $result = Database::query($sql); $array = Database::store_result($result, 'ASSOC'); return $array; }
/** * @param array $conditions * @param null $order_field_options_by * * @return array */ public function get_all($conditions = array(), $order_field_options_by = null) { $conditions = Database::parse_conditions(array('where' => $conditions)); if (empty($conditions)) { $conditions .= " WHERE extra_field_type = " . $this->extraFieldType; } else { $conditions .= " AND extra_field_type = " . $this->extraFieldType; } $sql = "SELECT * FROM {$this->table}\n {$conditions}\n ORDER BY field_order ASC\n "; $result = Database::query($sql); $extraFields = Database::store_result($result, 'ASSOC'); $option = new ExtraFieldOption($this->type); if (!empty($extraFields)) { foreach ($extraFields as &$extraField) { $extraField['options'] = $option->get_field_options_by_field($extraField['id'], false, $order_field_options_by); } } return $extraFields; }
/** * @param array $options * * @return array|bool */ public function get_usergroup_not_in_course($options = array()) { $course_id = null; if (isset($options['course_id'])) { $course_id = intval($options['course_id']); unset($options['course_id']); } if (empty($course_id)) { return false; } if ($this->useMultipleUrl) { $urlId = api_get_current_access_url_id(); $sql = "SELECT DISTINCT u.id, name FROM {$this->table} u INNER JOIN {$this->access_url_rel_usergroup} a ON (a.usergroup_id = u.id) LEFT OUTER JOIN {$this->usergroup_rel_course_table} urc ON (u.id = urc.usergroup_id AND course_id = $course_id) "; } else { $sql = "SELECT DISTINCT u.id, name FROM {$this->table} u LEFT OUTER JOIN {$this->usergroup_rel_course_table} urc ON (u.id = urc.usergroup_id AND course_id = $course_id) "; } $conditions = Database::parse_conditions($options); $sql .= $conditions; if ($this->useMultipleUrl) { $sql .= " AND access_url_id = $urlId"; } if (isset($options['LIMIT'])) { $limits = explode(',', $options['LIMIT']); $limits = array_map('intval', $limits); if (isset($limits[0]) && isset($limits[1])) { $sql .= " LIMIT ".$limits[0].', '.$limits[1]; } } $result = Database::query($sql); $array = Database::store_result($result, 'ASSOC'); return $array; }
/** * This method is the constructor for the learnpathList. It gets a list of available learning paths from * the database and creates the learnpath objects. This list depends on the user that is connected * (only displays) items if he has enough permissions to view them. * @param integer $user_id * @param string $course_code Optional course code (otherwise we use api_get_course_id()) * @param int $session_id Optional session id (otherwise we use api_get_session_id()) * @param string $order_by * @param string $check_publication_dates * @param int $categoryId * * @return void */ public function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false, $categoryId = null) { $course_info = api_get_course_info($course_code); $lp_table = Database::get_course_table(TABLE_LP_MAIN); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $this->course_code = $course_code; $this->user_id = $user_id; $course_id = $course_info['real_id']; if (empty($course_id)) { return false; } // Condition for the session. if (isset($session_id)) { $session_id = intval($session_id); } else { $session_id = api_get_session_id(); } $condition_session = api_get_session_condition($session_id, true, true); $order = "ORDER BY display_order ASC, name ASC"; if (isset($order_by)) { $order = Database::parse_conditions(array('order' => $order_by)); } $now = api_get_utc_datetime(); $time_conditions = ''; if ($check_publication_dates) { $time_conditions = " AND (\n (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '{$now}' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '{$now}' ) OR\n (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '{$now}' AND expired_on = '0000-00-00 00:00:00') OR\n (publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '{$now}') OR\n (publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' ))\n "; } if (!empty($categoryId)) { $categoryId = intval($categoryId); $categoryFilter = " AND category_id = {$categoryId}"; } else { $categoryFilter = " AND (category_id = 0 OR category_id IS NULL) "; } $sql = "SELECT * FROM {$lp_table}\n WHERE\n c_id = {$course_id}\n {$time_conditions}\n {$condition_session}\n {$categoryFilter}\n {$order}\n "; $res = Database::query($sql); $names = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { // Use domesticate here instead of Database::escape_string because // it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility()) // is done using domesticate() $myname = domesticate($row['name']); $mylink = 'newscorm/lp_controller.php?action=view&lp_id=' . $row['id'] . '&id_session=' . $session_id; $sql2 = "SELECT * FROM {$tbl_tool}\n WHERE\n c_id = {$course_id} AND (\n name='{$myname}' AND\n image='scormbuilder.gif' AND\n link LIKE '{$mylink}%'\n )"; $res2 = Database::query($sql2); if (Database::num_rows($res2) > 0) { $row2 = Database::fetch_array($res2); $pub = $row2['visibility']; } else { $pub = 'i'; } // Check if visible. $vis = api_get_item_visibility(api_get_course_info($course_code), 'learnpath', $row['id'], $session_id); if (!empty($row['created_on']) && $row['created_on'] != '0000-00-00 00:00:00') { $row['created_on'] = $row['created_on']; } else { $row['created_on'] = ''; } if (!empty($row['modified_on']) && $row['modified_on'] != '0000-00-00 00:00:00') { $row['modified_on'] = $row['modified_on']; } else { $row['modified_on'] = ''; } if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') { $row['publicated_on'] = $row['publicated_on']; } else { $row['publicated_on'] = ''; } if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') { $row['expired_on'] = $row['expired_on']; } else { $row['expired_on'] = ''; } $this->list[$row['id']] = array('lp_type' => $row['lp_type'], 'lp_session' => $row['session_id'], 'lp_name' => stripslashes($row['name']), 'lp_desc' => stripslashes($row['description']), 'lp_path' => $row['path'], 'lp_view_mode' => $row['default_view_mod'], 'lp_force_commit' => $row['force_commit'], 'lp_maker' => stripslashes($row['content_maker']), 'lp_proximity' => $row['content_local'], 'lp_encoding' => api_get_system_encoding(), 'lp_visibility' => $vis, 'lp_published' => $pub, 'lp_prevent_reinit' => $row['prevent_reinit'], 'seriousgame_mode' => $row['seriousgame_mode'], 'lp_scorm_debug' => $row['debug'], 'lp_display_order' => $row['display_order'], 'lp_preview_image' => stripslashes($row['preview_image']), 'autolaunch' => $row['autolaunch'], 'session_id' => $row['session_id'], 'created_on' => $row['created_on'], 'modified_on' => $row['modified_on'], 'publicated_on' => $row['publicated_on'], 'expired_on' => $row['expired_on'], 'subscribe_users' => $row['subscribe_users']); $names[$row['name']] = $row['id']; } $this->alpha_list = asort($names); }
public function get_usergroup_not_in_course($options = array()) { $course_id = null; if (isset($options['course_id'])) { $course_id = intval($options['course_id']); unset($options['course_id']); } if (empty($course_id)) { return false; } $sql = "SELECT DISTINCT u.id, name\n FROM {$this->table} u\n LEFT OUTER JOIN {$this->usergroup_rel_course_table} urc\n ON (u.id = urc.usergroup_id AND course_id = {$course_id})\n "; $conditions = Database::parse_conditions($options); $sql .= $conditions; $result = Database::query($sql); $array = Database::store_result($result, 'ASSOC'); return $array; }