Commit b3bdbdc9 authored by Robert Lyon's avatar Robert Lyon Committed by Cecilia Vela Gurovic
Browse files

Bug 1742347: Allow $versioning variable for block rendering



To allow us to restrict things being shown for block when in older
version.

behatnotneeded

Change-Id: I8d9ffe1e7b26a07fc84e3ce64e988b9d7babc396
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 4aa41f44
......@@ -115,7 +115,7 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
return false;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$smarty = smarty_core();
$artefactid = '';
$text = '';
......@@ -131,7 +131,7 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
$text = $artefact->get('description');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewid);
list($feedbackcount, $annotationfeedback) = ArtefactTypeAnnotationfeedback::get_annotation_feedback_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($feedbackcount, $annotationfeedback) = ArtefactTypeAnnotationfeedback::get_annotation_feedback_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
$smarty->assign('annotationfeedback', $annotationfeedback);
}
$smarty->assign('text', $text);
......
......@@ -46,7 +46,7 @@ class PluginBlocktypeBlog extends MaharaCoreBlocktype {
}
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $exporter;
$configdata = $instance->get('configdata');
......@@ -56,6 +56,7 @@ class PluginBlocktypeBlog extends MaharaCoreBlocktype {
$blog = $instance->get_artefact_instance($configdata['artefactid']);
$configdata['hidetitle'] = true;
$configdata['countcomments'] = true;
$configdata['versioning'] = $versioning;
$configdata['viewid'] = $instance->get('view');
if ($instance->get_view()->is_submitted()) {
// Don't display posts added after the submitted date.
......@@ -67,7 +68,7 @@ class PluginBlocktypeBlog extends MaharaCoreBlocktype {
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$posts = ArtefactTypeBlogpost::get_posts($blog->get('id'), $limit, 0, $configdata);
$template = 'artefact:blog:viewposts.tpl';
if ($exporter) {
if ($exporter || $versioning) {
$pagination = false;
}
else {
......@@ -225,6 +226,25 @@ class PluginBlocktypeBlog extends MaharaCoreBlocktype {
return $artefacts;
}
public static function get_current_artefacts(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$artefacts = array();
if (isset($configdata['artefactid'])) {
$blog = $instance->get_artefact_instance($configdata['artefactid']);
if ($blogposts = $blog->get_children_instances()) {
foreach ($blogposts as $blogpost) {
if ($blogpost->get('published')) {
$artefacts[] = $blogpost->get('id');
}
}
$artefacts = array_unique($artefacts);
}
}
return $artefacts;
}
public static function artefactchooser_element($default=null, $blogids=array()) {
return array(
'name' => 'artefactid',
......
......@@ -38,7 +38,7 @@ class PluginBlocktypeBlogpost extends MaharaCoreBlocktype {
return array('blog' => 11000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$configdata = $instance->get('configdata');
$result = '';
......@@ -55,7 +55,7 @@ class PluginBlocktypeBlogpost extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($configdata['viewid']);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
}
$smarty = smarty_core();
......
......@@ -107,7 +107,7 @@ class PluginBlocktypeRecentposts extends MaharaCoreBlocktype {
return $mostrecent;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $USER;
$result = '';
......
......@@ -168,7 +168,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
return $results;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $USER;
$configdata = $instance->get('configdata');
......@@ -231,7 +231,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
$result->commentcount = null;
}
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $viewobj, null, false);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $viewobj, null, false, false, $versioning);
$result->comments = $comments;
// get all tags for this post
......
......@@ -1016,6 +1016,9 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
$draftentries = count_records_sql('SELECT COUNT(*) ' . $from, array($id));
$from .= ' AND bp.published = 1';
if (!empty($viewoptions['existing_artefacts'])) {
$from .= ' AND bp.blogpost IN (' . join(',', (array)$viewoptions['existing_artefacts']) . ')';
}
}
$results['count'] = count_records_sql('SELECT COUNT(*) ' . $from, array($id));
......@@ -1078,9 +1081,12 @@ class ArtefactTypeBlogPost extends ArtefactType {
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewoptions['viewid']);
$artefact = artefact_instance_from_id($post->id);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, null, false);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, null, false, false, $viewoptions['versioning']);
$post->commentcount = $commentcount;
$post->comments = $comments;
if ($viewoptions['versioning']) {
$post->allowcomments = false;
}
}
}
if ($post->ctime != $post->mtime) {
......
......@@ -38,7 +38,7 @@ class PluginBlocktypeComment extends MaharaCoreBlocktype {
return array('portfolio');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $USER;
if ($editing) {
......
......@@ -677,11 +677,12 @@ class ArtefactTypeComment extends ArtefactType {
* @param int $blockid The id of the block instance that connects the artefact to the view
* @param bool $html Whether to return the information rendered as html or not
* @param bool $editing Whether we are view edit mode or not
* @param bool $versioning Whether we are view versioning mode or not
*
* @return array $commentcount, $comments The count of comments and either the comments
* or the html to render them.
*/
public function get_artefact_comments_for_view(ArtefactType $artefact, $view, $blockid, $html = true, $editing = false) {
public function get_artefact_comments_for_view(ArtefactType $artefact, $view, $blockid, $html = true, $editing = false, $versioning = false) {
global $USER;
if (!is_object($artefact) || !is_object($view)) {
......@@ -712,6 +713,7 @@ class ArtefactTypeComment extends ArtefactType {
$smarty->assign('commentcount', $commentcount);
$smarty->assign('comments', $comments);
$smarty->assign('editing', $editing);
$smarty->assign('versioning', $versioning); // Do not show comments in versioning
$smarty->assign('allowcomments', $artefact->get('allowcomments'));
$smarty->assign('allowcommentsadd', ($artefact->get('allowcomments') && ( $USER->is_logged_in() || (!$USER->is_logged_in() && get_config('anonymouscomments')))));
$render = $smarty->fetch('artefact/artefactcommentsview.tpl');
......
......@@ -25,7 +25,7 @@ class PluginBlocktypeFiledownload extends MaharaCoreBlocktype {
return array('fileimagevideo' => 3000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
require_once(get_config('docroot') . 'artefact/lib.php');
$configdata = $instance->get('configdata');
......
......@@ -38,7 +38,7 @@ class PluginBlocktypeFolder extends MaharaCoreBlocktype {
return array('fileimagevideo' => 4000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
require_once(get_config('docroot') . 'artefact/lib.php');
$configdata = $instance->get('configdata');
$configdata['viewid'] = $instance->get('view');
......@@ -56,7 +56,7 @@ class PluginBlocktypeFolder extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($configdata['viewid']);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
}
$smarty = smarty_core();
if ($artefactid) {
......@@ -204,4 +204,19 @@ class PluginBlocktypeFolder extends MaharaCoreBlocktype {
return 'full';
}
public static function get_current_artefacts(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$artefacts = array();
if (isset($configdata['artefactid'])) {
$folder = $instance->get_artefact_instance($configdata['artefactid']);
if ($files = $folder->get_children_instances()) {
foreach ($files as $file) {
$artefacts[] = $file->get('id');
}
}
$artefacts = array_unique($artefacts);
}
return $artefacts;
}
}
......@@ -78,7 +78,7 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
$configdata['viewid'] = $instance->get('view');
$style = isset($configdata['style']) ? intval($configdata['style']) : 2;
......@@ -328,6 +328,9 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
if (isset($configdata['select']) && $configdata['select'] == 1 && is_array($configdata['artefactids'])) {
$artefactids = $configdata['artefactids'];
}
else if ($versioning && !empty($configdata['existing_artefacts'])) {
$artefactids = (array) $configdata['existing_artefacts'];
}
else if (!empty($configdata['artefactid'])) {
// Get descendents of this folder.
$artefactids = artefact_get_descendants(array(intval($configdata['artefactid'])));
......@@ -425,7 +428,7 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($configdata['viewid']);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
$smarty->assign('commentcount', $commentcount);
$smarty->assign('comments', $comments);
}
......@@ -836,4 +839,14 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
public static function default_copy_type() {
return 'full';
}
public static function get_current_artefacts(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$artefacts = array();
if (isset($configdata['artefactid'])) {
safe_require('artefact', 'file');
$artefacts = artefact_get_descendants(array(intval($configdata['artefactid'])));
}
return $artefacts;
}
}
......@@ -25,7 +25,7 @@ class PluginBlocktypeHtml extends MaharaCoreBlocktype {
return array('fileimagevideo' => 9000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
$configdata['viewid'] = $instance->get('view');
......@@ -43,7 +43,7 @@ class PluginBlocktypeHtml extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($configdata['viewid']);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
}
$smarty = smarty_core();
......
......@@ -32,7 +32,7 @@ class PluginBlocktypeImage extends MaharaCoreBlocktype {
return array('shortcut' => 2000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
if (!isset($configdata['artefactid'])) {
......@@ -61,7 +61,7 @@ class PluginBlocktypeImage extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewid);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($image, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($image, $view, $instance->get('id'), true, $editing, $versioning);
$smarty = smarty_core();
$smarty->assign('commentcount', $commentcount);
$smarty->assign('comments', $comments);
......
......@@ -44,7 +44,7 @@ class PluginBlocktypeInternalmedia extends MaharaCoreBlocktype {
}
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
list($artefact, $width, $height) = self::get_mediaplayer_details($instance);
if (!$artefact) {
return '';
......@@ -73,7 +73,7 @@ class PluginBlocktypeInternalmedia extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($instance->get('view'));
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
$smarty = smarty_core();
......
......@@ -29,7 +29,7 @@ class PluginBlocktypePdf extends MaharaCoreBlocktype {
return array('fileimagevideo' => 8000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $USER;
require_once(get_config('docroot') . 'lib/view.php');
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
......@@ -79,7 +79,7 @@ class PluginBlocktypePdf extends MaharaCoreBlocktype {
require_once(get_config('docroot') . 'artefact/comment/lib.php');
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($configdata['viewid']);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
}
$smarty = smarty_core();
if ($artefactid) {
......
......@@ -2143,7 +2143,15 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
$smarty->assign('folderid', $this->get('id'));
$smarty->assign('downloadfolderzip', get_config_plugin('blocktype', 'folder', 'folderdownloadzip') ? !empty($options['folderdownloadzip']) : false);
if ($childrecords = $this->folder_contents()) {
$childrecords = false;
if (!empty($options['existing_artefacts'])) {
$childrecords = get_records_sql_array("SELECT * FROM {artefact} WHERE id IN (" . join(',', (array)$options['existing_artefacts']) . ")");
}
else {
$childrecords = $this->folder_contents();
}
if ($childrecords) {
$sortorder = (isset($options['sortorder']) && $options['sortorder'] == 'desc') ? 'my_files_cmp_desc' : 'my_files_cmp';
usort($childrecords, array('ArtefactTypeFileBase', $sortorder));
$children = array();
......
......@@ -29,8 +29,8 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
return array('js/configform.js');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
safe_require('artefact', 'internal');
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
safe_require('artefact', 'internal');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
......
......@@ -26,7 +26,7 @@ class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
return array('internal' => 27000);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$configdata = $instance->get('configdata');
$type = (isset($configdata['displaytype']) ? $configdata['displaytype'] : 'texticon');
......
......@@ -29,7 +29,7 @@ class PluginBlocktypeTextbox extends MaharaCoreBlocktype {
return true;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$configdata = $instance->get('configdata');
if (!empty($configdata['artefactid'])) {
......@@ -61,7 +61,7 @@ class PluginBlocktypeTextbox extends MaharaCoreBlocktype {
$smarty->assign('attachments', $attachments);
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewid);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing, $versioning);
$smarty->assign('commentcount', $commentcount);
$smarty->assign('comments', $comments);
$smarty->assign('blockid', $instance->get('id'));
......
......@@ -42,7 +42,7 @@ class PluginBlocktypePeerassessment extends MaharaCoreBlocktype {
return true;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $USER;
$configdata = $instance->get('configdata');
......
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