diff --git a/mod/data/lib.php b/mod/data/lib.php index 28f8b104b50..7adbedd7f3f 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -1272,6 +1272,10 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r $replacement[] = ''.fullname($record).''; + $patterns[] = '##userpicture##'; + $ruser = user_picture::unalias($record, null, 'userid'); + $replacement[] = $OUTPUT->user_picture($ruser, array('courseid' => $data->course)); + $patterns[]='##export##'; if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') @@ -3611,7 +3615,10 @@ function data_get_recordids($alias, $searcharray, $dataid, $recordids) { function data_get_advanced_search_sql($sort, $data, $recordids, $selectdata, $sortorder) { global $DB; - $namefields = get_all_user_name_fields(true, 'u'); + $namefields = user_picture::fields('u'); + // Remove the id from the string. This already exists in the sql statement. + $namefields = str_replace('u.id,', '', $namefields); + if ($sort == 0) { $nestselectsql = 'SELECT r.id, r.approved, r.timecreated, r.timemodified, r.userid, ' . $namefields . ' FROM {data_content} c, diff --git a/mod/data/templates.php b/mod/data/templates.php index 33fbf5ba9bb..f2c0388d2f9 100644 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -276,6 +276,7 @@ if ($mode != 'csstemplate' and $mode != 'jstemplate') { echo ''; echo ''; echo ''; + echo ''; if ($mode != 'singletemplate') { // more points to single template - not useable there echo ''; diff --git a/mod/data/tests/behat/add_entries.feature b/mod/data/tests/behat/add_entries.feature index f711fa18164..d8182f358f8 100644 --- a/mod/data/tests/behat/add_entries.feature +++ b/mod/data/tests/behat/add_entries.feature @@ -4,6 +4,7 @@ Feature: Users can add entries to database activities As a user I need to add entries to databases + @javascript Scenario: Students can add entries to a database Given the following "users" exist: | username | firstname | lastname | email | @@ -54,3 +55,12 @@ Feature: Users can add entries to database activities And I should not see "Student edited entry" And I should see "Student second entry" And I should see "Student third entry" + # Now I will bulk delete the rest of the entries. + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test database name" + And I press "Select all" + And I press "Delete selected" + And I press "Delete" + And I should see "No entries in database" \ No newline at end of file diff --git a/mod/data/tests/search_test.php b/mod/data/tests/search_test.php index 75c02ceb451..f2bd3766118 100644 --- a/mod/data/tests/search_test.php +++ b/mod/data/tests/search_test.php @@ -172,6 +172,9 @@ class data_advanced_search_sql_test extends advanced_testcase { $this->finalrecord[6]->lastnamephonetic = $user->lastnamephonetic; $this->finalrecord[6]->middlename = $user->middlename; $this->finalrecord[6]->alternatename = $user->alternatename; + $this->finalrecord[6]->picture = $user->picture; + $this->finalrecord[6]->imagealt = $user->imagealt; + $this->finalrecord[6]->email = $user->email; } /** diff --git a/mod/data/view.php b/mod/data/view.php index 5f2071ccb6e..4ed03797693 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -379,7 +379,9 @@ echo $OUTPUT->notification(get_string('recorddeleted','data'), 'notifysuccess'); } } else { // Print a confirmation page - $allnamefields = get_all_user_name_fields(true, 'u'); + $allnamefields = user_picture::fields('u'); + // Remove the id from the string. This already exists in the sql statement. + $allnamefields = str_replace('u.id,', '', $allnamefields); $dbparams = array($delete); if ($deleterecord = $DB->get_record_sql("SELECT dr.*, $allnamefields FROM {data_records} dr @@ -415,14 +417,20 @@ $validrecords = array(); $recordids = array(); foreach ($multidelete as $value) { - if ($deleterecord = $DB->get_record('data_records', array('id'=>$value))) { // Need to check this is valid - if ($deleterecord->dataid == $data->id) { // Must be from this database + $allnamefields = user_picture::fields('u'); + // Remove the id from the string. This already exists in the sql statement. + $allnamefields = str_replace('u.id,', '', $allnamefields); + $dbparams = array('id' => $value); + if ($deleterecord = $DB->get_record_sql("SELECT dr.*, $allnamefields + FROM {data_records} dr + JOIN {user} u ON dr.userid = u.id + WHERE dr.id = ?", $dbparams)) { // Need to check this is valid. + if ($deleterecord->dataid == $data->id) { // Must be from this database. $validrecords[] = $deleterecord; $recordids[] = $deleterecord->id; } } } - $serialiseddata = json_encode($recordids); $submitactions = array('d' => $data->id, 'sesskey' => sesskey(), 'confirm' => '1', 'serialdelete' => $serialiseddata); $action = new moodle_url('/mod/data/view.php', $submitactions); @@ -542,7 +550,9 @@ if ($showactivity) { $advparams = array(); // This is used for the initial reduction of advanced search results with required entries. $entrysql = ''; - $namefields = get_all_user_name_fields(true, 'u'); + $namefields = user_picture::fields('u'); + // Remove the id from the string. This already exists in the sql statement. + $namefields = str_replace('u.id,', '', $namefields); /// Find the field we are sorting on if ($sort <= 0 or !$sortfield = data_get_field_from_id($sort, $data)) {