Skip to content

Commit

Permalink
Dev Added logo for plugins.
Browse files Browse the repository at this point in the history
Dev Enabled plugin output in survey completion page.
  • Loading branch information
SamMousa committed Feb 8, 2013
1 parent 10dc1ff commit a054de6
Show file tree
Hide file tree
Showing 23 changed files with 399 additions and 202 deletions.
57 changes: 3 additions & 54 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,6 @@

class ConfigController extends LSYii_Controller {

public function __construct($id, $module = null)
{
parent::__construct($id, $module);
}

public function init()
{
parent::init();
$this->_sessioncontrol();
Yii::app()->setConfig('adminimageurl', Yii::app()->getConfig('styleurl') . Yii::app()->getConfig('admintheme') . '/images/');
Yii::app()->setConfig('adminstyleurl', Yii::app()->getConfig('styleurl') . Yii::app()->getConfig('admintheme') . '/');
}

/**
* Load and set session vars
* (copied from admincontroller)
*
* @access protected
* @return void
*/
protected function _sessioncontrol()
{
Yii::import('application.libraries.Limesurvey_lang');
// From personal settings
if (Yii::app()->request->getPost('action') == 'savepersonalsettings')
{
if (Yii::app()->request->getPost('lang') == 'auto')
{
$sLanguage = getBrowserLanguage();
} else
{
$sLanguage = Yii::app()->request->getPost('lang');
}
Yii::app()->session['adminlang'] = $sLanguage;
}

if (empty(Yii::app()->session['adminlang']))
Yii::app()->session["adminlang"] = Yii::app()->getConfig("defaultlang");

Yii::app()->setLang(new Limesurvey_lang(Yii::app()->session['adminlang']));

if (!empty($this->user_id))
$this->_GetSessionUserRights($this->user_id);
}

public function actionScript()
{
// Retrieve config options that should be available in JS.
Expand All @@ -60,19 +15,13 @@ public function actionScript()
$data[$option] = Yii::app()->getConfig($option);
}
$data['baseUrl'] = Yii::app()->getBaseUrl(true);
$data['showScriptName'] = Yii::app()->urlManager->showScriptName;
$data['urlFormat'] = Yii::app()->urlManager->urlFormat;
$data['layoutPath'] = Yii::app()->getLayoutPath();
$data['adminImageUrl'] = Yii::app()->getConfig('adminimageurl');

$this->layout = false;
$this->render('/js', compact('data'));
$this->render('/config/script', compact('data'));
}

public function beforeRender($view)
{
return parent::beforeRender($view);
}




}
61 changes: 61 additions & 0 deletions application/controllers/QuestionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* @todo Add proper security for this controller.
*/

class QuestionsController extends LSYii_Controller
{
/**
* Creates a new question object.
*/
public function actionCreate()
{
$question = new Questions();


if ($_POST['position'] == 'last')
{
$cmd = App()->db->createCommand();
$cmd->select(array('max(question_order) as max'));
$cmd->from(Questions::model()->tableName());
$cmd->where('sid = :sid', array('sid' =>$_POST['sid']));
$maxPosition = intval($cmd->queryScalar());
$question->question_order = $maxPosition + 1;
}
elseif ($_POST['position'] == 'first')
{
// We save the new question with order 0.
// After saving we will increase all ordering numbers by 1.
$question->question_order = 0;
}
else
{
$question->question_order = intval($_POST['position']) + 1;
}

$question->title = $_POST['title'];
$question->relevance = $_POST['relevance'];
$question->questiontype_id = $_POST['type'];
$question->sid = $_POST['sid'];
$question->gid = $_POST['gid'];


$attributes = $_POST;
unset($attributes['sid'], $attributes['gid'], $attributes['relevance'], $attributes['type'], $attributes['title'], $attributes['position']);
if (true || $question->save())
{
// @var $question iQuestion

echo '<pre>';
$questionObject = tidToQuestion($_POST['type']);
$questionObject->saveAttributes($question->qid, $attributes);
//$question->save();

echo '</pre>';
die();
}
}
}

?>
2 changes: 1 addition & 1 deletion application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ function index($sa = null)
} else {
$q = tidToQuestion(Yii::app()->request->getPost('type'));
$aLanguages=array_merge(array(Survey::model()->findByPk($surveyid)->language),Survey::model()->findByPk($surveyid)->additionalLanguages);

var_dump($_POST);
foreach ($q->availableAttributes() as $validAttribute)
{
if ($validAttribute['i18n'])
Expand Down
36 changes: 32 additions & 4 deletions application/controllers/admin/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,17 @@ public function index($sa, $surveyid, $gid, $qid=null)
if ($adding)
{
$oqresult = Questions::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $baselang, 'parent_qid'=> 0), array('order' => 'question_order'));


$aData['oqresult'] = $oqresult;
$questionOrderList = array(
'first' => $clang->gT("At beginning")
);
foreach ($oqresult as $oqr)
{
$questionOrderList[$oqr->attributes['question_order']] = $clang->gT('After:') . ' '. $oqr->attributes['title'];

}
// Change text of last entry.
$questionOrderList['last'] = $clang->gT("At end");
$aData['questionOrderList'] = $questionOrderList;
}
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . 'questions.js');

Expand Down Expand Up @@ -951,7 +959,27 @@ public function ajaxLocalizedAttributes()

);
$q = tidToQuestion($_REQUEST['questionType_id'], $data);
$settings = $q->getAttributes();
if ($q instanceof iQuestion)
{
$settings = $q->getAttributes();
}
else
{
// Static localized settings for "old" question objects.
$settings = array(
'question' => array(
'type' => 'html',
'localized' => 'true',
'label' => 'Question:'
),
'help' => array(
'type' => 'html',
'localized' => 'true',
'label' => 'Help:'
),

);
}
$localized = true;
$aLanguages = array_merge(array(Survey::model()->findByPk($surveyId)->language), Survey::model()->findByPk($surveyId)->additionalLanguages);
$language = $_REQUEST['language'];
Expand Down
39 changes: 31 additions & 8 deletions application/helpers/PluginSettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ class PluginSettingsHelper

public function renderSetting($name, array $metaData, $form = null, $return = false)
{
$defaults = array(
'class' => array(),
'type' => 'string'
);
$metaData = array_merge($defaults, $metaData);
if (is_string($metaData['class']))
{
$metaData['class'] = array($metaData['class']);
}
if (isset($metaData['type']))
{
$function = "render{$metaData['type']}";
if (isset($metaData['localized']) && $metaData['localized'] == true)
{
$name = "{$name}_{$metaData['language']}";
$name = "{$name}[{$metaData['language']}]";
}
$result = $this->$function($name, $metaData, $form);
if ($return)
Expand Down Expand Up @@ -65,8 +74,19 @@ public function renderFloat($name, array $metaData, $form = null)

public function renderHtml($name, array $metaData, $form = null)
{
return $this->renderString($name, $metaData, $form);
$out = '';
$id = $name;
$value = isset($metaData['current']) ? $metaData['current'] : '';
$metaData['class'][] = 'htmleditor';
$readOnly = isset($metaData['readOnly']) ? $metaData['readOnly'] : false;
if (isset($metaData['label']))
{
$out .= CHtml::label($metaData['label'], $id);
}
$out .= Chtml::tag('div', array('class' => implode(' ', $metaData['class'])), CHtml::textArea($id, $value, array('id' => $id, 'form' => $form, 'readonly' => $readOnly)));
return $out;
}

public function renderInt($name, array $metaData, $form = null)
{
$out = '';
Expand All @@ -85,20 +105,24 @@ public function renderInt($name, array $metaData, $form = null)
return $out;
}

public function renderLogo($name, array $metaData)
{
return CHtml::image($metaData['path']);
}
public function renderRelevance($name, array $metaData, $form = null)
{
$out = '';
$metaData['class'] = 'relevance';
$metaData['class'][] = 'relevance';
$id = $name;
$class = isset($metaData['class']) ? $metaData['class'] : '';


if (isset($metaData['label']))
{
$out .= CHtml::label($metaData['label'], $id);
}
$value = isset($metaData['current']) ? $metaData['current'] : '';

$out .= CHtml::textArea($name, $value, array('id' => $id, 'form' => $form, 'class' => $class));
$out .= CHtml::textArea($name, $value, array('id' => $id, 'form' => $form, 'class' => implode(' ', $metaData['class'])));

return $out;
}
Expand All @@ -112,7 +136,7 @@ public function renderSelect($name, array $metaData, $form = null)
{
$out .= CHtml::label($metaData['label'], $id);
}
$out .= CHtml::dropDownList($name, $metaData['current'], $metaData['options']);
$out .= CHtml::dropDownList($name, $metaData['current'], $metaData['options'], array('form' => $form));

return $out;
}
Expand All @@ -122,13 +146,12 @@ public function renderString($name, array $metaData, $form = null)
$out = '';
$id = $name;
$value = isset($metaData['current']) ? $metaData['current'] : '';
$class = isset($metaData['class']) ? $metaData['class'] : '';
$readOnly = isset($metaData['readOnly']) ? $metaData['readOnly'] : false;
if (isset($metaData['label']))
{
$out .= CHtml::label($metaData['label'], $id);
}
$out .= CHtml::textField($id, $value, array('id' => $id, 'form' => $form, 'class' => $class, 'readonly' => $readOnly));
$out .= CHtml::textField($id, $value, array('id' => $id, 'form' => $form, 'class' => implode(' ', $metaData['class']), 'readonly' => $readOnly));

return $out;
}
Expand Down
24 changes: 24 additions & 0 deletions application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,30 @@ function run($surveyid,$args) {
echo $content;
}
$redata['completed'] = $completed;

// @todo Remove direct session access.
$event = new PluginEvent('afterSurveyCompleted');
$event->set('responseId', $_SESSION[$LEMsessid]['srid']);
$event->set('surveyId', $surveyid);
App()->getPluginManager()->dispatchEvent($event);
if ($event->get('blocks', null) != null)
{
$blocks = array();
foreach ($event->get('blocks') as $blockData)
{

$defaults = array(
'class' => array('pluginblock'),
'contents' => '',
'id' => ''
);
$blockData = array_merge($defaults, $blockData);
$blocks[] = CHtml::tag('div', array('id' => $blockData['id'], 'class' => implode(' ', $blockData['class'])), $blockData['contents']);
}
}
$redata['completed'] = implode("\n", $blocks) ."\n". $redata['completed'];


echo templatereplace(file_get_contents($sTemplatePath."completed.pstpl"), array('completed' => $completed), $redata);
echo "\n<br />\n";
if ((($LEMdebugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING))
Expand Down
9 changes: 0 additions & 9 deletions application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3818,15 +3818,6 @@ private function _UpdateValuesInDatabase($updatedValues, $finished=false)
$message .= $query;
}
}
if ($finished)
{
// @todo Remove direct session access.
$event = new PluginEvent('afterSurveyCompleted');
$event->set('responseId', $_SESSION[$this->sessid]['srid']);
$event->set('surveyId', $this->sid);
App()->getPluginManager()->dispatchEvent($event);
$message = 'test123';
}
return $message;
}

Expand Down
41 changes: 41 additions & 0 deletions application/libraries/PluginManager/EventDocumentor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* This file will scan all files in the project and output an array with event names.
*/
$basePath = dirname(dirname(dirname(__FILE__)));

$i = new RecursiveDirectoryIterator($basePath);
$i2 = new RecursiveIteratorIterator($i);
$events = array();


foreach ($i2 as $file)
{
/* @var $file SplFileInfo */


if (substr($file->getFileName(), -3, 3) == 'php')
{
scanFile($file->getPathname());
}
}

$events = array_unique($events);
sort($events);
print_r($events);

function scanFile($fileName)
{
global $events;
$contents = file_get_contents($fileName);

$regex = '/(\$[[:alnum:]]*)[[:space:]]*=[[:space:]]*new[[:space:]]*PluginEvent[[:space:]]*\([[:space:]]*[\'"]+(.*)[\'"]+/';

$count = preg_match_all($regex, $contents, $matches);
if ($count > 0)
{
$events = array_merge($events, $matches[2]);
}
}

?>
Loading

0 comments on commit a054de6

Please sign in to comment.