Skip to content
GitLab
Menu
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
f8054374
Commit
f8054374
authored
Apr 03, 2020
by
Robert Lyon
Committed by
Gerrit Code Review
Apr 03, 2020
Browse files
Merge "Bug 1866148: Add function first view in a collection code"
parents
4b6089ca
139c67fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/plans/collection/viewcontent.json.php
View file @
f8054374
...
@@ -17,19 +17,18 @@ require_once(get_config('libroot') . 'collection.php');
...
@@ -17,19 +17,18 @@ require_once(get_config('libroot') . 'collection.php');
$id
=
param_integer
(
'id'
);
$id
=
param_integer
(
'id'
);
$collection
=
new
\
Collection
(
$id
);
$collection
=
new
\
Collection
(
$id
);
$viewIds
=
$collection
->
get_viewids
();
if
(
empty
(
$viewIds
))
{
$firstview
=
$collection
->
first_view
();
if
(
$firstview
===
null
)
{
json_reply
(
true
,
array
(
json_reply
(
true
,
array
(
'message'
=>
get_string
(
'noviewsincollection'
,
'collection'
),
'message'
=>
get_string
(
'noviewsincollection'
,
'collection'
),
));
));
}
}
$firstViewId
=
$viewIds
[
0
];
if
(
!
can_view_view
(
$firstview
))
{
if
(
!
can_view_view
(
$firstViewId
))
{
json_reply
(
'local'
,
get_string
(
'accessdenied'
,
'error'
));
json_reply
(
'local'
,
get_string
(
'accessdenied'
,
'error'
));
}
}
$firstview
=
new
View
(
$firstViewId
);
$collection
=
$firstview
->
get
(
'collection'
);
$collection
=
$firstview
->
get
(
'collection'
);
if
(
$firstview
->
uses_new_layout
())
{
if
(
$firstview
->
uses_new_layout
())
{
...
@@ -37,7 +36,7 @@ if ($firstview->uses_new_layout()) {
...
@@ -37,7 +36,7 @@ if ($firstview->uses_new_layout()) {
$newlayout
=
true
;
$newlayout
=
true
;
}
}
else
{
else
{
$blocks
=
$view
->
build_rows
();
$blocks
=
$
first
view
->
build_rows
();
$newlayout
=
false
;
$newlayout
=
false
;
}
}
...
...
htdocs/collection/viewcontent.json.php
View file @
f8054374
...
@@ -27,7 +27,7 @@ if ($firstview->uses_new_layout()) {
...
@@ -27,7 +27,7 @@ if ($firstview->uses_new_layout()) {
$newlayout
=
true
;
$newlayout
=
true
;
}
}
else
{
else
{
$blocks
=
$view
->
build_rows
();
$blocks
=
$
first
view
->
build_rows
();
$newlayout
=
false
;
$newlayout
=
false
;
}
}
...
...
htdocs/lib/collection.php
View file @
f8054374
...
@@ -673,6 +673,30 @@ class Collection {
...
@@ -673,6 +673,30 @@ class Collection {
return
$this
->
views
;
return
$this
->
views
;
}
}
/**
* Returns first view in the current collection
*
* @return View the first view of the collection, null if the collection is empty
*/
public
function
first_view
()
{
$viewid
=
get_field
(
'collection_view'
,
'view'
,
'collection'
,
$this
->
get
(
'id'
),
'displayorder'
,
'0'
);
$viewid
=
get_field_sql
(
"SELECT cv.view
FROM
{
collection_view
}
cv
WHERE cv.collection = ?
AND cv.displayorder = (
SELECT MIN(displayorder)
FROM
{
collection_view
}
cv2
WHERE cv2.collection = ?)"
,
array
(
$this
->
get
(
'id'
),
$this
->
get
(
'id'
)));
if
(
$viewid
)
{
require_once
(
'view.php'
);
$view
=
new
View
(
$viewid
);
return
$view
;
}
return
null
;
}
/**
/**
* Check that a collection can have a framework
* Check that a collection can have a framework
*
*
...
...
htdocs/module/framework/matrix.php
View file @
f8054374
...
@@ -57,8 +57,7 @@ $owner = $collection->get('owner');
...
@@ -57,8 +57,7 @@ $owner = $collection->get('owner');
$views
=
$collection
->
get
(
'views'
);
$views
=
$collection
->
get
(
'views'
);
// Get the first view from the collection
// Get the first view from the collection
$firstview
=
$views
[
'views'
][
0
];
$view
=
$collection
->
first_view
();
$view
=
new
View
(
$firstview
->
id
);
if
(
!
can_view_view
(
$view
->
get
(
'id'
)))
{
if
(
!
can_view_view
(
$view
->
get
(
'id'
)))
{
throw
new
AccessDeniedException
();
throw
new
AccessDeniedException
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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