public static function getInstance($type, SurveyPurposeQuestion $model = null)
 {
     $instance = new $type();
     if ($model) {
         $instance->attributes = $model->getAttributes();
         $instance->id = $model->id;
         $instance->isNewRecord = false;
     }
     return $instance;
 }
 public static function getQuestions($blockId)
 {
     $criteria = new CDbCriteria();
     $relationTableName = QuestionsBlockQuestion::model()->tableName();
     $criteria->addCondition("id NOT IN (SELECT DISTINCT questionId FROM {$relationTableName} WHERE questionBlockId = :blockId)");
     $criteria->params = array(':blockId' => $blockId);
     return CHtml::listData(SurveyPurposeQuestion::model()->findAll($criteria), 'id', 'title');
 }
 /**
  * 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 SurveyPurposeQuestion the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SurveyPurposeQuestion::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 protected function getParamsToRender()
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'sortOrder ASC';
     return array_merge(parent::getParamsToRender(), array('questions' => SurveyPurposeQuestion::model()->findAllByPk($this->questions, $criteria)));
 }
 public function rules()
 {
     // NOTE: you should only define rules for those attributes that
     // will receive user inputs.
     return array_merge(array(array('serializedAxis', 'required')), parent::rules());
 }
 public function getParamsForCalculation()
 {
     $questionIds = array();
     foreach ((array) $this->steps[4]->questions as $questionId) {
         if (!in_array(intval($questionId), (array) $this->steps[4]->deletedQuestions)) {
             $questionIds[] = intval($questionId);
         }
     }
     $questionsCountEx = 0;
     if (count($questionIds) > 0) {
         $criteria = new CDbCriteria();
         $criteria->addInCondition('id', $questionIds);
         $questions = SurveyPurposeQuestion::model()->findAll($criteria);
         foreach ($questions as $question) {
             switch ($question->type) {
                 case 'SurveyPurposeQuestionArray':
                 case 'SurveyPurposeQuestionGraduation5':
                 case 'SurveyPurposeQuestionGraduation10':
                     $questionsCountEx += count($question->getRows()) / 2;
                     break;
                 case 'SurveyPurposeQuestionListMultySelelection':
                     $questionsCountEx += 1.35;
                     break;
                 default:
                     $questionsCountEx++;
             }
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $this->steps[0]->purposes);
     $purposes = SurveyPurpose::model()->findAll($criteria);
     $surveysCount = 1;
     $methodsByPurposes = array();
     foreach ($purposes as $purpose) {
         /**
          * @var $purpose SurveyPurpose
          */
         $surveysCount *= $purpose->surveysCount;
         $serviceId = $purpose->serviceId;
         if ($serviceId) {
             if (isset($methodsByPurposes[$serviceId])) {
                 $methodsByPurposes[$serviceId] = max($purpose->serviceRatio, $methodsByPurposes[$serviceId]);
             } else {
                 $methodsByPurposes[$serviceId] = $purpose->serviceRatio;
             }
             $methodsByPurposes[$serviceId] = max(0, $methodsByPurposes[$serviceId]);
         }
     }
     $separatedRegions = count($this->steps[1]->regions) > 0 ? $this->steps[1]->regions : array();
     //        print_r($this->steps[ 4 ]);
     //        die;
     return array(static::PARAM_SEPARATED_REGIONS => $separatedRegions, static::PARAM_SEPARATED_REGIONS_COUNT => count($separatedRegions) > 0 ? count($separatedRegions) : 1, static::PARAM_QUESTIONS_COUNT => count($this->steps[4]->questions), static::PARAM_QUESTIONS_COUNT_EX => $questionsCountEx, static::PARAM_INVESTIGATIONS_COUNT => $this->steps[3]->minimalSelectionOfInvestigation, static::PARAM_NEED_COMPARE => $this->steps[2]->compareWithAnotherOrganizationsYesRussian || $this->steps[2]->compareWithAnotherOrganizationsYesEuropean || $this->steps[2]->compareWithAnotherOrganizationsYesWorld, static::PARAM_IS_BRAND_IN_TOP10 => $this->steps[1]->isBrandInTop10 == 'yes', static::PARAM_SURVEYS_COUNT => $surveysCount, static::PARAM_PURPOSES_COLLECTION_METHODS => $methodsByPurposes);
 }