コード例 #1
0
<?php

global $vqData;
try {
    // Delete a single player
    if (isset($_GET['playerId']) && is_numeric($_GET['playerId']) && isset($_GET['wpvq_quizId']) && is_numeric($_GET['wpvq_quizId'])) {
        global $wpdb;
        $wpdb->delete(WPViralQuiz::getTableName('players'), array('id' => $_GET['playerId']));
        $url_redirect = esc_url_raw(remove_query_arg(array('playerId', 'id', 'element', 'action', 'wp_nonce', 'noheader'), add_query_arg(array('referer' => 'remove', 'element' => 'players', 'action' => 'show', 'wpvq_quizId' => $_GET['wpvq_quizId']))));
        wp_redirect(url_origin($_SERVER) . $url_redirect);
    } elseif (isset($_GET['playerId']) && $_GET['playerId'] == 'all' && isset($_GET['wpvq_quizId']) && is_numeric($_GET['wpvq_quizId'])) {
        global $wpdb;
        $wpdb->delete(WPViralQuiz::getTableName('players'), array('quizId' => $_GET['wpvq_quizId']));
        $url_redirect = esc_url_raw(remove_query_arg(array('playerId', 'id', 'element', 'action', 'wp_nonce', 'noheader'), add_query_arg(array('referer' => 'removeAll', 'element' => 'players', 'action' => 'show', 'wpvq_quizId' => $_GET['wpvq_quizId']))));
        wp_redirect(url_origin($_SERVER) . $url_redirect);
    } else {
        throw new Exception(__("This player/quiz doesn't exist.", 'wpvq'));
    }
} catch (Exception $e) {
    echo $e->getMessage();
}
//include dirname(__FILE__) . '/../views/WPVQAddQuizz.php';
コード例 #2
0
 /**
  * Does an appreciation exist ?
  * @param  int $id ID of appr.
  * @return bool
  */
 public static function exists($id)
 {
     global $wpdb;
     if (!is_numeric($id)) {
         throw new Exception("Need numeric ID on Appreciation load ({$id}).");
     }
     // Fetch from DB
     $row = $wpdb->get_row('SELECT * FROM ' . WPViralQuiz::getTableName('appreciations') . ' WHERE ID = ' . $id);
     return !empty($row);
 }
コード例 #3
0
 /**
  * Install the plugin DB.
  */
 public static function install()
 {
     global $wpdb;
     $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPViralQuiz::getTableName('answers') . "` (\n\t\t\t`ID` int(200) NOT NULL AUTO_INCREMENT,\n\t\t\t`label` text NOT NULL,\n\t\t\t`pictureId` bigint(20) NOT NULL,\n\t\t\t`weight` smallint(30) NOT NULL,\n\t\t\t`content` text NOT NULL,\n\t\t\t`questionId` int(200) NOT NULL,\n\t\t\tPRIMARY KEY (`ID`)\n\t\t\t) CHARSET=utf8 AUTO_INCREMENT=1 ;");
     $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPViralQuiz::getTableName('appreciations') . "` (\n\t\t\t`ID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`quizId` int(200) NOT NULL,\n\t\t\t`scoreCondition` int(200) NULL,\n\t\t\t`label` text NOT NULL,\n\t\t\t`content` text NOT NULL,\n\t\t\tPRIMARY KEY (`ID`)\n\t\t\t) CHARSET=utf8 AUTO_INCREMENT=1 ;");
     $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPViralQuiz::getTableName('questions') . "` (\n\t\t\t`ID` int(200) NOT NULL AUTO_INCREMENT,\n\t\t\t`label` text NOT NULL,\n\t\t\t`quizId` int(200) NOT NULL,\n\t\t\t`position` int(200) NOT NULL,\n\t\t\t`pictureId` bigint(20) NOT NULL,\n\t\t\t`content` text NULL,\n\t\t\t`pageAfter` SMALLINT(2) NULL,\n\t\t\tPRIMARY KEY (`ID`)\n\t\t\t) CHARSET=utf8 AUTO_INCREMENT=1 ;");
     $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPViralQuiz::getTableName('players') . "` (\n\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`quizId` int(11) NOT NULL,\n\t\t\t`email` varchar(200) NULL,\n\t\t\t`nickname` varchar(200) NULL,\n\t\t\t`result` TEXT NOT NULL,\n\t\t\t`date` INT NOT NULL,\n\t\t\t`meta` TEXT NULL,\n\t\t\t  PRIMARY KEY (`ID`)\n\t\t\t) CHARSET=utf8 AUTO_INCREMENT=1 ;");
     $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPViralQuiz::getTableName('quizzes') . "` (\n\t\t\t`ID` int(200) NOT NULL AUTO_INCREMENT,\n\t\t\t`type` varchar(20) NOT NULL,\n\t\t\t`name` varchar(255) NOT NULL,\n\t\t\t`authorId` bigint(20) NOT NULL,\n\t\t\t`dateCreation` int(200) NOT NULL,\n\t\t\t`dateUpdate` int(200) NOT NULL,\n\t\t\t`showSharing` SMALLINT NOT NULL,\n\t\t\t`showCopyright` SMALLINT NOT NULL,\n\t\t\t`askInformations` VARCHAR(100) NULL,\n\t\t\t`forceToShare` VARCHAR(100) NULL,\n\t\t\t`skin` VARCHAR(50) NOT NULL,\n\t\t\tPRIMARY KEY (`ID`)\n\t\t\t) CHARSET=utf8 AUTO_INCREMENT=1 ;");
     $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPViralQuiz::getTableName('multipliers') . "` (\n\t\t\t  `id` int(200) NOT NULL AUTO_INCREMENT,\n\t\t\t  `quizId` int(200) NOT NULL,\n\t\t\t  `questionId` int(200) NOT NULL,\n\t\t\t  `answerId` int(200) NOT NULL,\n\t\t\t  `appreciationId` int(200) NOT NULL,\n\t\t\t  `multiplier` int(200) NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) CHARSET=utf8 AUTO_INCREMENT=1");
 }
コード例 #4
0
ファイル: WPVQGame.php プロジェクト: developmentDM2/Whohaha
 /** 	
  * Get type quizz by id
  * @return string [WPVQGameTrueFalse|WPVQGamePersonnality]
  */
 public static function getTypeById($id)
 {
     global $wpdb;
     if (!is_numeric($id)) {
         throw new Exception("Need numeric ID on Game load.");
     }
     $row = $wpdb->get_row('SELECT type FROM ' . WPViralQuiz::getTableName('quizzes') . ' WHERE ID = ' . $id);
     if (empty($row)) {
         throw new Exception("Quizz {$id} doesn't exist.");
     }
     return $row->type;
 }
コード例 #5
0
 /**
  * Duplicate question 
  * @param $newQuizId The new quiz ID
  */
 public function duplicate($newQuizId)
 {
     global $wpdb;
     $wpdb->query('CREATE TEMPORARY TABLE wpvq_tmptable_1 SELECT * FROM ' . WPViralQuiz::getTableName('questions') . ' WHERE id = ' . $this->id . '');
     $wpdb->query('UPDATE wpvq_tmptable_1 SET id = NULL, quizId = ' . $newQuizId . '');
     $wpdb->query('INSERT INTO ' . WPViralQuiz::getTableName('questions') . ' SELECT * FROM wpvq_tmptable_1');
     $wpdb->query('DROP TEMPORARY TABLE IF EXISTS wpvq_tmptable_1;');
     $newQuestionId = $wpdb->insert_id;
     foreach ($this->answers as $answers) {
         $answers->duplicate($newQuestionId, $newQuizId);
     }
 }
コード例 #6
0
 /**
  * Update meta fields for $playerId
  * @param  int $playerId index of player
  * @param  array $meta   an array of meta, serialized in the DB
  * @return bool
  */
 public static function updateMetaPlayer($playerId, $meta)
 {
     global $wpdb;
     $meta = serialize($meta);
     $dataSql = array('meta' => $meta);
     $typeSql = array('%s');
     $return = $wpdb->update(WPViralQuiz::getTableName('players'), $dataSql, array('id' => $playerId), $typeSql, array('%d')) or die(mysql_error());
     return $return;
 }
コード例 #7
0
ファイル: WPVQAnswer.php プロジェクト: developmentDM2/Whohaha
 /**
  * Duplicate answer 
  * @param $newQuizId The new quiz ID
  */
 public function duplicate($newQuestionId, $newQuizId)
 {
     global $wpdb;
     $wpdb->query('CREATE TEMPORARY TABLE wpvq_tmptable_1 SELECT * FROM ' . WPViralQuiz::getTableName('answers') . ' WHERE id = ' . $this->id . '');
     $wpdb->query('UPDATE wpvq_tmptable_1 SET id = NULL, questionId = ' . $newQuestionId . '');
     $wpdb->query('INSERT INTO ' . WPViralQuiz::getTableName('answers') . ' SELECT * FROM wpvq_tmptable_1');
     $wpdb->query('DROP TEMPORARY TABLE IF EXISTS wpvq_tmptable_1;');
     $newAnswerId = $wpdb->insert_id;
     // Duplicate multipliers
     // -1 to detect the multipliers for ::appreciation->duplicate()
     $wpdb->query('CREATE TEMPORARY TABLE wpvq_tmptable_1 SELECT * FROM ' . WPViralQuiz::getTableName('multipliers') . ' WHERE answerId = ' . $this->id . '');
     $wpdb->query('UPDATE wpvq_tmptable_1 SET id = NULL, answerId = ' . $newAnswerId . ', questionId = ' . $newQuestionId . ', quizId = -1');
     $wpdb->query('INSERT INTO ' . WPViralQuiz::getTableName('multipliers') . ' SELECT * FROM wpvq_tmptable_1');
     $wpdb->query('DROP TEMPORARY TABLE IF EXISTS wpvq_tmptable_1;');
 }