From 03368b83ddd98f95e041e2153eb4c2787182ef22 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 24 Sep 2015 10:35:07 +0200 Subject: [PATCH] Dev code clean up and moving components to a namespace. --- protected/components/AuthManager.php | 75 ++++++--- protected/components/Batch.php | 36 +++-- protected/components/DeferredValue.php | 14 +- protected/components/LocalizedFormatter.php | 27 +++- protected/components/MemoryValidator.php | 77 ++++----- protected/components/MigrationManager.php | 139 ++++++++-------- protected/components/PhpConfigFile.php | 36 +++-- protected/components/PluginIdentity.php | 40 +++-- protected/components/QuestionAnswer.php | 2 + .../components/QuestionResponseField.php | 59 ++++--- .../components/QuestionValidationResult.php | 32 ++-- .../QuestionValidationResultCollection.php | 27 ++-- protected/components/RenderedQuestion.php | 61 ++++--- protected/components/Renderer.php | 8 +- protected/components/ResponseField.php | 19 ++- protected/components/SubQuestion.php | 3 + protected/components/SurveyRenderer.php | 8 + protected/components/SurveySession.php | 153 ++++++++++++------ protected/components/SurveySessionManager.php | 32 ++-- protected/components/UuidDefaultValidator.php | 9 +- protected/components/VersionValidator.php | 63 ++++---- protected/components/WebUser.php | 92 ++++++----- protected/components/WritableValidator.php | 28 ++-- protected/config/internal.php | 44 ++--- protected/controllers/AdminController.php | 7 +- .../controllers/ParticipantsController.php | 2 +- protected/controllers/QuestionsController.php | 2 +- protected/controllers/TemplatesController.php | 2 +- protected/controllers/UsersController.php | 2 +- protected/core/WebApplication.php | 4 + protected/helpers/FrontEnd.php | 2 +- protected/helpers/Html.php | 6 - protected/helpers/Replacements.php | 2 +- protected/helpers/SurveyRuntime.php | 4 +- protected/helpers/admin/template_helper.php | 2 + protected/helpers/common_helper.php | 2 + .../helpers/expressions/em_manager_helper.php | 9 +- .../helpers/import/importers/Import178.php | 7 - .../helpers/import/importers/Import179.php | 7 - .../helpers/import/importers/Import181.php | 7 - .../helpers/import/importers/Import182.php | 7 - .../helpers/import/importers/Import3_0.php | 7 - protected/interfaces/iRenderable.php | 4 +- .../libraries/ExpressionManager/Stack.php | 7 - .../libraries/ExpressionManager/Token.php | 7 - .../ExpressionManager/TokenStream.php | 7 - .../libraries/PluginManager/PluginManager.php | 2 +- protected/models/DefaultValue.php | 1 - protected/models/DummyResponse.php | 6 - protected/models/Dynamic.php | 4 +- protected/models/Participant.php | 1 + protected/models/Question.php | 12 +- .../forms/ParticipantDatabaseSettings.php | 7 - protected/models/installer/PreCheck.php | 6 +- .../questions/ArrayByColumnQuestion.php | 7 - protected/models/questions/ArrayQuestion.php | 7 - .../models/questions/BaseArrayQuestion.php | 4 +- .../models/questions/DateTimeQuestion.php | 13 +- .../models/questions/DisplayQuestion.php | 13 +- .../models/questions/DropDownListQuestion.php | 13 +- .../questions/DualScaleArrayQuestion.php | 7 - .../models/questions/EquationQuestion.php | 6 +- .../questions/FivePointArrayQuestion.php | 13 +- .../questions/FivePointChoiceQuestion.php | 15 +- .../models/questions/FixedArrayQuestion.php | 13 +- .../models/questions/FixedChoiceQuestion.php | 13 +- protected/models/questions/GenderQuestion.php | 13 +- .../models/questions/HugeTextQuestion.php | 11 +- .../IncreaseSameDecreaseArrayQuestion.php | 15 +- .../models/questions/LanguageQuestion.php | 10 +- .../models/questions/LongTextQuestion.php | 12 +- .../questions/MultipleChoiceQuestion.php | 14 +- .../MultipleChoiceWithCommentQuestion.php | 2 +- .../questions/MultipleNumberQuestion.php | 14 +- .../models/questions/MultipleTextQuestion.php | 20 +-- .../questions/NumericalArrayQuestion.php | 8 - .../models/questions/NumericalQuestion.php | 6 +- .../models/questions/OpenArrayQuestion.php | 2 +- .../models/questions/RadioListQuestion.php | 14 +- .../models/questions/RankingQuestion.php | 10 +- .../models/questions/ShortTextQuestion.php | 15 +- .../models/questions/SingleChoiceQuestion.php | 6 +- .../SingleChoiceWithCommentQuestion.php | 2 +- protected/models/questions/SubQuestion.php | 8 - .../questions/TenPointArrayQuestion.php | 8 - protected/models/questions/UploadQuestion.php | 16 +- protected/models/questions/YesNoQuestion.php | 14 +- .../questions/YesNoUncertainArrayQuestion.php | 16 +- protected/views/participants/import.php | 4 +- protected/views/surveys/execute/run.php | 2 + public/scripts/timers.js | 1 - public/scripts/unobtrusive.js | 1 - 92 files changed, 811 insertions(+), 786 deletions(-) diff --git a/protected/components/AuthManager.php b/protected/components/AuthManager.php index ca4cdeba5d2..513c04c4570 100644 --- a/protected/components/AuthManager.php +++ b/protected/components/AuthManager.php @@ -1,91 +1,120 @@ authorizationPlugin = App()->pluginManager->getPlugin($id); + $this->authorizationPlugin = App()->pluginManager->getPlugin($id); } - public function addItemChild($itemName, $childName) { + + public function addItemChild($itemName, $childName) + { return $this->authorizationPlugin->addItemChild($itemName, $childName); } - public function assign($itemName, $userId, $bizRule = null, $data = null) { + public function assign($itemName, $userId, $bizRule = null, $data = null) + { return $this->authorizationPlugin->assign($itemName, $userId, $bizRule, $data); } - public function checkAccess($itemName, $userId, $params = array()) { + public function checkAccess($itemName, $userId, $params = array()) + { return $this->authorizationPlugin->checkAccess($itemName, $userId, $params); } - public function clearAll() { + public function clearAll() + { return $this->authorizationPlugin->clearAll(); } - public function clearAuthAssignments() { + public function clearAuthAssignments() + { return $this->authorizationPlugin->clearAuthAssignments(); } - public function createAuthItem($name, $type, $description = '', $bizRule = null, $data = null) { + public function createAuthItem($name, $type, $description = '', $bizRule = null, $data = null) + { return $this->authorizationPlugin->createAuthItem($name, $type, $description, $bizRule, $data); } - public function executeBizRule($bizRule, $params, $data) { + public function executeBizRule($bizRule, $params, $data) + { return $this->authorizationPlugin->executeBizRule($bizRule, $params, $data); } - public function getAuthAssignment($itemName, $userId) { + public function getAuthAssignment($itemName, $userId) + { return $this->authorizationPlugin->getAuthAssignment($itemName, $userId); } - public function getAuthAssignments($userId) { + public function getAuthAssignments($userId) + { return $this->authorizationPlugin->getAuthAssignments($userId); } - public function getAuthItem($name) { + public function getAuthItem($name) + { return $this->authorizationPlugin->getAuthItem($name); } - public function getAuthItems($type = null, $userId = null) { + public function getAuthItems($type = null, $userId = null) + { return $this->authorizationPlugin->getAuthItems($type, $userId); } - public function getItemChildren($itemName) { + public function getItemChildren($itemName) + { return $this->authorizationPlugin->getItemChildren($itemName); } - public function hasItemChild($itemName, $childName) { + public function hasItemChild($itemName, $childName) + { return $this->authorizationPlugin->hasItemChild($itemName, $childName); } - public function isAssigned($itemName, $userId) { + public function isAssigned($itemName, $userId) + { return $this->authorizationPlugin->isAssigned($itemName, $userId); } - public function removeAuthItem($name) { + public function removeAuthItem($name) + { return $this->authorizationPlugin->removeAuthItem($name); } - public function removeItemChild($itemName, $childName) { + public function removeItemChild($itemName, $childName) + { return $this->authorizationPlugin->removeItemChild($itemName, $childName); } - public function revoke($itemName, $userId) { + public function revoke($itemName, $userId) + { return $this->authorizationPlugin->revoke($itemName, $userId); } - public function save() { + public function save() + { return $this->authorizationPlugin->save(); } - public function saveAuthAssignment($assignment) { + public function saveAuthAssignment($assignment) + { return $this->authorizationPlugin->saveAuthAssignment($assignment); } - public function saveAuthItem($item, $oldName = null) { + public function saveAuthItem($item, $oldName = null) + { return $this->authorizationPlugin->saveAuthItem($item); } diff --git a/protected/components/Batch.php b/protected/components/Batch.php index 3372281f5de..c16d9737c1c 100644 --- a/protected/components/Batch.php +++ b/protected/components/Batch.php @@ -1,13 +1,14 @@ callback = $callback; $this->batchSize = $batchSize; $this->defaultCategory = $defaultCategory; } - public function add($elements, $category = null) { + public function add($elements, $category = null) + { if (!empty($elements) && is_scalar(reset($elements))) { $elements = [$elements]; } if (!isset($category)) { $category = $this->defaultCategory; } - foreach($elements as $element) { + foreach ($elements as $element) { $this->data[$category][] = ($element instanceof \CActiveRecord) ? $element->attributes : $element; @@ -41,19 +44,24 @@ public function add($elements, $category = null) { } } - public function commitCategory($category) { + public function commitCategory($category) + { $callback = $this->callback; $callback($this->data[$category], $category); $this->commitCount++; unset($this->data[$category]); } - public function commit() { - foreach($this->data as $key => $items) { + + public function commit() + { + foreach ($this->data as $key => $items) { $this->commitCategory($key); } } - public function __destruct() { + + public function __destruct() + { $this->commit(); } } \ No newline at end of file diff --git a/protected/components/DeferredValue.php b/protected/components/DeferredValue.php index aa66f4dcd7f..f9f354c3bd8 100644 --- a/protected/components/DeferredValue.php +++ b/protected/components/DeferredValue.php @@ -1,17 +1,23 @@ closure = $closure; } - public function __toString() { + public function __toString() + { $result = call_user_func($this->closure); + return "" . $result; } } \ No newline at end of file diff --git a/protected/components/LocalizedFormatter.php b/protected/components/LocalizedFormatter.php index 6ebda108839..291f315349c 100644 --- a/protected/components/LocalizedFormatter.php +++ b/protected/components/LocalizedFormatter.php @@ -1,26 +1,37 @@ toBytes($object->$attribute); - if($value > -1 && $this->min !== null && $value < $this->toBytes($this->min)) - { - $message=$this->tooSmall!==null?$this->tooSmall:Yii::t('yii','{attribute} is too small (minimum is {min}).'); - $this->addError($object,$attribute,$message,array('{min}'=>$this->min)); - } - if($this->max!==null && $value > $this->toBytes($this->max)) - { - $message=$this->tooBig!==null?$this->tooBig:Yii::t('yii','{attribute} is too big (maximum is {max}).'); - $this->addError($object,$attribute,$message,array('{max}'=>$this->max)); - } + if ($value > -1 && $this->min !== null && $value < $this->toBytes($this->min)) { + $message = $this->tooSmall !== null ? $this->tooSmall : Yii::t('yii', + '{attribute} is too small (minimum is {min}).'); + $this->addError($object, $attribute, $message, array('{min}' => $this->min)); + } + if ($this->max !== null && $value > $this->toBytes($this->max)) { + $message = $this->tooBig !== null ? $this->tooBig : Yii::t('yii', + '{attribute} is too big (maximum is {max}).'); + $this->addError($object, $attribute, $message, array('{max}' => $this->max)); + } } - - private function toBytes($value) { + + private function toBytes($value) + { $this->memoryPattern = '/^\s*(\d+)\s*([A-Za-z])\s*$/'; if (preg_match($this->memoryPattern, $value, $matches) == 0) { return $value; } - $multipliers = [ + $multipliers = [ 'M' => 1024 * 1024 ]; + return !isset($matches[2]) ? $matches[1] : $matches[1] * $multipliers[strtoupper($matches[2])]; - + } } diff --git a/protected/components/MigrationManager.php b/protected/components/MigrationManager.php index db26696c9b4..8e38a9ec56d 100644 --- a/protected/components/MigrationManager.php +++ b/protected/components/MigrationManager.php @@ -1,4 +1,6 @@ migrationHistory as $version => $time) - $applied[substr($version,1,13)] = true; + { + $applied = []; + foreach ($this->migrationHistory as $version => $time) { + $applied[substr($version, 1, 13)] = true; + } - $migrations = []; + $migrations = []; foreach ($this->migrationPaths as $migrationPath) { $handle = opendir($migrationPath); - while(($file=readdir($handle))!==false) - { - if($file==='.' || $file==='..') + while (($file = readdir($handle)) !== false) { + if ($file === '.' || $file === '..') { continue; + } $path = "$migrationPath/$file"; - if(preg_match('/^(m(\d{6}_\d{6})_.*?)\.php$/',$file,$matches) && is_file($path) && !isset($applied[$matches[2]])) - $migrations[]=$matches[1]; + if (preg_match('/^(m(\d{6}_\d{6})_.*?)\.php$/', $file, + $matches) && is_file($path) && !isset($applied[$matches[2]]) + ) { + $migrations[] = $matches[1]; + } } closedir($handle); } - sort($migrations); - return $migrations; - } - + sort($migrations); + + return $migrations; + } + protected function getMigrationHistory($limit = -1) - { - $db = App()->db; - if($db->schema->getTable($this->migrationTable,true)===null) - { - $this->createMigrationHistoryTable(); - } - return CHtml::listData($db->createCommand() - ->select('version, apply_time') - ->from($this->migrationTable) - ->order('version DESC') - ->limit($limit) - ->queryAll(), 'version', 'apply_time'); - } - - protected function createMigrationHistoryTable() - { + { + $db = App()->db; + if ($db->schema->getTable($this->migrationTable, true) === null) { + $this->createMigrationHistoryTable(); + } + + return CHtml::listData($db->createCommand() + ->select('version, apply_time') + ->from($this->migrationTable) + ->order('version DESC') + ->limit($limit) + ->queryAll(), 'version', 'apply_time'); + } + + protected function createMigrationHistoryTable() + { $db = App()->db; - return $db->createCommand()->createTable($this->migrationTable,array( - 'version'=>'varchar(180) NOT NULL PRIMARY KEY', - 'apply_time'=>'integer', - )) - && $db->createCommand()->insert($this->migrationTable,array( - 'version'=>self::BASE_MIGRATION, - 'apply_time'=>time(), - )); - } + return $db->createCommand()->createTable($this->migrationTable, array( + 'version' => 'varchar(180) NOT NULL PRIMARY KEY', + 'apply_time' => 'integer', + )) + && $db->createCommand()->insert($this->migrationTable, array( + 'version' => self::BASE_MIGRATION, + 'apply_time' => time(), + )); + + } /** * @param string $class The name of the migration class * @return string|boolean Result */ public function migrateUp($class, $captureOutput = false) - { + { if (!$captureOutput) { @ob_end_flush(); } else { ob_start(); } echo '
';
-		
+
         echo "*** applying $class\n";
-        
+
         $start = microtime(true);
-		$migration = $this->instantiateMigration($class);
-		if($migration->up()!== false){
-			App()->db->createCommand()->insert($this->migrationTable, [
-				'version' => $class,
-				'apply_time' => time(),
-			]);
-            
-			$time = microtime(true) - $start;
-			echo "*** applied $class (time: ".sprintf("%.3f",$time)."s)\n\n";
+        $migration = $this->instantiateMigration($class);
+        if ($migration->up() !== false) {
+            App()->db->createCommand()->insert($this->migrationTable, [
+                'version' => $class,
+                'apply_time' => time(),
+            ]);
+
+            $time = microtime(true) - $start;
+            echo "*** applied $class (time: " . sprintf("%.3f", $time) . "s)\n\n";
             echo '
'; $result = true; - } else { - $time = microtime(true) - $start; - echo "*** failed to apply $class (time: ".sprintf("%.3f",$time)."s)\n\n"; + } else { + $time = microtime(true) - $start; + echo "*** failed to apply $class (time: " . sprintf("%.3f", $time) . "s)\n\n"; echo ''; - $result = false; - } + $result = false; + } // If capturing output and migration succeeded, return the captured output. return $captureOutput && $result ? ob_get_clean() : $result; - } - + } + /** * @param string $class */ protected function instantiateMigration($class) - { + { // If classname is unqualified we prefix it. if (strpos($class, '\\') === false) { $class = "\\ls\\migrations\\" . $class; } - $migration=new $class; - $migration->setDbConnection(App()->db); - return $migration; - } + $migration = new $class; + $migration->setDbConnection(App()->db); + + return $migration; + } function __construct() { diff --git a/protected/components/PhpConfigFile.php b/protected/components/PhpConfigFile.php index 9e4ea7b014e..8c111fb19d1 100644 --- a/protected/components/PhpConfigFile.php +++ b/protected/components/PhpConfigFile.php @@ -1,34 +1,46 @@ file = $file; } - - public function setConfig(array $config, $merge = true) { + + public function setConfig(array $config, $merge = true) + { $this->_config = $merge ? CMap::mergeArray($this->fileConfig, $config) : $config; } - - public function getFileConfig() { + + public function getFileConfig() + { return file_exists($this->file) ? include($this->file) : []; } - - public function getConfig() { + + public function getConfig() + { if (!isset($this->_config)) { $this->_config = $this->getFileConfig(); } + return $this->_config; } - - public function save() { + + public function save() + { $code = "config, true) . ';'; + return false !== file_put_contents($this->file, $code); } } diff --git a/protected/components/PluginIdentity.php b/protected/components/PluginIdentity.php index d1e3513d5e2..f8258ee7f76 100644 --- a/protected/components/PluginIdentity.php +++ b/protected/components/PluginIdentity.php @@ -1,19 +1,28 @@ plugin = $plugin; } - public function authenticate() { + + public function authenticate() + { $result = $this->plugin->authenticate(Yii::app()->request); $this->setState('authenticationPlugin', $this->plugin->id); if (!$result instanceof ls\pluginmanager\iUser) { @@ -22,26 +31,29 @@ public function authenticate() { $this->errorCode = self::ERROR_NONE; $this->model = $result; } + return $this->errorCode === self::ERROR_NONE; } - - public function getId() { + + public function getId() + { return $this->model->getId(); } - - public function getName() { + + public function getName() + { return $this->model->getName(); } - - public function setModel($value) { + + public function setModel($value) + { return $this->setState('model', $value); } - public function getModel() { + + public function getModel() + { return $this->getState('model', []); } - - - } \ No newline at end of file diff --git a/protected/components/QuestionAnswer.php b/protected/components/QuestionAnswer.php index c46fb7e8084..06d3520c13d 100644 --- a/protected/components/QuestionAnswer.php +++ b/protected/components/QuestionAnswer.php @@ -1,5 +1,7 @@ _question = $question; } - public function getValue() { + public function getValue() + { if (!isset($this->_value)) { throw new \Exception("Value not set."); } } - public function setValue($value) { + public function setValue($value) + { $this->_value = $value; } - public function getQuestion() { + + public function getQuestion() + { return $this->_question; } - public function getRelevanceScript() { + public function getRelevanceScript() + { if (!isset($this->_relevanceScript)) { throw new \Exception("Relevance must be set for every field."); } + return $this->_relevanceScript; } - public function setRelevanceScript($value) { + public function setRelevanceScript($value) + { $this->_relevanceScript = $value; } /** * Check if this field only takes numerical values. */ - public function getIsNumerical() { + public function getIsNumerical() + { return $this->_numerical; } - public function setIsNumerical($value) { + public function setIsNumerical($value) + { return $this->_numerical = $value; } @@ -71,25 +89,28 @@ public function setIsNumerical($value) { */ function jsonSerialize() { - return [ - 'code' => $this->_code, - 'numerical' => $this->isNumerical, - 'value' => $this->_value, - 'name' => $this->_name, - 'relevance' => $this->getRelevanceScript(), - 'labels' => $this->getLabels() - ]; + return [ + 'code' => $this->_code, + 'numerical' => $this->isNumerical, + 'value' => $this->_value, + 'name' => $this->_name, + 'relevance' => $this->getRelevanceScript(), + 'labels' => $this->getLabels() + ]; } - public function getLabels() { + public function getLabels() + { return $this->_labels; } - public function setLabels(array $labels) { + public function setLabels(array $labels) + { $this->_labels = $labels; } - public function getLabel($answer) { + public function getLabel($answer) + { return TbArray::getValue($answer, $this->getLabels(), null); } diff --git a/protected/components/QuestionValidationResult.php b/protected/components/QuestionValidationResult.php index c7775c0d71f..ed9e582ca2f 100644 --- a/protected/components/QuestionValidationResult.php +++ b/protected/components/QuestionValidationResult.php @@ -1,14 +1,13 @@ _question = $question; } - public function getSuccess() { + public function getSuccess() + { return empty($this->_messages); } - public function addMessage($field, $message) { + public function addMessage($field, $message) + { $this->_messages[$field][] = $message; } - public function getQuestion() { + public function getQuestion() + { return $this->_question; } - public function getMessages() { + public function getMessages() + { return $this->_messages; } - public function getMessagesAsString($separator = "\n") { + public function getMessagesAsString($separator = "\n") + { return implode($separator, \Cake\Utility\Hash::flatten($this->_messages)); } diff --git a/protected/components/QuestionValidationResultCollection.php b/protected/components/QuestionValidationResultCollection.php index d3128acca78..8666834759c 100644 --- a/protected/components/QuestionValidationResultCollection.php +++ b/protected/components/QuestionValidationResultCollection.php @@ -1,10 +1,10 @@ iterator as $validationResult) { + foreach ($this->iterator as $validationResult) { if (!$validationResult->getPassedMandatory()) { return false; } } + return true; } /** * Returns true if all validation results in this collection have a success status. */ - public function getSuccess() { + public function getSuccess() + { /** @var QuestionValidationResult $validationResult */ - foreach($this->iterator as $validationResult) { + foreach ($this->iterator as $validationResult) { if (!$validationResult->getSuccess()) { return false; } } + return true; } @@ -47,9 +51,10 @@ public function getMessagesAsString($separator = "\n") { $messages = []; /** @var QuestionValidationResult $validationResult */ - foreach($this->iterator as $validationResult) { + foreach ($this->iterator as $validationResult) { $messages[] = $validationResult->getMessagesAsString($separator); } + return implode($separator, \Cake\Utility\Hash::flatten($messages)); } diff --git a/protected/components/RenderedQuestion.php b/protected/components/RenderedQuestion.php index 6e211c98623..635f8d1f575 100644 --- a/protected/components/RenderedQuestion.php +++ b/protected/components/RenderedQuestion.php @@ -1,5 +1,17 @@ _question = $question; } - public function setQuestionText($text) { + + public function setQuestionText($text) + { $this->_text = $text; } - public function addValidation($javascript, $message = null) { + + public function addValidation($javascript, $message = null) + { $this->_validations[$javascript] = $message; } @@ -110,7 +127,8 @@ public function offsetUnset($offset) throw new \Exception("Cannot unset values"); } - public function getMessages() { + public function getMessages() + { $result = ''; foreach ($this->_validations as $expression => $message) { @@ -123,10 +141,12 @@ public function getMessages() { 'data-irrelevance-expression' => $expression, ], $message); } + return $result; } - public function setHtml($html) { + public function setHtml($html) + { $this->_html = $html; } @@ -145,13 +165,12 @@ protected function getReplacements() // Core value : not replaced $replacements['QID'] = $this->_question->primaryKey; $replacements['GID'] = $this->_question->gid; - $replacements['SGQ']= $this->_question->sgqa; + $replacements['SGQ'] = $this->_question->sgqa; $replacements['QUESTION_CODE'] = null; $replacements['QUESTION_NUMBER'] = null; $iNumber = $this->_index + 1; // Nondevelopers people start counting from 1 for some reason.. - switch (SettingGlobal::get('showqnumcode', 'choose')) - { + switch (SettingGlobal::get('showqnumcode', 'choose')) { case 'both': $replacements['QUESTION_CODE'] = $this->_question->title; $replacements['QUESTION_NUMBER'] = $iNumber; @@ -161,13 +180,13 @@ protected function getReplacements() $replacements['QUESTION_CODE'] = $this->_question->title; break; case 'choose': - switch($survey->showqnumcode) { + switch ($survey->showqnumcode) { case 'B': // Both $replacements['QUESTION_CODE'] = $this->_question->title; - $replacements['QUESTION_NUMBER']=$iNumber; + $replacements['QUESTION_NUMBER'] = $iNumber; break; case 'N': - $replacements['QUESTION_NUMBER']=$iNumber; + $replacements['QUESTION_NUMBER'] = $iNumber; break; case 'C': $replacements['QUESTION_CODE'] = $this->_question->title; @@ -180,7 +199,7 @@ protected function getReplacements() } // Core value : user text $replacements['QUESTION_TEXT'] = $this['text']; - $replacements['QUESTIONHELP']= $this->_question->help;// User help + $replacements['QUESTIONHELP'] = $this->_question->help;// User help $classes = $this->_question->classes; $replacements['QUESTION_CLASS'] = implode(' ', $classes); @@ -191,7 +210,8 @@ protected function getReplacements() if (empty($this['html'])) { $rc = new ReflectionClass($this->_question); $url = "https://github.com/LimeSurvey/LimeSurvey/blob/develop/application/models/questions/{$rc->getShortName()}.php"; - throw new \CHttpException(500, "No HTML found. Is " . get_class($this->_question) . "::render() implemented in $url"); + throw new \CHttpException(500, + "No HTML found. Is " . get_class($this->_question) . "::render() implemented in $url"); } $replacements['ANSWER'] = $this['html']; @@ -233,13 +253,15 @@ protected function getReplacements() $replacements['QUESTION_VALID_MESSAGE'] = $event->get('valid_message'); // Always add id for QUESTION_ESSENTIALS $htmlOptions['id'] = "question{$this->_question->primaryKey}"; - $replacements['QUESTION_ESSENTIALS']= CHtml::renderAttributes($htmlOptions); + $replacements['QUESTION_ESSENTIALS'] = CHtml::renderAttributes($htmlOptions); eP(); + return $replacements; } - public function setTemplate($template) { + public function setTemplate($template) + { $this->_template = $template; } @@ -248,11 +270,14 @@ public function setTemplate($template) { * @return string * @throws CHttpException */ - public function render(SurveySession $session) { - return \ls\helpers\Replacements::templatereplace($this->_template, $this->getReplacements(), [], $this->_question->qid, $session); + public function render(SurveySession $session) + { + return \ls\helpers\Replacements::templatereplace($this->_template, $this->getReplacements(), [], + $this->_question->qid, $session); } - public function setIndex($i) { + public function setIndex($i) + { $this->_index = $i; } diff --git a/protected/components/Renderer.php b/protected/components/Renderer.php index 975b481b358..488a348ac44 100644 --- a/protected/components/Renderer.php +++ b/protected/components/Renderer.php @@ -1,11 +1,17 @@ session = $session; diff --git a/protected/components/ResponseField.php b/protected/components/ResponseField.php index 03f041480a5..db844ce55b9 100644 --- a/protected/components/ResponseField.php +++ b/protected/components/ResponseField.php @@ -1,5 +1,9 @@ _name = $name; $this->_code = $code; } @@ -20,7 +25,8 @@ public function __construct($name, $code) { * @return string The name of this field in sgqa format. * Example: 13455X123X12other */ - public function getName() { + public function getName() + { return $this->_name; } @@ -29,15 +35,18 @@ public function getName() { * Example: q1_other */ - public function getCode() { + public function getCode() + { return $this->_code; } - public function isNumerical() { + public function isNumerical() + { return $this->_numerical; } - public function getJavascriptName() { + public function getJavascriptName() + { return "java{$this->_name}"; } diff --git a/protected/components/SubQuestion.php b/protected/components/SubQuestion.php index ada9e14c1ea..289b9663b64 100644 --- a/protected/components/SubQuestion.php +++ b/protected/components/SubQuestion.php @@ -1,5 +1,8 @@ renderBody(); + return $this->renderLayout($body); } @@ -24,6 +31,7 @@ public function renderBody() default: throw new \Exception("Format {$this->session->format} not supported"); } + return $result; } diff --git a/protected/components/SurveySession.php b/protected/components/SurveySession.php index 6b3c8213170..2c8abe5e245 100644 --- a/protected/components/SurveySession.php +++ b/protected/components/SurveySession.php @@ -1,7 +1,9 @@ id = $id; } - public function getSurveyId() { + public function getSurveyId() + { return $this->surveyId; } /** * @return integer */ - public function getResponseId() { + public function getResponseId() + { return $this->_responseId; } - public function getIsFinished() { + public function getIsFinished() + { return $this->_finished; } - public function setIsFinished($value) { + public function setIsFinished($value) + { $this->_finished = $value; } - public function getToken() { + public function getToken() + { return $this->_response->getToken(); } - public function setToken($value) { + public function setToken($value) + { $this->_token = $value; } - public function getLanguage() { + + public function getLanguage() + { return $this->_language; } - public function setLanguage($value) { + public function setLanguage($value) + { $this->_language = $value; } + /** * Returns the session id for this session. * The session id is unique per browser session and does not need to be unguessable. * In fact it is just an auto incremented number. */ - public function getId() { + public function getId() + { return $this->id; } - public function getResponse() { + public function getResponse() + { if (!isset($this->_response)) { $responseClass = $this->_responseClass; $this->_response = $responseClass::loadById($this->_responseId); } + return $this->_response; } @@ -126,7 +143,8 @@ public function getResponse() { * @todo Improve performance. Query takes a short time but AR object creation takes ~4s for large surveys. * @param $id */ - protected function loadSurvey($id) { + protected function loadSurvey($id) + { bP(); $cache = App()->cache; $cacheKey = __CLASS__ . "loadSurvey{$this->id}-$id"; @@ -184,40 +202,50 @@ protected function loadSurvey($id) { if (!$result instanceof Survey) { throw new \Exception("Something went wrong in loadSurvey."); } + return $result; } + /** * This function gets the survey active record model for this survey session. * @return Survey The survey for this session. */ - public function getSurvey() { + public function getSurvey() + { if (!isset($this->_survey)) { $this->_survey = $this->loadSurvey($this->surveyId); } + return $this->_survey; } - public function setSurvey(\Survey $survey) { + public function setSurvey(\Survey $survey) + { $this->_survey = $survey; } + /** * Wrapper function that returns the question given by qid to make sure we always get the same object. * @param int $id The primary key of the question. * @return Question */ - public function getQuestion($id) { + public function getQuestion($id) + { bP(); $result = isset($this->survey->questions[$id]) ? $this->survey->questions[$id] : null; eP(); + return $result; } - public function getQuestionIndex($id) { + public function getQuestionIndex($id) + { \Yii::beginProfile(__CLASS__ . "::" . __FUNCTION__); $questions = $this->survey->questions; $question = $questions[$id]; $result = array_search($question, array_values($questions), true); \Yii::endProfile(__CLASS__ . "::" . __FUNCTION__); + return $result; } @@ -225,11 +253,12 @@ public function getQuestionIndex($id) { * @param $index * @return Question */ - public function getQuestionByIndex($index) { + public function getQuestionByIndex($index) + { $i = 0; // Get groups in order. - foreach($this->getGroups() as $group) { - foreach($this->getQuestions($group) as $question) { + foreach ($this->getGroups() as $group) { + foreach ($this->getQuestions($group) as $question) { if ($index == $i) { $result = $question; break 2; @@ -240,14 +269,16 @@ public function getQuestionByIndex($index) { if (!isset($result)) { throw new \Exception("Invalid step index: $index"); } + return $result; } - public function getQuestionByCode($code) { + public function getQuestionByCode($code) + { $i = 0; // Get groups in order. - foreach($this->getGroups() as $group) { - foreach($this->getQuestions($group) as $question) { + foreach ($this->getGroups() as $group) { + foreach ($this->getQuestions($group) as $question) { if ($code == $question->title) { $result = $question; break 2; @@ -258,10 +289,12 @@ public function getQuestionByCode($code) { if (!isset($result)) { throw new \Exception("Unknown code: $code"); } + return $result; } - public function getStepCount() { + public function getStepCount() + { switch ($this->format) { case Survey::FORMAT_ALL_IN_ONE: $result = 1; @@ -270,23 +303,27 @@ public function getStepCount() { $result = count($this->getGroups()); break; case Survey::FORMAT_QUESTION: - $result = array_sum(array_map(function(QuestionGroup $group) { + $result = array_sum(array_map(function (QuestionGroup $group) { return count($this->getQuestions($group)); }, $this->getGroups())); break; default: throw new \Exception("Unknown survey format."); } + return $result; } + /** * @return int */ - public function getStep() { + public function getStep() + { return $this->_step; } - public function setStep($value) { + public function setStep($value) + { if (!is_int($value)) { throw new \InvalidArgumentException('Parameter $value must be an integer.'); } @@ -303,30 +340,36 @@ public function setStep($value) { } - public function getMaxStep() { + public function getMaxStep() + { return $this->_maxStep; } /** * @return int The number of times the current page has been viewed. */ - public function getViewCount() { + public function getViewCount() + { return $this->_viewCount; } - public function getPrevStep() { + public function getPrevStep() + { return $this->_prevStep; } - public function setPrevStep($value) { + public function setPrevStep($value) + { $this->_prevStep = $value; } - public function __wakeup() { + public function __wakeup() + { $this->_viewCount++; } - public function __sleep() { + public function __sleep() + { return [ 'surveyId', 'id', @@ -347,21 +390,25 @@ public function __sleep() { * Sets the template dir to use for this session. * @param string $value */ - public function setTemplateDir($value) { + public function setTemplateDir($value) + { if (!is_dir($value)) { throw new \InvalidArgumentException("Invalid directory given: $value"); } $this->_templateDir = $value; } - public function getTemplateDir() { + public function getTemplateDir() + { if (!isset($this->_templateDir)) { $this->_templateDir = \Template::getTemplatePath($this->survey->template) . '/'; }; + return $this->_templateDir; } - public function getTemplateUrl() { + public function getTemplateUrl() + { return \Template::getTemplateURL($this->survey->template) . '/'; } @@ -369,7 +416,8 @@ public function getTemplateUrl() { * @param int $id The group id. * @return QuestionGroup */ - public function getGroup($id) { + public function getGroup($id) + { if (!is_numeric($id) || $id < 0) { throw new \InvalidArgumentException("\$id must of type integer and > 0"); } @@ -381,22 +429,27 @@ public function getGroup($id) { * Get the group by index. * @return QuestionGroup */ - public function getGroupByIndex($index) { + public function getGroupByIndex($index) + { if (!is_numeric($index)) { throw new \InvalidArgumentException("\$index must of type integer"); } + return $this->getGroups()[$index]; } - public function getGroupIndex($id) { + public function getGroupIndex($id) + { bP(); $groups = $this->groups; $group = $this->getGroup($id); $result = array_search($group, array_values($groups), true); eP(); + return $result; } + /** * Returns the list of question groups. * Ordered according to the randomization groups. @@ -440,6 +493,7 @@ public function getGroups() } } eP(); + return $order; } @@ -447,19 +501,20 @@ public function getGroups() * Getter for the format. In the future we could allow override per session. * @return FORMAT_QUESTION|FORMAT_GROUP|FORMAT_SURVEY; */ - public function getFormat() { + public function getFormat() + { return $this->survey->format; } - /** * Returns the questions in group $group, indexed by primary key, ordered as they are shown in the survey. * @todo Implement randomization / check randomization code. * @param QuestionGroup $group * @return Question[] */ - public function getQuestions(QuestionGroup $group) { + public function getQuestions(QuestionGroup $group) + { return $group->questions; $questions = $group->questions; @@ -470,7 +525,7 @@ public function getQuestions(QuestionGroup $group) { foreach ($questions as $question) { if (empty($question->randomization_group)) { $order[] = $question->randomization_group; - $randomizationGroups[$question->randomization_group][] =$question; + $randomizationGroups[$question->randomization_group][] = $question; } else { $order[] = $group; } @@ -493,21 +548,26 @@ public function getQuestions(QuestionGroup $group) { $randomizationGroups[$question] = array_values($randomizationGroups[$question]); } } + return $order; } - public function getPostKey() { + public function getPostKey() + { if (!isset($this->_postKey)) { $this->_postKey = \Cake\Utility\Text::uuid(); } + return $this->_postKey; } - public function setPostKey($value) { + public function setPostKey($value) + { $this->_postKey = $value; } - public function getCurrentGroup() { + public function getCurrentGroup() + { switch ($this->format) { case Survey::FORMAT_ALL_IN_ONE: throw new \UnexpectedValueException("An all in one survey does not have a current group."); @@ -519,6 +579,7 @@ public function getCurrentGroup() { $result = $this->getGroup($this->getQuestionByIndex($this->getStep())->gid); break; } + return $result; } diff --git a/protected/components/SurveySessionManager.php b/protected/components/SurveySessionManager.php index f5c6c0c2a26..2f716cde77b 100644 --- a/protected/components/SurveySessionManager.php +++ b/protected/components/SurveySessionManager.php @@ -1,7 +1,12 @@ session; $this->sessions = $session->get('SSM', null); if (!isset($this->sessions)) { - $session->add('SSM', $this->sessions = new CTypedMap('SurveySession')); + $session->add('SSM', $this->sessions = new CTypedMap('ls\components\SurveySession')); } if ((null !== $current = App()->request->getParam('SSM')) && isset($this->sessions[$current])) { $this->_current = $this->sessions[$current]; } } - public function getActive() { + public function getActive() + { return isset($this->_current); } @@ -40,32 +46,38 @@ public function getActive() { * @param $params * @return string */ - public function createUrl($route, $params = []) { + public function createUrl($route, $params = []) + { if ($this->active) { $params['SSM'] = array_search($this->_current, $this->sessions->toArray()); } + return App()->createUrl($route, $params); } /** * @return SurveySession */ - public function getCurrent() { + public function getCurrent() + { if (is_object($this->_current) && !$this->_current instanceof SurveySession) { throw new \Exception("Invalid session object of type: '" . get_class($this->_current)); } + return $this->_current; } - public function setCurrent(SurveySession $session) { + public function setCurrent(SurveySession $session) + { $this->_current = $session; } /** * @return SurveySession[] */ - public function getSessions() { + public function getSessions() + { return $this->sessions; } @@ -78,7 +90,7 @@ public function newSession($surveyId, \ls\interfaces\iResponse $response) { /** @var SurveySession $session */ - foreach($this->sessions as $session) { + foreach ($this->sessions as $session) { if ($session->getSurveyId() == $surveyId && $session->getResponseId() == $response->getId()) { throw new \Exception("Duplicate session detected."); } @@ -87,6 +99,7 @@ public function newSession($surveyId, \ls\interfaces\iResponse $response) $sessionId = rand(1, 1000); $this->_current = new SurveySession($surveyId, $response, $sessionId); $this->sessions->add($sessionId, $this->_current); + return $this->current; } @@ -94,7 +107,8 @@ public function newSession($surveyId, \ls\interfaces\iResponse $response) * Destroys a survey session, if no id is given the currently active session is destroyed. * @param int $id */ - public function destroySession($id = null) { + public function destroySession($id = null) + { if (isset($id)) { if ($this->_current == $this->sessions[$id]) { $this->_current = null; diff --git a/protected/components/UuidDefaultValidator.php b/protected/components/UuidDefaultValidator.php index 0390eb29e12..5f870d100de 100644 --- a/protected/components/UuidDefaultValidator.php +++ b/protected/components/UuidDefaultValidator.php @@ -1,10 +1,7 @@ $attribute; - - if($this->min !== null && version_compare($value, $this->min, '<')) - { - $message=$this->tooSmall!==null?$this->tooSmall:Yii::t('yii','{attribute} is too small (minimum is {min}).'); - $this->addError($object,$attribute,$message,array('{min}'=>$this->min)); - } - if($this->max!==null && version_compare($value, $this->max, '>')) - { - $message=$this->tooBig!==null?$this->tooBig:Yii::t('yii','{attribute} is too big (maximum is {max}).'); - $this->addError($object,$attribute,$message,array('{max}'=>$this->max)); - } + + if ($this->min !== null && version_compare($value, $this->min, '<')) { + $message = $this->tooSmall !== null ? $this->tooSmall : Yii::t('yii', + '{attribute} is too small (minimum is {min}).'); + $this->addError($object, $attribute, $message, array('{min}' => $this->min)); + } + if ($this->max !== null && version_compare($value, $this->max, '>')) { + $message = $this->tooBig !== null ? $this->tooBig : Yii::t('yii', + '{attribute} is too big (maximum is {max}).'); + $this->addError($object, $attribute, $message, array('{max}' => $this->max)); + } } - + } \ No newline at end of file diff --git a/protected/components/WebUser.php b/protected/components/WebUser.php index 80adfd31266..b8a7d215408 100644 --- a/protected/components/WebUser.php +++ b/protected/components/WebUser.php @@ -1,52 +1,62 @@ pluginManager->getPlugin($this->getState('authenticationPlugin')); - } + return App()->pluginManager->getPlugin($this->getState('authenticationPlugin')); + } - public function getModel() { - return $this->getPlugin()->getUser($this->id); - } - - public function getAuthManager() { - if (!isset($this->_authManager)) { - $this->_authManager = App()->authManager; - } - return $this->_authManager; + public function getModel() + { + return $this->getPlugin()->getUser($this->id); + } + + public function getAuthManager() + { + if (!isset($this->_authManager)) { + $this->_authManager = App()->authManager; } - - public function setAuthManager(IAuthManager $value) { - $this->_authManager = $value; + + return $this->_authManager; + } + + public function setAuthManager(IAuthManager $value) + { + $this->_authManager = $value; + } + + /** + * This implementation supports using a different auth manager. + * @param type $operation + * @param type $params + * @param type $allowCaching + * @return type + */ + public function checkAccess($operation, $params = array(), $allowCaching = true) + { + if ($allowCaching && $params === array() && isset($this->_access[$operation])) { + return $this->_access[$operation]; } - /** - * This implementation supports using a different auth manager. - * @param type $operation - * @param type $params - * @param type $allowCaching - * @return type - */ - public function checkAccess($operation,$params=array(),$allowCaching=true) - { - if($allowCaching && $params===array() && isset($this->_access[$operation])) - return $this->_access[$operation]; - - - $access = $this->getAuthManager()->checkAccess($operation,$this->getId(),$params); - if($allowCaching && $params===array()) - $this->_access[$operation]=$access; - - return $access; + + $access = $this->getAuthManager()->checkAccess($operation, $this->getId(), $params); + if ($allowCaching && $params === array()) { + $this->_access[$operation] = $access; } + return $access; } + +} diff --git a/protected/components/WritableValidator.php b/protected/components/WritableValidator.php index 47356f5025d..61dfa278e50 100644 --- a/protected/components/WritableValidator.php +++ b/protected/components/WritableValidator.php @@ -1,5 +1,9 @@ $attribute; if (!file_exists($value)) { $this->addError($object, $attribute, gT("File or directory does not exist.")); + return; } - + if (is_file($value) && $this->forceDirectory) { $this->addError($object, $attribute, gT("Path points to a file not a directory.")); + return; } - + $this->checkWritable($value, $object, $attribute); } - - protected function checkWritable($path, $object, $attribute) { + + protected function checkWritable($path, $object, $attribute) + { if (!is_writable($path)) { $this->addError($object, $attribute, gT("Path is not writable.")); + return false; } - + if (is_dir($path) && $this->recursive) { foreach (scandir($path) as $childPath) { if ($childPath != '.' && $childPath != '..') { @@ -46,7 +54,7 @@ protected function checkWritable($path, $object, $attribute) { } } } - + } } \ No newline at end of file diff --git a/protected/config/internal.php b/protected/config/internal.php index 04be3e29c30..607c10af4c0 100644 --- a/protected/config/internal.php +++ b/protected/config/internal.php @@ -6,24 +6,27 @@ * * */ +use ls\components\SurveySessionManager; +use ls\components\WebUser; + if (file_exists(__DIR__ . '/config.php')) { $userConfig = require(__DIR__ . '/config.php'); } else { $userConfig = []; } $internalConfig = array( - 'basePath' => __DIR__ . '/../', + 'basePath' => __DIR__ . '/../', 'timeZone' => 'UTC', 'sourceLanguage' => 'en', 'controllerNamespace' => '\\ls\\controllers', 'supportedLanguages' => include('locales.php'), 'theme' => 'default', - 'name' => 'LimeSurvey', + 'name' => 'LimeSurvey', 'loader' => $loader, 'localeClass' => \ls\core\Locale::class, - 'defaultController' => 'surveys', - 'aliases' => array( - 'vendor' => __DIR__ . '/../vendor', + 'defaultController' => 'surveys', + 'aliases' => array( + 'vendor' => __DIR__ . '/../vendor', 'bootstrap' => __DIR__ . '/../vendor/crisu83/yiistrap/widgets', 'yiiwheels' => __DIR__ . '/../vendor/2amigos/yiiwheels', @@ -35,31 +38,30 @@ 'public' => str_replace($webroot, '', $public), 'publicPath' => $public - ), - 'import' => array( - 'application.core.*', - 'application.components.*', - 'application.models.*', + ), + 'import' => array( + 'application.core.*', + 'application.models.*', 'application.models.installer.*', - 'application.controllers.*', - 'application.modules.*', - ), + 'application.controllers.*', + 'application.modules.*', + ), 'preload' => [ - 'log', + 'log', file_exists(__DIR__ . '/config.php') ? 'pluginManager' : null ], - 'components' => [ + 'components' => [ 'surveySessionManager' => [ 'class' => SurveySessionManager::class ], 'migrationManager' => [ - 'class' => 'MigrationManager' + 'class' => 'ls\components\MigrationManager' ], 'bootstrap' => [ 'class' => 'TbApi', ], 'format' => [ - 'class' => 'LocalizedFormatter' + 'class' => 'ls\components\LocalizedFormatter' ], 'clientScript'=> [ 'class' => CClientScript::class, @@ -139,7 +141,7 @@ 'pluginDirs' => [ __DIR__ . '/../core/plugins', __DIR__ . '/../../plugins', - + ], 'loader' => $loader // Composer classloader. ], @@ -147,7 +149,7 @@ 'class' => \YiiWheels::class ], 'authManager' => [ - 'class' => \AuthManager::class + 'class' => \ls\components\AuthManager::class ], 'themeManager' => [ 'class' => ThemeManager::class, @@ -164,6 +166,4 @@ $result = CMap::mergeArray($internalConfig, $userConfig); -return $result; -/* End of file internal.php */ -/* Location: ./application/config/internal.php */ +return $result; \ No newline at end of file diff --git a/protected/controllers/AdminController.php b/protected/controllers/AdminController.php index 94f8c0b049c..8ad5176ff0f 100644 --- a/protected/controllers/AdminController.php +++ b/protected/controllers/AdminController.php @@ -17,9 +17,12 @@ class AdminController extends Controller { public $layout = false; protected $user_id = 0; - - public function actionIndex() { + + public function actionIndex() + { $this->redirect(['surveys/index']); + + } /** diff --git a/protected/controllers/ParticipantsController.php b/protected/controllers/ParticipantsController.php index 6765b026f5f..6ac6b36b938 100644 --- a/protected/controllers/ParticipantsController.php +++ b/protected/controllers/ParticipantsController.php @@ -119,7 +119,7 @@ public function actionAjaxImport(array $items, array $map, $querySize = 1000) $fields = array_flip($participant->safeAttributeNames); - $batchInserter = new \Batch(function(array $batch, $category = null) { + $batchInserter = new \ls\components\Batch(function(array $batch, $category = null) { if (!empty($batch)) { \Yii::beginProfile('query'); try { diff --git a/protected/controllers/QuestionsController.php b/protected/controllers/QuestionsController.php index 1b93efdd137..9b3c8d6902c 100644 --- a/protected/controllers/QuestionsController.php +++ b/protected/controllers/QuestionsController.php @@ -185,7 +185,7 @@ public function actionPreview($id) { $question = $this->loadModel($id); $this->layout = 'showsurvey'; $dummy = new \DummyResponse($question->survey); - $session = new \SurveySession($question->sid, $dummy, null); + $session = new \ls\components\SurveySession($question->sid, $dummy, null); App()->surveySessionManager->setCurrent($session); $renderedQuestion = $question->render($dummy, $session); $path = \Template::getTemplatePath($question->survey->template); diff --git a/protected/controllers/TemplatesController.php b/protected/controllers/TemplatesController.php index 1d970eb159a..e00e4d3aa74 100644 --- a/protected/controllers/TemplatesController.php +++ b/protected/controllers/TemplatesController.php @@ -4,7 +4,7 @@ use ls\models\questions\RadioListQuestion; use ls\models\questions\ShortTextQuestion; use \Yii; -use \SurveySession; +use ls\components\SurveySession; use \DummyResponse; use \Survey; use SurveyLanguageSetting; diff --git a/protected/controllers/UsersController.php b/protected/controllers/UsersController.php index b84d3a209e0..a181c267a9b 100644 --- a/protected/controllers/UsersController.php +++ b/protected/controllers/UsersController.php @@ -4,7 +4,7 @@ use ls\pluginmanager\iAuthorizationPlugin; use ls\pluginmanager\PluginEvent; use Yii; -use PluginIdentity; +use ls\components\PluginIdentity; class UsersController extends Controller { diff --git a/protected/core/WebApplication.php b/protected/core/WebApplication.php index 1507befed99..7e578b98f6d 100644 --- a/protected/core/WebApplication.php +++ b/protected/core/WebApplication.php @@ -10,6 +10,10 @@ * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ +use ls\components\LocalizedFormatter; +use ls\components\MigrationManager; +use ls\components\SurveySessionManager; +use ls\components\WebUser; /** * Implements global config diff --git a/protected/helpers/FrontEnd.php b/protected/helpers/FrontEnd.php index c11206e2cea..55998a7d3f5 100644 --- a/protected/helpers/FrontEnd.php +++ b/protected/helpers/FrontEnd.php @@ -448,7 +448,7 @@ public static function sendSubmitNotifications($surveyid) * Adding a hidden input for default behaviour without javascript * Use button name="move" for real browser (with or without javascript) and IE6/7/8 with javascript */ - public static function surveymover(\SurveySession $session) + public static function surveymover(\ls\components\SurveySession $session) { $surveyid = $session->surveyId; diff --git a/protected/helpers/Html.php b/protected/helpers/Html.php index 04645c6e913..72b2b3e22d7 100644 --- a/protected/helpers/Html.php +++ b/protected/helpers/Html.php @@ -1,10 +1,4 @@ survey; diff --git a/protected/helpers/SurveyRuntime.php b/protected/helpers/SurveyRuntime.php index d79fb330683..e117c7db8f9 100644 --- a/protected/helpers/SurveyRuntime.php +++ b/protected/helpers/SurveyRuntime.php @@ -1,7 +1,7 @@ questions as $question) { foreach($question->getFields() as $field) { if (!$field instanceof QuestionResponseField) { - throw new \Exception("getFields() must return an array of QuestionResponseField"); + throw new \Exception("getFields() must return an array of ls\components\QuestionResponseField"); } $fields[$field->code] = $field; if (YII_DEBUG) { diff --git a/protected/helpers/import/importers/Import178.php b/protected/helpers/import/importers/Import178.php index e46076ec110..35448ced63c 100644 --- a/protected/helpers/import/importers/Import178.php +++ b/protected/helpers/import/importers/Import178.php @@ -1,11 +1,4 @@ pluginFile); + $file = new \ls\components\PhpConfigFile($this->pluginFile); $file->setConfig(array_map(function(PluginConfig $config) { return $config->attributes; }, $plugins), false); diff --git a/protected/models/DefaultValue.php b/protected/models/DefaultValue.php index e7402c67319..6b42d0bc380 100644 --- a/protected/models/DefaultValue.php +++ b/protected/models/DefaultValue.php @@ -74,4 +74,3 @@ function insertRecords($data) return $values->save(); } } - diff --git a/protected/models/DummyResponse.php b/protected/models/DummyResponse.php index 0e454302a2f..5e7f3ee6460 100644 --- a/protected/models/DummyResponse.php +++ b/protected/models/DummyResponse.php @@ -1,11 +1,5 @@ setIndex($session->getQuestionIndex($this->primaryKey)); $em = $this->getExpressionManager($response); diff --git a/protected/models/forms/ParticipantDatabaseSettings.php b/protected/models/forms/ParticipantDatabaseSettings.php index e36f93a3c47..1d549e97302 100644 --- a/protected/models/forms/ParticipantDatabaseSettings.php +++ b/protected/models/forms/ParticipantDatabaseSettings.php @@ -1,11 +1,4 @@ $this->getRequiredValue('version'), 'on' => ['required']], - ['memoryLimit', 'MemoryValidator', 'min' => $this->getRequiredValue('memoryLimit'), 'on' => ['required']], + ['version', 'ls\components\VersionValidator', 'min' => $this->getRequiredValue('version'), 'on' => ['required']], + ['memoryLimit', 'ls\components\MemoryValidator', 'min' => $this->getRequiredValue('memoryLimit'), 'on' => ['required']], ['pdoSupport', 'required', 'requiredValue' => true, 'on' => ['required']], ['multibyteSupport', 'required', 'requiredValue' => true, 'on' => ['required']], ['sessionSupport', 'required', 'requiredValue' => true, 'on' => ['required']], - [['configPath', 'uploadPath', 'tempPath'], 'WritableValidator', 'forceDirectory' => true, 'recursive' => false, 'on' => ['required']], + [['configPath', 'uploadPath', 'tempPath'], 'ls\components\WritableValidator', 'forceDirectory' => true, 'recursive' => false, 'on' => ['required']], // Optional modules that Limesurvey can use. ['gdSupport', 'required', 'requiredValue' => true, 'on' => ['optional']], ['ldapSupport', 'required', 'requiredValue' => true, 'on' => ['optional']], diff --git a/protected/models/questions/ArrayByColumnQuestion.php b/protected/models/questions/ArrayByColumnQuestion.php index b0e1cd95256..e338a48e558 100644 --- a/protected/models/questions/ArrayByColumnQuestion.php +++ b/protected/models/questions/ArrayByColumnQuestion.php @@ -1,11 +1,4 @@ getExpressionManager(); foreach ($this->subQuestions as $subQuestion) { - $result[] = $field = new \QuestionResponseField($this->sgqa . $subQuestion->title, "{$this->title}_{$subQuestion->title}", $this); + $result[] = $field = new \ls\components\QuestionResponseField($this->sgqa . $subQuestion->title, "{$this->title}_{$subQuestion->title}", $this); $filter = strtr($this->filterExpression, ['{VALUE}' => explode('|', $subQuestion->question, 2)[0]]); diff --git a/protected/models/questions/DateTimeQuestion.php b/protected/models/questions/DateTimeQuestion.php index 5e146ed4496..75f3dcbd37f 100644 --- a/protected/models/questions/DateTimeQuestion.php +++ b/protected/models/questions/DateTimeQuestion.php @@ -1,11 +1,4 @@ setHtml(\TbHtml::dateField($this->sgqa, $response->{$this->sgqa})); diff --git a/protected/models/questions/DisplayQuestion.php b/protected/models/questions/DisplayQuestion.php index 4a595d421a8..a5f19b55756 100644 --- a/protected/models/questions/DisplayQuestion.php +++ b/protected/models/questions/DisplayQuestion.php @@ -1,11 +1,4 @@ setHtml(' '); diff --git a/protected/models/questions/DropDownListQuestion.php b/protected/models/questions/DropDownListQuestion.php index 5b204660ef1..ba79f163286 100644 --- a/protected/models/questions/DropDownListQuestion.php +++ b/protected/models/questions/DropDownListQuestion.php @@ -1,11 +1,4 @@ setHtml(" "); diff --git a/protected/models/questions/FivePointArrayQuestion.php b/protected/models/questions/FivePointArrayQuestion.php index e47ef14dfd0..a75cbe2f085 100644 --- a/protected/models/questions/FivePointArrayQuestion.php +++ b/protected/models/questions/FivePointArrayQuestion.php @@ -1,11 +1,4 @@ bool_mandatory && $this->survey->bool_shownoanswer) { - $answers[] = new \QuestionAnswer("", gT("No answer")); + $answers[] = new \ls\components\QuestionAnswer("", gT("No answer")); } return $answers; } /** * @param null $scale - * @return \QuestionAnswer[] + * @return \ls\components\QuestionAnswer[] */ public function getAnswers($scale = null) { diff --git a/protected/models/questions/FivePointChoiceQuestion.php b/protected/models/questions/FivePointChoiceQuestion.php index a7b595541bc..a08f4a1eac9 100644 --- a/protected/models/questions/FivePointChoiceQuestion.php +++ b/protected/models/questions/FivePointChoiceQuestion.php @@ -1,11 +1,4 @@ bool_mandatory && $this->survey->bool_shownoanswer) { - $result[] = new \QuestionAnswer("", gT("No answer")); + $result[] = new \ls\components\QuestionAnswer("", gT("No answer")); } return $answers; } @@ -47,10 +40,10 @@ public function getClasses() * It MUST NOT produce any output. * It should return a string or an object that can be converted to string. * @param \ls\interfaces\Response $response - * @param \SurveySession $session + * @param \ls\components\SurveySession $session * @return string */ - public function render(iResponse$response, \SurveySession $session) + public function render(iResponse$response, \ls\components\SurveySession $session) { $result = parent::render($response, $session); diff --git a/protected/models/questions/FixedArrayQuestion.php b/protected/models/questions/FixedArrayQuestion.php index 75c0742a5a6..829e12af35e 100644 --- a/protected/models/questions/FixedArrayQuestion.php +++ b/protected/models/questions/FixedArrayQuestion.php @@ -1,11 +1,4 @@ sgqa, $response->{$this->sgqa}, \TbHtml::listData($this->getAnswers(), function(iAnswer $answer) { diff --git a/protected/models/questions/GenderQuestion.php b/protected/models/questions/GenderQuestion.php index ea872e74c74..6a2e34dba7f 100644 --- a/protected/models/questions/GenderQuestion.php +++ b/protected/models/questions/GenderQuestion.php @@ -1,11 +1,4 @@ bool_mandatory) { - $result[] = new \QuestionAnswer('', gT('No answer')); + $result[] = new \ls\components\QuestionAnswer('', gT('No answer')); } return $result; diff --git a/protected/models/questions/HugeTextQuestion.php b/protected/models/questions/HugeTextQuestion.php index 9d05228e585..a61d2edd790 100644 --- a/protected/models/questions/HugeTextQuestion.php +++ b/protected/models/questions/HugeTextQuestion.php @@ -1,11 +1,4 @@ text_input_width)) { $this->text_input_width = 70; diff --git a/protected/models/questions/IncreaseSameDecreaseArrayQuestion.php b/protected/models/questions/IncreaseSameDecreaseArrayQuestion.php index 6233e6f8a10..a6740c54c96 100644 --- a/protected/models/questions/IncreaseSameDecreaseArrayQuestion.php +++ b/protected/models/questions/IncreaseSameDecreaseArrayQuestion.php @@ -1,11 +1,4 @@ bool_mandatory) { - $result[] = new \QuestionAnswer('', gT('No answer')); + $result[] = new \ls\components\QuestionAnswer('', gT('No answer')); } return $result; diff --git a/protected/models/questions/LanguageQuestion.php b/protected/models/questions/LanguageQuestion.php index 060d5122bc8..bf509ce0ef9 100644 --- a/protected/models/questions/LanguageQuestion.php +++ b/protected/models/questions/LanguageQuestion.php @@ -1,14 +1,6 @@ survey->getAllLanguages()); } diff --git a/protected/models/questions/LongTextQuestion.php b/protected/models/questions/LongTextQuestion.php index e17392fd530..811015f14d9 100644 --- a/protected/models/questions/LongTextQuestion.php +++ b/protected/models/questions/LongTextQuestion.php @@ -1,14 +1,6 @@ subQuestions as $subQuestion) { - $result[] = $field = new \QuestionResponseField($this->sgqa . $subQuestion->title, "{$this->title}_{$subQuestion->title}", $this); + $result[] = $field = new \ls\components\QuestionResponseField($this->sgqa . $subQuestion->title, "{$this->title}_{$subQuestion->title}", $this); /** * @todo Include subquestion relevance. */ @@ -86,10 +86,10 @@ public function getFields() { * It MUST NOT produce any output. * It should return a string or an object that can be converted to string. * @param \ls\interfaces\Response $response - * @param \SurveySession $session - * @return \RenderedQuestion + * @param \ls\components\SurveySession $session + * @return \ls\components\RenderedQuestion */ - public function render(iResponse $response, \SurveySession $session) + public function render(iResponse $response, \ls\components\SurveySession $session) { $result = parent::render($response, $session); @@ -105,7 +105,7 @@ public function render(iResponse $response, \SurveySession $session) return $result; } - public function renderSubQuestion(\Question $question, iResponse $response, \SurveySession $session) { + public function renderSubQuestion(\Question $question, iResponse $response, \ls\components\SurveySession $session) { // Render a line in the multiple choice question. $result = ''; $field = $this->sgqa . $question->title; diff --git a/protected/models/questions/MultipleChoiceWithCommentQuestion.php b/protected/models/questions/MultipleChoiceWithCommentQuestion.php index f3ac2a2d8d6..23cf81fcd0f 100644 --- a/protected/models/questions/MultipleChoiceWithCommentQuestion.php +++ b/protected/models/questions/MultipleChoiceWithCommentQuestion.php @@ -57,7 +57,7 @@ public function getClasses() } - public function renderSubQuestion(\Question $question, iResponse $response, \SurveySession $session) { + public function renderSubQuestion(\Question $question, iResponse $response, \ls\components\SurveySession $session) { $result = parent::renderSubQuestion($question, $response, $session); // Render a line in the multiple choice question. diff --git a/protected/models/questions/MultipleNumberQuestion.php b/protected/models/questions/MultipleNumberQuestion.php index e7df3bbed42..3412d7628f9 100644 --- a/protected/models/questions/MultipleNumberQuestion.php +++ b/protected/models/questions/MultipleNumberQuestion.php @@ -1,14 +1,6 @@ subQuestions as $subQuestion) { - $fields[] = $field = new \QuestionResponseField($this->sgqa . $subQuestion->title, "{$this->title}_{$subQuestion->title}", $this); + $fields[] = $field = new \ls\components\QuestionResponseField($this->sgqa . $subQuestion->title, "{$this->title}_{$subQuestion->title}", $this); $field->setRelevanceScript($this->getRelevanceScript() . ' && ' .$subQuestion->getRelevanceScript()); } @@ -61,10 +53,10 @@ public function getClasses() * It MUST NOT produce any output. * It should return a string or an object that can be converted to string. * @param \ls\interfaces\Response $response - * @param \SurveySession $session - * @return \RenderedQuestion + * @param \ls\components\SurveySession $session + * @return \ls\components\RenderedQuestion */ - public function render(\ls\interfaces\iResponse $response, \SurveySession $session) + public function render(\ls\interfaces\iResponse $response, \ls\components\SurveySession $session) { $result = parent::render($response, $session); $html =''; @@ -79,7 +71,7 @@ public function render(\ls\interfaces\iResponse $response, \SurveySession $sessi return $result; } - public function renderSubQuestion(\Question $question, \ls\interfaces\iResponse $response, \SurveySession $session) { + public function renderSubQuestion(\Question $question, \ls\interfaces\iResponse $response, \ls\components\SurveySession $session) { $extraclass =""; diff --git a/protected/models/questions/NumericalArrayQuestion.php b/protected/models/questions/NumericalArrayQuestion.php index eabf582abff..a5382dc1efc 100644 --- a/protected/models/questions/NumericalArrayQuestion.php +++ b/protected/models/questions/NumericalArrayQuestion.php @@ -1,14 +1,6 @@ _fields[] = $field = new \QuestionResponseField("{$this->sgqa}{$yQuestion->title}_{$xQuestion->title}", "{$this->title}_{$yQuestion->title}_{$xQuestion->title}", $this); + $this->_fields[] = $field = new \ls\components\QuestionResponseField("{$this->sgqa}{$yQuestion->title}_{$xQuestion->title}", "{$this->title}_{$yQuestion->title}_{$xQuestion->title}", $this); $field->setRelevanceScript('true'); } } diff --git a/protected/models/questions/RadioListQuestion.php b/protected/models/questions/RadioListQuestion.php index 49ac582d83c..141f6d5a80a 100644 --- a/protected/models/questions/RadioListQuestion.php +++ b/protected/models/questions/RadioListQuestion.php @@ -1,14 +1,6 @@ answers); $i++) { - $result[] = new \SubQuestion("{$this->title}$i", $i); + $result[] = new \ls\components\SubQuestion("{$this->title}$i", $i); } return $result; } @@ -63,7 +63,7 @@ public function getFields() { $result = []; for ($i = 1; $i <= count($this->answers); $i++) { - $result[] = $field = new \QuestionResponseField($this->sgqa . $i, "{$this->title}_{$i}", $this); + $result[] = $field = new \ls\components\QuestionResponseField($this->sgqa . $i, "{$this->title}_{$i}", $this); $field->setRelevanceScript($this->getRelevanceScript()); } return $result; @@ -87,10 +87,10 @@ public function getClasses() * It MUST NOT produce any output. * It should return a string or an object that can be converted to string. * @param \ls\interfaces\Response $response - * @param \SurveySession $session - * @return \RenderedQuestion + * @param \ls\components\SurveySession $session + * @return \ls\components\RenderedQuestion */ - public function render(\ls\interfaces\iResponse $response, \SurveySession $session) + public function render(\ls\interfaces\iResponse $response, \ls\components\SurveySession $session) { $result = parent::render($response, $session); $imageurl = App()->getConfig("imageurl"); diff --git a/protected/models/questions/ShortTextQuestion.php b/protected/models/questions/ShortTextQuestion.php index 5e474eefb9f..96de4fc1927 100644 --- a/protected/models/questions/ShortTextQuestion.php +++ b/protected/models/questions/ShortTextQuestion.php @@ -1,14 +1,7 @@ setHtml('TODO'); diff --git a/protected/models/questions/SingleChoiceWithCommentQuestion.php b/protected/models/questions/SingleChoiceWithCommentQuestion.php index b1ceab674d2..cef35e42f81 100644 --- a/protected/models/questions/SingleChoiceWithCommentQuestion.php +++ b/protected/models/questions/SingleChoiceWithCommentQuestion.php @@ -20,7 +20,7 @@ public function getFields() { bP(); $result = parent::getFields(); - $result[$this->sgqa . 'other'] = new \QuestionResponseField($this->sgqa . 'comment', $this->title . 'comment', $this); + $result[$this->sgqa . 'other'] = new \ls\components\QuestionResponseField($this->sgqa . 'comment', $this->title . 'comment', $this); eP(); return $result; diff --git a/protected/models/questions/SubQuestion.php b/protected/models/questions/SubQuestion.php index 5b574fdf080..7e6deac9c4c 100644 --- a/protected/models/questions/SubQuestion.php +++ b/protected/models/questions/SubQuestion.php @@ -1,14 +1,6 @@ sgqa . '_filecount', $this->title . '_filecount', $this); + $result[] = $field = new \ls\components\QuestionResponseField($this->sgqa . '_filecount', $this->title . '_filecount', $this); $field->setRelevanceScript($this->getRelevanceScript()); return $result; @@ -42,10 +34,10 @@ public function getClasses() * It MUST NOT produce any output. * It should return a string or an object that can be converted to string. * @param \ls\interfaces\Response $response - * @param \SurveySession $session - * @return \RenderedQuestion + * @param \ls\components\SurveySession $session + * @return \ls\components\RenderedQuestion */ - public function render(\ls\interfaces\iResponse $response, \SurveySession $session) + public function render(\ls\interfaces\iResponse $response, \ls\components\SurveySession $session) { $result = parent::render($response, $session); diff --git a/protected/models/questions/YesNoQuestion.php b/protected/models/questions/YesNoQuestion.php index cd65fa1dbcb..86a09d6ac9b 100644 --- a/protected/models/questions/YesNoQuestion.php +++ b/protected/models/questions/YesNoQuestion.php @@ -1,14 +1,6 @@ bool_mandatory) { - $result[] = new \QuestionAnswer("", gT('No answer')); + $result[] = new \ls\components\QuestionAnswer("", gT('No answer')); } return $result; diff --git a/protected/models/questions/YesNoUncertainArrayQuestion.php b/protected/models/questions/YesNoUncertainArrayQuestion.php index f9042ca4a0a..73fce3e9a14 100644 --- a/protected/models/questions/YesNoUncertainArrayQuestion.php +++ b/protected/models/questions/YesNoUncertainArrayQuestion.php @@ -1,14 +1,6 @@ bool_mandatory) { - $result[] = new \QuestionAnswer('', gT('No answer')); + $result[] = new \ls\components\QuestionAnswer('', gT('No answer')); } return $result; diff --git a/protected/views/participants/import.php b/protected/views/participants/import.php index 607e87d5010..1e24614f0e8 100644 --- a/protected/views/participants/import.php +++ b/protected/views/participants/import.php @@ -40,7 +40,7 @@ ]); echo TbHtml::numberFieldControlGroup('batchSize', 5000, [ - 'label' => gT("Batch size for uploading"), + 'label' => gT("ls\components\Batch size for uploading"), 'required' => true, 'formLayout' => TbHtml::FORM_LAYOUT_HORIZONTAL, 'labelWidthClass' => 'col-sm-6', @@ -49,7 +49,7 @@ ]); echo TbHtml::numberFieldControlGroup('querySize', 2500, [ - 'label' => gT("Batch size for queries"), + 'label' => gT("ls\components\Batch size for queries"), 'required' => true, 'formLayout' => TbHtml::FORM_LAYOUT_HORIZONTAL, 'labelWidthClass' => 'col-sm-6', diff --git a/protected/views/surveys/execute/run.php b/protected/views/surveys/execute/run.php index 3debab7677a..e803ba26b08 100644 --- a/protected/views/surveys/execute/run.php +++ b/protected/views/surveys/execute/run.php @@ -1,5 +1,7 @@ render(); diff --git a/public/scripts/timers.js b/public/scripts/timers.js index e881fa4d334..39f5ca729f9 100644 --- a/public/scripts/timers.js +++ b/public/scripts/timers.js @@ -1,5 +1,4 @@ /** - * Created by sam on 9/16/15. * This file implements unobtrusive time limits for questions. * * @todo Include this somewhere and decide what actions we still need to implement: diff --git a/public/scripts/unobtrusive.js b/public/scripts/unobtrusive.js index 0e1b4be7a26..2a4f5d893d0 100644 --- a/public/scripts/unobtrusive.js +++ b/public/scripts/unobtrusive.js @@ -1,6 +1,5 @@ /** * This file adds support for unobtrusive javascript. - * Created by sam on 6/16/15. */ (function($) {