- // {{{ static function retrieveList() : gets the list of available survey (current, old and not validated surveys)
- public static function retrieveList($type, $tpl = true)
- {
- switch ($type) {
- case 'w':
- case 'waiting' :
- $where = 'valid=0';
- break;
- case 'c':
- case 'current':
- $where = 'valid=1 AND end > NOW()';
- break;
- case 'o':
- case 'old':
- $where = 'valid=1 AND end <= NOW()';
- break;
- default:
- return null;
- }
- $sql = 'SELECT survey_id, title, end
- FROM survey_questions
- WHERE '.$where.';';
- if ($tpl) {
- return XDB::iterator($sql);
- } else {
- return XDB::iterRow($sql);
- }
- }
- // }}}
-
- // {{{ static function proposeSurvey() : stores a proposition of survey in database (before validation)
- public static function proposeSurvey($survey)
- {
- $sql = 'INSERT INTO survey_questions
- SET questions={?},
- title={?},
- description={?},
- author_id={?},
- end={?},
- promos={?},
- valid=0;';
- $data = $survey->storeArray();
- return XDB::execute($sql, serialize($survey), $data['question'], $data['comment'], S::v('uid'), $data['end'], $data['promos']);
- }
- // }}}
-
- // {{{ static function updateSurvey() : updates a survey in database (before validation)
- public static function updateSurvey($survey, $sid)
- {
- $sql = 'UPDATE survey_questions
- SET questions={?},
- title={?},
- description={?},
- end={?},
- promos={?}
- WHERE survey_id={?};';
- $data = $survey->storeArray();
- return XDB::execute($sql, serialize($survey), $data['question'], $data['comment'], $data['end'], $data['promos'], $sid);
- }
- // }}}
-
- // {{{ 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, promos, valid
- FROM survey_questions
- WHERE survey_id={?}';
- $res = XDB::query($sql, $sid);
- $data = $res->fetchOneAssoc();
- if (is_null($data) || !is_array($data)) {
- return null;
- }
- $survey = unserialize($data['questions']);
- if (isset($data['end'])) {
- $data['end'] = preg_replace('#^(\d{4})-(\d{2})-(\d{2})$#', '\3/\2/\1', $data['end']);
- }
- $survey->update(array('question' => $data['title'], 'comment' => $data['description'], 'end' => $data['end'], 'promos' => $data['promos']));
- $survey->setValid($data['valid']);
- return $survey;
- }
- // }}}
-
- // {{{ static function retrieveSurveyInfo() : gets information about a survey (title, description, end date, restrictions) but does not unserialize the survey object structure
- public static function retrieveSurveyInfo($sid)
- {
- $sql = 'SELECT title, description, end, promos, valid
- FROM survey_questions
- WHERE survey_id={?}';
- $res = XDB::query($sql, $sid);
- return $res->fetchOneAssoc();
- }
- // }}}
-
- // {{{ static function validateSurvey() : validates a survey
- public static function validateSurvey($sid)
- {
- $sql = 'UPDATE survey_questions
- SET valid=1
- WHERE survey_id={?};';
- return XDB::execute($sql, $sid);
- }
- // }}}
-
- // {{{ static function deleteSurvey() : deletes a survey (and all its votes)
- public static function deleteSurvey($sid)
- {
- $sql1 = 'DELETE FROM survey_questions
- WHERE survey_id={?};';
- $sql2 = 'DELETE FROM survey_answers
- WHERE survey_id={?};';
- $sql3 = 'DELETE FROM survey_votes
- WHERE survey_id={?};';
- return (XDB::execute($sql1, $sid) && XDB::execute($sql2, $sid) && XDB::execute($sql3, $sid));
- }
- // }}}
-}
-// }}}
-
-// {{{ abstract class SurveyQuestion
-abstract class SurveyQuestion
-{
- // {{{ static properties and methods regarding question types
- private static $types = array('text' => 'texte court',
- 'textarea' => 'texte long',
- 'num' => 'numérique',
- 'radio' => 'radio',
- 'checkbox' => 'checkbox',
- 'personal' => 'informations personnelles');
+ // {{{ static properties and functions, regarding survey modes and question types
+ const MODE_ALL = 0;
+ const MODE_XANON = 1;
+ const MODE_XIDENT = 2;
+ private static $longModes = array(self::MODE_ALL => "sondage ouvert à tout le monde, anonyme",
+ self::MODE_XANON => "sondage restreint aux polytechniciens, anonyme",
+ self::MODE_XIDENT => "sondage restreint aux polytechniciens, non anonyme");
+ private static $shortModes = array(self::MODE_ALL => "tout le monde, anonyme",
+ self::MODE_XANON => "polytechniciens, anonyme",
+ self::MODE_XIDENT => "polytechniciens, non anonyme");
+
+ public static function getModes($long = true) {
+ return ($long)? self::$longModes : self::$shortModes;
+ }
+
+ private static $types = array('text' => 'Texte court',
+ 'textarea' => 'Texte long',
+ 'num' => 'Numérique',
+ 'radio' => 'Choix multiples (une réponse)',
+ 'checkbox' => 'Choix multiples (plusieurs réponses)',
+ 'radiotable' => 'Questions multiples à choix multiples (une réponse)',
+ 'checkboxtable' => 'Questions multiples à choix mutliples (plusieurs réponses)');