Commit dc709740 authored by Son Nguyen's avatar Son Nguyen

Add tagging feature for plans and tasks (Bug #1180997)

Add a new function Artefact::artefact_get_tags($artefactid)
to return a list of sorted tags associated to an artefact

Display tags of plans

Change-Id: I3720b4954be2e928539e75362dab8059fbe35169
parent beff568b
......@@ -196,10 +196,7 @@ 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->tags = ArtefactType::artefact_get_tags($this->id);
}
// load group permissions
......@@ -694,6 +691,8 @@ abstract class ArtefactType {
public function render_self($options) {
$smarty = smarty_core();
$smarty->assign('title', $this->get('title'));
$smarty->assign('owner', $this->get('owner'));
$smarty->assign('tags', $this->get('tags'));
$smarty->assign('description', $this->get('description'));
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this));
......@@ -1183,6 +1182,24 @@ abstract class ArtefactType {
set_field_select('artefact', 'locked', 0, $select, array($userid));
db_commit();
}
/**
* Return an array of tags associated to an artefact
*
* @param int ID of the artefact
*
* @return array of strings
*/
public static function artefact_get_tags($id) {
if (empty($id)) {
return array();
}
$tags = get_column_sql('SELECT tag FROM {artefact_tag} WHERE artefact = ? ORDER BY tag', array($id));
if (!$tags) {
return array();
}
return $tags;
}
}
/**
......
......@@ -74,6 +74,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
$smarty = smarty_core();
if (isset($configdata['artefactid'])) {
$plan = artefact_instance_from_id($configdata['artefactid']);
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid']);
$template = 'artefact:plans:taskrows.tpl';
$blockid = $instance->get('id');
......@@ -97,7 +98,9 @@ class PluginBlocktypePlans extends PluginBlocktype {
. '&view=' . $instance->get('view');
$tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
}
$smarty->assign('tasks',$tasks);
$smarty->assign('owner', $plan->get('owner'));
$smarty->assign('tags', $plan->get('tags'));
$smarty->assign('tasks', $tasks);
}
else {
$smarty->assign('noplans','blocktype.plans/plans');
......
{if $tags}<p class="tags s"><label>{str tag=tags}:</label> {list_tags owner=$owner tags=$tags}</p>{/if}
{if $tasks.data}
<table id="tasktable_{$blockid}" class="plansblocktable">
<colgroup width="50%" span="2"></colgroup>
......
......@@ -68,6 +68,7 @@ $string['notasks'] = 'No tasks to display.';
$string['notasksaddone'] = 'No tasks yet. %sAdd one%s.';
$string['savetask'] = 'Save task';
$string['task'] = 'task';
$string['Task'] = 'Task';
$string['tasks'] = 'tasks';
$string['taskdeletedsuccessfully'] = 'Task deleted successfully.';
$string['tasksavedsuccessfully'] = 'Task saved successfully.';
......@@ -54,6 +54,11 @@ class PluginArtefactPlans extends PluginArtefact {
);
}
public static function get_artefact_type_content_types() {
return array(
'task' => array('text'),
);
}
}
class ArtefactTypePlan extends ArtefactType {
......@@ -66,7 +71,9 @@ class ArtefactTypePlan extends ArtefactType {
}
public static function get_links($id) {
return array();
return array(
'_default' => get_config('wwwroot') . 'artefact/plans/plan.php?id=' . $id,
);
}
public function delete() {
......@@ -80,6 +87,8 @@ class ArtefactTypePlan extends ArtefactType {
}
public static function get_icon($options=null) {
global $THEME;
return $THEME->get_url('images/plan.gif', false, 'artefact/plans');
}
public static function is_singular() {
......@@ -101,6 +110,11 @@ class ArtefactTypePlan extends ArtefactType {
WHERE owner = ? AND artefacttype = 'plan'
ORDER BY title ASC", array($USER->get('id')), $offset, $limit))
|| ($plans = array());
foreach ($plans as &$plan) {
if (!isset($plan->tags)) {
$plan->tags = ArtefactType::artefact_get_tags($plan->id);
}
}
$result = array(
'count' => count_records('artefact', 'owner', $USER->get('id'), 'artefacttype', 'plan'),
'data' => $plans,
......@@ -174,6 +188,7 @@ class ArtefactTypePlan extends ArtefactType {
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->set('tags', $values['tags']);
$artefact->commit();
$SESSION->add_ok_msg(get_string('plansavedsuccessfully', 'artefact.plans'));
......@@ -234,6 +249,11 @@ class ArtefactTypePlan extends ArtefactType {
'defaultvalue' => null,
'title' => get_string('description', 'artefact.plans'),
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescprofile'),
),
);
if (!empty($plan)) {
......@@ -294,6 +314,8 @@ class ArtefactTypePlan extends ArtefactType {
else {
$smarty->assign('license', false);
}
$smarty->assign('owner', $this->get('owner'));
$smarty->assign('tags', $this->get('tags'));
return array('html' => $smarty->fetch('artefact:plans:viewplan.tpl'), 'javascript' => '');
}
......@@ -329,10 +351,14 @@ class ArtefactTypeTask extends ArtefactType {
}
public static function get_links($id) {
return array();
return array(
'_default' => get_config('wwwroot') . 'artefact/plans/edit/task.php?id=' . $id,
);
}
public static function get_icon($options=null) {
global $THEME;
return $THEME->get_url('images/plantask.gif', false, 'artefact/plans');
}
public static function is_singular() {
......@@ -475,6 +501,11 @@ class ArtefactTypeTask extends ArtefactType {
'defaultvalue' => null,
'title' => get_string('description', 'artefact.plans'),
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescprofile'),
),
'completed' => array(
'type' => 'checkbox',
'defaultvalue' => null,
......@@ -538,6 +569,7 @@ class ArtefactTypeTask extends ArtefactType {
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->set('tags', $values['tags']);
$artefact->commit();
$SESSION->add_ok_msg(get_string('plansavedsuccessfully', 'artefact.plans'));
......
......@@ -61,6 +61,8 @@ EOF;
$smarty = smarty(array('paginator'));
$smarty->assign_by_ref('tasks', $tasks);
$smarty->assign_by_ref('plan', $id);
$smarty->assign_by_ref('tags', $plan->get('tags'));
$smarty->assign_by_ref('owner', $plan->get('owner'));
$smarty->assign('strnotasksaddone',
get_string('notasksaddone', 'artefact.plans',
'<a href="' . get_config('wwwroot') . 'artefact/plans/new.php?id='.$plan->get('id').'">', '</a>'));
......
......@@ -3,6 +3,7 @@
<div class="rbuttons">
<a class="btn" href="{$WWWROOT}artefact/plans/new.php?id={$plan}">{str section="artefact.plans" tag="newtask"}</a>
</div>
{if $tags}<p class="tags s"><label>{str tag=tags}:</label> {list_tags owner=$owner tags=$tags}</p>{/if}
{if !$tasks.data}
<div>{str tag="planstasksdesc" section="artefact.plans"}</div>
<div class="message">{$strnotasksaddone|safe}</div>
......
......@@ -8,7 +8,9 @@
</div>
<h3><a href="{$WWWROOT}artefact/plans/plan.php?id={$plan->id}">{$plan->title}</a></h3>
{if $plan->tags}
<div>{str tag=tags}: {list_tags tags=$plan->tags owner=$plan->owner}</div>
{/if}
<div class="codesc">{$plan->description}</div>
</td>
</tr>
......
{if $tags}<p class="tags s"><label>{str tag=tags}:</label> {list_tags owner=$owner tags=$tags}</p>{/if}
<table id="tasktable">
<thead>
<tr>
......
......@@ -3028,7 +3028,12 @@ function build_portfolio_search_html(&$data) {
$links = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_links', $item->id);
$item->url = $links['_default'];
$item->icon = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_icon', array('id' => $item->id));
$item->typestr = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin);
if ($item->artefacttype == 'task') {
$item->typestr = get_string('Task', 'artefact.plans');
}
else {
$item->typestr = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin);
}
}
}
......
......@@ -992,7 +992,7 @@ class PluginSearchInternal extends PluginSearch {
}
}
if (!empty($ids['artefact'])) {
if ($artefacttags = get_records_select_array('artefact_tag', 'artefact IN (' . join(',', array_keys($ids['artefact'])) . ')')) {
if ($artefacttags = get_records_select_array('artefact_tag', 'artefact IN (' . join(',', array_keys($ids['artefact'])) . ')', NULL, 'tag')) {
foreach ($artefacttags as &$at) {
$data['artefact:' . $at->artefact]->tags[] = $at->tag;
}
......
<h2>{$title}</h2>
{if $tags}<p class="tags s"><label>{str tag=tags}:</label> {list_tags owner=$owner tags=$tags}</p>{/if}
<p>{$description|clean_html|safe}</p>
{if $license}
<div class="artefactlicense">
......
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