Commit 1ee390e5 authored by Son Nguyen's avatar Son Nguyen
Browse files

Add new parameter to template creation functions (Bug #886080)



Add new parameter $titlefromtemplate to
 - Collection::create_from_template()
 - View::create_from_template()

If titlefromtemplate == true, the title of new collection or view
will be exactly copied from the template

Change-Id: Ib32058fae34d0df153e03b5e0d0ea45e6e0e9cf1
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 86d8cc21
......@@ -200,8 +200,8 @@ class Collection {
* Creates a Collection for the given user, based off a given template and other
* Collection information supplied.
*
* Will set a default title of 'Copy of $collectiontitle' if title is not
* specified in $collectiondata.
* Will set a default name of 'Copy of $collectiontitle' if name is not
* specified in $collectiondata and $titlefromtemplate == false.
*
* @param array $collectiondata Contains information of the old collection, submitted in form
* @param int $templateid The ID of the Collection to copy
......@@ -214,7 +214,7 @@ class Collection {
* @throws SystemException under various circumstances, see the source for
* more information
*/
public static function create_from_template($collectiondata, $templateid, $userid=null, $checkaccess=true) {
public static function create_from_template($collectiondata, $templateid, $userid=null, $checkaccess=true, $titlefromtemplate=false) {
require_once(get_config('libroot') . 'view.php');
global $SESSION;
......@@ -228,11 +228,20 @@ class Collection {
$colltemplate = new Collection($templateid);
$data = new StdClass;
$desiredname = $colltemplate->get('name');
if (get_config('renamecopies')) {
$desiredname = get_string('Copyof', 'mahara', $desiredname);
// Set a default name if one wasn't set in $collectiondata
if ($titlefromtemplate) {
$data->name = $colltemplate->get('name');
}
else if (!isset($collectiondata['name'])) {
$desiredname = $colltemplate->get('name');
if (get_config('renamecopies')) {
$desiredname = get_string('Copyof', 'mahara', $desiredname);
}
$data->name = self::new_name($desiredname, (object)$collectiondata);
}
else {
$data->name = $collectiondata['name'];
}
$data->name = self::new_name($desiredname, (object)$collectiondata);
$data->description = $colltemplate->get('description');
$data->navigation = $colltemplate->get('navigation');
if (!empty($collectiondata['group'])) {
......@@ -262,7 +271,7 @@ class Collection {
'institution' => isset($data->institution) ? $data->institution : null,
'usetemplate' => $v->view
);
list($view, $template, $copystatus) = View::create_from_template($values, $v->view, $userid, $checkaccess);
list($view, $template, $copystatus) = View::create_from_template($values, $v->view, $userid, $checkaccess, $titlefromtemplate);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->clear('messages');
return array(null, $colltemplate, array('quotaexceeded' => true));
......
......@@ -213,7 +213,7 @@ class View {
* View information supplied.
*
* Will set a default title of 'Copy of $viewtitle' if title is not
* specified in $viewdata.
* specified in $viewdata and $titlefromtemplate == false.
*
* @param array $viewdata See View::_create
* @param int $templateid The ID of the View to copy
......@@ -226,7 +226,7 @@ class View {
* @throws SystemException under various circumstances, see the source for
* more information
*/
public static function create_from_template($viewdata, $templateid, $userid=null, $checkaccess=true) {
public static function create_from_template($viewdata, $templateid, $userid=null, $checkaccess=true, $titlefromtemplate=false) {
if (is_null($userid)) {
global $USER;
$userid = $USER->get('id');
......@@ -253,7 +253,10 @@ class View {
$view = self::_create($viewdata, $userid);
// Set a default title if one wasn't set
if (!isset($viewdata['title'])) {
if ($titlefromtemplate) {
$view->set('title', $template->get('title'));
}
else if (!isset($viewdata['title'])) {
$desiredtitle = $template->get('title');
if (get_config('renamecopies')) {
$desiredtitle = get_string('Copyof', 'mahara', $desiredtitle);
......
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