Commit 1ac5c5d8 authored by Melissa Draper's avatar Melissa Draper Committed by Gerrit Code Review
Browse files

Merge "Find profiles, group homepages, and portfolio pages by urlid"

parents 10ff13f4 15e062d7
......@@ -35,8 +35,15 @@ require_once(get_config('docroot') . 'interaction/lib.php');
require_once(get_config('libroot') . 'view.php');
safe_require('artefact', 'file');
define('GROUP', param_integer('id'));
$group = group_current_group();
if ($urlid = param_alphanumext('homepage', null)) {
define('GROUPURLID', $urlid);
$group = group_current_group();
}
else {
define('GROUP', param_integer('id'));
$group = group_current_group();
}
if (!is_logged_in() && !$group->public) {
throw new AccessDeniedException();
}
......
......@@ -106,6 +106,7 @@ $string['accessdeniedexception'] = 'You do not have access to view this page';
$string['viewnotfoundexceptiontitle'] = 'Page not found';
$string['viewnotfoundexceptionmessage'] = 'You tried to access a page that doesn\'t exist.';
$string['viewnotfound'] = 'Page with id %s not found';
$string['viewnotfoundbyname'] = 'Page %s by %s not found';
$string['youcannotviewthisusersprofile'] = 'You cannot view this user\'s profile';
$string['artefactnotfoundmaybedeleted'] = "Artefact with id %s not found (maybe it has been deleted already?)";
......
......@@ -185,6 +185,7 @@ $string['groupsiminvitedto'] = 'Groups I\'m invited to';
$string['groupsiwanttojoin'] = 'Groups I want to join';
$string['requestedtojoin'] = 'You have requested to join this group';
$string['groupnotfound'] = 'Group with id %s not found';
$string['groupnotfoundname'] = 'Group %s not found';
$string['groupconfirmleave'] = 'Are you sure you want to leave this group?';
$string['cantleavegroup'] = 'You can\'t leave this group';
$string['usercantleavegroup'] = 'This user cannot leave this group';
......
......@@ -1697,6 +1697,13 @@ function group_current_group() {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', GROUP));
}
}
else if (defined('GROUPURLID')) {
$group = get_record_select('group', 'urlid = ? AND deleted = 0', array(GROUPURLID), '*, ' . db_format_tsfield('ctime'));
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfoundname', 'group', GROUPURLID));
}
define('GROUP', $group->id);
}
else {
$group = null;
}
......
......@@ -116,7 +116,29 @@ class View {
);
public function __construct($id=0, $data=null) {
if (!empty($id)) {
if (is_array($id) && isset($id['urlid']) && isset($id['ownerurlid'])) {
$tempdata = get_record_sql('
SELECT v.*
FROM {view} v JOIN {usr} u ON v.owner = u.id
WHERE v.urlid = ? AND u.urlid = ?',
array($id['urlid'], $id['ownerurlid'])
);
if (empty($tempdata)) {
throw new ViewNotFoundException(get_string('viewnotfoundbyname', 'error', $id['urlid'], $id['ownerurlid']));
}
}
else if (is_array($id) && isset($id['urlid']) && isset($id['groupurlid'])) {
$tempdata = get_record_sql('
SELECT v.*
FROM {view} v JOIN {group} g ON v.group = g.id
WHERE v.urlid = ? AND g.urlid = ? AND g.deleted = 0',
array($id['urlid'], $id['groupurlid'])
);
if (empty($tempdata)) {
throw new ViewNotFoundException(get_string('viewnotfoundbyname', 'error', $id['urlid'], $id['groupurlid']));
}
}
else if (!empty($id) && is_numeric($id)) {
$tempdata = get_record_sql('
SELECT v.*
FROM {view} v LEFT JOIN {group} g ON v.group = g.id
......@@ -126,13 +148,15 @@ class View {
if (empty($tempdata)) {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $id));
}
}
if (isset($tempdata)) {
if (!empty($data)) {
$data = array_merge((array)$tempdata, $data);
}
else {
$data = $tempdata; // use what the database has
}
$this->id = $id;
$this->id = $tempdata->id;
}
else {
$this->ctime = time();
......
......@@ -45,7 +45,14 @@ else if (param_variable('addfriend_submit', null)) {
}
$loggedinid = $USER->get('id');
if (!empty($loggedinid)) {
if ($profileurlid = param_alphanumext('profile', null)) {
if (!$user = get_record('usr', 'urlid', $profileurlid, 'deleted', 0)) {
throw new UserNotFoundException("User $profileurlid not found");
}
$userid = $user->id;
}
else if (!empty($loggedinid)) {
$userid = param_integer('id', $loggedinid);
}
else {
......@@ -56,9 +63,10 @@ if ($userid == 0) {
}
// Get the user's details
if (!$user = get_record('usr', 'id', $userid, 'deleted', 0)) {
throw new UserNotFoundException("User with id $userid not found");
if (!isset($user)) {
if (!$user = get_record('usr', 'id', $userid, 'deleted', 0)) {
throw new UserNotFoundException("User with id $userid not found");
}
}
$is_friend = is_friend($userid, $loggedinid);
......
......@@ -54,6 +54,18 @@ else if ($usertoken) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
}
else if ($pageurl = param_alphanumext('page', null)) {
if ($profile = param_alphanumext('profile', null)) {
$view = new View(array('urlid' => $pageurl, 'ownerurlid' => $profile));
}
else if ($homepage = param_alphanumext('homepage', null)) {
$view = new View(array('urlid' => $pageurl, 'groupurlid' => $homepage));
}
else {
throw new ViewNotFoundException(get_string('viewnotfoundexceptiontitle', 'error'));
}
$viewid = $view->get('id');
}
else {
$viewid = param_integer('id');
}
......@@ -73,7 +85,9 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$showcomment = param_integer('showcomment', null);
$view = new View($viewid);
if (!isset($view)) {
$view = new View($viewid);
}
// Create the "make feedback private form" now if it's been submitted
if (param_variable('make_public_submit', null)) {
......
Supports Markdown
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