Commit 859e334f authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Tagging stuff for blogs and posts, includes base class tagging support, and

database changes
parent 68eab753
......@@ -344,6 +344,7 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact->set('owner', $user->get('id'));
$artefact->set('commentsallowed', $values['commentsallowed'] ? true : false);
$artefact->set('commentsnotify', $values['commentsnotify'] ? true : false);
$artefact->set('tags', $values['tags']);
$artefact->commit();
}
......@@ -367,6 +368,7 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact->set('description', $values['description']);
$artefact->set('commentsallowed', $values['commentsallowed'] ? true : false);
$artefact->set('commentsnotify', $values['commentsnotify'] ? true : false);
$artefact->set('tags', $values['tags']);
$artefact->commit();
}
......@@ -690,6 +692,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$artefact->set('published', $values['published']);
$artefact->set('tags', $values['tags']);
$artefact->commit();
return true;
}
......
......@@ -54,6 +54,11 @@ $form = pieform(array(
'required' => false
)
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdesc'),
),
'commentsallowed' => array(
'type' => 'radio',
'title' => get_string('commentsallowed', 'artefact.blog'),
......
......@@ -55,6 +55,7 @@ if (!$blogpost) {
$title = '';
$description = '';
$checked = '';
$tags = array();
$pagetitle = 'newblogpost';
$focuselement = 'title';
define('TITLE', get_string('newblogpost','artefact.blog'));
......@@ -67,6 +68,7 @@ else {
$blog = $blogpostobj->get('parent');
$title = $blogpostobj->get('title');
$description = $blogpostobj->get('description');
$tags = $blogpostobj->get('tags');
$checked = !$blogpostobj->get('published');
$pagetitle = 'editblogpost';
$focuselement = 'description'; // Doesn't seem to work with tinyMCE.
......@@ -114,6 +116,12 @@ $textinputform = pieform(array(
),
'defaultvalue' => $description
),
'tags' => array(
'defaultvalue' => $tags,
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdesc'),
),
)
));
......@@ -322,7 +330,8 @@ function saveblogpost() {
}
data.body = $('editpost_description').value;
sendjsonrequest('saveblogpost.json.php', data, 'POST', function (result) {
data.tags = $('editpost_tags').value;
sendjsonrequest('saveblogpost.json.php', data, 'POST', function (result) {
if (result.error) {
// Error messages should appear near the save button so
// that users can actually see them.
......@@ -673,8 +682,10 @@ function editpost_submit(Pieform $form, array $values) {
global $USER;
$values['published'] = !$values['thisisdraft'];
if ((!empty($values['id']) && ArtefactTypeBlogPost::edit_post($USER, $values))
|| (empty($values['id']) && ArtefactTypeBlogPost::new_post($USER, $values))) {
if (
(!empty($values['id']) && ArtefactTypeBlogPost::edit_post($USER, $values))
|| (empty($values['id']) && ArtefactTypeBlogPost::new_post($USER, $values))
) {
// Redirect to the blog page.
redirect('/artefact/blog/view/?id=' . $values['parent']);
}
......
......@@ -40,6 +40,7 @@ $blogpost = param_integer('blogpost');
$uploads = json_decode(param_variable('uploads'));
$artefacts = json_decode(param_variable('artefacts'));
$body = param_variable('body');
$tags = param_variable('tags');
$userid = $USER->get('id');
......@@ -64,6 +65,7 @@ if (!empty($uploads)) {
$postobj = new ArtefactTypeBlogPost($blogpost, null);
$postobj->set('title', $title);
$postobj->set('description', $body);
$postobj->set('tags', preg_split("/\s*,\s*/", trim($tags)));
$postobj->set('published', !$draft);
if (!$blogpost) {
$postobj->set('parent', $blog);
......
......@@ -65,6 +65,12 @@ $form = pieform(array(
),
'defaultvalue' => $blog->get('description')
),
'tags' => array(
'defaultvalue' => $blog->get('tags'),
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdesc'),
),
'commentsallowed' => array(
'type' => 'radio',
'title' => get_string('commentsallowed', 'artefact.blog'),
......
......@@ -88,6 +88,7 @@ abstract class ArtefactType {
protected $title;
protected $description;
protected $note;
protected $tags = array();
protected $viewsinstances;
protected $viewsmetadata;
......@@ -129,6 +130,14 @@ abstract class ArtefactType {
}
}
// load tags
if ($this->id) {
$tags = get_column('artefact_tag', 'tag', 'artefact', $this->id);
if (is_array($tags)) {
$this->tags = $tags;
}
}
$this->atime = time();
$this->artefacttype = $this->get_artefact_type();
}
......@@ -335,6 +344,20 @@ abstract class ArtefactType {
else {
update_record('artefact', $fordb, 'id');
}
delete_records('artefact_tag', 'artefact', $this->id);
if (is_array($this->tags)) {
foreach ($this->tags as $tag) {
insert_record(
'artefact_tag',
(object) array(
'artefact' => $this->id,
'tag' => $tag,
)
);
}
}
activity_occurred('watchlist', (object) array('artefact' => $this->id,
'subject' => get_string('artefactmodified')));
if (!empty($this->parentdirty)) {
......
......@@ -29,6 +29,9 @@ function globalErrorHandler(data) {
if (data.returnCode == 3) {
// Logged out!
}
else {
displayMessage(data.message, 'error');
}
}
// Form related functions
......
......@@ -56,6 +56,9 @@ $string['sendrequest'] = 'Send request';
$string['reason'] = 'Reason';
$string['select'] = 'Select';
$string['tags'] = 'Tags';
$string['tagsdesc'] = 'Enter comma separated tags for this item';
// Quota strings
$string['quota'] = 'Quota';
$string['quotausage'] = 'You have used <span id="quota_used">%s</span> of your <span id="quota_total">%s</span> quota.';
......
......@@ -369,6 +369,16 @@
<KEY NAME="usrfk" TYPE="foreign" FIELDS="owner" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_tag">
<FIELDS>
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="tag" TYPE="char" LENGTH="128" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="artefact,tag" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_parent_cache">
<FIELDS>
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
......@@ -603,6 +613,16 @@
<KEY NAME="submittedtofk" TYPE="foreign" FIELDS="submittedto" REFTABLE="community" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_tag">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="tag" TYPE="char" LENGTH="128" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="view,tag" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_artefact">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
......
......@@ -196,6 +196,24 @@ function xmldb_core_upgrade($oldversion=0) {
add_field($table, $field);
}
if ($oldversion < 2007020300) {
// artefact_tag table
$table = new XMLDBTable('artefact_tag');
$table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
$table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
$table->addFieldInfo('tag', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('artefact', 'tag'));
create_table($table);
// view_tag table
$table = new XMLDBTable('view_tag');
$table->addFieldInfo('view', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
$table->addKeyInfo('viewfk', XMLDB_KEY_FOREIGN, array('view'), 'view', array('id'));
$table->addFieldInfo('tag', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('view', 'tag'));
create_table($table);
}
return $status;
}
......
......@@ -27,8 +27,8 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2007020200;
$config->release = '0.6.0';
$config->version = 2007020300;
$config->release = '0.7.0.dev';
$config->minupgradefrom = 2007011600;
$config->minupgraderelease = '0.4.0 (build tag BUILD_20070122)';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment