Commit 0c50cd84 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Clean up view submission from group page.


- Allow for multiple views by one user submitted to a single group
- Don't show already-submitted views in the submit form drop-down
Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 3a5f0d1c
......@@ -113,24 +113,32 @@ if ($role) {
$sharedviews = View::get_sharedviews_data(null, 0, $group->id);
if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
// Display a list of views submitted to the group
$submittedviews = View::get_submitted_views($group->id);
$allsubmittedviews = View::get_submitted_views($group->id);
}
}
if (group_allows_submission($group->grouptype) && ($userviewdata = View::get_user_views())) {
$submitted = get_record_select('view', 'owner = ? AND submittedgroup = ?', array($USER->get('id'), $group->id));
if (!$submitted) {
$group_view_submission_form = group_view_submission_form($group->id, $userviewdata);
}
else {
if ($submitted->submittedtime) {
$pieces = explode(' ', $submitted->submittedtime);
$group_view_submission_form = get_string('youhavesubmittedon', 'view', get_config('wwwroot') . 'view/view.php?id=' . $submitted->id, $submitted->title, $pieces[0], $pieces[1]);
}
else {
$group_view_submission_form = get_string('youhavesubmitted', 'view', get_config('wwwroot') . 'view/view.php?id=' . $submitted->id, $submitted->title);
// A user can submit more than one view to the same group, but no view can be
// submitted to more than one group.
// Display a list of views this user has submitted to this group, and a submission
// form containing drop-down of their unsubmitted views.
$mysubmittedviews = View::get_submitted_views($group->id, $USER->get('id'));
if (!empty($mysubmittedviews)) {
foreach ($mysubmittedviews as &$v) {
$url = get_config('wwwroot') . 'view/view.php?id=' . $v['id'];
if ($v['submittedtime']) {
$v['strsubmitted'] = get_string('youhavesubmittedon', 'view', $url, $v['title'], format_date($v['submittedtime']));
}
else {
$v['strsubmitted'] = get_string('youhavesubmitted', 'view', $url, $v['title']);
}
}
}
$group_view_submission_form = group_view_submission_form($group->id, $userviewdata);
}
$smarty = smarty();
......@@ -145,8 +153,11 @@ $smarty->assign('foldercount', $filecounts->folders);
if (isset($sharedviews)) {
$smarty->assign('sharedviews', $sharedviews->data);
}
if (isset($submittedviews)) {
$smarty->assign('submittedviews', $submittedviews);
if (isset($allsubmittedviews)) {
$smarty->assign('allsubmittedviews', $allsubmittedviews);
}
if (isset($mysubmittedviews)) {
$smarty->assign('mysubmittedviews', $mysubmittedviews);
}
if (isset($group_view_submission_form)) {
$smarty->assign('group_view_submission_form', $group_view_submission_form);
......
......@@ -81,7 +81,7 @@ $string['viewssharedtogroupbyothers'] = 'Views shared to this group by others';
$string['viewssubmittedtogroup'] = 'Views submitted to this group';
$string['submitaviewtogroup'] = 'Submit a view to this group';
$string['youhavesubmitted'] = 'You have submitted <a href="%s">%s</a> to this group';
$string['youhavesubmittedon'] = 'You submitted <a href="%s">%s</a> to this group on %s at %s';
$string['youhavesubmittedon'] = 'You submitted <a href="%s">%s</a> to this group on %s';
// access levels
$string['public'] = 'Public';
......
......@@ -694,7 +694,12 @@ function group_removeuser_submit(Pieform $form, $values) {
function group_view_submission_form($groupid, $viewdata) {
$options = array();
foreach ($viewdata as $view) {
$options[$view->id] = $view->title;
if (empty($view->submittedgroup) && empty($view->submittedhost)) {
$options[$view->id] = $view->title;
}
}
if (empty($options)) {
return;
}
return pieform(array(
'name' => 'group_view_submission_form_' . $groupid,
......
......@@ -2147,8 +2147,8 @@ class View {
global $USER;
$userid = $USER->get('id');
}
if ($views = get_records_sql_array(
"SELECT v.id, v.title
if ($views = get_records_sql_assoc(
"SELECT v.*
FROM {view} v
WHERE v.owner = ?
AND v.type != 'profile'
......@@ -2449,7 +2449,7 @@ class View {
);
if ($viewdata) {
View::get_extra_view_info($viewdata);
View::get_extra_view_info($viewdata, false);
}
else {
$viewdata = array();
......@@ -2465,24 +2465,34 @@ class View {
/**
* Get views submitted to a group
*/
public static function get_submitted_views($groupid) {
public static function get_submitted_views($groupid, $userid=null) {
$values = array($groupid);
$where = 'submittedgroup = ?';
if (!empty($userid)) { // Filter by view owner
$values[] = (int) $userid;
$where .= ' AND owner = ?';
}
$viewdata = get_records_sql_assoc('
SELECT id, title, description, owner, ownerformat, "group", institution, submittedtime
SELECT
id, title, description, owner, ownerformat, "group", institution,
' . db_format_tsfield('submittedtime') . '
FROM {view}
WHERE submittedgroup = ?
WHERE ' . $where . '
ORDER BY title, id',
array($groupid)
$values
);
if ($viewdata) {
View::get_extra_view_info($viewdata);
View::get_extra_view_info($viewdata, false);
return array_values($viewdata);
}
return false;
}
public static function get_extra_view_info(&$viewdata) {
public static function get_extra_view_info(&$viewdata, $getartefacts = true) {
if ($viewdata) {
// Get view owner details for display
$owners = array();
......@@ -2497,27 +2507,30 @@ class View {
$institutions[$v->institution] = $v->institution;
}
}
$viewidlist = join(',', array_keys($viewdata));
$artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin
FROM {view_artefact} va
INNER JOIN {artefact} a ON va.artefact = a.id
INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name
WHERE va.view IN (' . $viewidlist . ')
GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin
ORDER BY a.title, va.artefact', '');
if ($artefacts) {
foreach ($artefacts as $artefactrec) {
safe_require('artefact', $artefactrec->plugin);
$classname = generate_artefact_class_name($artefactrec->artefacttype);
$artefactobj = new $classname(0, array('title' => $artefactrec->title));
$artefactobj->set('dirty', false);
if (!$artefactobj->in_view_list()) {
continue;
}
$artname = $artefactobj->display_title(30);
if (strlen($artname)) {
$viewdata[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact,
'title' => $artname);
if ($getartefacts) {
$artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin
FROM {view_artefact} va
INNER JOIN {artefact} a ON va.artefact = a.id
INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name
WHERE va.view IN (' . $viewidlist . ')
GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin
ORDER BY a.title, va.artefact', '');
if ($artefacts) {
foreach ($artefacts as $artefactrec) {
safe_require('artefact', $artefactrec->plugin);
$classname = generate_artefact_class_name($artefactrec->artefacttype);
$artefactobj = new $classname(0, array('title' => $artefactrec->title));
$artefactobj->set('dirty', false);
if (!$artefactobj->in_view_list()) {
continue;
}
$artname = $artefactobj->display_title(30);
if (strlen($artname)) {
$viewdata[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact,
'title' => $artname);
}
}
}
}
......
......@@ -62,31 +62,32 @@
</p>
{/if}
{if $group_view_submission_form}
{if $mysubmittedviews || $group_view_submission_form}
<h3>{str tag="submitaviewtogroup" section="view"}</h3>
<div>{$group_view_submission_form}</div>
{if $mysubmittedviews}
{foreach from=$mysubmittedviews item=view}
<div>{$view.strsubmitted}</div>
{/foreach}
{/if}
{if $group_view_submission_form}
<div>{$group_view_submission_form}</div>
{/if}
{/if}
{if $submittedviews}
{if $allsubmittedviews}
<h3>{str tag="viewssubmittedtogroup" section="view"}</h3>
<p>
<table class="fullwidth">
{foreach from=$submittedviews item=view}
{foreach from=$allsubmittedviews item=view}
<tr class="{cycle values='r0,r1'}">
<td>
<a href="{$WWWROOT}view/view.php?id={$view.id}">{$view.title|escape}</a>
{if $view.sharedby}
{str tag=by section=view}
{if $view.group}
<a href="{$WWWROOT}group/view.php?id={$view.group}">{$view.sharedby}</a>
{elseif $view.owner}
<a href="{$WWWROOT}user/view.php?id={$view.owner}">{$view.sharedby}</a>
{else}
{$view.sharedby}
{/if}
<a href="{$WWWROOT}user/view.php?id={$view.owner}">{$view.sharedby}</a>
{/if}
{if $view.submittedtime}
<span> ({str tag=timeofsubmission section=view}: {$view.submittedtime})</span>
<span> ({str tag=timeofsubmission section=view}: {$view.submittedtime|format_date})</span>
{/if}
<div>{$view.shortdescription}</div>
{if $view.tags}<div class="tags">{str tag=tags}: {list_tags owner=$view.owner tags=$view.tags}</div>{/if}
......
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