Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'wip-MDL-34448-MOODLE_22_STABLE' of git://github.com/abg…

…reeve/moodle into MOODLE_22_STABLE
  • Loading branch information...
commit 6d4386a6dbba2d14e08d0ab9bd4496120a119664 2 parents 0766ae0 + b562dfb
@nebgor nebgor authored
Showing with 51 additions and 16 deletions.
  1. +19 −13 mod/data/lib.php
  2. +25 −3 mod/data/view.php
  3. +7 −0 mod/upgrade.txt
View
32 mod/data/lib.php
@@ -3467,21 +3467,28 @@ function data_user_can_delete_preset($context, $preset) {
/**
* Get all of the record ids from a database activity.
*
- * @param int $dataid The dataid of the database module.
- * @return array $idarray An array of record ids
+ * @param int $dataid The dataid of the database module.
+ * @param object $selectdata Contains an additional sql statement for the
+ * where clause for group and approval fields.
+ * @param array $params Parameters that coincide with the sql statement.
+ * @return array $idarray An array of record ids
*/
-function data_get_all_recordids($dataid) {
+function data_get_all_recordids($dataid, $selectdata = '', $params = null) {
global $DB;
- $initsql = 'SELECT c.recordid
- FROM {data_fields} f,
- {data_content} c
- WHERE f.dataid = :dataid
- AND f.id = c.fieldid
- GROUP BY c.recordid';
- $initrecord = $DB->get_recordset_sql($initsql, array('dataid' => $dataid));
+ $initsql = 'SELECT r.id
+ FROM {data_records} r
+ WHERE r.dataid = :dataid';
+ if ($selectdata != '') {
+ $initsql .= $selectdata;
+ $params = array_merge(array('dataid' => $dataid), $params);
+ } else {
+ $params = array('dataid' => $dataid);
+ }
+ $initsql .= ' GROUP BY r.id';
+ $initrecord = $DB->get_recordset_sql($initsql, $params);
$idarray = array();
foreach ($initrecord as $data) {
- $idarray[] = $data->recordid;
+ $idarray[] = $data->id;
}
// Close the record set and free up resources.
$initrecord->close();
@@ -3626,8 +3633,7 @@ function data_get_advanced_search_sql($sort, $data, $recordids, $selectdata, $so
} else {
list($insql, $inparam) = $DB->get_in_or_equal(array('-1'), SQL_PARAMS_NAMED);
}
- $nestfromsql .= ' AND c.recordid ' . $insql . $groupsql;
- $nestfromsql = "$nestfromsql $selectdata";
+ $nestfromsql .= ' AND c.recordid ' . $insql . $selectdata . $groupsql;
$sqlselect['sql'] = "$nestselectsql $nestfromsql $sortorder";
$sqlselect['params'] = $inparam;
return $sqlselect;
View
28 mod/data/view.php
@@ -322,6 +322,13 @@
groups_print_activity_menu($cm, $returnurl);
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
+ // If a student is not part of a group and seperate groups is enabled, we don't
+ // want them seeing all records.
+ if ($currentgroup == 0 && $groupmode == 1 && !has_capability('mod/data:manageentries', $context)) {
+ $canviewallrecords = false;
+ } else {
+ $canviewallrecords = true;
+ }
// detect entries not approved yet and show hint instead of not found error
if ($record and $data->approval and !$record->approved and $record->userid != $USER->id and !has_capability('mod/data:manageentries', $context)) {
@@ -466,7 +473,13 @@
$groupselect = " AND (r.groupid = :currentgroup OR r.groupid = 0)";
$params['currentgroup'] = $currentgroup;
} else {
- $groupselect = ' ';
+ if ($canviewallrecords) {
+ $groupselect = ' ';
+ } else {
+ // If separate groups are enabled and the user isn't in a group or
+ // a teacher, manager, admin etc, then just show them entries for 'All participants'.
+ $groupselect = " AND r.groupid = 0";
+ }
}
// Init some variables to be used by advanced search
@@ -590,10 +603,19 @@
$fromsql = "FROM $tables $advtables $where $advwhere $groupselect $approveselect $searchselect $advsearchselect";
$allparams = array_merge($params, $advparams);
- $recordids = data_get_all_recordids($data->id);
+ // Provide initial sql statements and parameters to reduce the number of total records.
+ $selectdata = $groupselect . $approveselect;
+ $initialparams = array();
+ if ($currentgroup) {
+ $initialparams['currentgroup'] = $params['currentgroup'];
+ }
+ if (!$approvecap && $data->approval && isloggedin()) {
+ $initialparams['myid1'] = $params['myid1'];
+ }
+
+ $recordids = data_get_all_recordids($data->id, $selectdata, $initialparams);
$newrecordids = data_get_advance_search_ids($recordids, $search_array, $data->id);
$totalcount = count($newrecordids);
- $selectdata = $groupselect . $approveselect;
if (!empty($advanced)) {
$advancedsearchsql = data_get_advanced_search_sql($sort, $data, $newrecordids, $selectdata, $sortorder);
View
7 mod/upgrade.txt
@@ -10,12 +10,19 @@ required changes in code:
* textlib->asort() replaced by specialized collatorlib::asort()
* use new make_temp_directory() and make_cache_directory()
+optional - no changes needed:
+
+* mod/data/lib.php data_get_all_recordids() now has two new optional variables: $selectdata and $params.
=== 2.1 ===
required changes in code:
* add new support for basic restore from 1.9
+optional - no changes needed:
+
+* mod/data/lib.php data_get_all_recordids() now has two new optional variables: $selectdata and $params.
+
=== 2.0 ===
Please sign in to comment.
Something went wrong with that request. Please try again.