Commit 0a9b430a authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add copy settings (full/reference/none) to blog/recentpost block configuration

parent b4cb838d
......@@ -82,9 +82,11 @@ class PluginBlocktypeBlog 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, 'blog'),
);
}
......@@ -144,6 +146,10 @@ class PluginBlocktypeBlog extends PluginBlocktype {
return true;
}
public static function default_copy_type() {
return 'nocopy';
}
}
?>
......@@ -142,6 +142,10 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
return false;
}
public static function default_copy_type() {
return 'nocopy';
}
}
?>
......@@ -80,9 +80,11 @@ class PluginBlocktypeRecentposts extends PluginBlocktype {
}
public static function instance_config_form($instance) {
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blog'),
);
}
......@@ -120,6 +122,10 @@ class PluginBlocktypeRecentposts extends PluginBlocktype {
return true;
}
public static function default_copy_type() {
return 'nocopy';
}
}
?>
......@@ -126,4 +126,7 @@ $string['absolutebottom'] = 'Absolute bottom';
$string['left'] = 'Left';
$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';
?>
......@@ -105,6 +105,31 @@ class PluginArtefactBlog extends PluginArtefact {
closedir($basedir);
}
public static function block_advanced_options_element($configdata, $artefacttype) {
$strartefacttype = get_string($artefacttype, 'artefact.blog');
return array(
'type' => 'fieldset',
'name' => 'advanced',
'collapsible' => true,
'collapsed' => false,
'legend' => get_string('moreoptions', 'view'),
'elements' => array(
'copytype' => array(
'type' => 'select',
'title' => get_string('blockcopypermission', 'view'),
'description' => get_string('blockcopypermissiondesc', 'view'),
'defaultvalue' => isset($configdata['copytype']) ? $configdata['copytype'] : 'nocopy',
'options' => array(
'nocopy' => get_string('copynocopy', 'artefact.blog'),
'reference' => get_string('copyreference', 'artefact.blog', $strartefacttype),
'full' => get_string('copyfull', 'artefact.blog', $strartefacttype),
),
),
),
);
}
}
/**
......
......@@ -132,6 +132,11 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
public static function artefactchooser_get_element_data($artefact) {
return ArtefactTypeFileBase::artefactchooser_get_file_data($artefact);
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -124,6 +124,10 @@ class PluginBlocktypeFolder extends PluginBlocktype {
return 'parent, title';
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -98,6 +98,10 @@ class PluginBlocktypeHtml extends PluginBlocktype {
return array('portfolio', 'profile');
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -133,6 +133,10 @@ class PluginBlocktypeImage extends PluginBlocktype {
return ArtefactTypeFileBase::artefactchooser_get_file_data($artefact);
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -406,6 +406,10 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
<script defer="defer" src="' . get_config('wwwroot') . 'artefact/file/blocktype/internalmedia/eolas_fix.js" type="text/javascript"></script>';
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -166,6 +166,10 @@ class PluginBlocktypeContactinfo extends PluginBlocktype {
return $configdata;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
......@@ -227,6 +227,10 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
return $configdata;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
......@@ -141,6 +141,10 @@ class PluginBlocktypeEntireresume extends PluginBlocktype {
return false;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
......@@ -152,6 +152,10 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
return $configdata;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
......@@ -367,6 +367,11 @@ class PluginBlocktypeExternalfeed extends SystemBlocktype {
return $result;
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -174,6 +174,11 @@ class PluginBlocktypeExternalvideo extends SystemBlocktype {
</ul>
EOF;
}
public static function default_copy_type() {
return 'full';
}
}
?>
......@@ -187,6 +187,22 @@ abstract class PluginBlocktype extends Plugin {
return $configdata;
}
/*
* The copy_type of a block affects how it should be copied when its view gets copied.
* nocopy: The block doesn't appear in the new view at all.
* shallow: A new block of the same type is created in the new view with a default configuration.
* reference: Block configuration is copied as-is. If the block contains artefacts, the original artefact ids are
* retained in the new block's configuration even though they may have a different owner from the view.
* full: All artefacts referenced by the block are copied to the new owner's portfolio, and ids in the new
* block are updated to point to the copied artefacts.
*
* If the old owner and the new owner are the same, reference is always used.
* If a block contains no artefacts, reference and full are equivalent.
*/
public static function default_copy_type() {
return 'shallow';
}
}
abstract class SystemBlockType extends PluginBlockType {
......@@ -720,9 +736,20 @@ class BlockInstance {
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
$copyconfig = $view->get('copyconfig');
if (!$copyconfig->sameowner && !call_static_method($blocktypeclass, 'copy_allowed', $copyconfig->ownertype)) {
$configdata = $this->get('configdata');
if (isset($configdata['copytype'])) {
$copytype = $configdata['copytype'];
}
else {
$copytype = call_static_method($blocktypeclass, 'default_copy_type');
}
if (!$copyconfig->sameowner
&& ($copytype == 'nocopy' || !call_static_method($blocktypeclass, 'copy_allowed', $copyconfig->ownertype))) {
return false;
}
$newblock = new BlockInstance(0, array(
'blocktype' => $this->get('blocktype'),
'title' => $this->get('title'),
......@@ -731,14 +758,15 @@ class BlockInstance {
'order' => $this->get('order'),
));
$configdata = $this->get('configdata');
if ($copyconfig->sameowner) {
if ($copyconfig->sameowner || $copytype == 'reference') {
$newblock->set('configdata', $configdata);
$newblock->commit();
return true;
}
$artefactids = PluginBlockType::get_artefacts($this);
if (!empty($artefactids) && call_static_method($blocktypeclass, 'copy_artefacts_allowed', $copyconfig->ownertype)) {
if (!empty($artefactids)
&& $copytype == 'full'
&& call_static_method($blocktypeclass, 'copy_artefacts_allowed', $copyconfig->ownertype)) {
// Copy artefacts & put the new artefact ids into the new block.
// Artefacts may have children (defined using the parent column of the artefact table) and attachments (currently
// only for blogposts). If we copy an artefact we must copy all its descendents & attachments too.
......
......@@ -99,6 +99,11 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
public static function has_instance_config() {
return false;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
......@@ -66,6 +66,11 @@ class PluginBlocktypeMyGroups extends SystemBlocktype {
public static function has_instance_config() {
return false;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
......@@ -99,6 +99,11 @@ class PluginBlocktypeMyviews extends SystemBlocktype {
public static function has_instance_config() {
return false;
}
public static function default_copy_type() {
return 'shallow';
}
}
?>
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