当前位置: 首页>>代码示例>>PHP>>正文


PHP Result::save方法代码示例

本文整理汇总了PHP中Result::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Result::save方法的具体用法?PHP Result::save怎么用?PHP Result::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Result的用法示例。


在下文中一共展示了Result::save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save($id = null)
 {
     if (permission("reports", "extra")) {
         if ($_POST) {
             if (@empty($_POST["import_time"])) {
                 $_POST["import_time"] = date("Y-m-d");
             }
             $data = new Result($id);
             $data->from_array($_POST);
             $data->save();
             if (@$_POST["file_path"]) {
                 $data->file_size = @filesize($data->file_path);
                 $data->save();
             }
             $type = $id ? 'edit' : 'add';
             // for logs.
             save_logs($type, $data->id);
         }
     }
     redirect("admin/reports");
 }
开发者ID:ultraauchz,项目名称:asean_cultural_mapping,代码行数:21,代码来源:reports.php

示例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");
     }
 }
开发者ID:Romandre90,项目名称:vectortraveler,代码行数:65,代码来源:StepController+-+Copy.php

示例3: EvalForm

    $select_eval_edit = Security::remove_XSS($_GET['selecteval']);
    $resultedit = Result::load($edit_res_xml);
    $edit_res_form = new EvalForm(EvalForm::TYPE_RESULT_EDIT, $eval[0], $resultedit[0], 'edit_result_form', null, api_get_self() . '?editres=' . $resultedit[0]->get_id() . '&selecteval=' . $select_eval_edit . '&' . api_get_cidreq());
    if ($edit_res_form->validate()) {
        $values = $edit_res_form->exportValues();
        $result = new Result();
        $resultlog = new Result();
        $resultlog->add_result__log($values['hid_user_id'], $select_eval_edit);
        $result->set_id($edit_res_xml);
        $result->set_user_id($values['hid_user_id']);
        $result->set_evaluation_id($select_eval_edit);
        $row_value = isset($values['score']) ? (double) $values['score'] : 0;
        if (!empty($row_value) || $row_value == 0) {
            $result->set_score(floatval(number_format($row_value, api_get_setting('gradebook_number_decimals'))));
        }
        $result->save();
        unset($result);
        header('Location: gradebook_view_result.php?selecteval=' . $select_eval_edit . '&editresmessage=&' . api_get_cidreq());
        exit;
    }
}
$file_type = null;
if (isset($_GET['import'])) {
    $interbreadcrumb[] = array('url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&' . api_get_cidreq(), 'name' => get_lang('ViewResult'));
    $import_result_form = new DataForm(DataForm::TYPE_IMPORT, 'import_result_form', null, api_get_self() . '?import=&selecteval=' . Security::remove_XSS($_GET['selecteval']), '_blank', '');
    if (!$import_result_form->validate()) {
        Display::display_header(get_lang('Import'));
    }
    $eval[0]->check_lock_permissions();
    if ($_POST['formSent']) {
        if (!empty($_FILES['import_file']['name'])) {
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:31,代码来源:gradebook_view_result.php

示例4: actionUpdate

 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     //this parameter is the issueId!
     Result::model()->cleanRecords();
     //clean old remaining records
     $this->layout = "//layouts/column1";
     $issue = $this->loadIssue($id);
     $redirect = false;
     $issueId = $id;
     //checking if the document is already opened
     $opened = Opendocs::model()->find("issueId={$issueId}");
     //if there has been any
     if (isset($_POST['Result']) or isset($_POST['Checks']) or isset($_POST['Table']) or isset($_POST['File'])) {
         $redirect = true;
         //true means it is actually saving a document. False means is opening the update view
     }
     if (isset($opened)) {
         //the issue has a record in open docs
         $now = time();
         $morethanyesterday = strtotime($opened->createTime);
         $morethanyesterday = $morethanyesterday + 86400;
         if ($now < $morethanyesterday) {
             //less than 24h
             $user = User::model()->findByPk($opened->userId);
             if ($opened->userId == Yii::app()->user->id) {
                 //actual user is the issue's owner
                 if ($redirect) {
                     // the user is on the update view already and has clicked "save" button
                     //saving process:
                     if (isset($_POST['Result'])) {
                         //Result::model()->reset($id);//RESET
                         $redirect = true;
                         $post = $_POST['Result'];
                         if (isset($post['elementid'])) {
                             $elementId = $post['elementid'];
                             foreach ($elementId as $key => $value) {
                                 //if ($value != '') {
                                 if (is_array($value)) {
                                     foreach ($value as $option) {
                                         $model = new Result();
                                         $model->elementId = $key;
                                         $model->issueId = $issueId;
                                         if ($model->value != $option) {
                                             $model->value = $option;
                                             $model->save();
                                         }
                                     }
                                 } else {
                                     $model = Result::model()->find("elementId = {$key} and issueId = {$issueId}");
                                     if ($model === null) {
                                         $model = new Result();
                                         $model->elementId = $key;
                                         $model->issueId = $issueId;
                                     }
                                     if ($model->value != $value) {
                                         $model->value = $value;
                                         $model->save();
                                     }
                                 }
                                 //}
                             }
                         }
                     }
                     if (isset($_POST['Checks'])) {
                         //For Checkboxes: once one is selected there must be at least one checked option. It's impossible to uncheck all of them.
                         // that's the way is supposed to be. Keep track record.
                         $redirect = true;
                         $typeId = 6;
                         $post = $_POST['Checks'];
                         $values = array();
                         if (isset($post['elementid'])) {
                             $elementId = $post['elementid'];
                             foreach ($elementId as $key => $value) {
                                 if (is_array($value)) {
                                     foreach ($value as $option) {
                                         $values[] = $option;
                                         $model = new Result();
                                         $model->elementId = $key;
                                         $model->issueId = $issueId;
                                         if (in_array($option, $value)) {
                                             $what = Element::doesExist($key, $issueId, $option);
                                             if ($what < 1) {
                                                 $model->value = $option;
                                                 $model->save();
                                             }
                                         }
                                     }
                                 }
                                 $statement = " ";
                                 foreach ($values as $cond) {
                                     $statement .= " and t.value NOT like '{$cond}'";
                                 }
                                 $statement = "issueId= {$issueId} and elementId = {$key} " . $statement;
                                 $criteria = new CDbCriteria();
                                 $criteria->condition = $statement;
//.........这里部分代码省略.........
开发者ID:Romandre90,项目名称:vectortraveler,代码行数:101,代码来源:ResultController.php

示例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()));
         }
     }
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:77,代码来源:PollController.php

示例6: get_result

 public function get_result()
 {
     require_once "application/libraries/simple_html_dom.php";
     ini_set('error_reporting', E_ALL);
     ini_set('display_errors', 1);
     ini_set("allow_url_fopen", TRUE);
     $html = new Simple_HTML_DOM($this->result_list);
     if (empty($html)) {
         echo "ไม่สามารถดึงข้อมูลได้";
     } else {
         $num = count($html->find("table[width=500] tbody tr td a"));
         $x = 3;
         for ($i = 0; $i < $num; $i++) {
             $result_type_id = 0;
             //	set default
             $links = iconv("tis-620", "utf-8", $html->find("table[width=500] tbody tr td a", $i)->href);
             $file_name = str_replace("Data/", "", $links);
             if (stripos(trim(iconv("tis-620", "utf-8", $html->find("table[width=500] tbody tr td a", $i)->plaintext)), "สัปดาห์")) {
                 $result_type_id = 1;
             }
             if (stripos(trim(iconv("tis-620", "utf-8", $html->find("table[width=500] tbody tr td a", $i)->plaintext)), "เดือน")) {
                 $result_type_id = 2;
             }
             if (!file_exists("uploads/results/" . $file_name)) {
                 if (!file_exists("uploads/results")) {
                     $maskdir = @umask(0);
                     @mkdir("uploads/results", 0777);
                     @umask($maskdir);
                 }
                 $data = @file_get_contents("http://164.115.100.119/rpt_m/" . $links);
                 @file_put_contents("uploads/results/" . $file_name, $data);
                 $title = trim(iconv("tis-620", "utf-8", $html->find("table[width=500] tbody tr td a", $i)->plaintext));
                 $date = @trim(iconv("tis-620", "utf-8", $html->find("table[width=500] tbody tr", $x)->children(2)->plaintext));
                 $date .= " " . @trim(iconv("tis-620", "utf-8", $html->find("table[width=500] tbody tr", $x)->children(2)->next_sibling()->plaintext));
                 $foo = new Result();
                 $foo->title = $title . " (กส.9)";
                 $foo->result_type_id = $result_type_id;
                 $foo->deposits = 2;
                 $foo->file_path = "uploads/results/{$file_name}";
                 $foo->import_time = $date;
                 $foo->show_date = $date;
                 $foo->file_size = filesize($foo->file_path);
                 $foo->save();
             }
             $x++;
         }
     }
 }
开发者ID:ultraauchz,项目名称:asean_cultural_mapping,代码行数:48,代码来源:reports.php

示例7: array

 static function transaction_33($original_data, $web_service_details)
 {
     global $data_list;
     $data = Migration::soap_call($web_service_details, 'notaDetalles', array('uididpersona' => $original_data['item_id'], 'uididprograma' => $original_data['orig_id'], 'intIdSede' => $original_data['branch_id']));
     if ($data['error'] == false) {
         $uidIdPrograma = $original_data['orig_id'];
         $uidIdPersona = $original_data['item_id'];
         $score = $data['name'];
         $session_id = self::get_session_id_by_programa_id($uidIdPrograma, $data_list);
         $user_id = self::get_user_id_by_persona_id($uidIdPersona, $data_list);
         if (empty($user_id)) {
             return array('message' => "User does not exists in DB: {$uidIdPersona}", 'status_id' => self::TRANSACTION_STATUS_FAILED);
         }
         if (empty($session_id)) {
             return array('message' => "Session does not exists in DB: {$uidIdPrograma}", 'status_id' => self::TRANSACTION_STATUS_FAILED);
         }
         $course_list = SessionManager::get_course_list_by_session_id($session_id);
         if (!empty($course_list)) {
             $course_data = current($course_list);
             if (isset($course_data['code'])) {
                 $gradebook = new Gradebook();
                 $gradebook = $gradebook->get_first(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id))));
                 error_log("Looking gradebook in course code:  {$course_data['code']} - session_id: {$session_id}");
                 if (!empty($gradebook)) {
                     //Check if gradebook exists
                     $eval = new Evaluation();
                     $evals_found = $eval->load(null, null, null, $gradebook['id'], null, null);
                     //Try to create a gradebook evaluation
                     if (empty($evals_found)) {
                         error_log("Trying to create a new evaluation in course code:  {$course_data['code']} - session_id: {$session_id}");
                         $params = array('session_id' => $session_id, 'gradebook_description' => 'Evaluación General', 'gradebook_evaluation_type_id' => 0);
                         self::create_gradebook_evaluation($params);
                         $evals_found = $eval->load(null, null, null, $gradebook['id'], null, null);
                     }
                     if (!empty($evals_found)) {
                         $evaluation = current($evals_found);
                         $eval_id = $evaluation->get_id();
                         error_log("Gradebook exists: {$gradebook['id']} eval_id: {$eval_id}");
                         //Eval found
                         $res = new Result();
                         $check_result = Result::load(null, $user_id, $eval_id);
                         if (!empty($check_result) && isset($check_result[0])) {
                             // Gradebook result found. Updating...
                             $res->set_evaluation_id($eval_id);
                             $res->set_user_id($user_id);
                             $res->set_score($score);
                             $res->set_id($check_result[0]->get_id());
                             $res->save();
                             $eval_result = Result::load(null, $user_id, $eval_id);
                             return array('entity' => 'gradebook_evaluation_result', 'before' => $check_result, 'after' => $eval_result, 'message' => "Gradebook result edited ", 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL);
                         } else {
                             // Gradebook result not found. Creating...
                             // @todo disable when moving to production
                             $res->set_evaluation_id($eval_id);
                             $res->set_user_id($user_id);
                             //if no scores are given, don't set the score
                             $res->set_score($score);
                             $res->add();
                             $eval_result = Result::load(null, $user_id, $eval_id);
                             //$message = "Gradebook result not modified because gradebook result does not exist for user_id: $user_id - eval_id: $eval_id - gradebook_id: {$gradebook['id']} - course: {$course_data['code']} - session_id: $session_id";
                             return array('entity' => 'gradebook_evaluation_result', 'before' => null, 'after' => $eval_result, 'message' => "Gradebook result added because it did not exist for update", 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL);
                         }
                     } else {
                         $message = "Evaluation not found in gradebook: {$gradebook['id']} : in course: {$course_data['code']} - session_id: {$session_id}";
                     }
                 } else {
                     $message = "Gradebook does not exists in course: {$course_data['code']} - session_id: {$session_id}";
                 }
             } else {
                 $message = "Something is wrong with the course ";
             }
         } else {
             $message = "NO course found for session id: {$session_id}";
         }
         return array('message' => $message, 'status_id' => self::TRANSACTION_STATUS_FAILED);
     } else {
         return $data;
     }
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:79,代码来源:migration.custom.class.php

示例8: 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");
     }
 }
开发者ID:Romandre90,项目名称:vectortraveler,代码行数:58,代码来源:StepControllerQUEPASA.php

示例9: add_result

 public function add_result()
 {
     $requirements = ['exp_id', 'user_id', 'data'];
     $check = self::check_requirements($requirements);
     if ($check) {
         return Error::make(0, 100, $check);
     }
     $experiment = Experiment::where('exp_id', '=', Input::get('exp_id'))->first();
     if (is_null($experiment)) {
         return Error::make(1, 10);
     }
     $user = User::where('user_id', '=', Input::get('user_id'))->first();
     if (is_null($user)) {
         return Error::make(1, 1);
     }
     if (Input::has('result_id')) {
         $res = Result::where('result_id', '=', Input::get('result_id'))->first();
         if (intval(Input::get('exp_id')) != intval($res->exp_id)) {
             return Error::make(1, 11);
         }
         if (intval(Input::get('user_id')) != intval($res->user_id)) {
             return Error::make(1, 12);
         }
     }
     $columns = json_decode($experiment->specifications, true)["columns"];
     $results = json_decode(Input::get('data'), true);
     foreach ($results as $reading) {
         foreach ($columns as $column) {
             if (array_key_exists($column["title"], $reading)) {
                 if (!is_null($column["subcolumns"]) && sizeof($column["subcolumns"]) > 0) {
                     foreach ($column["subcolumns"] as $subcolumn) {
                         if (!array_key_exists($subcolumn["title"], $reading[$column["title"]])) {
                             return Error::make(101, 101, "Column " . $column["title"] . " has missing subcolumn " . $subcolumn["title"]);
                         }
                     }
                 }
             } else {
                 return Error::make(101, 101, "Missing column " . $column["title"]);
             }
         }
     }
     if (Input::has('result_id')) {
         try {
             Result::where('result_id', '=', intval(Input::get('result_id')))->update(array('data' => json_encode($results)));
             return Error::success("Results successfully updated", array('result_id' => intval(Input::get('result_id'))));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     } else {
         $res = new Result();
         $res->data = json_encode($results);
         $res->user_id = intval(Input::get('user_id'));
         $res->exp_id = intval(Input::get('exp_id'));
         try {
             $res->save();
             return Error::success("Result successfully added!", array('result_id' => $res->id));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     }
 }
开发者ID:martiansideofthemoon,项目名称:Labman-Server,代码行数:61,代码来源:HomeController.php

示例10: submitExam

 public function submitExam($id)
 {
     $questions = $this->getExamData($id);
     $marks = 0;
     for ($i = 0; $i <= $questions['size']; $i = $i + 2) {
         if (trim(Input::get('opt' . $i)) === trim($questions['opt' . $i][4])) {
             $marks = $marks + 2;
         }
     }
     $result = new Result();
     $result->marks = $marks;
     $result->studentloginid = Session::get('user')->id;
     $result->examdate = date(1);
     $result->examid = $id;
     $result->attempt = 1;
     if ($result->save()) {
         return 'your marks are ' . $marks;
     } else {
         return 'try again';
     }
 }
开发者ID:pankaja455,项目名称:WebSchool,代码行数:21,代码来源:AdminController.php

示例11: actionUpdate

 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     //$id corresponds to issueID NOT TO id!!!!!!!!!!!!
     $keys = Result::model()->encontrarPorId($id);
     $todos = implode(" , ", $keys);
     //$keysCont=0;
     //Result::model()->encontrarPorId($id);
     $this->layout = "//layouts/column1";
     $issue = $this->loadIssue($id);
     $redirect = false;
     $issueId = $id;
     //checking if the document is already opened
     $opened = Opendocs::model()->find("issueId={$issueId}");
     if (isset($_POST['Result'])) {
         //Result::model()->reset($id);//RESET
         $redirect = true;
         $post = $_POST['Result'];
         if (isset($post['elementid'])) {
             $elementId = $post['elementid'];
             foreach ($elementId as $key => $value) {
                 //if ($value != '') {
                 if (is_array($value)) {
                     foreach ($value as $option) {
                         $model = new Result();
                         $model->elementId = $key;
                         $model->issueId = $issueId;
                         if ($model->value != $option) {
                             $model->value = $option;
                             $model->save();
                         }
                     }
                 } else {
                     $model = Result::model()->find("elementId = {$key} and issueId = {$issueId}");
                     if ($model === null) {
                         $model = new Result();
                         $model->elementId = $key;
                         $model->issueId = $issueId;
                     }
                     if ($model->value != $value) {
                         $model->value = $value;
                         $model->save();
                     }
                 }
                 //}
             }
         }
     }
     if (isset($_POST['Checks'])) {
         //Result::model()->resetBox($id);//RESET
         $redirect = true;
         $typeId = 6;
         $post = $_POST['Checks'];
         $values = array();
         if (isset($post['elementid'])) {
             $elementId = $post['elementid'];
             foreach ($elementId as $key => $value) {
                 if (is_array($value)) {
                     foreach ($value as $option) {
                         $values[] = $option;
                         $model = new Result();
                         $model->elementId = $key;
                         $model->issueId = $issueId;
                         if (in_array($option, $value)) {
                             $what = Element::doesExist($key, $issueId, $option);
                             if ($what < 1) {
                                 $model->value = $option;
                                 $model->save();
                             }
                         }
                     }
                 }
                 $statement = " ";
                 foreach ($values as $cond) {
                     $statement .= " and t.value NOT like '{$cond}'";
                 }
                 $statement = "issueId= {$issueId} and elementId = {$key} " . $statement;
                 $criteria = new CDbCriteria();
                 $criteria->condition = $statement;
                 //"issueId = $issueId and elementId = $key and value NOT LIKE ('$values')";
                 $modelo = Result::model()->findAll($criteria);
                 foreach ($modelo as $borrar) {
                     $borrar->delete();
                 }
             }
         }
     }
     if (isset($_POST['Table'])) {
         //Result::model()->resetTable($id);
         //Result::model()->setTableOFF($id);
         $redirect = true;
         $tables = $_POST['Table'];
         foreach ($tables as $key => $value) {
             $elementId = $key;
             foreach ($value as $row => $array) {
                 foreach ($array as $column => $response) {
//.........这里部分代码省略.........
开发者ID:Romandre90,项目名称:vectortraveler,代码行数:101,代码来源:ResultController+-+Copy.php

示例12: storeAction

 /**
  * Store the answer
  *
  * @return mixed
  */
 public function storeAction()
 {
     $token = $this->getToken();
     if (!$token) {
         return Redirect::route('info')->with('message', 'Токен не найден');
     }
     if ($token->status != Token::TOKEN_STATUS_STARTED) {
         return Redirect::route('token.index', ['token' => $token->token]);
     }
     if (!$this->isTokenValid($token)) {
         Session::forget('token_string');
         $token->status = Token::TOKEN_STATUS_EXPIRED;
         $token->save();
         return Redirect::route('info')->with('message', 'Время теста истекло, ответ не засчитан');
     }
     $questionId = Session::get('question_id', false);
     $testAnswers = Session::get('test_answers', []);
     if (!$questionId || !is_numeric($questionId)) {
         return Redirect::route('info')->with('message', 'Ошибка данных сессии.');
     }
     $question = Question::find((int) $questionId);
     if (!$question) {
         return Redirect::route('info')->with('message', 'Ошибка данных сессии. Вопрос не найден.');
     }
     $data = Input::all();
     $result = new Result();
     $result->token = $token->token;
     $result->test_id = $token->test->id;
     $result->question_id = (int) $questionId;
     $result->q_text = $question->text;
     $result->q_image = $question->image;
     /**
      * Process the answer depending on question type
      */
     switch ($question->type) {
         case Question::TYPE_RADIO:
             if (!isset($data['answer']) || !$data['answer']) {
                 return Redirect::route('info')->with('message', 'Ожидается ответ.');
             }
             foreach ($testAnswers as $id => $hash) {
                 if ($hash == $data['answer']) {
                     $answer = Answer::find($id);
                 }
             }
             if (!$answer) {
                 return Redirect::route('info')->with('message', 'Такой ответ не найден.');
             }
             $result->a_text = $answer->text;
             $result->a_image = $answer->image;
             $result->is_correct = $answer->is_correct;
             $result->weight = $answer->weight;
             break;
         case Question::TYPE_CHECKBOX:
             $answer = isset($data['answer']) ? $data['answer'] : [];
             // has to be an array
             if (!is_array($answer)) {
                 return Redirect::route('info')->with('message', 'Ответ должен быть массивом.');
             }
             $answer_ = $answer;
             // we need to find real answer ids
             $answer = [];
             foreach ($testAnswers as $id => $hash) {
                 foreach ($answer_ as $a_) {
                     if ($hash == $a_) {
                         $answer[] = Answer::find($id)->id;
                     }
                 }
             }
             if (!empty($answer)) {
                 $answers = DB::table('answer')->whereIn('id', $answer)->get();
             } else {
                 $answers = [];
             }
             $isThereACorrectAnswer = false;
             $correctNum = 0;
             // Is there at least one correct answer?
             foreach ($question->answers as $ans) {
                 if ($ans->is_correct) {
                     $isThereACorrectAnswer = true;
                     $correctNum++;
                 }
             }
             $result->a_text = '';
             if (!$isThereACorrectAnswer && count($answers) > 0) {
                 // There are no correct answers, but user have chosen something
                 $result->is_correct = false;
             } elseif (!$isThereACorrectAnswer && count($answers) == 0) {
                 $result->is_correct = true;
             } elseif ($isThereACorrectAnswer && count($answers) == 0) {
                 $result->is_correct = false;
             } elseif ($isThereACorrectAnswer && count($answers) > 0 && count($answers) != $correctNum) {
                 $result->is_correct = false;
             } elseif ($isThereACorrectAnswer && count($answers) > 0 && count($answers) == $correctNum) {
                 // check if all correct answers selected
                 $result->is_correct = true;
//.........这里部分代码省略.........
开发者ID:himor,项目名称:testing,代码行数:101,代码来源:TestController.php


注:本文中的Result::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。