Exemplo n.º 1
0
		<?php 
$data = CompetitionQuestionCategory::model()->GetCompetitionCategoryNameIdList();
echo CHtml::activeDropDownList($model, 'competition_category_id', CHtml::listData($data, 'id', 'name'), array('empty' => Yii::t('app', 'choose')));
?>
                <?php 
echo $form->error($model, 'competition_category_id');
?>
 
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'competiton_question_difficulty_id');
?>
		<?php 
$data = CompetitionQuestionCategory::model()->GetCompetitionQuestionDifficultyNameIdList();
echo CHtml::activeDropDownList($model, 'competiton_question_difficulty_id', CHtml::listData($data, 'id', 'name'), array('empty' => Yii::t('app', 'choose')));
?>
                <?php 
echo $form->error($model, 'competiton_question_difficulty_id');
?>
 
	</div>

	<div class="row buttons">
        <br /><?php 
$this->widget('zii.widgets.jui.CJuiButton', array('name' => 'button', 'caption' => Yii::t('app', 'search'), 'value' => Yii::t('app', 'search')));
?>
	</div>

<?php 
Exemplo n.º 2
0
 public function importCompetitiors($competition_id, $competition_category_id, $content)
 {
     $lines = explode("\n", $content);
     $header = explode(';', $lines[0]);
     $competition_questions = CompetitionQuestionCategory::model()->with('competitionQuestion')->with('competitionQuestion.question')->findAll('competition_category_id=:competition_category_id and competitionQuestion.competition_id=:competition_id', array(':competition_category_id' => $competition_category_id, ':competition_id' => $competition_id));
     $questions_to_import = array();
     foreach ($competition_questions as $cq) {
         if ($cq == null) {
             $cq = new CompetitionQuestionCategory();
         }
         $questions_to_import[trim($cq->competitionQuestion->question->title)] = $cq->competition_question_id;
     }
     echo 'Question to import:<br />';
     pre_print($questions_to_import);
     // map fields
     $colQuestionMap = array();
     $found_c = array();
     for ($i = 0; $i < count($header); ++$i) {
         $col = explode('(', $header[$i]);
         $c = trim($col[0]);
         if (isset($questions_to_import[$c])) {
             $colQuestionMap[$i] = $questions_to_import[$c];
             $found_c[] = $c;
         }
     }
     if (count($colQuestionMap) != count($questions_to_import)) {
         echo 'Question to import and question in CSV does not match!';
         echo 'Question to import:<br />';
         pre_print($questions_to_import);
         echo 'Found questions: <br />';
         pre_print($found_c);
         echo 'CSV header line cols: <br />';
         pre_print($header);
         echo 'Question column mapping found:<br />';
         pre_print($colQuestionMap);
         die;
     } else {
         echo 'Question column exist, we can start importing.<br />';
     }
     // check for required columns
     $required_fields = array('Priimek' => -1, 'Ime' => -1, 'Mentor' => -1, 'Šola' => -1, 'Spol' => -1, 'Razred' => -1);
     $required_keys = array_keys($required_fields);
     // not required fields
     $required_fields['ID1'] = -1;
     $required_fields['ID2'] = -1;
     $required_keys2 = array_keys($required_fields);
     for ($i = 0; $i < count($header); ++$i) {
         if (in_array(trim($header[$i]), $required_keys2)) {
             $required_fields[trim($header[$i])] = $i;
         }
     }
     $missing_fields = array();
     for ($i = 0; $i < count($required_keys); ++$i) {
         if ($required_fields[$required_keys[$i]] == -1) {
             $missing_fields[] = $required_keys[$i];
         }
     }
     if (count($missing_fields) > 0) {
         echo 'Some required fields are missing:<br />';
         pre_print($missing_fields);
         die;
     }
     $competition = Competition::model()->findByPk($competition_id);
     if ($competition == null) {
         echo 'Provided Competition does not exist!';
         die;
     }
     $competitionCategory = CompetitionCategory::model()->findByPk($competition_category_id);
     if ($competitionCategory == null) {
         echo 'Provided Competition Category does not exist!';
         die;
     }
     for ($i = 1; $i < count($lines); ++$i) {
         if (trim($lines[$i]) == '') {
             continue;
         }
         $cols = explode(';', $lines[$i]);
         $cu = new CompetitionUser();
         $cu->competition_category_id = $competition_category_id;
         $cu->competition_id = $competition_id;
         $cu->first_name = $cols[$required_fields['Ime']];
         $cu->last_name = $cols[$required_fields['Priimek']];
         $cu->gender = $cols[$required_fields['Spol']] == 'M' ? 0 : 1;
         $cu->class = $cols[$required_fields['Razred']];
         $sc = School::model()->find('name=:name', array(':name' => trim($cols[$required_fields['Šola']])));
         if ($sc == null) {
             echo 'Provided school not found in database! School name: ', $cols[$required_fields['Šola']], '<br />';
             die;
         }
         $cu->school_id = $sc->id;
         $scm = SchoolMentor::model()->with('user.profile')->find('school_id=:school_id and CONCAT_WS(\' \', `profile`.`last_name`, `profile`.`first_name`) LIKE :mentor', array(':school_id' => $sc->id, ':mentor' => trim($cols[$required_fields['Mentor']])));
         if ($scm == null) {
             echo 'Provided school mentor not found in database! School name: ', $cols[$required_fields['Šola']], ', School mentor: ', $cols[$required_fields['Mentor']], '<br />';
             die;
         }
         // ali je šola prijavljena na tekmovanje za to kategorijo
         $ccs = CompetitionCategorySchool::model()->find('competition_id=:competition_id and competition_category_id=:competition_category_id and school_id=:school_id', array(':competition_id' => $competition_id, ':competition_category_id' => $competition_category_id, ':school_id' => $sc->id));
         if ($ccs == null) {
             echo 'Provided school is not competing in this category! School name: ', $cols[$required_fields['Šola']], ', Competition: ', $competition->name, ', Competition category: ', $competitionCategory->name, '<br />';
             die;
         }
         // ali je mentor prijavljen na tej šoli za to tekmovalno kategorijo
         $ccsm = CompetitionCategorySchoolMentor::model()->find('competition_category_school_id=:competition_category_school_id and user_id=:user_id', array(':competition_category_school_id' => $ccs->id, ':user_id' => $scm->user_id));
         if ($ccsm == null) {
             echo 'Provided mentor is not competing on this school on this competition in this category! School mentor: ', $cols[$required_fields['Mentor']], ', School name: ', $cols[$required_fields['Šola']], ', Competition: ', $competition->name, ', Competition category: ', $competitionCategory->name, '<br />';
             die;
         }
         $cu->competition_category_school_mentor_id = $ccsm->id;
         $cu->start_time = null;
         $cu->finish_time = null;
         $cu->finished = 2;
         if (isset($cols[$required_fields['ID1']])) {
             $cut = CompetitionUser::model()->findByPk($cols[$required_fields['ID1']]);
             if ($cut != null) {
                 if ($cut == null) {
                     $cut = new CompetitionUser();
                 }
                 $cu->start_time = $cut->start_time;
                 $cu->finish_time = $cut->finish_time;
                 $cut->disqualified_reason = 'Prenos v pravilno kategorijo tekmovanja';
                 $cut->disqualified_request = 1;
                 $cut->disqualified = 1;
                 $cut->save();
             }
         }
         if (isset($cols[$required_fields['ID2']])) {
             $cut = CompetitionUser::model()->findByPk($cols[$required_fields['ID2']]);
             if ($cut != null) {
                 if ($cut == null) {
                     $cut = new CompetitionUser();
                 }
                 if ($cu->start_time == null) {
                     $cu->start_time = $cut->start_time;
                     $cu->finish_time = $cut->finish_time;
                 } else {
                     $time_diff1 = strtotime($cu->finish_time) - strtotime($cu->start_time);
                     $time_diff2 = strtotime($cut->finish_time) - strtotime($cut->start_time);
                     if ($time_diff2 > $time_diff1) {
                         $cu->start_time = $cut->start_time;
                         $cu->finish_time = $cut->finish_time;
                     }
                 }
                 $cut->disqualified_reason = 'Prenos v pravilno kategorijo tekmovanja';
                 $cut->disqualified_request = 1;
                 $cut->disqualified = 1;
                 $cut->save();
             }
         }
         // ali tekmovalec s temi podatki že obstaja
         $cuc = CompetitionUser::model()->find('competition_id=:competition_id and competition_category_id=:competition_category_id and competition_category_school_mentor_id=:competition_category_school_mentor_id and school_id=:school_id and first_name=:first_name and last_name=:last_name and gender=:gender and class=:class', array(':competition_id' => $competition_id, ':competition_category_id' => $competition_category_id, ':competition_category_school_mentor_id' => $cu->competition_category_school_mentor_id, ':school_id' => $cu->school_id, ':last_name' => $cu->last_name, ':first_name' => $cu->first_name, ':gender' => $cu->gender, ':class' => $cu->class));
         if ($cuc != null) {
             echo 'Competition User already exists, skipping...';
             continue;
         }
         $cu->save();
         // import answers
         $question_keys = array_keys($colQuestionMap);
         for ($k = 0; $k < count($question_keys); ++$k) {
             $cuq = new CompetitionUserQuestion();
             $cuq->competition_user_id = $cu->id;
             $cuq->competition_question_id = $colQuestionMap[$question_keys[$k]];
             $cuq->ordering = $k + 1;
             $cuq->random_seed = number_format(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax(), 9, '.', '');
             $cuq->last_change = $cu->finish_time;
             $custom_answer_ex = explode('|', $cols[$question_keys[$k]]);
             $custom_answer = trim($custom_answer_ex[0]);
             $cuq->custom_answer = $custom_answer;
             $cuq->save();
         }
         echo 'Successfully imported user with ID: ', $cu->id, '<br />';
     }
 }
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = CompetitionQuestionCategory::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $model;
 }