public static function getAvailableParents(SurveyPurpose $forPurpose = null) { $purposes = array('' => 'Корневой элемент'); $condition = ''; if ($forPurpose && $forPurpose->id) { $exclusiveIds = array($forPurpose->id); $exclusiveIds = array_merge($exclusiveIds, static::getChildrenIds($forPurpose)); if (!empty($exclusiveIds)) { $condition = 'id NOT IN (' . implode(',', $exclusiveIds) . ')'; } } foreach (SurveyPurpose::model()->findAll($condition) as $purpose) { $purposes[$purpose->id] = $purpose->title; } return $purposes; }
public static function getAvailablePurposes() { return CHtml::listData(SurveyPurpose::model()->findAll(array('order' => 'title')), 'id', 'title'); }
protected function getParamsToRender() { return array_merge(parent::getParamsToRender(), array('rootPurposes' => SurveyPurpose::model()->findAll("parentId IS NULL"))); }
/** * 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 SurveyPurpose the loaded model * @throws CHttpException */ public function loadModel($id) { $model = SurveyPurpose::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
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); }