Commit 8432ef33 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use clean urls in View::get_url() function



Bug #1006634, part 3

The existing get_url method for views is modified to generate clean
profile and group homepage urls.

When the view is just a portfolio view, the view's urlid is appended
to the user or group url.  This requires calls to
View::get_owner_object() and View::get_group_object(), which are
potentially too slow to be calling on long lists of views, but this is
addressed in subsequent commits.

A flag is also added to force get_url to use old-style urls with ids.
Sometimes an id is required by existing javascript which parses an
href attribute.

Change-Id: I8758cf2fc566f4c523c297d015c262007f365243
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 62306210
......@@ -3757,20 +3757,41 @@ class View {
/**
* Makes a URL for a view page
*
* @param bool $full return a full url
* @param bool $useid ignore clean url settings and always return a url with an id in it
*
* @return string
*/
public function get_url($full=true) {
public function get_url($full=true, $useid=false) {
if ($this->type == 'profile') {
if (!$useid) {
return profile_url($this->get_owner_object(), $full);
}
$url = 'user/view.php?id=' . (int) $this->owner;
}
else if ($this->type == 'dashboard') {
$url = '';
}
else if ($this->type == 'grouphomepage') {
if (!$useid) {
return group_homepage_url($this->get_group_object(), $full);
}
$url = 'group/view.php?id=' . $this->group;
}
else {
else if (!$useid && !is_null($this->urlid) && get_config('cleanurls')) {
if ($this->owner && !is_null($this->get_owner_object()->urlid)) {
return profile_url($this->ownerobj, $full) . '/' . $this->urlid;
}
else if ($this->group && !is_null($this->get_group_object()->urlid)) {
return group_homepage_url($this->groupobj, $full) . '/' . $this->urlid;
}
}
if (!isset($url)) {
$url = 'view/view.php?id=' . (int) $this->id;
}
return $full ? (get_config('wwwroot') . $url) : $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