Commit 352c9373 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I127ab478,Ia6cba7a8,I3c548ca4,I0a2b4c4b

* changes:
  Remove unnecessary variables and functions in collection module
  The collection id is required when editing an existing collection
  Remove the redundant use of get_record_select() for getting collection info from database because Collection::_construct() will do this
  Remove the use of hsc for TITLE in collection/index.php because this will be escaped in the template.
parents 7e0d8030 936e8378
......@@ -39,8 +39,7 @@ define('TITLE', get_string('deletecollection', 'collection'));
$id = param_integer('id');
$data = get_record_select('collection', 'id = ?', array($id));
$collection = new Collection($id, (array)$data);
$collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('cantdeletecollection', 'collection'));
redirect('/collection/');
......
......@@ -37,27 +37,23 @@ require_once('pieforms/pieform.php');
require_once('collection.php');
$new = param_boolean('new', 0);
$id = param_integer('id', 0);
$id = !$new ? param_integer('id') : 0;
$data = null;
if ($data = get_record_select('collection', 'id = ?', array($id))) {
$collection = new Collection($id, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown', 'collection'));
redirect('/collection/');
}
$collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown', 'collection'));
redirect('/collection/');
}
// if not a new collection
if (!$new) {
define('COLLECTION', $id);
define('TITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection'));
}
else {
define('TITLE', get_string('edittitleanddesc', 'collection'));
}
$elements = Collection::get_collectionform_elements($data);
$elements = $collection->get_collectionform_elements();
$submitstr = $new ? array('cancel' => get_string('cancel'), 'submit' => get_string('next') . ': ' . get_string('editviews', 'collection'))
: array(get_string('save'), get_string('cancel'));
$confirm = $new ? array('cancel' => get_string('confirmcancelcreatingcollection','collection')) : null;
......
......@@ -71,5 +71,5 @@ $smarty->assign('collections', $data->data);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('strnocollectionsaddone',
get_string('nocollectionsaddone','collection','<a href="' . get_config('wwwroot') . 'collection/edit.php?new=1">', '</a>'));
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('PAGEHEADING', TITLE);
$smarty->display('collection/index.tpl');
......@@ -36,32 +36,23 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
$new = param_integer('new',0);
$id = param_integer('id');
$newurl = $new ? '&new=1' : '';
// view addition/displayorder values
$view = param_integer('view',0);
$direction = param_variable('direction','');
$data = get_record_select('collection', 'id = ?', array($id), '*');
$collection = new Collection($id, (array)$data);
$collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown', 'collection'));
redirect('/collection/');
}
if (!$new) {
define('COLLECTION', $id);
define('TITLE', $collection->get('name') . ': ' . get_string('editviews', 'collection'));
}
else {
define('TITLE', get_string('editviews', 'collection'));
}
define('TITLE', $collection->get('name') . ': ' . get_string('editviews', 'collection'));
if ($view AND !empty($direction)) {
$collection->set_viewdisplayorder($view,$direction);
redirect('/collection/views.php?id='.$id.$newurl);
redirect('/collection/views.php?id='.$id);
}
$views = $collection->views();
......@@ -114,14 +105,14 @@ if ($available = Collection::available_views()) {
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('displayurl',get_config('wwwroot').'collection/views.php?id='.$id.$newurl);
$smarty->assign('removeurl',get_config('wwwroot').'collection/deleteview.php?id='.$id.$newurl);
$smarty->assign('displayurl',get_config('wwwroot').'collection/views.php?id='.$id);
$smarty->assign('removeurl',get_config('wwwroot').'collection/deleteview.php?id='.$id);
$smarty->assign_by_ref('views', $views);
$smarty->assign_by_ref('viewsform', $viewsform);
$smarty->display('collection/views.tpl');
function addviews_submit(Pieform $form, $values) {
global $SESSION, $collection, $newurl;
global $SESSION, $collection;
$count = $collection->add_views($values);
if ($count > 1) {
$SESSION->add_ok_msg(get_string('viewsaddedtocollection', 'collection'));
......@@ -129,33 +120,13 @@ function addviews_submit(Pieform $form, $values) {
else {
$SESSION->add_ok_msg(get_string('viewaddedtocollection', 'collection'));
}
redirect('/collection/views.php?id='.$collection->get('id').$newurl);
}
redirect('/collection/views.php?id='.$collection->get('id'));
function manageviews_submit(Pieform $form, $values) {
global $collection, $new, $SESSION, $views;
if (param_boolean('back')) {
redirect('/collection/edit.php?id='.$collection->get('id').'&new=1');
}
else {
$collection->set('navigation',(int)$values['navigation']);
$collection->commit();
if ($new) {
if ($views) {
$SESSION->add_ok_msg(get_string('collectioncreatedsuccessfullyshare', 'collection'));
}
else {
$SESSION->add_ok_msg(get_string('collectioncreatedsuccessfully', 'collection'));
}
}
redirect('/collection/');
}
}
function removeview_submit(Pieform $form, $values) {
global $SESSION, $collection, $newurl;
global $SESSION, $collection;
$collection->remove_view((int)$values['view']);
$SESSION->add_ok_msg(get_string('viewremovedsuccessfully','collection'));
redirect('/collection/views.php?id='.$collection->get('id').$newurl);
redirect('/collection/views.php?id='.$collection->get('id'));
}
......@@ -316,7 +316,7 @@ class Collection {
* @param array collection
* @return array $elements
*/
public static function get_collectionform_elements($data=null) {
public function get_collectionform_elements() {
$elements = array(
'name' => array(
'type' => 'text',
......@@ -344,17 +344,17 @@ class Collection {
);
// populate the fields with the existing values if any
if (!empty($data)) {
if (!empty($this->id)) {
foreach ($elements as $k => $element) {
$elements[$k]['defaultvalue'] = $data->$k;
$elements[$k]['defaultvalue'] = $this->$k;
}
$elements['id'] = array(
'type' => 'hidden',
'value' => $data->id,
'value' => $this->id,
);
$elements['owner'] = array(
'type' => 'hidden',
'value' => $data->owner,
'value' => $this->owner,
);
}
......
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