/** * Constructor * * @param string|moodle_url $pageurl */ public function __construct($pageurl) { global $OUTPUT; parent::__construct(); $this->attributes['class'] = 'generaltable tag-areas-table'; $this->head = array(get_string('tagareaname', 'core_tag'), get_string('component', 'tag'), get_string('tagareaenabled', 'core_tag'), get_string('tagcollection', 'tag'), get_string('showstandard', 'tag') . $OUTPUT->help_icon('showstandard', 'tag')); $this->data = array(); $this->rowclasses = array(); $tagareas = core_tag_area::get_areas(); $tagcollections = core_tag_collection::get_collections_menu(true); $tagcollectionsall = core_tag_collection::get_collections_menu(); $standardchoices = array(core_tag_tag::BOTH_STANDARD_AND_NOT => get_string('standardsuggest', 'tag'), core_tag_tag::STANDARD_ONLY => get_string('standardforce', 'tag'), core_tag_tag::HIDE_STANDARD => get_string('standardhide', 'tag')); foreach ($tagareas as $itemtype => $it) { foreach ($it as $component => $record) { $areaname = core_tag_area::display_name($record->component, $record->itemtype); $tmpl = new \core_tag\output\tagareaenabled($record); $enabled = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT)); $tmpl = new \core_tag\output\tagareacollection($record); $collectionselect = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT)); $tmpl = new \core_tag\output\tagareashowstandard($record); $showstandardselect = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT)); $this->data[] = array($areaname, $record->component === 'core' || preg_match('/^core_/', $record->component) ? get_string('coresystem') : get_string('pluginname', $record->component), $enabled, $collectionselect, $showstandardselect); $this->rowclasses[] = $record->enabled ? '' : 'dimmed_text'; } } }
/** * Constructor * * @param string|moodle_url $pageurl */ public function __construct($pageurl) { global $OUTPUT; parent::__construct(); $this->attributes['class'] = 'generaltable tag-areas-table'; $this->head = array(get_string('tagareaname', 'core_tag'), get_string('component', 'tag'), get_string('tagareaenabled', 'core_tag'), get_string('tagcollection', 'tag')); $this->data = array(); $this->rowclasses = array(); $tagareas = core_tag_area::get_areas(); $tagcollections = core_tag_collection::get_collections_menu(true); $tagcollectionsall = core_tag_collection::get_collections_menu(); foreach ($tagareas as $itemtype => $it) { foreach ($it as $component => $record) { $areaname = core_tag_area::display_name($record->component, $record->itemtype); $baseurl = new moodle_url($pageurl, array('ta' => $record->id, 'sesskey' => sesskey())); if ($record->enabled) { $enableurl = new moodle_url($baseurl, array('action' => 'areadisable')); $enabled = html_writer::link($enableurl, $OUTPUT->pix_icon('i/hide', get_string('disable'))); } else { $enableurl = new moodle_url($baseurl, array('action' => 'areaenable')); $enabled = html_writer::link($enableurl, $OUTPUT->pix_icon('i/show', get_string('enable'))); } if ($record->enabled && empty($record->locked) && count($tagcollections) > 1) { $changecollurl = new moodle_url($baseurl, array('action' => 'areasetcoll')); $select = new single_select($changecollurl, 'areacollid', $tagcollections, $record->tagcollid, null); $select->set_label(get_string('changetagcoll', 'core_tag', $areaname), array('class' => 'accesshide')); $collectionselect = $OUTPUT->render($select); } else { $collectionselect = $tagcollectionsall[$record->tagcollid]; } $this->data[] = array($areaname, $record->component === 'core' || preg_match('/^core_/', $record->component) ? get_string('coresystem') : get_string('pluginname', $record->component), $enabled, $collectionselect); $this->rowclasses[] = $record->enabled ? '' : 'dimmed_text'; } } }
/** * Constructor * * @param core_tag_tag|stdClass $tag * @param string $component * @param string $itemtype * @param string $content * @param bool $exclusivemode * @param int $fromctx context id where the link was displayed, may be used by callbacks * to display items in the same context first * @param int $ctx context id where we need to search for items * @param int $rec search items in sub contexts as well * @param int $page * @param bool $totalpages */ public function __construct($tag, $component, $itemtype, $content, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0, $totalpages = 1) { $this->record = new stdClass(); $this->tag = $tag; $tagareas = \core_tag_area::get_areas(); if (!isset($tagareas[$itemtype][$component])) { throw new \coding_exception('Tag area for component ' . $component . ' and itemtype ' . $itemtype . ' is not defined'); } $this->tagarea = $tagareas[$itemtype][$component]; $this->record->tagid = $tag->id; $this->record->ta = $this->tagarea->id; $this->record->itemtype = $itemtype; $this->record->component = $component; $a = (object) array('tagarea' => \core_tag_area::display_name($component, $itemtype), 'tag' => \core_tag_tag::make_display_name($tag)); if ($exclusivemode) { $this->record->title = get_string('itemstaggedwith', 'tag', $a); } else { $this->record->title = (string) $a->tagarea; } $this->record->content = $content; $this->record->nextpageurl = null; $this->record->prevpageurl = null; $this->record->exclusiveurl = null; $url = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, $exclusivemode, $fromctx, $ctx, $rec); $urlparams = array('ta' => $this->tagarea->id); if ($totalpages > $page + 1) { $this->record->nextpageurl = new moodle_url($url, $urlparams + array('page' => $page + 1)); } if ($page > 0) { $this->record->prevpageurl = new moodle_url($url, $urlparams + array('page' => $page - 1)); } if (!$exclusivemode && ($totalpages > 1 || $page)) { $this->record->exclusiveurl = new moodle_url($url, $urlparams + array('excl' => 1)); } $this->record->exclusivetext = get_string('exclusivemode', 'tag', $a); $this->record->hascontent = $totalpages > 1 || $page || $content; $this->record->anchor = $component . '_' . $itemtype; }
/** * Deletes a custom tag collection * * @param stdClass $tagcoll existing record in DB table tag_coll * @return bool wether the tag collection was deleted */ public static function delete($tagcoll) { global $DB, $CFG; $defaulttagcollid = self::get_default(); if ($tagcoll->id == $defaulttagcollid) { return false; } // Move all tags from this tag collection to the default one. $allitemtypes = core_tag_area::get_areas($tagcoll->id); foreach ($allitemtypes as $it) { foreach ($it as $v) { core_tag_area::update($v, array('tagcollid' => $defaulttagcollid)); } } // Delete tags from this tag_coll. core_tag_tag::delete_tags($DB->get_fieldset_select('tag', 'id', 'tagcollid = ?', array($tagcoll->id))); // Delete the tag collection. $DB->delete_records('tag_coll', array('id' => $tagcoll->id)); // Reset cache. cache::make('core', 'tags')->delete('tag_coll'); \core\event\tag_collection_deleted::create_from_record($tagcoll)->trigger(); return true; }