本文整理汇总了PHP中Result::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Result::model方法的具体用法?PHP Result::model怎么用?PHP Result::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Result
的用法示例。
在下文中一共展示了Result::model方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Запускаем отрисовку виджета
*
* @return void
*/
public function run()
{
// Авторизован ли пользователь
if (Yii::app()->user->isAuthenticated() === false) {
return;
}
if (($user = Yii::app()->user->getProfile()) === null) {
return;
}
$poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active'), 'questions.variants' => array('scopes' => 'active')))->findByPK((int) $this->model_id);
if ($poll === null) {
return;
}
// Подгружаем результаты пользователя
$userId = $user->id;
if (Yii::app()->user->isSuperUser() && Yii::app()->user->getState('adminUserId') !== null) {
// Для администратора показываем результаты опроса пользователя в случае подмены
$viewedUser = User::model()->findByPK((int) Yii::app()->user->getState('adminUserId'));
if ($viewedUser) {
$userId = $viewedUser->id;
}
}
$result = Result::model()->with('answers')->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $userId, ':poll_id' => $poll->id));
$this->render($this->view, array('model' => $poll, 'result' => $result));
}
示例2: actionimportExcelTable
public function actionimportExcelTable($id, $issueId)
{
//step id
if (isset($_FILES['Excel'])) {
$post = Result::model()->importExcelTable($_FILES['Excel']);
//throw new CHttpException(403,$_FILES['File']);
Yii::import('ext.phpexcel.IOFactory');
Yii::import('ext.phpexcel.*');
Yii::import('ext.phpexcel.XPHPExcel');
Yii::import('ext.phpexcel.shared.string');
$newsheet = XPHPExcel::createPHPExcel();
//$inputFileName='c:\inetpub\wwwroot\vector2014\protected\extensions\examples\reader\sampledata\book1.xlsx';
$inputFileName = $post["tmp_name"];
Result::model()->alsjkd($inputFileName);
//var_dump($post);
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch (PHPExcel_Reader_Exception $e) {
die('Error loading file: ' . $e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumnIndex = $sheet->getHighestColumn();
$index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
$highestColumn = $index[$highestColumnIndex];
$index = array_slice($index, 0, $highestColumn);
$element = new Element();
$element->stepId = $id;
$element->typeId = 13;
$element->save();
$elementId = $element->id;
$step = $this->loadModel($id);
for ($row = 1; $row <= $highestRow; $row++) {
$rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
}
$columns = array();
//for ($column =1 ; $column<=$highestColumn; $column++){
foreach ($index as $key => $position) {
$columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
}
$salida = $step->addGrid($element, $rows, $columns);
$issue = new Issue();
//$travelerId= $step->travelerId;
for ($row = 1; $row <= $highestRow; $row++) {
foreach ($index as $key => $position) {
if ($row >= 1 && $position > 0) {
$result = new Result();
$result->elementId = $elementId;
$result->issueId = $issueId;
$result->value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, $row)->getValue();
//throw new CHttpException(403, 'row: '.$row.'. Columna: '.$position.'.Value: '.$result->value);
$result->colonne = $position - 1;
$result->ligne = $row - 2;
$result->save();
}
//throw new CHttpException (403,"exception: ". $iasdasdeId);
//$objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A',$row)->getValue();
}
}
$alsdjk = $LKSJAD;
} else {
$alsdjk = $LKSJAD;
throw new CHttpException(403, "Error in the file");
}
}
示例3: getResultCode
/**
* Получение кода для нового результата
*
* @param string $attributeCode
*
* @return string
*/
public function getResultCode($attributeCode)
{
$index = 1;
$code = Result::model()->find(array('select' => 't.code', 'condition' > 't.code LIKE ":code-%%"', 'params' => array(':code' => $attributeCode), 'sort' => 't.id DESC'));
if ($code) {
$tempArr = explode('-', $code);
$index = (int) $tempArr[1] + 1;
}
return $attributeCode . '-' . $index;
}
示例4: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Result the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = Result::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例5: 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()));
}
}
}
示例6: actionResults
/**
* Poll results.
*
* @return void
*/
public function actionResults($id, $format = null)
{
$model = $this->loadModel($id);
$results = Result::model()->with(array('answers', 'user', 'user.profile'))->findAll('t.poll_id = :poll_id', array(':poll_id' => $id));
$this->render('results', array('model' => $model, 'results' => $results));
}
示例7: beforeDelete
/**
* Метод перед удалением:
*
* @return void
*/
public function beforeDelete()
{
if (User::model()->admin()->count() === 1 && $this->_oldRole === User::getSuperuserRole()) {
$this->addError('role', Yii::t('UserModule.user', 'You can\'t make this changes!'));
return false;
}
// убираем связь удаленного пользователя с ролью
//$auth = Yii::app()->authManager;
//$auth->revoke($this->role, $this->id);
//$auth->save();
// Удаляем токены
foreach ($this->tokens as $token) {
$token->delete();
}
// Обнуляем связанные элементы обратной связи
Yii::import("application.modules.feedback.models.Feedback");
foreach (Feedback::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
$item->user_id = null;
$item->save(false, array('user_id'));
}
// Обнуляем связанные подписки
Yii::import("application.modules.subscription.models.Subscription");
foreach (Subscription::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
$item->user_id = null;
$item->save(false, array('user_id'));
}
// Обнуляем связанные результаты голосования
Yii::import("application.modules.poll.models.*");
foreach (Result::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
$item->user_id = null;
$item->save(false, array('user_id'));
}
// Удаляем интересные мысли пользователя
Yii::import("application.modules.classroom.models.Quote");
Quote::model()->deleteAllByAttributes(array('user_id' => $this->id));
// Удаляем последние прочитанные страницы пользователя
Yii::import("application.modules.classroom.models.LastReadPage");
LastReadPage::model()->deleteAllByAttributes(array('user_id' => $this->id));
// Удаляем настройки пользователя
foreach (yupe\models\Settings::model()->findAllByAttributes(array('user_id' => $this->id)) as $item) {
$item->delete();
}
// Удаляем профиль
$this->profile->delete();
return parent::beforeDelete();
}
示例8: doesExist
public function doesExist($elementId, $issueId, $value)
{
$criteria = new CDbCriteria();
$criteria->condition = "issueId = {$issueId} and elementId = {$elementId} and value like '{$value}'";
$modelo = Result::model()->count($criteria);
return $modelo;
/*
if($modelo) return false;
else return true;*/
}
示例9: actionimportExcelTable
public function actionimportExcelTable($id, $issueId)
{
//step id
if (isset($_FILES['Excel'])) {
$post = Result::model()->importExcelTable($_FILES['Excel']);
//var_dump($post);
Yii::import('ext.phpexcel.IOFactory');
Yii::import('ext.phpexcel.*');
Yii::import('ext.phpexcel.XPHPExcel');
Yii::import('ext.phpexcel.shared.string');
$newsheet = XPHPExcel::createPHPExcel();
$inputFileName = $post;
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch (PHPExcel_Reader_Exception $e) {
die('Error loadinng file: ' . $post);
//$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumnIndex = $sheet->getHighestColumn();
$index = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8);
$highestColumn = $index[$highestColumnIndex];
$index = array_slice($index, 0, $highestColumn);
$element = new Element();
$element->stepId = $id;
$element->typeId = 13;
$element->save();
$elementId = $element->id;
$step = $this->loadModel($id);
for ($row = 1; $row <= $highestRow; $row++) {
$rows[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', $row)->getValue();
}
$columns = array();
foreach ($index as $key => $position) {
$columns[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, 1)->getValue();
}
//$salida=$step->addGrid($element, $rows, $columns);
$issue = new Issue();
for ($row = 1; $row <= $highestRow; $row++) {
foreach ($index as $key => $position) {
if ($row >= 1 && $position > 0) {
$result = new Result();
$result->elementId = $elementId;
$result->issueId = $issueId;
$result->value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($position, $row)->getValue();
$result->colonne = $position - 1;
$result->ligne = $row - 2;
throw new CHttpException(403, 'row: ' . $result->ligne . '. Columna: ' . $result->colonne . '.Value: ' . $result->value);
$result->save();
}
}
}
//$this->redirect(array('view','id'=>$id));
} else {
throw new CHttpException(403, "Failure loading file");
}
}
示例10: setTableOFF
public function setTableOFF($id)
{
$results = Result::model()->with('element')->findAll("issueId = {$id} and typeId IN(13,14)");
foreach ($results as $result) {
$result->value = "off";
$result->save();
}
}
示例11: actionexcelComp
public function actionexcelComp($id, $elementId)
{
//issueId and elementId
$element = Element::model()->findByPk($elementId);
Yii::import('ext.phpexcel.XPHPExcel');
$title = Element::model()->findByPk($elementId);
$newsheet = XPHPExcel::createPHPExcel();
switch ($element->typeId) {
case 0:
case 1:
case 3:
case 4:
$criteria = "elementId={$elementId}";
$results = Result::model()->findAll($criteria);
//$results=Result::model()->findAll($title->label);
$newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "Issue ID");
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "User");
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, 1, "Fill date");
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, 1, $title->label);
$newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$cont = 2;
foreach ($results as $result) {
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $cont, $result->issueId);
$issue = $this->loadIssue($result->issueId);
$user = Element::model()->getUserForExcel($result->issueId, $elementId);
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, $cont, $user);
//
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, $cont, Yii::app()->dateFormatter->format("HH:mm d/M/y", $result->createTime));
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, $cont, $result->value);
$cont++;
}
$traveler = Traveler::model()->findByPk($issue->travelerId);
if (isset($issue)) {
if (strlen($traveler->name) > 28) {
$traveler->name = substr($traveler->name, 0, 28);
}
$newsheet->getActiveSheet()->setTitle($traveler->name);
}
//else throw new CHttpException(403, 'There is a problem with the data');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx');
header('Cache-Control: max-age=0');
//metada:
$newsheet->getProperties()->setCreator(Yii::app()->user->username);
$objWriter = PHPExcel_IOFactory::createWriter($newsheet, 'Excel2007');
$objWriter->save('php://output');
break;
case 5:
//devuelve el value de result, que es el id de value!!
//center 1st column
$newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//name first column
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "Issue ID");
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "User");
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, 1, "Fill date");
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, 1, $title->label);
//center data cells
$newsheet->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$newsheet->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
//color
$newsheet->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
$newsheet->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('AFDBFF');
//size
$newsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$newsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$newsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$newsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$criteria = "elementId={$elementId}";
$preresults = Result::model()->findAll($criteria);
$cont = 2;
foreach ($preresults as $preresult) {
$issue = $this->loadIssue($preresult->issueId);
$user = Element::model()->getUserForExcel($preresult->issueId, $elementId);
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(0, $cont, $preresult->issueId);
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(1, $cont, $user);
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(2, $cont, Yii::app()->dateFormatter->format("HH:mm d/M/y", $preresult->createTime));
$value = Value::model()->findByPk($preresult->value);
$newsheet->getActiveSheet()->setCellValueByColumnAndRow(3, $cont, $value->value);
//.........这里部分代码省略.........
示例12: beforeDelete
protected function beforeDelete()
{
foreach (Nonconformity::model()->findAll("issueId = {$this->id}") as $discrepancy) {
$discrepancy->delete();
}
foreach (Comment::model()->findAll("issueId = {$this->id}") as $comment) {
$comment->delete();
}
foreach (Result::model()->findAll("issueId = {$this->id}") as $result) {
$result->delete();
}
return parent::beforeDelete();
}