/** * Remove the inappropriate flag on a tag. */ public function reset_flag() { global $DB; $this->ensure_fields_exist(array('name', 'userid', 'rawname', 'flag'), 'flag'); if (!$this->flag) { // Nothing to do. return false; } $this->timemodified = time(); $this->flag = 0; $DB->update_record('tag', array('timemodified' => $this->timemodified, 'flag' => 0, 'id' => $this->id)); $event = \core\event\tag_unflagged::create(array('objectid' => $this->id, 'relateduserid' => $this->userid, 'context' => context_system::instance(), 'other' => array('name' => $this->name, 'rawname' => $this->rawname))); $event->trigger(); }
/** * Remove the inappropriate flag on a tag. * * @param int|array $tagids a single tagid, or an array of tagids */ function tag_unset_flag($tagids) { global $DB; $tagids = (array) $tagids; // Use the tagids to create a select statement to be used later. list($tagsql, $tagparams) = $DB->get_in_or_equal($tagids, SQL_PARAMS_NAMED); // Update all the tags to unflagged. $sql = "UPDATE {tag}\n SET flag = 0, timemodified = :time\n WHERE id {$tagsql}"; // Update all the tags. $DB->execute($sql, array_merge(array('time' => time()), $tagparams)); // Get all the tags. if ($tags = $DB->get_records_select('tag', 'id ' . $tagsql, $tagparams, 'id ASC')) { // Loop through and fire an event for each tag that it was unflagged. foreach ($tags as $tag) { $event = \core\event\tag_unflagged::create(array('objectid' => $tag->id, 'relateduserid' => $tag->userid, 'context' => context_system::instance(), 'other' => array('name' => $tag->name, 'rawname' => $tag->rawname))); $event->add_record_snapshot('tag', $tag); $event->trigger(); } } }