Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
003527c6
Commit
003527c6
authored
Jan 30, 2015
by
Aaron Wells
Browse files
Options to specify sortorder on group pages block
Bug 1417357 Change-Id: I886bca645fe063c74b0185288204a2119bf92dec
parent
5b7b2927
Changes
4
Hide whitespace changes
Inline
Side-by-side
htdocs/blocktype/groupviews/lang/en.utf8/blocktype.groupviews.php
View file @
003527c6
...
...
@@ -28,3 +28,9 @@ $string['itemstoshowdesc'] = 'The number of pages or collections shown for each
$string
[
'showbyanybody'
]
=
'By anybody'
;
$string
[
'showbygroupmembers'
]
=
'By members of this group'
;
$string
[
'shownone'
]
=
'None'
;
$string
[
'sortgroupviewstitle'
]
=
'Sort group pages by'
;
$string
[
'sortsharedviewstitle'
]
=
'Sort shared pages & collections by'
;
$string
[
'sortsubmittedtitle'
]
=
'Sort submitted pages & collections by'
;
$string
[
'sortviewsbyalphabetical'
]
=
'Alphabetical'
;
$string
[
'sortviewsbylastupdate'
]
=
'Most recently updated'
;
$string
[
'sortviewsbytimesubmitted'
]
=
'Most recently submitted'
;
htdocs/blocktype/groupviews/lib.php
View file @
003527c6
...
...
@@ -15,6 +15,10 @@ defined('INTERNAL') || die();
require_once
(
'group.php'
);
class
PluginBlocktypeGroupViews
extends
SystemBlocktype
{
const
SORTBY_TITLE
=
0
;
const
SORTBY_LASTUPDATE
=
1
;
const
SORTBY_TIMESUBMITTED
=
2
;
public
static
function
get_title
()
{
return
get_string
(
'title'
,
'blocktype.groupviews'
);
}
...
...
@@ -182,6 +186,15 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'separator'
=>
'<br>'
,
'defaultvalue'
=>
isset
(
$configdata
[
'showgroupviews'
])
?
$configdata
[
'showgroupviews'
]
:
1
,
),
'sortgroupviewsby'
=>
array
(
'type'
=>
'select'
,
'title'
=>
get_string
(
'sortgroupviewstitle'
,
'blocktype.groupviews'
),
'options'
=>
array
(
PluginBlocktypeGroupViews
::
SORTBY_TITLE
=>
get_string
(
'sortviewsbyalphabetical'
,
'blocktype.groupviews'
),
PluginBlocktypeGroupViews
::
SORTBY_LASTUPDATE
=>
get_string
(
'sortviewsbylastupdate'
,
'blocktype.groupviews'
),
),
'defaultvalue'
=>
isset
(
$configdata
[
'sortgroupviewsby'
])
?
(
int
)
$configdata
[
'sortgroupviewsby'
]
:
0
),
'showsharedviews'
=>
array
(
'type'
=>
'radio'
,
'title'
=>
get_string
(
'displaysharedviews'
,
'blocktype.groupviews'
),
...
...
@@ -206,6 +219,15 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'separator'
=>
'<br>'
,
'defaultvalue'
=>
isset
(
$configdata
[
'showsharedcollections'
])
?
$configdata
[
'showsharedcollections'
]
:
1
,
),
'sortsharedviewsby'
=>
array
(
'type'
=>
'select'
,
'title'
=>
get_string
(
'sortsharedviewstitle'
,
'blocktype.groupviews'
),
'options'
=>
array
(
PluginBlocktypeGroupViews
::
SORTBY_TITLE
=>
get_string
(
'sortviewsbyalphabetical'
,
'blocktype.groupviews'
),
PluginBlocktypeGroupViews
::
SORTBY_LASTUPDATE
=>
get_string
(
'sortviewsbylastupdate'
,
'blocktype.groupviews'
),
),
'defaultvalue'
=>
isset
(
$configdata
[
'sortsharedviewsby'
])
?
(
int
)
$configdata
[
'sortsharedviewsby'
]
:
0
),
'showsubmitted'
=>
array
(
'type'
=>
'radio'
,
'title'
=>
get_string
(
'displaysubmissions'
,
'blocktype.groupviews'
),
...
...
@@ -217,6 +239,15 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
'separator'
=>
'<br>'
,
'defaultvalue'
=>
isset
(
$configdata
[
'showsubmitted'
])
?
$configdata
[
'showsubmitted'
]
:
1
,
),
'sortsubmittedby'
=>
array
(
'type'
=>
'select'
,
'title'
=>
get_string
(
'sortsubmittedtitle'
,
'blocktype.groupviews'
),
'options'
=>
array
(
PluginBlocktypeGroupViews
::
SORTBY_TITLE
=>
get_string
(
'sortviewsbyalphabetical'
,
'blocktype.groupviews'
),
PluginBlocktypeGroupViews
::
SORTBY_TIMESUBMITTED
=>
get_string
(
'sortviewsbytimesubmitted'
,
'blocktype.groupviews'
),
),
'defaultvalue'
=>
isset
(
$configdata
[
'sortsubmittedby'
])
?
(
int
)
$configdata
[
'sortsubmittedby'
]
:
0
),
'count'
=>
array
(
'type'
=>
'text'
,
'title'
=>
get_string
(
'itemstoshow'
,
'blocktype.groupviews'
),
...
...
@@ -241,14 +272,33 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
// get the currently requested group
$group
=
group_current_group
();
$role
=
group_user_access
(
$group
->
id
);
$bi
=
group_get_homepage_view_groupview_block
(
$group
->
id
);
$configdata
=
$bi
->
get
(
'configdata'
);
if
(
!
isset
(
$configdata
[
'sortsubmittedby'
])
||
$configdata
[
'sortsubmittedby'
]
==
PluginBlocktypeGroupViews
::
SORTBY_TITLE
)
{
$sortsubmittedby
=
'c.name, v.title'
;
}
else
{
$sortsubmittedby
=
'c.submittedtime DESC, v.submittedtime DESC'
;
}
if
(
$role
)
{
$bi
=
group_get_homepage_view_groupview_block
(
$group
->
id
);
$configdata
=
$bi
->
get
(
'configdata'
);
$limit
=
isset
(
$configdata
[
'count'
])
?
intval
(
$configdata
[
'count'
])
:
5
;
$limit
=
(
$limit
>
0
)
?
$limit
:
5
;
// Get all views created in the group
$sort
=
array
(
array
(
'column'
=>
'type=\'grouphomepage\''
,
'desc'
=>
true
));
// Sortorder: Group homepage should be first, then sort by sortorder
$sort
=
array
(
array
(
'column'
=>
"type='grouphomepage'"
,
'desc'
=>
true
)
);
// Find out what order to sort them by (default is titles)
if
(
!
isset
(
$configdata
[
'sortgroupviewsby'
])
||
$configdata
[
'sortgroupviewsby'
]
==
PluginBlocktypeGroupViews
::
SORTBY_TITLE
)
{
$sort
[]
=
array
(
'column'
=>
'title'
);
}
else
{
$sort
[]
=
array
(
'column'
=>
'mtime'
,
'desc'
=>
true
);
}
$data
[
'groupviews'
]
=
View
::
view_search
(
null
,
null
,
(
object
)
array
(
'group'
=>
$group
->
id
),
null
,
$limit
,
0
,
true
,
$sort
);
foreach
(
$data
[
'groupviews'
]
->
data
as
&
$view
)
{
if
(
!
$editing
&&
isset
(
$view
[
'template'
])
&&
$view
[
'template'
])
{
...
...
@@ -256,6 +306,21 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
}
}
// Find out what order to sort them by (default is titles)
if
(
!
isset
(
$configdata
[
'sortsharedviewsby'
])
||
$configdata
[
'sortsharedviewsby'
]
==
PluginBlocktypeGroupViews
::
SORTBY_TITLE
)
{
$sortsharedviewsby
=
'v.title'
;
$sortsharedcollectionsby
=
array
(
array
(
'column'
=>
'c.name'
));
}
else
{
$sortsharedviewsby
=
'v.mtime DESC'
;
$sortsharedcollectionsby
=
array
(
array
(
'column'
=>
'GREATEST(c.mtime, (SELECT MAX(v.mtime) FROM {view} v INNER JOIN {collection_view} cv ON v.id=cv.view WHERE cv.collection=c.id))'
,
'desc'
=>
true
)
);
}
// For group members, display a list of views that others have
// shared to the group
if
(
empty
(
$configdata
[
'showsharedviews'
]))
{
...
...
@@ -271,7 +336,8 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
$limit
,
0
,
$group
->
id
,
(
$configdata
[
'showsharedviews'
]
==
2
?
false
:
true
)
(
$configdata
[
'showsharedviews'
]
==
2
?
false
:
true
),
$sortsharedviewsby
);
foreach
(
$data
[
'sharedviews'
]
->
data
as
&
$view
)
{
if
(
!
$editing
&&
isset
(
$view
[
'template'
])
&&
$view
[
'template'
])
{
...
...
@@ -293,13 +359,14 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
$limit
,
0
,
$group
->
id
,
(
$configdata
[
'showsharedcollections'
]
==
2
?
false
:
true
)
(
$configdata
[
'showsharedcollections'
]
==
2
?
false
:
true
),
$sortsharedcollectionsby
);
}
if
(
group_user_can_assess_submitted_views
(
$group
->
id
,
$USER
->
get
(
'id'
)))
{
// Display a list of views submitted to the group
list
(
$collections
,
$views
)
=
View
::
get_views_and_collections
(
null
,
null
,
null
,
null
,
false
,
$group
->
id
);
list
(
$collections
,
$views
)
=
View
::
get_views_and_collections
(
null
,
null
,
null
,
null
,
false
,
$group
->
id
,
$sortsubmittedby
);
$allsubmitted
=
array_merge
(
array_values
(
$collections
),
array_values
(
$views
));
$data
[
'allsubmitted'
]
=
array
(
'data'
=>
array_slice
(
$allsubmitted
,
0
,
$limit
),
...
...
@@ -319,7 +386,7 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
// Display a list of views this user has submitted to this group, and a submission
// form containing drop-down of their unsubmitted views.
list
(
$collections
,
$views
)
=
View
::
get_views_and_collections
(
$USER
->
get
(
'id'
),
null
,
null
,
null
,
false
,
$group
->
id
);
list
(
$collections
,
$views
)
=
View
::
get_views_and_collections
(
$USER
->
get
(
'id'
),
null
,
null
,
null
,
false
,
$group
->
id
,
$sortsubmittedby
);
$data
[
'mysubmitted'
]
=
array_merge
(
array_values
(
$collections
),
array_values
(
$views
));
// Only render the submission form in viewing mode
...
...
htdocs/lib/collection.php
View file @
003527c6
...
...
@@ -103,6 +103,7 @@ class Collection {
$id
=
0
;
}
$collection
=
new
Collection
(
$id
,
$data
);
$collection
->
set
(
'mtime'
,
time
());
$collection
->
commit
();
return
$collection
;
// return newly created Collections id
...
...
htdocs/lib/view.php
View file @
003527c6
...
...
@@ -4135,7 +4135,7 @@ class View {
$orderby
.
=
(
!
empty
(
$item
[
'tablealias'
])
?
$item
[
'tablealias'
]
:
'v'
)
.
'.'
.
$item
[
'column'
];
}
if
(
$item
[
'desc'
])
{
if
(
!
empty
(
$item
[
'desc'
])
)
{
$orderby
.
=
' DESC'
;
}
else
{
...
...
@@ -4342,10 +4342,11 @@ class View {
* @param int $limit
* @param int $offset
* @param int $groupid
* @param boolean $membersonly Only return pages owned by members of the gorup
* @param boolean $membersonly Only return pages owned by members of the group
* @param string $orderby Columns to sort by (defaults to (title, id) if empty)
* @throws AccessDeniedException
*/
public
static
function
get_sharedviews_data
(
$limit
=
10
,
$offset
=
0
,
$groupid
,
$membersonly
=
false
)
{
public
static
function
get_sharedviews_data
(
$limit
=
10
,
$offset
=
0
,
$groupid
,
$membersonly
=
false
,
$orderby
=
null
)
{
global
$USER
;
$userid
=
$USER
->
get
(
'id'
);
require_once
(
get_config
(
'libroot'
)
.
'group.php'
);
...
...
@@ -4366,11 +4367,17 @@ class View {
$ph
[]
=
$groupid
;
}
$count
=
count_records_sql
(
'SELECT COUNT(DISTINCT(v.id)) '
.
$from
.
$where
,
$ph
);
if
(
$orderby
===
null
)
{
$ordersql
=
' ORDER BY v.title, v.id'
;
}
else
{
$ordersql
=
' ORDER BY '
.
$orderby
.
', v.id'
;
}
$viewdata
=
get_records_sql_assoc
(
'
SELECT DISTINCT v.id, v.title, v.startdate, v.stopdate, v.description, v.group, v.owner, v.ownerformat, v.institution, v.urlid '
SELECT DISTINCT v.id, v.title, v.startdate, v.stopdate, v.description, v.group, v.owner, v.ownerformat, v.institution, v.urlid
, v.mtime
'
.
$from
.
$where
.
' ORDER BY v.title, v.id'
,
.
$ordersql
,
$ph
,
$offset
,
$limit
...
...
@@ -4704,9 +4711,10 @@ class View {
* @param integer $offset
* @param integer $groupid
* @param boolean $membersonly Only return collections owned by members of the gorup
* @param array $sort Columns to sort by (defaults to (title, id) if empty)
* @return array of collections
*/
public
static
function
get_sharedcollections_data
(
$limit
=
10
,
$offset
=
0
,
$groupid
,
$membersonly
=
false
)
{
public
static
function
get_sharedcollections_data
(
$limit
=
10
,
$offset
=
0
,
$groupid
,
$membersonly
=
false
,
$sort
=
null
)
{
global
$USER
;
$userid
=
$USER
->
get
(
'id'
);
...
...
@@ -4730,11 +4738,26 @@ class View {
}
$count
=
count_records_sql
(
'SELECT COUNT(DISTINCT c.id) '
.
$from
.
$where
,
$ph
);
$collectiondata
=
get_records_sql_assoc
(
'
SELECT DISTINCT c.id, c.name, c.description, c.owner, c.group, c.institution '
.
$from
.
$where
.
' ORDER BY c.name, c.id'
,
$select
=
'SELECT DISTINCT c.id, c.name, c.description, c.owner, c.group, c.institution'
;
$orderby
=
' ORDER BY '
;
if
(
is_array
(
$sort
))
{
foreach
(
$sort
as
$sortitem
)
{
$select
.
=
",
{
$sortitem
[
'column'
]
}
"
;
$orderby
.
=
"
{
$sortitem
[
'column'
]
}
"
;
if
(
!
empty
(
$sortitem
[
'desc'
]))
{
$orderby
.
=
" DESC"
;
}
}
$orderby
.
=
', c.id'
;
}
else
{
$orderby
=
' ORDER BY c.name, c.id'
;
}
$collectiondata
=
get_records_sql_assoc
(
$select
.
$from
.
$where
.
$orderby
,
$ph
,
$offset
,
$limit
);
...
...
@@ -5499,10 +5522,11 @@ class View {
* @param string $matchconfig record all matches with given config hash (see set_access)
* @param boolean $includeprofile include profile view
* @param integer $submittedgroup return only views & collections submitted to this group
* @param $string $sort Order to sort by (defaults to 'c.name, v.title')
*
* @return array, array
*/
function
get_views_and_collections
(
$owner
=
null
,
$group
=
null
,
$institution
=
null
,
$matchconfig
=
null
,
$includeprofile
=
true
,
$submittedgroup
=
null
)
{
function
get_views_and_collections
(
$owner
=
null
,
$group
=
null
,
$institution
=
null
,
$matchconfig
=
null
,
$includeprofile
=
true
,
$submittedgroup
=
null
,
$sort
=
null
)
{
$excludelocked
=
$group
&&
group_user_access
(
$group
)
!=
'admin'
;
// Anonymous public viewing of a group with 'Allow submissions' checked needs to avoid including the dummy root profile page.
...
...
@@ -5538,7 +5562,12 @@ class View {
$values
[]
=
(
int
)
$submittedgroup
;
}
$sql
.
=
'ORDER BY c.name, v.title'
;
if
(
$sort
==
null
)
{
$sql
.
=
'ORDER BY c.name, v.title'
;
}
else
{
$sql
.
=
"ORDER BY
{
$sort
}
"
;
}
$records
=
get_records_sql_assoc
(
$sql
,
$values
);
$collections
=
array
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment