Commit 3ba72d71 authored by Yuliya Bozhko's avatar Yuliya Bozhko Committed by Robert Lyon

Some artefact refactoring (Bug #1298646)

Fixes in this patch:

- Moved artefact.php to artefacts directory to separate it from pages.
- Fixed reference to a wrong 'artefactonlyviewableinview' string.
- Removed add_to_render_path() and its calls which have no purpose at all.
- Removed 'artefact_parent_cache' table.
- Removed cron jobs related to 'artefact_parent_cache' from DB.
- Added 'path' column in 'artefact' table to easier calculate hierarchy.
- Added ArtefactTest.php for artefacts unit tests

Change-Id: Ia14cd85b94c32a950354446ee3565bd2964c625c
Signed-off-by: default avatarYuliya Bozhko <yuliya.bozhko@totaralms.com>
parent b19a318b
......@@ -12,7 +12,7 @@
define('INTERNAL', 1);
define('PUBLIC', 1);
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PLUGINNAME', 'core');
define('SECTION_PAGE', 'artefact');
require(dirname(dirname(__FILE__)) . '/init.php');
......@@ -22,8 +22,7 @@ safe_require('artefact', 'comment');
$artefactid = param_integer('artefact');
$viewid = param_integer('view');
$blockid = param_integer('block',null);
$path = param_variable('path', null);
$blockid = param_integer('block', null);
$view = new View($viewid);
if (!can_view_view($view)) {
......@@ -32,31 +31,35 @@ if (!can_view_view($view)) {
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($artefactid);
// Build the path to the artefact, through its parents
if (!$artefact->in_view_list()) {
throw new AccessDeniedException(get_string('artefactonlyviewableinview', 'error'));
}
// Build the path to the artefact through its parents.
$artefactpath = array();
$parent = $artefact->get('parent');
$ancestors = $artefact->get_item_ancestors();
$artefactok = false;
if (artefact_in_view($artefact->get('id'), $viewid)) {
if (artefact_in_view($artefact, $viewid)) {
$artefactok = true;
$baseobject = $artefact;
}
while ($parent !== null) {
// This loop could get expensive when there are a lot of parents. But at least
// it works, unlike the old attempt
$parentobj = artefact_instance_from_id($parent);
if (artefact_in_view($parent, $viewid)) {
array_unshift($artefactpath, array(
'url' => get_config('wwwroot') . 'view/artefact.php?artefact=' . $parent . '&view=' . $viewid,
'title' => $parentobj->display_title(),
));
}
$parent = $parentobj->get('parent');
if (artefact_in_view($parentobj->get('id'), $viewid)) {
$artefactok = true;
$baseobject = $parentobj;
if (!empty($ancestors)) {
foreach ($ancestors as $ancestor) {
$pathitem = artefact_instance_from_id($ancestor);
if (artefact_in_view($pathitem, $viewid)) {
$artefactpath[] = array(
'url' => get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $pathitem->get('id') . '&view=' . $viewid,
'title' => $pathitem->display_title(),
);
$artefactok = true;
$baseobject = $pathitem;
}
}
}
if ($artefactok == false) {
throw new AccessDeniedException(get_string('artefactnotinview', 'error', $artefactid, $viewid));
}
......@@ -66,7 +69,6 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$showcomment = param_integer('showcomment', null);
if ($artefact && $viewid && $blockid) {
// use the block instance title rather than the artefact title if it exists
$title = artefact_title_for_view_and_block($artefact, $viewid, $blockid);
......@@ -74,9 +76,6 @@ if ($artefact && $viewid && $blockid) {
else {
$title = $artefact->display_title();
}
if (!$artefact->in_view_list()) {
throw new AccessDeniedException(get_string('artefactsonlyviewableinview', 'error'));
}
// Create the "make feedback private form" now if it's been submitted
if (param_variable('make_public_submit', null)) {
......@@ -91,19 +90,17 @@ define('TITLE', $title . ' ' . get_string('in', 'view') . ' ' . $view->get('titl
// Render the artefact
$options = array(
'viewid' => $viewid,
'path' => $path,
'details' => true,
'metadata' => 1,
);
if ($artefact->get('artefacttype') == 'folder') {
// get folder block sort order - returns the first instance of folder on view unless $blockid is set.
// Why you'd want more than one folder block on the same view is m̶a̶d̶n̶e̶s̶s̶ user preference.
// TO DO: get the clicking on a subfolder to carry the block id as well - that way we can get exact configdata
// Get folder block sort order - returns the first instance of folder on view unless $blockid is set.
// TODO: get the clicking on a subfolder to carry the block id as well - that way we can get exact configdata.
if ($block = get_records_sql_array('SELECT block FROM {view_artefact} WHERE view = ? AND artefact = ?', array($viewid, $baseobject->get('id')))) {
require_once(get_config('docroot') . 'blocktype/lib.php');
$key = 0;
// If we have a $blockid then we will use that one's configdata
// If we have a $blockid, then we will use block's configdata.
if ($blockid) {
foreach ($block as $k => $b) {
if ($b->block == $blockid) {
......@@ -129,11 +126,6 @@ if (!empty($rendered['javascript'])) {
}
$content .= $rendered['html'];
$artefactpath[] = array(
'url' => '',
'title' => $title,
);
// Feedback
$feedback = ArtefactTypeComment::get_comments($limit, $offset, $showcomment, $view, $artefact);
......@@ -181,10 +173,10 @@ else {
$hasfeed = false;
$feedlink = '';
// add a link to the ATOM feed in the header if the view is public
if($artefact->get('artefacttype') == 'blog' && $view->is_public()) {
if ($artefact->get('artefacttype') == 'blog' && $view->is_public()) {
$hasfeed = true;
$feedlink = get_config('wwwroot') . 'artefact/blog/atom.php?artefact=' .
$artefactid . '&view=' . $viewid;
$artefactid . '&view=' . $viewid;
$headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '">';
}
......@@ -195,7 +187,7 @@ $smarty = smarty(
array(
'stylesheets' => $extrastylesheets,
'sidebars' => false,
'skin' => $skin,
'skin' => $skin,
)
);
......@@ -234,4 +226,4 @@ $smarty->assign('objectionform', $objectionform);
$smarty->assign('notrudeform', $notrudeform);
$smarty->assign('viewbeingwatched', $viewbeingwatched);
$smarty->display('view/artefact.tpl');
$smarty->display('artefact/artefact.tpl');
......@@ -98,7 +98,7 @@ else {
'name' => implode(' ', array($owner[0]->firstname, $owner[0]->lastname)),
'uri' => sanitize_url($personal_site),
);
$link = get_config('wwwroot') . 'view/artefact.php?artefact=' .
$link = get_config('wwwroot') . 'artefact/artefact.php?artefact=' .
$artefactid . '&view=' . $viewid;
$selflink = get_config('wwwroot') . 'artefact/blog/atom.php?artefact=' .
$artefactid . '&view=' . $viewid;
......@@ -176,7 +176,7 @@ else {
}
$posts[] = array(
'title' => $post->get('title'),
'link' => get_config('wwwroot') . 'view/artefact.php?artefact=' .
'link' => get_config('wwwroot') . 'artefact/artefact.php?artefact=' .
$post->get('id') . '&view=' . $viewid,
'id' => implode(',', array(get_config('wwwroot'), $post->get('id'), $viewid)),
'description' => $post->get('description'),
......
......@@ -76,7 +76,7 @@ class PluginBlocktypeBlog extends PluginBlocktype {
$smarty = smarty_core();
if (isset($configdata['viewid'])) {
$artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $blog->get('id') . '&view='
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $blog->get('id') . '&view='
. $configdata['viewid'];
$smarty->assign('artefacttitle', '<a href="' . $artefacturl . '">' . hsc($blog->get('title')) . '</a>');
if ($exporter && $posts['count'] > $limit) {
......
......@@ -15,9 +15,9 @@
<ul class="recentblogpost">
{foreach from=$mostrecent item=post}
<li>
<strong><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&amp;view={$view}">{$post->title}</a></strong>
<strong><a href="{$WWWROOT}artefact/artefact.php?artefact={$post->id}&amp;view={$view}">{$post->title}</a></strong>
{str tag='postedin' section='blocktype.blog/recentposts'}
<a href="{$WWWROOT}view/artefact.php?artefact={$post->parent}&amp;view={$view}">{$post->parenttitle}</a>
<a href="{$WWWROOT}artefact/artefact.php?artefact={$post->parent}&amp;view={$view}">{$post->parenttitle}</a>
{str tag='postedon' section='blocktype.blog/recentposts'}
<span>{$post->displaydate}</span>
</li>
......
......@@ -21,11 +21,11 @@
<div id="postlist_{$blockid}" class="postlist fullwidth">
{foreach from=$results item=post}
<div class="post">
<h3 class="title"><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></h3>
<h3 class="title"><a href="{$WWWROOT}artefact/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></h3>
<div class="postdetails">{$post->postedbyon}</div>
<div class="detail">{$post->description|clean_html|safe}</div>
<div class="tags">{str tag=tags}: {list_tags owner=$post->owner tags=$post->taglist}</div>
{if $post->allowcomments}<div class="postdetails"><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{str tag=Comments section=artefact.comment} ({$post->commentcount})</a></div>{/if}
{if $post->allowcomments}<div class="postdetails"><a href="{$WWWROOT}artefact/artefact.php?artefact={$post->id}&view={$view}">{str tag=Comments section=artefact.comment} ({$post->commentcount})</a></div>{/if}
</div>
{/foreach}
</div>
......@@ -33,10 +33,10 @@
{else}<ul class="taggedposts">{foreach from=$results item=post}
<li>
<strong><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></strong>
<strong><a href="{$WWWROOT}artefact/artefact.php?artefact={$post->id}&view={$view}">{$post->title}</a></strong>
{str tag='postedin' section='blocktype.blog/taggedposts'}
{if $viewowner}{$post->parenttitle}
{else}<a href="{$WWWROOT}view/artefact.php?artefact={$post->parent}&view={$view}">{$post->parenttitle}</a>{/if}
{else}<a href="{$WWWROOT}artefact/artefact.php?artefact={$post->parent}&view={$view}">{$post->parenttitle}</a>{/if}
<span class="postdetails">{str tag='postedon' section='blocktype.blog/taggedposts'} {$post->displaydate}</span>
</li>
{/foreach}</ul>
......
......@@ -194,8 +194,6 @@ class ArtefactTypeBlog extends ArtefactType {
* @return array A two key array, 'html' and 'javascript'.
*/
public function render_self($options) {
$this->add_to_render_path($options);
if (!isset($options['limit'])) {
$limit = self::pagination;
}
......@@ -216,7 +214,7 @@ class ArtefactTypeBlog extends ArtefactType {
$template = 'artefact:blog:viewposts.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id;
$baseurl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $this->id;
if (!empty($options['viewid'])) {
$baseurl .= '&view=' . $options['viewid'];
}
......@@ -231,7 +229,7 @@ class ArtefactTypeBlog extends ArtefactType {
$smarty = smarty_core();
if (isset($options['viewid'])) {
$smarty->assign('artefacttitle', '<a href="' . get_config('wwwroot') . 'view/artefact.php?artefact='
$smarty->assign('artefacttitle', '<a href="' . get_config('wwwroot') . 'artefact/artefact.php?artefact='
. $this->get('id') . '&view=' . $options['viewid']
. '">' . hsc($this->get('title')) . '</a>');
}
......@@ -622,7 +620,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
public function render_self($options) {
$smarty = smarty_core();
$artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->get('id');
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $this->get('id');
if (isset($options['viewid'])) {
$artefacturl .= '&view=' . $options['viewid'];
}
......@@ -660,13 +658,12 @@ class ArtefactTypeBlogPost extends ArtefactType {
$attachments = $this->get_attachments();
if ($attachments) {
$this->add_to_render_path($options);
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($attachments as &$attachment) {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
$attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0));
$attachment->viewpath = get_config('wwwroot') . 'view/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
if (isset($options['viewid'])) {
$attachment->downloadpath .= '&view=' . $options['viewid'];
......@@ -752,7 +749,11 @@ class ArtefactTypeBlogPost extends ArtefactType {
if ($files) {
safe_require('artefact', 'file');
foreach ($files as &$file) {
$file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', array('id' => $file->attachment));
$params = array('id' => $file->attachment);
if (!empty($viewoptions['viewid'])) {
$params['viewid'] = $viewoptions['viewid'];
}
$file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', $params);
$data[$file->artefact]->files[] = $file;
}
}
......
......@@ -42,7 +42,7 @@ if ($blockid = param_integer('block', null)) {
ArtefactTypeBlogpost::render_posts($posts, $template, $configdata, $pagination);
}
else {
// No block, we're just rendering the blog by itself on view/artefact.php
// No block, we're just rendering the blog by itself.
$limit = param_integer('limit', ArtefactTypeBlog::pagination);
$blogid = param_integer('artefact');
$viewid = param_integer('view');
......@@ -56,7 +56,7 @@ else {
$posts = ArtefactTypeBlogpost::get_posts($blogid, $limit, $offset, $options);
$template = 'artefact:blog:viewposts.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $blogid . '&view=' . $viewid;
$baseurl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $blogid . '&view=' . $viewid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'blogpost_pagination',
......
{foreach from=$posts item=post}
<div class="post">
<h3 class="title"><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$options.viewid}">{$post->title}</a></h3>
<h3 class="title"><a href="{$WWWROOT}artefact/artefact.php?artefact={$post->id}&view={$options.viewid}">{$post->title}</a></h3>
<div class="postdetails">{$post->postedby}</div>
<div>{$post->description|clean_html|safe}
{if $post->tags}
......@@ -25,7 +25,7 @@
<td class="icon-container"><img src="{$file->icon}" alt=""></td>
<td>
<h3 class="title">
<a href="{$WWWROOT}view/artefact.php?artefact={$file->attachment}&view={$options.viewid}">{$file->title}</a>
<a href="{$WWWROOT}artefact/artefact.php?artefact={$file->attachment}&view={$options.viewid}">{$file->title}</a>
<span class="description">({$file->size|display_size}) - <a href="{$WWWROOT}artefact/file/download.php?file={$file->attachment}&view={$options.viewid}">{str tag=Download section=artefact.file}</a></span>
</h3>
<div class="detail">{$file->description}</div>
......@@ -35,6 +35,6 @@
</tbody>
</table>
{/if}
{if $options.viewid && $post->allowcomments}<div class="postdetails"><a href="{$WWWROOT}view/artefact.php?artefact={$post->id}&view={$options.viewid}">{str tag=Comments section=artefact.comment} ({$post->commentcount})</a></div>{/if}
{if $options.viewid && $post->allowcomments}<div class="postdetails"><a href="{$WWWROOT}artefact/artefact.php?artefact={$post->id}&view={$options.viewid}">{str tag=Comments section=artefact.comment} ({$post->commentcount})</a></div>{/if}
</div>
{/foreach}
......@@ -601,7 +601,7 @@ class ArtefactTypeComment extends ArtefactType {
$data->jsonscript = 'artefact/comment/comments.json.php';
if (!empty($data->artefact)) {
$data->baseurl = get_config('wwwroot') . 'view/artefact.php?view=' . $data->view . '&artefact=' . $data->artefact;
$data->baseurl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $data->view . '&artefact=' . $data->artefact;
$extradata['artefact'] = $data->artefact;
}
else {
......@@ -751,7 +751,7 @@ class ArtefactTypeComment extends ArtefactType {
public function get_view_url($viewid, $showcomment=true, $full=true) {
if ($artefact = $this->get('onartefact')) {
$url = 'view/artefact.php?view=' . $viewid . '&artefact=' . $artefact;
$url = 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $artefact;
}
else {
$url = 'view/view.php?id=' . $viewid;
......@@ -959,7 +959,7 @@ function delete_comment_submit(Pieform $form, $values) {
$viewid = $view->get('id');
if ($artefact = $comment->get('onartefact')) {
$url = 'view/artefact.php?view=' . $viewid . '&artefact=' . $artefact;
$url = 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $artefact;
}
else {
$url = $view->get_url(false);
......@@ -1254,7 +1254,7 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
$userid = $artefactinstance->get('owner');
}
if (empty($this->url)) {
$this->url = 'view/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
$this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
}
}
else { // feedback on view.
......
......@@ -5,7 +5,7 @@
<h3 class="title"><a href="{$file.downloadurl}" target="_blank">{$file.title}</a></h3>
{if $file.description}<div class="detail">{$file.description}</div>{/if}
<div class="description">{$file.size|display_size} | {$file.ctime|format_date:'strftimedaydate'}
| <a href="{$WWWROOT}view/artefact.php?artefact={$file.id}&view={$viewid}">{str tag=Details section=artefact.file}</a></div>
| <a href="{$WWWROOT}artefact/artefact.php?artefact={$file.id}&view={$viewid}">{str tag=Details section=artefact.file}</a></div>
</div>
</div>
{/foreach}
......@@ -364,7 +364,7 @@ class PluginBlocktypeGallery extends PluginBlocktype {
$link = $src . '&maxwidth=' . get_config_plugin('blocktype', 'gallery', 'previewwidth');
}
else {
$link = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view');
$link = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view');
}
// If the Thumbnails are Square or not...
......
......@@ -51,7 +51,7 @@ class PluginBlocktypeImage extends PluginBlocktype {
}
$smarty = smarty_core();
$smarty->assign('url', $wwwroot . 'view/artefact.php?artefact=' . $id . '&view=' . $viewid);
$smarty->assign('url', $wwwroot . 'artefact/artefact.php?artefact=' . $id . '&view=' . $viewid);
$smarty->assign('src', $src);
$smarty->assign('description', $description);
$smarty->assign('showdescription', !empty($configdata['showdescription']) && !empty($description));
......
......@@ -33,18 +33,21 @@ else {
if ($viewid && $fileid) {
$file = artefact_instance_from_id($fileid);
$parent = $file->get('parent');
$ancestors = $file->get_item_ancestors();
$artefactok = false;
if (artefact_in_view($file->get('id'), $viewid)) {
if (artefact_in_view($file, $viewid)) {
$artefactok = true;
}
// Check to see if the artefact has a parent that is allowed to be in this view
// for example subdirectory of a folder artefact on a view
while ($parent !== null) {
$parentobj = artefact_instance_from_id($parent);
$parent = $parentobj->get('parent');
if (artefact_in_view($parentobj->get('id'), $viewid)) {
$artefactok = true;
// Check to see if the artefact has a parent that is allowed to be in this view.
// For example, subdirectory of a folder artefact on a view.
if (!empty($ancestors) && !$artefactok) {
foreach ($ancestors as $ancestor) {
$pathitem = artefact_instance_from_id($ancestor);
if (artefact_in_view($pathitem, $viewid)) {
$artefactok = true;
break;
}
}
}
......@@ -81,7 +84,7 @@ else {
// If the file is in the public directory, it's fine to serve
$fileispublic = $file->get('institution') == 'mahara';
$fileispublic = $fileispublic && (bool)get_field('artefact_parent_cache', 'artefact', 'artefact', $fileid, 'parent', ArtefactTypeFolder::admin_public_folder_id());
$fileispublic = $fileispublic && (bool)get_field('artefact', 'id', 'id', $fileid, 'parent', ArtefactTypeFolder::admin_public_folder_id());
if (!$fileispublic) {
// If the file is in the logged in menu and the user is logged in then
......
......@@ -27,13 +27,12 @@ $institution = param_alpha('institution', 0);
* current user can view the view)
*/
function can_download_artefact($artefact) {
global $USER;
global $viewid;
global $USER, $viewid;
if ($USER->can_view_artefact($artefact)) {
return true;
}
else if (artefact_in_view($artefact->get('id'), $viewid)) {
else if (artefact_in_view($artefact, $viewid)) {
return can_view_view($viewid);
}
......@@ -41,7 +40,7 @@ function can_download_artefact($artefact) {
while ($parent !== null) {
$parentobj = artefact_instance_from_id($parent);
$parent = $parentobj->get('parent');
if (artefact_in_view($parentobj->get('id'), $viewid)) {
if (artefact_in_view($parentobj, $viewid)) {
return can_view_view($viewid);
}
}
......@@ -216,11 +215,9 @@ if ($folderid === 0) {
if ($institution == 'mahara' && !$USER->get('admin')) {
// If non-admins are browsing site files, only let them see the public folder & its contents
$publicfolder = ArtefactTypeFolder::admin_public_folder_id();
$from .= '
LEFT OUTER JOIN {artefact_parent_cache} pub ON (a.id = pub.artefact AND pub.parent = ?)';
$where .= '
AND (pub.parent = ? OR a.id = ?)';
$phvals = array($publicfolder, $publicfolder, $publicfolder);
AND (a.path = ? OR a.path LIKE ?)';
$phvals = array("/$publicfolder", db_like_escape("/$publicfolder/") . '%');
}
$where .= '
AND a.institution = ? AND a.owner IS NULL';
......
......@@ -435,15 +435,21 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
if ($institution == 'mahara' && !$USER->get('admin')) {
// If non-admins are browsing site files, only let them see the public folder & its contents
$publicfolder = ArtefactTypeFolder::admin_public_folder_id();
$from .= '
LEFT OUTER JOIN {artefact_parent_cache} pub ON (a.id = pub.artefact AND pub.parent = ?)';
$where .= '
AND (pub.parent = ? OR a.id = ?)';
$phvals = array($publicfolder, $publicfolder, $publicfolder);
AND (a.path = ? OR a.path LIKE ?)';
$phvals = array("/$publicfolder", "/$publicfolder/%");
}
else {
$from .= '
LEFT OUTER JOIN {usr_institution} ui ON ui.institution = a.institution';
$where .= ' AND a.institution = ? ';
$phvals[] = $institution;
// Check if user is an admin in this institution.
if (!$USER->get('admin')) {
$where .= ' AND ui.admin = 1 AND ui.usr = ? ';
$phvals[] = $USER->get('id');
}
}
$where .= '
AND a.institution = ? AND a.owner IS NULL';
$phvals[] = $institution;
}
else if ($group) {
$select .= ',
......@@ -453,12 +459,12 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
SELECT ar.artefact, ar.can_edit, ar.can_view, ar.can_republish
FROM {artefact_access_role} ar
INNER JOIN {group_member} gm ON ar.role = gm.role
WHERE gm.group = ? AND gm.member = ?
WHERE gm.group = ? AND gm.member = ?
) r ON r.artefact = a.id';
$phvals[] = $group;
$phvals[] = $USER->get('id');
$where .= '
AND a.group = ? AND a.owner IS NULL AND (r.can_view = 1 OR a.author = ?)';
AND a.group = ? AND (r.can_view = 1 OR a.author = ?)';
$phvals[] = $group;
$phvals[] = $USER->get('id');
$groupby .= ', r.can_edit, r.can_view, r.can_republish, a.author';
......@@ -1747,7 +1753,6 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
$smarty->assign('downloadfolderzip', get_config_plugin('blocktype', 'folder', 'folderdownloadzip') ? !empty($options['folderdownloadzip']) : false);
if ($childrecords = $this->folder_contents()) {
$this->add_to_render_path($options);
$sortorder = (isset($options['sortorder']) && $options['sortorder'] == 'desc') ? 'my_files_cmp_desc' : 'my_files_cmp';
usort($childrecords, array('ArtefactTypeFileBase', $sortorder));
$children = array();
......@@ -2039,7 +2044,7 @@ class ArtefactTypeImage extends ArtefactTypeFile {
public function render_self($options) {
$downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $this->id;
$url = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id;
$url = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $this->id;
if (isset($options['viewid'])) {
$downloadpath .= '&view=' . $options['viewid'];
$url .= '&view=' . $options['viewid'];
......
......@@ -18,7 +18,7 @@
{foreach from=$children item=child}
<tr class="{cycle values='r0,r1'}">
<td class="icon-container"><img src="{$child->iconsrc}" alt="{$child->artefacttype}"></td>
<td class="filename"><a href="{$WWWROOT}view/artefact.php?artefact={$child->id}&amp;view={$viewid}" title="{$child->hovertitle}">{$child->title}</a></td>
<td class="filename"><a href="{$WWWROOT}artefact/artefact.php?artefact={$child->id}&amp;view={$viewid}" title="{$child->hovertitle}">{$child->title}</a></td>
<td class="filedescription">{$child->description}</td>
{if !$simpledisplay}
<td class="filedate">{$child->date}</td>
......
......@@ -45,13 +45,12 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
$attachments = $artefact->get_attachments();
if ($attachments) {
$artefact->add_to_render_path($options);
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($attachments as &$attachment) {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
$attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0));
$attachment->viewpath = get_config('wwwroot') . 'view/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($viewid) ? $viewid : 0);
$attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($viewid) ? $viewid : 0);
$attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
if (isset($viewid)) {
$attachment->downloadpath .= '&view=' . $viewid;
......@@ -64,7 +63,7 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
if ($artefact->get('allowcomments')) {
$commentcount = ArtefactTypeComment::count_comments(null, array($configdata['artefactid']));
$commentcount = isset($commentcount[$configdata['artefactid']]) ? $commentcount[$configdata['artefactid']]->comments : 0;
$artefacturl = get_config('wwwroot') . 'view/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid'];
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid'];
$smarty->assign('artefacturl', $artefacturl);
$smarty->assign('commentcount', $commentcount);
}
......
......@@ -880,13 +880,12 @@ class ArtefactTypeHtml extends ArtefactType {
}
$attachments = $this->get_attachments();
if ($attachments) {
$this->add_to_render_path($options);
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($attachments as &$attachment) {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
$attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0));
$attachment->viewpath = get_config('wwwroot') . 'view/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
if (isset($options['viewid'])) {
$attachment->downloadpath .= '&view=' . $options['viewid'];
......
This diff is collapsed.
......@@ -78,7 +78,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);
if ($exporter && $tasks['count'] > $tasks['limit']) {
$artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $configdata['artefactid']
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $configdata['artefactid']
. '&view=' . $instance->get('view');
$tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
}
......
......@@ -269,8 +269,6 @@ class ArtefactTypePlan extends ArtefactType {
}
public function render_self($options) {
$this->add_to_render_path($options);
$limit = !isset($options['limit']) ? 10 : (int) $options['limit'];
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
......@@ -278,7 +276,7 @@ class ArtefactTypePlan extends ArtefactType {
$template = 'artefact:plans:taskrows.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id;
$baseurl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $this->id;
if (!empty($options['viewid'])) {
$baseurl .= '&view=' . $options['viewid'];
}
......
......@@ -49,7 +49,7 @@ else {
$tasks = ArtefactTypeTask::get_tasks($planid, $offset, $limit);
$template = 'artefact:plans:taskrows.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $planid . '&view=' . $options['viewid'];
$baseurl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $planid . '&view=' . $options['viewid'];
$pagination = array(
'baseurl' => $baseurl,
'id' => 'task_pagination',
......
......@@ -893,7 +893,7 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
$attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0));
$attachment->viewpath = get_config('wwwroot') . 'view/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
$attachment->description = $f->description;
}
......@@ -1889,7 +1889,7 @@ class ArtefactTypeResumeGoalAndSkill extends ArtefactTypeResume {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
$attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0));
$attachment->viewpath = get_config('wwwroot') . 'view/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($options['viewid']) ? $options['viewid'] : 0);
$attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
$attachment->description = $f->description;
}
......
......@@ -968,7 +968,7 @@ class User {
if ($a instanceof ArtefactTypeFileBase) {
$publicfolderid = ArtefactTypeFolder::admin_public_folder_id();
$fileispublic = ($a->get('id') == $publicfolderid)
|| (($a->get('institution') == 'mahara') && (bool)get_field('artefact_parent_cache', 'artefact', 'artefact', $a->get('id'), 'parent', $publicfolderid));
|| (($a->get('institution') == 'mahara') && (bool)get_field('artefact', 'id', 'id', $a->get('id'), 'parent', $publicfolderid));
if ($fileispublic) {
return true;
}
......
......@@ -796,7 +796,7 @@ class BlockInstance {
$configdata = $this->get('configdata');
if (!empty($configdata['artefactid'])) {
if (call_static_method($classname, 'has_title_link')) {
$smarty->assign('viewartefacturl', get_config('wwwroot') . 'view/artefact.php?artefact='
$smarty->assign('viewartefacturl', get_config('wwwroot') . 'artefact/artefact.php?artefact='
. $configdata['artefactid'] . '&view=' . $this->get('view') . '&block=' . $this->get('id'));
}
}
......
......@@ -714,6 +714,8 @@ $string['republish'] = 'Publish';
$string['view'] = 'Page';