Esempio n. 1
0
 /**
  * Updates the value in database and returns itself, called from inplace_editable callback
  *
  * @param int $itemid
  * @param mixed $newvalue
  * @return \self
  */
 public static function update($itemid, $newvalue)
 {
     global $DB;
     require_capability('moodle/tag:manage', context_system::instance());
     $tagarea = $DB->get_record('tag_area', array('id' => $itemid), '*', MUST_EXIST);
     $newvalue = $newvalue ? 1 : 0;
     $data = array('enabled' => $newvalue);
     \core_tag_area::update($tagarea, $data);
     $tagarea->enabled = $newvalue;
     $tmpl = new self($tagarea);
     return $tmpl;
 }
Esempio n. 2
0
 public function test_move_tags_corrupted()
 {
     global $DB;
     list($collid1, $collid2, $user1, $user2, $blogpost) = $this->prepare_move_tags();
     $collid3 = core_tag_collection::create(array('name' => 'weirdcoll'))->id;
     // We already have Tag1 in coll1, now let's create it in coll3.
     $extratag1 = $this->getDataGenerator()->create_tag(array('rawname' => 'Tag1', 'tagcollid' => $collid3, 'tagtype' => 'official'));
     // Artificially add 'Tag1' from coll3 to user2.
     $DB->insert_record('tag_instance', array('tagid' => $extratag1->id, 'itemtype' => 'user', 'component' => 'core', 'itemid' => $user2->id, 'ordering' => 3));
     // Now we have corrupted data: both users are tagged with 'Tag1', however these are two tags in different collections.
     $user1tags = array_values(core_tag_tag::get_item_tags('core', 'user', $user1->id));
     $user2tags = array_values(core_tag_tag::get_item_tags('core', 'user', $user2->id));
     $this->assertEquals('Tag1', $user1tags[0]->rawname);
     $this->assertEquals('Tag1', $user2tags[2]->rawname);
     $this->assertNotEquals($user1tags[0]->tagcollid, $user2tags[2]->tagcollid);
     // Move user interests tag area into coll2.
     $tagarea = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
     core_tag_area::update($tagarea, array('tagcollid' => $collid2));
     // Now all tags are correctly moved to the new collection and both tags 'Tag1' were merged.
     $user1tags = array_values(core_tag_tag::get_item_tags('core', 'user', $user1->id));
     $user2tags = array_values(core_tag_tag::get_item_tags('core', 'user', $user2->id));
     $this->assertEquals('Tag1', $user1tags[0]->rawname);
     $this->assertEquals('Tag1', $user2tags[2]->rawname);
     $this->assertEquals($collid2, $user1tags[0]->tagcollid);
     $this->assertEquals($collid2, $user2tags[2]->tagcollid);
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
     break;
 case 'areasetcoll':
     if ($tagarea) {
         require_sesskey();
         if ($newtagcollid = optional_param('areacollid', null, PARAM_INT)) {
             core_tag_area::update($tagarea, array('tagcollid' => $newtagcollid));
             redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
         }
     }
     redirect($manageurl);
     break;
 case 'areasetshowstandard':
     if ($tagarea) {
         require_sesskey();
         if (($showstandard = optional_param('showstandard', null, PARAM_INT)) !== null) {
             core_tag_area::update($tagarea, array('showstandard' => $showstandard));
             redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
         }
     }
     redirect($manageurl);
     break;
 case 'delete':
     require_sesskey();
     if (!$tagschecked && $tagid) {
         $tagschecked = array($tagid);
     }
     core_tag_tag::delete_tags($tagschecked);
     redirect(new moodle_url($PAGE->url, $tagschecked ? array('notice' => 'deleted') : null));
     break;
 case 'setflag':
     require_sesskey();
Esempio n. 5
0
     break;
 case 'areaenable':
 case 'areadisable':
     if ($tagarea) {
         require_sesskey();
         $data = array('enabled' => $action === 'areaenable' ? 1 : 0);
         core_tag_area::update($tagarea, $data);
         redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
     }
     redirect($manageurl);
     break;
 case 'areasetcoll':
     if ($tagarea) {
         require_sesskey();
         if ($newtagcollid = optional_param('areacollid', null, PARAM_INT)) {
             core_tag_area::update($tagarea, array('tagcollid' => $newtagcollid));
             redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
         }
     }
     redirect($manageurl);
     break;
 case 'delete':
     require_sesskey();
     if (!$tagschecked && $tagid) {
         $tagschecked = array($tagid);
     }
     core_tag_tag::delete_tags($tagschecked);
     redirect(new moodle_url($PAGE->url, $tagschecked ? array('notice' => 'deleted') : null));
     break;
 case 'setflag':
     require_sesskey();