mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'wip-MDL-36014-master' of git://github.com/marinaglancy/moodle
Conflicts: lib/db/install.xml lib/db/upgrade.php version.php
This commit is contained in:
commit
4a813f3959
26 changed files with 704 additions and 238 deletions
|
@ -723,8 +723,7 @@ $capabilities = array(
|
|||
)
|
||||
),
|
||||
|
||||
// view members of a cohort, this can be used in course context too,
|
||||
// this also controls the ability to actually use cohort
|
||||
// View visible and hidden cohorts defined in the current context.
|
||||
'moodle/cohort:view' => array(
|
||||
|
||||
'captype' => 'read',
|
||||
|
|
|
@ -2092,6 +2092,7 @@
|
|||
<FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="Unique identifier of a cohort, useful especially for mapping to external entities"/>
|
||||
<FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Standard description text box"/>
|
||||
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Visibility to teachers"/>
|
||||
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="Component (plugintype_pluignname) that manages the cohort, manual modifications are allowed only when set to NULL"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
|
|
|
@ -3949,5 +3949,20 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint(true, 2014100700.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2014100700.01) {
|
||||
|
||||
// Define field visible to be added to cohort.
|
||||
$table = new xmldb_table('cohort');
|
||||
$field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'descriptionformat');
|
||||
|
||||
// Conditionally launch add field visible.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2014100700.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4448,3 +4448,93 @@ function coursemodule_visible_for_user($cm, $userid=0) {
|
|||
'Replace with \core_availability\info_module::is_user_visible().');
|
||||
return \core_availability\info_module::is_user_visible($cm, $userid, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the cohorts the user is able to view.
|
||||
*
|
||||
* @deprecated since Moodle 2.8 MDL-36014 please use enrol_cohort_search_cohorts()
|
||||
*
|
||||
* @param course_enrolment_manager $manager
|
||||
* @return array
|
||||
*/
|
||||
function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/enrol/cohort/locallib.php');
|
||||
debugging('Function enrol_cohort_get_cohorts() is deprecated, use enrol_cohort_search_cohorts() or '.
|
||||
'cohort_get_available_cohorts() instead', DEBUG_DEVELOPER);
|
||||
return enrol_cohort_search_cohorts($manager, 0, 0, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if cohort exists and user is allowed to enrol it.
|
||||
*
|
||||
* This function is deprecated, use {@link cohort_can_view_cohort()} instead since it also
|
||||
* takes into account current context
|
||||
*
|
||||
* @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
|
||||
*
|
||||
* @param int $cohortid Cohort ID
|
||||
* @return boolean
|
||||
*/
|
||||
function enrol_cohort_can_view_cohort($cohortid) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/cohort/lib.php');
|
||||
debugging('Function enrol_cohort_can_view_cohort() is deprecated, use cohort_can_view_cohort() instead',
|
||||
DEBUG_DEVELOPER);
|
||||
return cohort_can_view_cohort($cohortid, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of cohorts from course parent contexts.
|
||||
*
|
||||
* Note: this function does not implement any capability checks,
|
||||
* it means it may disclose existence of cohorts,
|
||||
* make sure it is displayed to users with appropriate rights only.
|
||||
*
|
||||
* It is advisable to use {@link cohort_get_available_cohorts()} instead.
|
||||
*
|
||||
* @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
|
||||
*
|
||||
* @param stdClass $course
|
||||
* @param bool $onlyenrolled true means include only cohorts with enrolled users
|
||||
* @return array of cohort names with number of enrolled users
|
||||
*/
|
||||
function cohort_get_visible_list($course, $onlyenrolled=true) {
|
||||
global $DB;
|
||||
|
||||
debugging('Function cohort_get_visible_list() is deprecated. Please use function cohort_get_available_cohorts() ".
|
||||
"that correctly checks capabilities.', DEBUG_DEVELOPER);
|
||||
|
||||
$context = context_course::instance($course->id);
|
||||
list($esql, $params) = get_enrolled_sql($context);
|
||||
list($parentsql, $params2) = $DB->get_in_or_equal($context->get_parent_context_ids(), SQL_PARAMS_NAMED);
|
||||
$params = array_merge($params, $params2);
|
||||
|
||||
if ($onlyenrolled) {
|
||||
$left = "";
|
||||
$having = "HAVING COUNT(u.id) > 0";
|
||||
} else {
|
||||
$left = "LEFT";
|
||||
$having = "";
|
||||
}
|
||||
|
||||
$sql = "SELECT c.id, c.name, c.contextid, c.idnumber, c.visible, COUNT(u.id) AS cnt
|
||||
FROM {cohort} c
|
||||
$left JOIN ({cohort_members} cm
|
||||
JOIN ($esql) u ON u.id = cm.userid) ON cm.cohortid = c.id
|
||||
WHERE c.contextid $parentsql
|
||||
GROUP BY c.id, c.name, c.contextid, c.idnumber
|
||||
$having
|
||||
ORDER BY c.name, c.idnumber, c.visible";
|
||||
|
||||
$cohorts = $DB->get_records_sql($sql, $params);
|
||||
|
||||
foreach ($cohorts as $cid=>$cohort) {
|
||||
$cohorts[$cid] = format_string($cohort->name, true, array('context'=>$cohort->contextid));
|
||||
if ($cohort->cnt) {
|
||||
$cohorts[$cid] .= ' (' . $cohort->cnt . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $cohorts;
|
||||
}
|
||||
|
|
|
@ -335,6 +335,10 @@ EOD;
|
|||
$record['descriptionformat'] = FORMAT_MOODLE;
|
||||
}
|
||||
|
||||
if (!isset($record['visible'])) {
|
||||
$record['visible'] = 1;
|
||||
}
|
||||
|
||||
if (!isset($record['component'])) {
|
||||
$record['component'] = '';
|
||||
}
|
||||
|
|
|
@ -34,6 +34,11 @@ DEPRECATIONS:
|
|||
access the activity.
|
||||
* Constant FEATURE_GROUPMEMBERSONLY (used in module _supports functions) is
|
||||
deprecated.
|
||||
* cohort_get_visible_list() is deprecated. There is a better function cohort_get_available_cohorts()
|
||||
that respects user capabilities to view cohorts.
|
||||
* enrol_cohort_get_cohorts() is deprecated; replace with enrol_cohort_search_cohorts() or
|
||||
cohort_get_available_cohorts()
|
||||
* enrol_cohort_can_view_cohort() is deprecated; replace with cohort_can_view_cohort()
|
||||
|
||||
=== 2.6.4 / 2.7.1 ===
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue