本文整理匯總了PHP中Vote::setSurvey方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vote::setSurvey方法的具體用法?PHP Vote::setSurvey怎麽用?PHP Vote::setSurvey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Vote
的用法示例。
在下文中一共展示了Vote::setSurvey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: survey_submit
function survey_submit()
{
// get global user object
global $user;
// protect from unauthorized access
if (!isset($user) || !isset($_POST['formSurveySubmit'])) {
logout();
die;
}
// create empty array for $_POST container
$post = array();
// escape mysql injections array
foreach ($_POST as $key => $value) {
$post[$key] = stripslashes($value);
}
$post_keys = array_keys($_POST);
$substring = 'Answer';
$pattern = '/' . $substring . '/';
$survey_keys = preg_grep($pattern, $post_keys);
foreach ($survey_keys as $key) {
// get question
preg_match_all('!\\d+!', $key, $matches);
$question_id = $matches[0][0];
$question = new Question();
$question->get_from_db($question_id);
//get answer value
$answer_value = $_POST[$key];
//get answer id
$answer_id = $answer_value;
if (isset($matches[0][1])) {
$answer_id = $matches[0][1];
}
// get current time
$time_now = date("Y-m-d H:i:s");
// create vote object
$vote = new Vote();
$vote->setIsActive(1);
$vote->setCreatedOn($time_now);
$vote->setLastEditedOn($time_now);
$vote->setUser($user->getId());
$vote->setSurvey($question->getSurvey());
$vote->setQuestion($question_id);
$vote->setAnswer($answer_id);
$vote->setValue($answer_value);
$vote->store_in_db();
}
// set message cookie
$cookie_key = 'msg';
$cookie_value = 'Благодарим Ви за отговорения въпрос!';
setcookie($cookie_key, $cookie_value, time() + 1);
header('location:' . ROOT_DIR . '?page=survey');
}