Commit b49fc4ee authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Refactored limit checking, added user access checking, and made it work ...

even if you DO have no friends ;-)
parent f3f514a2
...@@ -1113,10 +1113,15 @@ function get_views($users, $userlooking=null, $limit=5) { ...@@ -1113,10 +1113,15 @@ function get_views($users, $userlooking=null, $limit=5) {
v.id=a.view v.id=a.view
AND ( AND (
accesstype IN (\'public\',\'loggedin\') accesstype IN (\'public\',\'loggedin\')
OR ( ' . (
accesstype = \'friends\' count(preg_grep('/^friend$/', $users)) > 0
AND v.owner IN (' . join(',',array_map('db_quote', array_keys(preg_grep('/^friend$/', $users)))) . ') ? 'OR (
) accesstype = \'friends\'
AND v.owner IN (' . join(',',array_map('db_quote', array_keys(preg_grep('/^friend$/', $users)))) . ')
)'
: ''
)
. '
) )
WHERE WHERE
v.owner IN (' . join(',',array_map('db_quote', array_keys($users))) . ') v.owner IN (' . join(',',array_map('db_quote', array_keys($users))) . ')
...@@ -1131,7 +1136,42 @@ function get_views($users, $userlooking=null, $limit=5) { ...@@ -1131,7 +1136,42 @@ function get_views($users, $userlooking=null, $limit=5) {
} }
} }
// repeated if (_get_views_trim_list($list, $users, $limit)) {
return $list;
}
if ($results = get_records_sql_array(
'SELECT
v.*,
' . db_format_tsfield('atime') . ',
' . db_format_tsfield('mtime') . ',
' . db_format_tsfield('ctime') . '
FROM
' . $prefix . 'view v
INNER JOIN view_access_usr a ON v.id=a.view AND a.usr=?
WHERE
v.owner IN (' . join(',',array_map('db_quote', array_keys($users))) . ')
AND ( v.startdate IS NULL OR v.startdate < ? )
AND ( v.stopdate IS NULL OR v.stopdate < ? )
',
array($userlooking, $dbnow, $dbnow)
)
) {
foreach ($results as &$row) {
$list[$row->owner][$row->id] = $row;
}
}
log_debug('Users remaing');
log_debug($users);
return $list;
}
function _get_views_trim_list(&$list, &$users, $limit) {
if ($limit === null) {
return;
}
foreach ($list as $user_id => &$views) { foreach ($list as $user_id => &$views) {
if($limit and count($views) > $limit) { if($limit and count($views) > $limit) {
$views = array_slice($views, 0, $limit); $views = array_slice($views, 0, $limit);
...@@ -1141,14 +1181,9 @@ function get_views($users, $userlooking=null, $limit=5) { ...@@ -1141,14 +1181,9 @@ function get_views($users, $userlooking=null, $limit=5) {
} }
} }
if (count($users) == 0) { if (count($users) == 0) {
return $list; return true;
} }
// end repeated return false;
log_debug('Users remaing');
log_debug($users);
return $list;
} }
function artefact_in_view($artefact, $view) { function artefact_in_view($artefact, $view) {
......
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