Commit 33404332 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Generate view urls in get_extra_view_info



Bug #1006634, part 3

This function is used when a set of view records needs to be augmented
with tags and data about the view owner (user, group, or institution).
It is useful on many pages to add the url of each view into the set of
results, because the url can no longer be determined from the view id
alone.

To use the get_url() method, a temporary View object is created, and
this is prepopulated with the appropriate owner or group (which we
have already pulled from the db), so that later calls to
get_owner_object() and get_group_object() don't need to perform any
more queries.

Change-Id: I26528ff573d057847747273cf9983fcacc70d20a
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 8432ef33
......@@ -116,6 +116,7 @@ class View {
);
public function __construct($id=0, $data=null) {
global $USER;
if (is_array($id) && isset($id['urlid']) && isset($id['ownerurlid'])) {
$tempdata = get_record_sql('
SELECT v.*
......@@ -164,14 +165,24 @@ class View {
$this->dirty = true;
}
if (empty($data)) {
$data = array();
}
foreach ((array)$data as $field => $value) {
$data = empty($data) ? array() : (array)$data;
foreach ($data as $field => $value) {
if (property_exists($this, $field)) {
$this->{$field} = $value;
}
}
// Add in owner and group objects if we already happen to have them from view_search(), etc.
if (isset($data['user']) && isset($data['user']->id) && $data['user']->id == $this->owner) {
$this->ownerobj = $data['user'];
}
else if (isset($data['groupdata']->id) && $data['groupdata']->id == $this->group) {
$this->groupobj = $data['groupdata'];
}
else if (!isset($data['user']) && !empty($this->owner) && $this->owner == $USER->get('id')) {
$this->ownerobj = $USER;
}
$this->atime = time();
$this->columns = array();
$this->dirtycolumns = array();
......@@ -3427,6 +3438,7 @@ class View {
'id,username,firstname,lastname,preferredname,admin,staff,studentid,email,profileicon,urlid');
}
if (!empty($groups)) {
require_once('group.php');
$groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name,urlid');
}
if (!empty($institutions)) {
......@@ -3444,6 +3456,14 @@ class View {
$v->sharedby = $institutions[$v->institution]->displayname;
}
$v = (array)$v;
// Now that we have the owner & group records, create a temporary View object
// so that we can use display_title_editing and get_url methods.
$view = new View(0, $v);
$view->set('dirty', false);
$v['displaytitle'] = $view->display_title_editing();
$v['url'] = $view->get_url(false);
$v['fullurl'] = get_config('wwwroot') . $v['url'];
}
}
}
......
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