Commit 7caf24a6 authored by Robert Lyon's avatar Robert Lyon

Bug 1775106: Creating page from tags

Added the 'create via tags' field to Page settings.
Can add certain tagged artefacts/blocks to the page

Note: if the block with the tag already exists on the page it will not
add it again

behatnotneeded

Change-Id: I97e930e36a40d43a4ffdbf0337ae3303dbb72f19
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 85303f91
......@@ -472,33 +472,37 @@ EOF;
$tagselect = $values['tagselect'];
unset($values['tagselect']);
if (!empty($tagselect)) {
delete_records('blocktype_taggedposts_tags', 'block_instance', $instance->get('id'));
foreach ($tagselect as $tag) {
$value = PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE;
if (substr($tag, 0, 1) == '-') {
$value = PluginBlocktypeTaggedposts::TAGTYPE_EXCLUDE;
$tag = substr($tag, 1);
}
// If tag is institution tag, save it's correct form.
if (strpos($tag, ':')) {
$tagarray = explode(': ', $tag);
$sql = "SELECT t.id
FROM {tag} t
JOIN {institution} i ON i.name = t.ownerid
WHERE t.tag = ? AND t.resourcetype = 'institution' AND i.displayname = ?";
$insttagid = get_field_sql($sql, array($tagarray[1], $tagarray[0]));
$tag = 'tagid_' . $insttagid;
}
$todb = new stdClass();
$todb->block_instance = $instance->get('id');
$todb->tag = htmlspecialchars_decode($tag);
$todb->tagtype = $value;
insert_record('blocktype_taggedposts_tags', $todb);
}
self::save_tag_selection($tagselect, $instance);
}
return $values;
}
public static function save_tag_selection($tagselect, BlockInstance $instance) {
delete_records('blocktype_taggedposts_tags', 'block_instance', $instance->get('id'));
foreach ($tagselect as $tag) {
$value = PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE;
if (substr($tag, 0, 1) == '-') {
$value = PluginBlocktypeTaggedposts::TAGTYPE_EXCLUDE;
$tag = substr($tag, 1);
}
// If tag is institution tag, save it's correct form.
if (strpos($tag, ':')) {
$tagarray = explode(': ', $tag);
$sql = "SELECT t.id
FROM {tag} t
JOIN {institution} i ON i.name = t.ownerid
WHERE t.tag = ? AND t.resourcetype = 'institution' AND i.displayname = ?";
$insttagid = get_field_sql($sql, array($tagarray[1], $tagarray[0]));
$tag = 'tagid_' . $insttagid;
}
$todb = new stdClass();
$todb->block_instance = $instance->get('id');
$todb->tag = htmlspecialchars_decode($tag);
$todb->tagtype = $value;
insert_record('blocktype_taggedposts_tags', $todb);
}
}
/**
* Returns a list of artefact IDs that are "in" this blockinstance.
*
......
......@@ -736,6 +736,10 @@ class BlockInstance {
private function set_tags($tags) {
global $USER;
if (empty($this->view_obj)) {
$this->get_view();
}
if ($this->view_obj->get('group')) {
$ownertype = 'group';
$ownerid = $this->view_obj->get('group');
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Create page via tags</h3>
<p>You can select some tags to populate the page with content containing those tags.</p>
<p>The resulting page will contain the content (artefacts and blocks) that you tagged. You can then re-arrange the blocks on the page.</p>
<p>For example, if you tag:<p>
<ul>
<li>One image and then select that tag here, it will be added as an image block to the page.</li>
<li>Three images with the same two tags and select these tags here, the images will be displayed in an image gallery.</li>
<li>One PDF and select that tag here, the PDF block will be added to the page.</li>
<li>An existing block on another page, e.g. the "Text" block, it will copy that block to this page.</li>
</ul>
<h4>Content mappings:</h4>
<table>
<tr>
<th>Type</th>
<th>Count</th>
<th>Block</th>
</tr>
<tr>
<td rowspan="2" valign="top">Image</td>
<td>1</td>
<td valign="top">Image</td>
</tr>
<tr>
<td valign="top">2+</td>
<td valign="top">Image gallery slideshow</td>
</tr>
<td rowspan="2" valign="top">PDF</td>
<td valign="top">1</td>
<td valign="top">PDF block</td>
</tr>
<tr>
<td valign="top">2+</td>
<td valign="top">Files to download</td>
</tr>
<td valign="top">Generic files</td>
<td valign="top">1+</td>
<td>Files to download</td>
</tr>
<tr>
<td rowspan="2" valign="top">Audio/video</td>
<td valign="top">1</td>
<td valign="top">Internal media</td>
</tr>
<tr>
<td valign="top">2+</td>
<td valign="top">Files to download</td>
</tr>
<tr>
<td valign="top">Folder</td>
<td valign="top">1+</td>
<td valign="top">Folder block per folder</td>
</tr>
<tr>
<td valign="top">Journal</td>
<td valign="top">1+</td>
<td valign="top">Journal block per journal</td>
</tr>
<tr>
<td valign="top">Journal entry</td>
<td valign="top">1+</td>
<td valign="top">Tagged journal entries</td>
</tr>
<tr>
<td valign="top">Notes</td>
<td valign="top">1+</td>
<td valign="top">Note block per note</td>
</tr>
<tr>
<td valign="top">Plan/tasks</td>
<td valign="top">1+</td>
<td valign="top">Plan, i.e. the entire plan(s) that contain the tagged tasks</td>
</tr>
</table>
<p><strong>Note</strong>: The selected tags are only used to add the initial blocks to the page. If you tag other content afterwards, you would need to add that to the page yourself. Also, when you remove a block, it will not be added back automatically.</p>
<p>If you select a different tag (or the same again) the next time, the new content will be added to the page.</p>
......@@ -48,6 +48,8 @@ $string['unrecogniseddateformat'] = 'Unrecognised date format';
$string['allowcommentsonview1'] = 'Allow users to leave comments.';
$string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'How do you want people who look at your page to see your name?';
$string['createtags'] = 'Create via tags';
$string['createtagsdesc'] = 'Search for or enter tags that you want to use for pulling existing content into your page. If you have a lot of content tagged, this may take a little bit. You can then re-arrange and delete blocks from your page.';
$string['anonymise'] = 'Anonymise';
$string['anonymisedescription'] = 'Hide your name as the author of the page from other users. Administrators will still be able to see your name if they so desire.';
$string['Locked'] = 'Locked';
......
......@@ -4542,7 +4542,7 @@ function build_portfolio_search_html(&$data) {
safe_require('artefact', $artefacttypes[$item->artefacttype]->plugin);
$links = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_links', $item->id);
$item->url = $links['_default'];
$item->typestr = $item->artefacttype;
$item->typestr = isset($item->specialtype) ? $item->specialtype : $item->artefacttype;
if ($item->artefacttype == 'task') {
$item->typelabel = get_string('Task', 'artefact.plans');
}
......
......@@ -2916,7 +2916,7 @@ class View {
/**
* returns the current max block position within a column
*/
private function get_current_max_order($row, $column) {
public function get_current_max_order($row, $column) {
return get_field('block_instance', 'max("order")', 'column', $column, 'view', $this->get('id'), 'row', $row);
}
......
......@@ -1148,6 +1148,17 @@ class PluginSearchInternal extends PluginSearch {
}
$d->views = $record_views;
}
// Check if the file is a pdf
if ($d->artefacttype == 'file') {
if (get_field_sql("SELECT artefact
FROM {artefact_file_files}
WHERE artefact = ?
AND filetype IN (
SELECT mimetype FROM {artefact_file_mime_types}
WHERE description = ?)", array($d->id, 'pdf'))) {
$d->specialtype = 'pdf';
}
}
}
else if ($d->type == 'collection') {
$c = new Collection($d->id);
......@@ -1319,6 +1330,7 @@ class PluginSearchInternal extends PluginSearch {
$result->data = $data;
}
}
return $result;
}
......
......@@ -26,6 +26,7 @@
<strong>{str tag=tags}:</strong> {list_tags owner=$plan.owner tags=$plan.tags view=$plan.view}
</div>
{/if}
{if !$plan.description && !$plan.tags} &nbsp; {/if}
{if $plan.numtasks != 0}
{foreach from=$alltasks item=tasks}
......
This diff is collapsed.
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