Example #1
0
 /**
  * Flag a tag as inappropriate
  */
 public function flag()
 {
     global $DB;
     $this->ensure_fields_exist(array('name', 'userid', 'rawname', 'flag'), 'flag');
     // Update all the tags to flagged.
     $this->timemodified = time();
     $this->flag++;
     $DB->update_record('tag', array('timemodified' => $this->timemodified, 'flag' => $this->flag, 'id' => $this->id));
     $event = \core\event\tag_flagged::create(array('objectid' => $this->id, 'relateduserid' => $this->userid, 'context' => context_system::instance(), 'other' => array('name' => $this->name, 'rawname' => $this->rawname)));
     $event->trigger();
 }
Example #2
0
/**
 * Flag a tag as inappropriate.
 *
 * @param int|array $tagids a single tagid, or an array of tagids
 */
function tag_set_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 flagged.
    $sql = "UPDATE {tag}\n               SET flag = flag + 1, 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 flagged.
        foreach ($tags as $tag) {
            $event = \core\event\tag_flagged::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();
        }
    }
}