Created
August 18, 2014 10:23
-
-
Save hissy/3739da85b8e2761aae28 to your computer and use it in GitHub Desktop.
フォームの回答から抽選するスクリプト、toolsに設置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('C5_EXECUTE') or die("Access Denied."); | |
// Formブロックをロード | |
Loader::block('form'); | |
// ヘルパーのロード | |
$valn = Loader::helper('validation/numbers'); | |
// フォームの結果を見れる権限があるかのチェック | |
$c = Page::getByPath('/dashboard/reports/forms'); | |
$cp = new Permissions($c); | |
if (!$cp->canRead()) { | |
die(t("Access Denied.")); | |
} | |
$questions = array(); | |
$presents = array( | |
'Coda2', | |
'これからの「標準」を身につける HTML+CSSデザインレシピ', | |
'これからの「標準」を身につける HTML+CSSデザインレシピ', | |
'Web制作者のためのGit入門', | |
'頼られるWeb担当者になる! ネットプロモーション教本', | |
'はじめてでもよくわかる! Webマーケティング集中講義', | |
'よくわかるWeb/モバイル/ソーシャルメディアマーケティングの教科書', | |
'ノンデザイナーズ・デザインブック [フルカラー新装増補版]', | |
); | |
// QuestionSetIDの取得 | |
$qsid = $_GET['qsid']; | |
// 検証 | |
if (!empty($qsid) && $valn->integer($qsid)) { | |
// qsIDから質問の取得 | |
$res = MiniSurvey::loadQuestions($qsid); | |
$handleNameMsqID = 0; | |
$nameMsqID = 0; | |
while( $question = $res->fetchRow() ){ | |
if ($question['question'] == 'ハンドルネーム') { | |
$handleNameMsqID = $question['msqID']; | |
} | |
if ($question['question'] == 'お名前') { | |
$nameMsqID = $question['msqID']; | |
} | |
} | |
// qsIDから回答の取得 | |
$answerSetsArray = FormBlockStatistics::buildAnswerSetsArray($qsid); | |
shuffle($answerSetsArray); // シャッフル | |
if (count($answerSetsArray) > 0 ) { | |
foreach ($answerSetsArray as $answerSetId => $answerSet) { | |
$q = new stdClass; | |
$q->handleName = $answerSet['answers'][$handleNameMsqID]['answer']; | |
$q->name = $answerSet['answers'][$nameMsqID]['answer']; | |
$questions[] = $q; | |
} | |
} else { | |
die('回答がありません。'); | |
} | |
} else { | |
die(t("Access Denied.")); | |
} | |
?> | |
<!DOCTYPE html> | |
<title>『concrete5 公式活用ガイドブック』の書評で当たる!キャンペーン 抽選結果</title> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> | |
<div class="container"> | |
<h1>夏休み感想文キャンペーン 抽選結果</h1> | |
<?php foreach ($presents as $key => $present) : | |
if (isset($questions[$key])) : | |
?> | |
<div class="result panel panel-info"> | |
<div class="panel-heading"> | |
<h4><?php echo $present; ?></h4> | |
</div> | |
<div class="panel-body"> | |
<?php $name = ($questions[$key]->handleName) ? $questions[$key]->handleName : $questions[$key]->name; ?> | |
<p class="name lead" style="display:none;"><?php echo h($name); ?>さん</p> | |
<a href="#" class="btn btn-info">表示</a> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</div> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<script> | |
$(function(){ | |
$('.result a').click(function(e){ | |
e.preventDefault(); | |
$(this).parent().find('.name').show(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment