/** * Unassign the tracks from the userset. * @param array $elements An array of track information to unassign from the userset. * @param bool $bulkaction Whether this is a bulk-action or not. * @return array An array to format as JSON and return to the Javascript. */ protected function _respond_to_js(array $elements, $bulkaction) { global $DB; $usersetid = required_param('id', PARAM_INT); foreach ($elements as $trackid => $label) { if ($this->can_unassign($usersetid, $trackid) === true) { $assignrec = $DB->get_record(clustertrack::TABLE, array('clusterid' => $usersetid, 'trackid' => $trackid)); $usertrack = new clustertrack($assignrec); $usertrack->delete(); } } return array('result' => 'success', 'msg' => 'Success'); }