Commit 1fea3063 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow blog post blocks to be copied and create a blog to hold them

parent 800bf6f8
......@@ -139,11 +139,11 @@ class PluginBlocktypeBlog extends PluginBlocktype {
//}
public static function copy_allowed($newowner=null) {
return true;
return $newowner == 'user';
}
public static function copy_artefacts_allowed($newowner=null) {
return true;
return $newowner == 'user';
}
public static function default_copy_type() {
......
......@@ -80,9 +80,11 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
}
public static function instance_config_form($instance) {
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost'),
);
}
......@@ -135,11 +137,11 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
}
public static function copy_allowed($newowner=null) {
return false;
return $newowner == 'user';
}
public static function copy_artefacts_allowed($newowner=null) {
return false;
return $newowner == 'user';
}
public static function default_copy_type() {
......
......@@ -115,11 +115,11 @@ class PluginBlocktypeRecentposts extends PluginBlocktype {
}
public static function copy_allowed($newowner=null) {
return true;
return $newowner == 'user';
}
public static function copy_artefacts_allowed($newowner=null) {
return true;
return $newowner == 'user';
}
public static function default_copy_type() {
......
......@@ -129,4 +129,7 @@ $string['right'] = 'Right';
$string['copyfull'] = 'Others will get their own copy of your %s';
$string['copyreference'] = 'Others may display your %s in their View';
$string['copynocopy'] = 'Skip this block entirely when copying the View';
$string['viewposts'] = 'Copied posts (%s)';
$string['postscopiedfromview'] = 'Posts copied from %s';
?>
......@@ -811,6 +811,33 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
}
/**
* During the copying of a view, we might be allowed to copy
* blogposts but not the containing blog. We need to create a new
* blog to hold the copied posts.
*/
public function default_parent_for_copy(&$view, &$template) {
static $blogid;
if (!empty($blogid)) {
return $blogid;
}
$blogname = get_string('viewposts', 'artefact.blog', $view->get('id'));
$data = (object) array(
'title' => $blogname,
'description' => get_string('postscopiedfromview', 'artefact.blog', $template->get('title')),
'owner' => $view->get('owner'),
'group' => $view->get('group'),
'institution' => $view->get('institution'),
);
$blog = new ArtefactTypeBlog(0, $data);
$blog->commit();
$blogid = $blog->get('id');
return $blogid;
}
}
......
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