Skip to content

Commit

Permalink
Dev First working version of custom relevance.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Apr 24, 2013
1 parent edd2049 commit c907f90
Show file tree
Hide file tree
Showing 33 changed files with 3,120 additions and 427 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -2,7 +2,7 @@
/upload/surveys/*
/styles/gringegreen/images/Thumbs.db
/upload/templates/*
/tmp/runtime/HTML
/tmp/runtime/*
/application/controllers/admin/updater.php
/tmp/*.html
/tmp/*.lss
Expand Down
8 changes: 7 additions & 1 deletion application/config/internal.php
Expand Up @@ -10,14 +10,20 @@
'runtimePath' => dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'runtime',
'name' => 'LimeSurvey',
'defaultController' => 'survey',

'theme' => 'default',
'import' => array(
'application.core.*',
'application.models.*',
'application.controllers.*',
'application.modules.*',
),
'preload' => array(
'limescript'
),
'components' => array(
'limescript' => array(
'class' => 'ext.LimeScript.LimeScript'
),
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap',
'responsiveCss' => false,
Expand Down
59 changes: 58 additions & 1 deletion application/controllers/GroupsController.php
Expand Up @@ -11,6 +11,8 @@ public function actionPreview($id, $language = 'en')
$renderedQuestions = array();
if (isset($group))
{
App()->getSurveySession()->create($group->sid, true);


if (!isset($language))
{
Expand All @@ -21,15 +23,70 @@ public function actionPreview($id, $language = 'en')
'gid' => $id,
'parent_id' => null
));
Yii::import('ext.ExpressionManager.ExpressionManager');
$em = new ExpressionManager(array(
'isValidVariable' => function($name) {
//echo 'isvalid:<br>'; var_dump($name);
return true;
},
'GetVarAttribute' => function($name, $attr, $default) {
//echo 'getattr:<br>'; var_dump(func_get_args());
switch ($attr) {
case 'code': return $name;
case 'jsName' : return 'JS' . $name;
default: return $default;
}
}

));

$renderedQuestions = array();
$data = array();
$i = 0;
foreach ($questions as $question)
{
$questionObject = App()->getPluginManager()->constructQuestionFromGUID($question->questiontype, $question->qid);
$renderedQuestions[] = $questionObject->render("{$group->group_name}-{$question->qid}", $language, true);
if (!isset($data[$questionObject->getGUID()]))
{
$data[$questionObject->getGUID()] = $questionObject->getJavascript();
}
$name = "{$group->group_name}-{$question->qid}";
$renderedQuestions[] = $questionObject->render($name, $language, true);
App()->getLimeScript()->add("p.questions.{$question->code}.type", $questionObject->getGUID());
App()->getLimeScript()->add("p.questions.{$question->code}.div", "question$i");
// Register variables.
$code = $question->code;
// More variables shoudl be added here.
App()->getLimeScript()->add("p.VariableToCode.$code", $code);



App()->getLimeScript()->add("p.questions.{$question->code}.id", $name);
if ($question->relevance != null)
{
$em->ProcessBooleanExpression($question->relevance);
$js = $em->GetJavaScriptEquivalentOfExpression();
App()->getLimeScript()->add("p.questions.{$question->code}.relevanceStatus", new CJavaScriptExpression('function() { return ' . $js . '; }'));

}
foreach ($questionObject->getVariables() as $variable)
{
App()->getLimeScript()->add("p.VariableToCode.{$code}_{$variable}", $code);
}
$i++;
}
App()->getLimeScript()->add("p.QuestionTypes", $data);
}
$template = Survey::model()->findFieldByPk($group->sid, 'template');
$this->layout = 'survey';

/*
var_dump($em->ProcessBooleanExpression('q1 == 1'));
echo '---------------------';
var_dump($em->GetJavaScriptEquivalentOfExpression());
echo '---------------------';
var_dump($em->sProcessStringContainingExpressions('test123 {1+2}'));
*/
$this->render('/groups/preview', compact('renderedQuestions', 'template'));
}

Expand Down
6 changes: 6 additions & 0 deletions application/controllers/QuestionsController.php
Expand Up @@ -113,6 +113,7 @@ public function actionUpdate($id, $questiontype = null)
// Always redirect to prevent reloading from resubmitting.
$this->redirect(array($this->route, 'id' => $id));
}

/**
* @todo Add support for save & close button; in case of close redirect to overview page.
*/
Expand All @@ -121,8 +122,13 @@ public function actionUpdate($id, $questiontype = null)
$this->navData['surveyId'] = $question['sid'];
$this->navData['groupId'] = $question['gid'];
$this->navData['questionId'] = $id;


$survey = Survey::model()->findByPk($question['sid']);


$languages = $survey->getLanguages();

$groups = Groups::model()->findListByAttributes(array('sid' => $question['sid']), 'group_name');
$questions = Questions::model()->findListByAttributes(array('sid' => $question['sid']), 'code', null, array('order'=> 'sortorder'));
if (App()->request->getIsAjaxRequest())
Expand Down
12 changes: 10 additions & 2 deletions application/core/LSYii_Application.php
Expand Up @@ -109,7 +109,7 @@ public function __construct($config = null)

parent::__construct($config);
// Load the default and environmental settings from different files into self.

Yii::setPathOfAlias('bootstrap' , Yii::getPathOfAlias('ext.bootstrap'));
$ls_config = require(Yii::getPathOfAlias('application.config') . '/config-defaults.php');
$email_config = require(Yii::getPathOfAlias('application.config') . '/email.php');
$version_config = require(Yii::getPathOfAlias('application.config') . '/version.php');
Expand Down Expand Up @@ -253,7 +253,15 @@ public function setLang(Limesurvey_lang $lang)
{
$this->lang = $lang;
}


/**
* Get the script manager.
* @return LimeScript
*/
public function getLimeScript()
{
return $this->getComponent('limescript');
}
/**
* Get the pluginManager
*
Expand Down
2 changes: 1 addition & 1 deletion application/core/LSYii_Controller.php
Expand Up @@ -39,9 +39,9 @@ public function __construct($id, $module = null)
$this->loadHelper('common');
$this->loadHelper('survey');
$this->loadLibrary('limesurvey_lang');
$this->loadHelper('expressions.em_manager');
$this->loadHelper('replacements');
$this->_init();

}

/**
Expand Down

0 comments on commit c907f90

Please sign in to comment.