From: tjhunt Date: Fri, 16 Jan 2009 07:08:58 +0000 (+0000) Subject: blog / tags: MDL-17900 Use the new tags field type to tag blog posts. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=fc23301cedc8c8281d2331d82cd1ddbbf295dc50;p=moodle.git blog / tags: MDL-17900 Use the new tags field type to tag blog posts. --- diff --git a/blog/edit.php b/blog/edit.php index fb46a81aed..033018d0a4 100755 --- a/blog/edit.php +++ b/blog/edit.php @@ -112,16 +112,10 @@ switch ($action) { $post->summary = $existing->summary; $post->publishstate = $existing->publishstate; $post->format = $existing->format; + $post->tags = tag_get_tags_array('post', $post->id); $post->action = $action; $strformheading = get_string('updateentrywithid', 'blog'); - if ($itemptags = tag_get_tags_csv('post', $post->id, TAG_RETURN_TEXT, 'default')) { - $post->ptags = $itemptags; - } - - if ($itemotags = tag_get_tags_array('post', $post->id, 'official')) { - $post->otags = array_keys($itemotags); - } break; default : print_error('unknowaction'); @@ -179,16 +173,17 @@ function do_add($post, $blogeditform) { $post->created = time(); // Insert the new blog entry. - if ($id = $DB->insert_record('post', $post)) { - $post->id = $id; - // add blog attachment + if ($post->id = $DB->insert_record('post', $post)) { + // Add blog attachment if ($blogeditform->get_new_filename('attachment')) { if ($blogeditform->save_stored_file('attachment', SYSCONTEXTID, 'blog', $post->id, '/', false, $USER->id)) { $DB->set_field("post", "attachment", 1, array("id"=>$post->id)); } } - add_tags_info($post->id); + // Update tags. + tag_set('post', $post->id, $post->tags); + add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject); } else { @@ -216,15 +211,9 @@ function do_edit($post, $blogeditform) { } } - // update record + // Update record if ($DB->update_record('post', $post)) { - // delete all tags associated with this entry - - //$DB->delete_records('blog_tag_instance', array('entryid'=>$post->id)); - //$DB->delete_records('tag_instance', array('itemid'=>$post->id, 'itemtype'=>'blog')); - //untag_an_item('post', $post->id); - // add them back - add_tags_info($post->id); + tag_set('post', $post->id, $post->tags); add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$USER->id.'&postid='.$post->id, $post->subject); @@ -233,25 +222,4 @@ function do_edit($post, $blogeditform) { } } -/** - * function to attach tags into a post - * @param int postid - id of the blog - */ -function add_tags_info($postid) { - - $tags = array(); - if ($otags = optional_param('otags', '', PARAM_INT)) { - foreach ($otags as $tagid) { - // TODO : make this use the tag name in the form - if ($tag = tag_get('id', $tagid)) { - $tags[] = $tag->name; - } - } - } - - $manual_tags = optional_param('ptags', '', PARAM_NOTAGS); - $tags = array_merge($tags, explode(',', $manual_tags)); - - tag_set('post', $postid, $tags); -} ?> diff --git a/blog/edit_form.php b/blog/edit_form.php index 71b2426e24..2c26d0e456 100644 --- a/blog/edit_form.php +++ b/blog/edit_form.php @@ -32,16 +32,9 @@ class blog_edit_form extends moodleform { if (!empty($CFG->usetags)) { $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); - $mform->createElement('select', 'otags', get_string('otags','tag')); - - $otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'tag'), array(), 'size="5"'); - $otagsselEl->setMultiple(true); - $this->otags_select_setup(); - - $mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5')); - $mform->setType('ptagsadd', PARAM_NOTAGS); + $mform->addElement('tags', 'tags', get_string('tags')); } - + $this->add_action_buttons(); $mform->addElement('hidden', 'action');