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) { ...@@ -113,24 +113,32 @@ if ($role) {
$sharedviews = View::get_sharedviews_data(null, 0, $group->id); $sharedviews = View::get_sharedviews_data(null, 0, $group->id);
if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) { if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
// Display a list of views submitted to the group // 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())) { 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)); // A user can submit more than one view to the same group, but no view can be
if (!$submitted) { // submitted to more than one group.
$group_view_submission_form = group_view_submission_form($group->id, $userviewdata);
// 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 { else {
if ($submitted->submittedtime) { $v['strsubmitted'] = get_string('youhavesubmitted', 'view', $url, $v['title']);
$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);
} }
} }
$group_view_submission_form = group_view_submission_form($group->id, $userviewdata);
} }
$smarty = smarty(); $smarty = smarty();
...@@ -145,8 +153,11 @@ $smarty->assign('foldercount', $filecounts->folders); ...@@ -145,8 +153,11 @@ $smarty->assign('foldercount', $filecounts->folders);
if (isset($sharedviews)) { if (isset($sharedviews)) {
$smarty->assign('sharedviews', $sharedviews->data); $smarty->assign('sharedviews', $sharedviews->data);
} }
if (isset($submittedviews)) { if (isset($allsubmittedviews)) {
$smarty->assign('submittedviews', $submittedviews); $smarty->assign('allsubmittedviews', $allsubmittedviews);
}
if (isset($mysubmittedviews)) {
$smarty->assign('mysubmittedviews', $mysubmittedviews);
} }
if (isset($group_view_submission_form)) { if (isset($group_view_submission_form)) {
$smarty->assign('group_view_submission_form', $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'; ...@@ -81,7 +81,7 @@ $string['viewssharedtogroupbyothers'] = 'Views shared to this group by others';
$string['viewssubmittedtogroup'] = 'Views submitted to this group'; $string['viewssubmittedtogroup'] = 'Views submitted to this group';
$string['submitaviewtogroup'] = 'Submit a view 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['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 // access levels
$string['public'] = 'Public'; $string['public'] = 'Public';
......
...@@ -694,8 +694,13 @@ function group_removeuser_submit(Pieform $form, $values) { ...@@ -694,8 +694,13 @@ function group_removeuser_submit(Pieform $form, $values) {
function group_view_submission_form($groupid, $viewdata) { function group_view_submission_form($groupid, $viewdata) {
$options = array(); $options = array();
foreach ($viewdata as $view) { foreach ($viewdata as $view) {
if (empty($view->submittedgroup) && empty($view->submittedhost)) {
$options[$view->id] = $view->title; $options[$view->id] = $view->title;
} }
}
if (empty($options)) {
return;
}
return pieform(array( return pieform(array(
'name' => 'group_view_submission_form_' . $groupid, 'name' => 'group_view_submission_form_' . $groupid,
'method' => 'post', 'method' => 'post',
......
...@@ -2147,8 +2147,8 @@ class View { ...@@ -2147,8 +2147,8 @@ class View {
global $USER; global $USER;
$userid = $USER->get('id'); $userid = $USER->get('id');
} }
if ($views = get_records_sql_array( if ($views = get_records_sql_assoc(
"SELECT v.id, v.title "SELECT v.*
FROM {view} v FROM {view} v
WHERE v.owner = ? WHERE v.owner = ?
AND v.type != 'profile' AND v.type != 'profile'
...@@ -2449,7 +2449,7 @@ class View { ...@@ -2449,7 +2449,7 @@ class View {
); );
if ($viewdata) { if ($viewdata) {
View::get_extra_view_info($viewdata); View::get_extra_view_info($viewdata, false);
} }
else { else {
$viewdata = array(); $viewdata = array();
...@@ -2465,24 +2465,34 @@ class View { ...@@ -2465,24 +2465,34 @@ class View {
/** /**
* Get views submitted to a group * 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(' $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} FROM {view}
WHERE submittedgroup = ? WHERE ' . $where . '
ORDER BY title, id', ORDER BY title, id',
array($groupid) $values
); );
if ($viewdata) { if ($viewdata) {
View::get_extra_view_info($viewdata); View::get_extra_view_info($viewdata, false);
return array_values($viewdata); return array_values($viewdata);
} }
return false; return false;
} }
public static function get_extra_view_info(&$viewdata) { public static function get_extra_view_info(&$viewdata, $getartefacts = true) {
if ($viewdata) { if ($viewdata) {
// Get view owner details for display // Get view owner details for display
$owners = array(); $owners = array();
...@@ -2497,7 +2507,9 @@ class View { ...@@ -2497,7 +2507,9 @@ class View {
$institutions[$v->institution] = $v->institution; $institutions[$v->institution] = $v->institution;
} }
} }
$viewidlist = join(',', array_keys($viewdata)); $viewidlist = join(',', array_keys($viewdata));
if ($getartefacts) {
$artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin
FROM {view_artefact} va FROM {view_artefact} va
INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact} a ON va.artefact = a.id
...@@ -2521,6 +2533,7 @@ class View { ...@@ -2521,6 +2533,7 @@ class View {
} }
} }
} }
}
$tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')');
if ($tags) { if ($tags) {
foreach ($tags as &$tag) { foreach ($tags as &$tag) {
......
...@@ -62,31 +62,32 @@ ...@@ -62,31 +62,32 @@
</p> </p>
{/if} {/if}
{if $group_view_submission_form} {if $mysubmittedviews || $group_view_submission_form}
<h3>{str tag="submitaviewtogroup" section="view"}</h3> <h3>{str tag="submitaviewtogroup" section="view"}</h3>
{if $mysubmittedviews}
{foreach from=$mysubmittedviews item=view}
<div>{$view.strsubmitted}</div>
{/foreach}
{/if}
{if $group_view_submission_form}
<div>{$group_view_submission_form}</div> <div>{$group_view_submission_form}</div>
{/if}
{/if} {/if}
{if $submittedviews} {if $allsubmittedviews}
<h3>{str tag="viewssubmittedtogroup" section="view"}</h3> <h3>{str tag="viewssubmittedtogroup" section="view"}</h3>
<p> <p>
<table class="fullwidth"> <table class="fullwidth">
{foreach from=$submittedviews item=view} {foreach from=$allsubmittedviews item=view}
<tr class="{cycle values='r0,r1'}"> <tr class="{cycle values='r0,r1'}">
<td> <td>
<a href="{$WWWROOT}view/view.php?id={$view.id}">{$view.title|escape}</a> <a href="{$WWWROOT}view/view.php?id={$view.id}">{$view.title|escape}</a>
{if $view.sharedby} {if $view.sharedby}
{str tag=by section=view} {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> <a href="{$WWWROOT}user/view.php?id={$view.owner}">{$view.sharedby}</a>
{else}
{$view.sharedby}
{/if}
{/if} {/if}
{if $view.submittedtime} {if $view.submittedtime}
<span> ({str tag=timeofsubmission section=view}: {$view.submittedtime})</span> <span> ({str tag=timeofsubmission section=view}: {$view.submittedtime|format_date})</span>
{/if} {/if}
<div>{$view.shortdescription}</div> <div>{$view.shortdescription}</div>
{if $view.tags}<div class="tags">{str tag=tags}: {list_tags owner=$view.owner tags=$view.tags}</div>{/if} {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