From: Florent Bruneau Date: Mon, 11 Oct 2010 09:37:15 +0000 (+0200) Subject: Allow access to the results of a survey by its owner before the end of the X-Git-Tag: xorg/1.0.1~67 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=dd36cc0d7c791ef442c43eb90e4c52c748947dc3;p=platal.git Allow access to the results of a survey by its owner before the end of the survey. Closes #964 Signed-off-by: Florent Bruneau --- diff --git a/modules/survey.php b/modules/survey.php index 1057622..8ce9d73 100644 --- a/modules/survey.php +++ b/modules/survey.php @@ -106,7 +106,7 @@ class SurveyModule extends PLModule $survey = Survey::retrieveSurvey($id); // retrieves the survey object structure if ($survey == null || !$survey->isValid()) { return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey'); - } elseif (!$survey->isEnded()) { + } elseif (!$survey->isEnded() && !$survey->canSeeEarlyResults(S::user())) { return $this->show_error($page, "Le sondage ".$survey->getTitle()." n'est pas encore terminé.", 'survey'); } if (!$this->check_surveyPerms($page, $survey)) { diff --git a/modules/survey/survey.inc.php b/modules/survey/survey.inc.php index 7057a0d..299b7fb 100644 --- a/modules/survey/survey.inc.php +++ b/modules/survey/survey.inc.php @@ -65,6 +65,7 @@ class Survey private $promos; private $valid; private $questions; + private $creator; public function __construct($args, $id = -1, $valid = false, $questions = null) { @@ -79,13 +80,19 @@ class Survey $this->title = $args['title']; $this->description = $args['description']; $this->end = $args['end']; - $this->mode = (isset($args['mode']))? $args['mode'] : self::MODE_ALL; + $this->mode = (isset($args['mode']))? $args['mode'] : self::MODE_ALL; + $this->creator = $args['uid']; if ($this->mode == self::MODE_ALL) { $args['promos'] = ''; } $args['promos'] = str_replace(' ', '', $args['promos']); $this->promos = ($args['promos'] == '' || preg_match('#^(\d{4}-?|(\d{4})?-\d{4})(,(\d{4}-?|(\d{4})?-\d{4}))*$#', $args['promos']))? $args['promos'] : '#'; } + + public function canSeeEarlyResults(User $user) + { + return $user->id() == $this->creator || $user->checkPerms('admin'); + } // }}} // {{{ functions to access general information @@ -356,7 +363,7 @@ class Survey // {{{ static function retrieveSurvey() : gets a survey in database (and unserialize the survey object structure) public static function retrieveSurvey($sid) { - $sql = 'SELECT questions, title, description, end, mode, promos + $sql = 'SELECT questions, title, description, end, mode, promos, uid FROM surveys WHERE id={?}'; $res = XDB::query($sql, $sid); diff --git a/templates/survey/index.tpl b/templates/survey/index.tpl index 9a97536..1110521 100644 --- a/templates/survey/index.tpl +++ b/templates/survey/index.tpl @@ -24,50 +24,62 @@ {* Survey::MODE_ALL equals 0. *} {assign var=SurveyMODE_ALL value=0} +{if $survey_current->total() > 0 || $smarty.session.auth} - {iterate item=s from=$survey_current} {if $smarty.session.auth || $s.mode == $SurveyMODE_ALL} - + + {assign var="has_cs" value="true"} {/if} {/iterate} -
+ Sondages en cours
- • - - {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}] - + + {$s.title} + {if $s.uid eq $smarty.session.user->id() || hasPerm('admin')} + (résultats partiels) + {/if} + + {$s.end|date_format:"%x"} + + {$survey_modes[$s.mode]}
- {if !$has_cs}Aucun sondage en cours{/if} - {if $smarty.session.auth}{icon name=page_edit} Proposer un sondage{/if} + + {if $smarty.session.auth}{icon name=page_edit} Proposer un sondage{/if}
+{/if}
- {iterate item=s from=$survey_old} {if $smarty.session.auth || $s.mode == $SurveyMODE_ALL} - + + {assign var="has_os" value="true"} {/if}
+ Anciens sondages
- • + - {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}] + {$s.title} + {$s.end|date_format:"%x"} + + {$survey_modes[$s.mode]} +