Commit 9bfa3f39 authored by Son Nguyen's avatar Son Nguyen
Browse files

Remove the redundant use of get_record_select()


for getting collection info from database because
Collection::_construct() will do this

Change-Id: I3c548ca489fd95d044d23ddcb520b7969a51c561
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent fab8abdf
......@@ -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/');
......
......@@ -39,13 +39,10 @@ require_once('collection.php');
$new = param_boolean('new', 0);
$id = 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
......@@ -57,7 +54,7 @@ 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;
......
......@@ -44,8 +44,7 @@ $newurl = $new ? '&new=1' : '';
$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/');
......
......@@ -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