Commit cdf30c42 authored by Jiri Baum's avatar Jiri Baum
Browse files

License metadata - blogs and blog posts, comments, plans, internal artefacts. (Bug #1095499)



Add license metadata to various artefact types where this involves only adding
the elements to the form and saving the value.

Change-Id: I8b0070cff71f0fa1dce5784a4ea89908b7e29ccc
Signed-off-by: default avatarJiri Baum <jiri@catalyst-au.net>
parent 6794c0bd
......@@ -247,6 +247,13 @@ class ArtefactTypeBlog extends ArtefactType {
$smarty->assign('artefacttitle', hsc($this->get('title')));
}
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this));
}
else {
$smarty->assign('license', false);
}
$options['hidetitle'] = true;
$smarty->assign('options', $options);
$smarty->assign('description', $this->get('description'));
......@@ -335,6 +342,9 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact->set('description', $values['description']);
$artefact->set('owner', $user->get('id'));
$artefact->set('tags', $values['tags']);
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
$artefact->commit();
}
......@@ -357,6 +367,9 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$artefact->set('tags', $values['tags']);
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
$artefact->commit();
}
......@@ -615,6 +628,13 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
$smarty->assign('artefactdescription', $postcontent);
$smarty->assign('artefact', $this);
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this));
}
else {
$smarty->assign('license', false);
}
$attachments = $this->get_attachments();
if ($attachments) {
$this->add_to_render_path($options);
......@@ -824,6 +844,9 @@ class ArtefactTypeBlogPost extends ArtefactType {
$artefact->set('description', $values['description']);
$artefact->set('published', $values['published']);
$artefact->set('tags', $values['tags']);
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
$artefact->commit();
return true;
}
......
......@@ -33,6 +33,7 @@ define('SECTION_PAGE', 'post');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
require_once('license.php');
safe_require('artefact', 'blog');
safe_require('artefact', 'file');
......@@ -136,6 +137,8 @@ $form = pieform(array(
'description' => get_string('tagsdesc'),
'help' => true,
),
'license' => license_form_el_basic(isset($blogpostobj) ? $blogpostobj : null),
'licensing_advanced' => license_form_el_advanced(isset($blogpostobj) ? $blogpostobj : null),
'filebrowser' => array(
'type' => 'filebrowser',
'title' => get_string('attachments', 'artefact.blog'),
......@@ -288,6 +291,11 @@ function editpost_submit(Pieform $form, $values) {
$postobj->set('title', $values['title']);
$postobj->set('description', $values['description']);
$postobj->set('tags', $values['tags']);
if (get_config('licensemetadata')) {
$postobj->set('license', $values['license']);
$postobj->set('licensor', $values['licensor']);
$postobj->set('licensorurl', $values['licensorurl']);
}
$postobj->set('published', !$values['draft']);
$postobj->set('allowcomments', (int) $values['allowcomments']);
if (!$blogpost) {
......
......@@ -34,6 +34,7 @@ define('SECTION_PAGE', 'settings');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
define('TITLE', get_string('blogsettings','artefact.blog'));
require_once('pieforms/pieform.php');
require_once('license.php');
safe_require('artefact', 'blog');
$id = param_integer('id');
......@@ -83,6 +84,8 @@ $form = pieform(array(
'description' => get_string('tagsdescprofile'),
'help' => true,
),
'license' => license_form_el_basic($blog),
'licensing_advanced' => license_form_el_advanced($blog),
'submit' => array(
'type' => 'submitcancel',
'value' => array(
......
......@@ -18,6 +18,11 @@
{if $posts.pagination}
<div id="blogpost_page_container{if $blockid}_{$blockid}{/if}" class="hidden center">{$posts.pagination|safe}</div>
{/if}
{if $license}
<div class="bloglicense">
{$license|safe}
</div>
{/if}
{if $posts.pagination_js}
<script>
addLoadEvent(function() {literal}{{/literal}
......
......@@ -23,4 +23,9 @@
{if isset($commentcount) && $artefact->get('allowcomments')} | <a href="{$artefacturl}">{str tag=Comments section=artefact.comment} ({$commentcount})</a>{/if}
</div>
{if $license}
<div class="postlicense">
{$license|safe}
</div>
{/if}
</div>
......@@ -91,6 +91,10 @@ $elements['ispublic'] = array(
'title' => get_string('makepublic', 'artefact.comment'),
'defaultvalue' => !$comment->get('private'),
);
if (get_config('licensemetadata')) {
$elements['license'] = license_form_el_basic($comment);
$elements['licensing_advanced'] = license_form_el_advanced($comment);
}
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('save'), get_string('cancel')),
......
......@@ -27,6 +27,7 @@
defined('INTERNAL') || die();
require_once('activity.php');
require_once('license.php');
define('MIN_RATING', 1);
define('MAX_RATING', 5);
......@@ -595,6 +596,10 @@ class ArtefactTypeComment extends ArtefactType {
'title' => get_string('makepublic', 'artefact.comment'),
'defaultvalue' => !$defaultprivate,
);
if (get_config('licensemetadata')) {
$form['elements']['license'] = license_form_el_basic(null);
$form['elements']['licensing_advanced'] = license_form_el_advanced(null);
}
if ($moderate) {
$form['elements']['ispublic']['description'] = get_string('approvalrequired', 'artefact.comment');
$form['elements']['moderate'] = array(
......@@ -953,6 +958,12 @@ function add_feedback_form_submit(Pieform $form, $values) {
$data->private = (int) !$values['ispublic'];
}
if (get_config('licensemetadata')) {
$data->license = $values['license'];
$data->licensor = $values['licensor'];
$data->licensorurl = $values['licensorurl'];
}
if (isset($values['rating'])) {
$data->rating = valid_rating($values['rating']);
}
......
......@@ -177,6 +177,7 @@ EOF;
public static function instance_config_form($instance) {
global $USER;
require_once('license.php');
$instance->set('artefactplugin', 'internal');
$configdata = $instance->get('configdata');
if (!$height = get_config('blockeditorheight')) {
......@@ -274,6 +275,19 @@ EOF;
. get_string('managealltextboxcontent', 'blocktype.internal/textbox') . ' &raquo;</a>',
),
);
if ($readonly) {
if ($license = render_license(isset($artefact) ? $artefact : null)) {
$elements['license'] = array(
'type' => 'html',
'title' => get_string('license'),
'value' => $license,
);
}
}
else {
$elements['license'] = license_form_el_basic(isset($artefact) ? $artefact : null);
$elements['license_advanced'] = license_form_el_advanced(isset($artefact) ? $artefact : null);
}
return $elements;
}
......@@ -302,6 +316,9 @@ EOF;
$artefact = new ArtefactTypeHtml(0, $data);
$artefact->set('title', $title);
$artefact->set('description', $values['text']);
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
else {
$artefact = new ArtefactTypeHtml((int)$values['artefactid']);
......@@ -321,6 +338,9 @@ EOF;
&& !$artefact->get('locked')
&& $USER->can_edit_artefact($artefact)) {
$artefact->set('description', $values['text']);
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
}
......
......@@ -26,6 +26,7 @@
define('INTERNAL', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('license.php');
safe_require('artefact', 'internal');
define('TITLE', get_string('editnote', 'artefact.internal'));
......@@ -50,7 +51,7 @@ else {
define('MENUITEM', 'content/notes');
}
$form = pieform(array(
$form = array(
'name' => 'editnote',
'elements' => array(
'title' => array(
......@@ -65,6 +66,8 @@ $form = pieform(array(
'cols' => 70,
'defaultvalue' => $artefact->get('description'),
),
'license' => license_form_el_basic($artefact),
'licensing_advanced' => license_form_el_advanced($artefact),
'allowcomments' => array(
'type' => 'checkbox',
'title' => get_string('allowcomments', 'artefact.comment'),
......@@ -83,7 +86,12 @@ $form = pieform(array(
'goto' => $goto,
),
),
));
);
if (!get_config('licensemetadata')) {
unset($form['elements']['license']);
unset($form['elements']['licensing_advanced']);
}
$form = pieform($form);
$smarty = smarty();
$smarty->assign('PAGEHEADING', $artefact->get('title'));
......@@ -99,6 +107,11 @@ function editnote_submit(Pieform $form, array $values) {
$artefact->set('rolepermissions', $values['perms']);
$artefact->set('dirty', true);
}
if (get_config('licensemetadata')) {
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->commit();
$SESSION->add_ok_msg(get_string('noteupdated', 'artefact.internal'));
redirect($goto);
......
......@@ -695,6 +695,12 @@ abstract class ArtefactType {
$smarty = smarty_core();
$smarty->assign('title', $this->get('title'));
$smarty->assign('description', $this->get('description'));
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this));
}
else {
$smarty->assign('license', false);
}
return array(
'html' => $smarty->fetch('artefact.tpl'),
......
......@@ -169,6 +169,11 @@ class ArtefactTypePlan extends ArtefactType {
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
if (get_config('licensemetadata')) {
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->commit();
$SESSION->add_ok_msg(get_string('plansavedsuccessfully', 'artefact.plans'));
......@@ -187,6 +192,7 @@ class ArtefactTypePlan extends ArtefactType {
*/
public static function get_form($plan=null) {
require_once(get_config('libroot') . 'pieforms/pieform.php');
require_once('license.php');
$elements = call_static_method(generate_artefact_class_name('plan'), 'get_planform_elements', $plan);
$elements['submit'] = array(
'type' => 'submitcancel',
......@@ -240,6 +246,11 @@ class ArtefactTypePlan extends ArtefactType {
);
}
if (get_config('licensemetadata')) {
$elements['license'] = license_form_el_basic($plan);
$elements['license_advanced'] = license_form_el_advanced($plan);
}
return $elements;
}
......@@ -277,6 +288,13 @@ class ArtefactTypePlan extends ArtefactType {
}
$smarty->assign('plan', $this);
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this));
}
else {
$smarty->assign('license', false);
}
return array('html' => $smarty->fetch('artefact:plans:viewplan.tpl'), 'javascript' => '');
}
}
......@@ -401,6 +419,7 @@ class ArtefactTypeTask extends ArtefactType {
*/
public static function get_form($parent, $task=null) {
require_once(get_config('libroot') . 'pieforms/pieform.php');
require_once('license.php');
$elements = call_static_method(generate_artefact_class_name('task'), 'get_taskform_elements', $parent, $task);
$elements['submit'] = array(
'type' => 'submitcancel',
......@@ -473,6 +492,10 @@ class ArtefactTypeTask extends ArtefactType {
'value' => $task->id,
);
}
if (get_config('licensemetadata')) {
$elements['license'] = license_form_el_basic($task);
$elements['license_advanced'] = license_form_el_advanced($task);
}
$elements['parent'] = array(
'type' => 'hidden',
......@@ -510,6 +533,11 @@ class ArtefactTypeTask extends ArtefactType {
$artefact->set('description', $values['description']);
$artefact->set('completed', $values['completed'] ? 1 : 0);
$artefact->set('completiondate', $values['completiondate']);
if (get_config('licensemetadata')) {
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->commit();
$SESSION->add_ok_msg(get_string('plansavedsuccessfully', 'artefact.plans'));
......
......@@ -11,6 +11,11 @@
</tbody>
</table>
<div id="plans_page_container">{$tasks.pagination|safe}</div>
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
<script>
{literal}
function rewriteTaskTitles() {
......
......@@ -196,6 +196,30 @@ class ArtefactTypeResume extends ArtefactType {
}
}
}
public function get_license_artefact() {
if ($this->get_artefact_type() == 'personalinformation')
return $this;
$pi = get_record('artefact',
'artefacttype', 'personalinformation',
'owner', $this->owner);
if (!$pi)
return null;
require_once(get_config('docroot') . 'artefact/lib.php');
return artefact_instance_from_id($pi->id);
}
public function render_license($options, &$smarty) {
if (!empty($options['details']) and get_config('licensemetadata')) {
$smarty->assign('license', render_license($this->get_license_artefact()));
}
else {
$smarty->assign('license', false);
}
}
}
class ArtefactTypeCoverletter extends ArtefactTypeResume {
......@@ -236,6 +260,8 @@ class ArtefactTypeContactinformation extends ArtefactTypeResume {
catch (Exception $e) { }
}
$this->render_license($options, $smarty);
return array('html' => $smarty->fetch('artefact:resume:fragments/contactinformation.tpl'));
}
......@@ -362,6 +388,7 @@ class ArtefactTypePersonalinformation extends ArtefactTypeResume {
$fields[get_string($field, 'artefact.resume')] = $value;
}
$smarty->assign('fields', $fields);
$this->render_license($options, $smarty);
return array('html' => $smarty->fetch('artefact:resume:fragments/personalinformation.tpl'));
}
......@@ -587,6 +614,7 @@ abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume {
// Give the artefact type a chance to format the data how it sees fit
$data = call_static_method(generate_artefact_class_name($type), 'format_render_self_data', $data);
$smarty->assign('rows', $data);
$this->render_license($options, $smarty);
$content = array(
'html' => $smarty->fetch('artefact:resume:fragments/' . $type . '.tpl'),
......
......@@ -34,4 +34,9 @@
<button id="addbookbutton" class="cancel" onclick="toggleCompositeForm('book');">{str tag='add'}</button>
</div>
{/if}
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
</fieldset>
......@@ -34,4 +34,9 @@
<button id="addcertificationbutton" class="cancel" onclick="toggleCompositeForm('certification');">{str tag='add'}</button>
</div>
{/if}
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
</fieldset>
......@@ -50,3 +50,8 @@
{/if}
</table>
{/if}
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
......@@ -36,4 +36,9 @@
<button id="addeducationhistorybutton" class="cancel" onclick="toggleCompositeForm('educationhistory');">{str tag='add'}</button>
</div>
{/if}
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
</fieldset>
......@@ -36,4 +36,9 @@
<button id="addemploymenthistorybutton" class="submit" onclick="toggleCompositeForm('employmenthistory');">{str tag='add'}</button>
</div>
{/if}
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
</fieldset>
......@@ -36,4 +36,9 @@
<button id="addmembershipbutton" class="cancel" onclick="toggleCompositeForm('membership');">{str tag='add'}</button>
</div>
{/if}
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
</fieldset>
......@@ -8,3 +8,8 @@
{/if}
{/foreach}
</table>
{if $license}
<div class="resumelicense">
{$license|safe}
</div>
{/if}
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