本文整理汇总了PHP中Result::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Result::validate方法的具体用法?PHP Result::validate怎么用?PHP Result::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Result
的用法示例。
在下文中一共展示了Result::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSave
public function actionSave($id)
{
// Получаем куки для опроса
/*
define('COOKIE_NAME', 'poll_genplanmos_ru');
$isCookie = isset(Yii::app()->request->cookies[COOKIE_NAME]->value);
$pollCookie = $isCookie ?
Yii::app()->request->cookies[COOKIE_NAME] :
new CHttpCookie(COOKIE_NAME, '');
$pollCookieValue = $isCookie? CJSON::decode($pollCookie->value) : array();
*
*/
// Авторизован ли пользователь
if (Yii::app()->user->isAuthenticated() === false) {
$this->redirect(Yii::app()->user->loginUrl);
}
if (($user = Yii::app()->user->getProfile()) === null) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'User not found.'));
Yii::app()->user->logout();
$this->redirect((array) '/user/account/login');
}
$poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active')))->findByPK((int) $id);
if (!$poll) {
throw new CHttpException(404, Yii::t('PollModule.poll', 'Страница не найдена'));
}
// Поиск результата
$result = Result::model()->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $user->id, ':poll_id' => $poll->id));
if ($result !== null) {
throw new CHttpException(403, Yii::t('PollModule.poll', 'Вы уже проходили данный опрос'));
}
$result = new Result();
$result->user_id = $user->id;
$result->poll_id = $poll->id;
// Обработка результата
if (($data = Yii::app()->getRequest()->getPost('question')) !== null) {
// Формирование списка ответов
$answers = array();
foreach ($poll->questions as $question) {
$formValue = isset($data[$question->id]) ? $data[$question->id] : null;
switch ($question->type) {
case Question::TYPE_VARIANT:
$answer = new Answer();
$answer->question_id = $question->id;
$answer->variant_id = $formValue !== null ? (int) $formValue : $formValue;
$answers[] = $answer;
break;
case Question::TYPE_MULTIPLE:
// Просматриваем полученные ответы
if (!isset($formValue) || !is_array($formValue)) {
break;
}
foreach ($formValue as $value) {
$answer = new Answer();
$answer->question_id = $question->id;
$answer->variant_id = (int) $value;
$answers[] = $answer;
}
break;
default:
$answer = new Answer();
$answer->question_id = $question->id;
$answer->value = $formValue !== null ? $formValue : '';
$answers[] = $answer;
break;
}
$result->answers = $answers;
}
if ($result->validate()) {
$result->save();
Yii::app()->ajax->success(array('html' => $this->widget('application.modules.poll.widgets.PollWidget', array('model_id' => $poll->id), true)));
} else {
Yii::app()->ajax->failure(array('message' => '', 'errors' => $result->getErrors()));
}
}
}
示例2: testValidate16
/**
* Generated from @assert ('0-1*') === false.
*
* @covers pgn\tags\Result::validate
*/
public function testValidate16()
{
$this->assertSame(false, $this->object->validate('0-1*'));
}
示例3: importExcelTable
public function importExcelTable()
{
if (isset($_FILES['Excel'])) {
$model = new Result();
$model->attributes = $_FILES['Excel'];
$model->excel = CUploadedFile::getInstanceByName('Excel');
if ($model->validate()) {
$post = $_FILES['Excel'];
//$post=(string)$post;
$dossier = Yii::app()->params['dfs'] . "/temp/";
$dir = "temp/";
$rnd = rand(0, 99999);
$fichier = "{$rnd}-";
if (move_uploaded_file($post['tmp_name'], $dossier . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $fichier))) {
return $dossier . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $fichier);
} else {
return $dossier . $post['tmp_name'];
}
} else {
throw new CHttpException(403, "File upload failure ");
}
} else {
throw new CHttpException(403, "File upload failure");
}
}