diff --git a/application/controllers/admin/index.php b/application/controllers/admin/index.php index 2ab5914bcaf..b949498962d 100644 --- a/application/controllers/admin/index.php +++ b/application/controllers/admin/index.php @@ -71,8 +71,8 @@ public function run() $aData['showLastQuestion'] = false; } - $aData['countSurveyList'] = count((array) getSurveyList(true)); - + $aData['countSurveyList'] = Survey::model()->count(); + // We get the home page display setting $aData['bShowSurveyList'] = (getGlobalSetting('show_survey_list') == "show"); $aData['bShowSurveyListSearch'] = (getGlobalSetting('show_survey_list_search') == "show"); diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index d29e5ed7f12..834df4dd01b 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -106,17 +106,10 @@ function getSurveyList($bReturnArray = false) if (is_null($cached)) { $surveyidresult = Survey::model() ->permission(Yii::app()->user->getId()) + ->with('languagesettings') ->findAll(); foreach ($surveyidresult as $result) { - if (!empty($result->defaultlanguage)) { - $surveynames[] = array_merge($result->attributes, $result->defaultlanguage->attributes); - } elseif (!($bCheckIntegrity)) { - $bCheckIntegrity = true; - Yii::app()->setFlashMessage( - CHtml::link(gT("One or more surveys seem to be broken - please use the data integrity check tool to fix this."), array("admin/checkintegrity")) - , - 'error'); - } + $surveynames[] = array_merge($result->attributes,$result->languagesettings[$result->language]->attributes); } usort($surveynames, function($a, $b) diff --git a/application/models/Survey.php b/application/models/Survey.php index 4c0ce47033c..bed04130dba 100755 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -186,7 +186,7 @@ public function init() $this->template = Template::templateNameFilter(getGlobalSetting('defaulttheme')); $validator = new LSYii_Validators; $this->language = $validator->languageFilter(Yii::app()->getConfig('defaultlang')); - $this->attachEventHandler("onAfterFind", array($this, 'fixSurveyAttribute')); + $this->attachEventHandler("onAfterFind", array($this, 'afterFindSurvey')); } /** @inheritdoc */ @@ -289,15 +289,15 @@ public static function model($class = __CLASS__) public function relations() { return array( - 'permissions' => array(self::HAS_MANY, 'Permission', array('entity_id'=> 'sid'), 'together' => true), // - 'languagesettings' => array(self::HAS_MANY, 'SurveyLanguageSetting', 'surveyls_survey_id', 'index' => 'surveyls_language', 'together' => true), - 'defaultlanguage' => array(self::BELONGS_TO, 'SurveyLanguageSetting', array('language' => 'surveyls_language', 'sid' => 'surveyls_survey_id'), 'together' => true), - 'correct_relation_defaultlanguage' => array(self::HAS_ONE, 'SurveyLanguageSetting', array('surveyls_language' => 'language', 'surveyls_survey_id' => 'sid'), 'together' => true), - 'owner' => array(self::BELONGS_TO, 'User', 'owner_id', 'together' => true), - 'groups' => array(self::HAS_MANY, 'QuestionGroup', 'sid', 'together' => true, 'order'=>'group_order ASC'), + 'permissions' => array(self::HAS_MANY, 'Permission', array('entity_id'=> 'sid')), // + 'languagesettings' => array(self::HAS_MANY, 'SurveyLanguageSetting', 'surveyls_survey_id', 'index' => 'surveyls_language'), + 'defaultlanguage' => array(self::BELONGS_TO, 'SurveyLanguageSetting', array('language' => 'surveyls_language', 'sid' => 'surveyls_survey_id')), + 'correct_relation_defaultlanguage' => array(self::HAS_ONE, 'SurveyLanguageSetting', array('surveyls_language' => 'language', 'surveyls_survey_id' => 'sid')), + 'owner' => array(self::BELONGS_TO, 'User', 'owner_id',), + 'groups' => array(self::HAS_MANY, 'QuestionGroup', 'sid', 'order'=>'group_order ASC'), 'quotas' => array(self::HAS_MANY, 'Quota', 'sid', 'order'=>'name ASC'), 'surveymenus' => array(self::HAS_MANY, 'Surveymenu', array('survey_id' => 'sid')), - 'surveygroup' => array(self::BELONGS_TO, 'SurveysGroups', array('gsid' => 'gsid'), 'together' => true), + 'surveygroup' => array(self::BELONGS_TO, 'SurveysGroups', array('gsid' => 'gsid')), 'templateModel' => array(self::HAS_ONE, 'Template', array('name' => 'template')) ); } @@ -392,16 +392,16 @@ public function rules() /** - * fixSurveyAttribute to fix and/or add some survey attribute + * afterFindSurvey to fix and/or add some survey attribute * - Fix template name to be sure template exist */ - public function fixSurveyAttribute() + public function afterFindSurvey() { - $event = new PluginEvent('afterFindSurvey'); + $event = new PluginEvent('afterFindSurvey'); $event->set('surveyid', $this->sid); App()->getPluginManager()->dispatchEvent($event); // set the attributes we allow to be fixed - $allowedAttributes = array('template', 'usecookie', 'allowprev', + $allowedAttributes = array( 'template', 'usecookie', 'allowprev', 'showxquestions', 'shownoanswer', 'showprogress', 'questionindex', 'usecaptcha', 'showgroupinfo', 'showqnumcode', 'navigationdelay'); foreach ($allowedAttributes as $attribute) { @@ -409,7 +409,6 @@ public function fixSurveyAttribute() $this->{$attribute} = $event->get($attribute); } } - $this->template = Template::templateNameFilter($this->template); } diff --git a/application/models/SurveyLanguageSetting.php b/application/models/SurveyLanguageSetting.php index b682f946191..00479e74e5a 100644 --- a/application/models/SurveyLanguageSetting.php +++ b/application/models/SurveyLanguageSetting.php @@ -123,6 +123,11 @@ public function rules() array('surveyls_numberformat', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true), ); } + + public function defaultScope() + { + return array('index'=>'surveyls_language'); + } /** * Defines the customs validation rule lsdefault