Skip to content

Commit

Permalink
Fixed issue: Default tutorials out of db and reset surveymenues to wo…
Browse files Browse the repository at this point in the history
…rk well with translations
  • Loading branch information
lacrioque committed Jan 23, 2018
1 parent 5838137 commit eabc4e7
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 1,708 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@


$config['versionnumber'] = '3.0.5'; //The current version of this branch, LS3
$config['dbversionnumber'] = 345;
$config['dbversionnumber'] = 346;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30008';
Expand Down
28 changes: 14 additions & 14 deletions application/controllers/admin/TutorialsController.php
Expand Up @@ -59,7 +59,7 @@ public function servertutorial()
$this->getController()->redirect(['/admin']);
}
$tutorialname = Yii::app()->request->getParam('tutorialname', '');
$model = Tutorials::model()->find('name=:name', [':name' => $tutorialname]);
$model = Tutorial::model()->findByName($tutorialname);
$aTutorialArray = $model->getTutorialDataArray($tutorialname);
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
Expand All @@ -79,13 +79,13 @@ public function servertutorial()
*/
public function create()
{
$model = new Tutorials;
$model = new Tutorial;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if (isset($_POST['Tutorials'])) {
$model->attributes = $_POST['Tutorials'];
if (isset($_POST['Tutorial'])) {
$model->attributes = $_POST['Tutorial'];
if ($model->save()) {
$this->redirect(array('view', 'id'=>$model->tid));
}
Expand All @@ -111,8 +111,8 @@ public function update($id)
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if (isset($_POST['Tutorials'])) {
$model->attributes = $_POST['Tutorials'];
if (isset($_POST['Tutorial'])) {
$model->attributes = $_POST['Tutorial'];
if ($model->save()) {
$this->redirect(array('view', 'id'=>$model->tid));
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public function delete($id)

public function triggerfinished($tid)
{
$oTutorial = Tutorials::model()->find($tid);
$oTutorial = Tutorial::model()->find($tid);
$oTutorial->setFinished(App()->user->id);
echo '{"success": true}';
}
Expand All @@ -158,7 +158,7 @@ public function view()
//$this->checkPermission();

$data = array();
$data['model'] = Tutorials::model();
$data['model'] = Tutorial::model();
//App()->getClientScript()->registerPackage('surveymenufunctions');
$this->_renderWrappedTemplate(null, array('tutorials/index'), $data);
}
Expand All @@ -168,10 +168,10 @@ public function view()
*/
public function admin()
{
$model = new Tutorials('search');
$model = new Tutorial('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Tutorials'])) {
$model->attributes = $_GET['Tutorials'];
if (isset($_GET['Tutorial'])) {
$model->attributes = $_GET['Tutorial'];
}

$this->render(
Expand All @@ -186,12 +186,12 @@ public function admin()
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Tutorials the loaded model
* @return Tutorial the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = Tutorials::model()->findByPk($id);
$model = Tutorial::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
Expand All @@ -200,7 +200,7 @@ public function loadModel($id)

/**
* Performs the AJAX validation.
* @param Tutorials $model the model to be validated
* @param Tutorial $model the model to be validated
*/
protected function performAjaxValidation($model)
{
Expand Down
35 changes: 23 additions & 12 deletions application/core/LsDefaultDataSets.php

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions application/helpers/common_helper.php
Expand Up @@ -909,16 +909,13 @@ function getSurveyInfo($surveyid, $languagecode = '')
*/
function templateDefaultTexts($sLanguage, $mode = 'html', $sNewlines = 'text')
{
$sOldLanguage = App()->language;
App()->setLanguage($sLanguage);


$aDefaultTexts = LsDefaultDataSets::getTemplateDefaultTexts($mode);

if ($sNewlines == 'html') {
$aDefaultTexts = array_map('nl2br', $aDefaultTexts);
}

App()->setLanguage($sOldLanguage);

return $aDefaultTexts;
}

Expand Down
1,680 changes: 70 additions & 1,610 deletions application/helpers/update/updatedb_helper.php

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions application/models/Surveymenu.php
Expand Up @@ -333,9 +333,7 @@ public function onAfterSave($event)
*/
public function restoreDefaults()
{
$sOldLanguage = App()->language;
App()->setLanguage('en');


$oDB = Yii::app()->db;
$oTransaction = $oDB->beginTransaction();
try {
Expand All @@ -350,8 +348,6 @@ public function restoreDefaults()
App()->setLanguage($sOldLanguage);
return false;
}

App()->setLanguage($sOldLanguage);
return true;
}

Expand Down
5 changes: 1 addition & 4 deletions application/models/SurveymenuEntries.php
Expand Up @@ -508,8 +508,7 @@ public function search()
*/
public function restoreDefaults()
{
$sOldLanguage = App()->language;
App()->setLanguage('en');

$oDB = Yii::app()->db;
$oTransaction = $oDB->beginTransaction();
try {
Expand All @@ -524,12 +523,10 @@ public function restoreDefaults()
$oTransaction->commit();

} catch (Exception $e) {
App()->setLanguage($sOldLanguage);
throw $e;
return false;
}

App()->setLanguage($sOldLanguage);
return true;
}

Expand Down
Expand Up @@ -16,7 +16,7 @@
* The followings are the available model relations:
* @property TutorialEntry[] $tutorialEntries
*/
class Tutorials extends LSActiveRecord
class Tutorial extends LSActiveRecord
{

/**
Expand Down Expand Up @@ -137,9 +137,36 @@ public function search()
));
}

public function findByName($tutorialName){
$defaultTutorials = LsDefaultDataSets::getTutorialData();
if(array_key_exists($tutorialName, $defaultTutorials)){
$oTutorial = new Tutorial();
$oTutorial->setAttributes($defaultTutorials[$tutorialName]);
return $oTutorial;
}
$tutorial = $this->find('name=:name', [':name' => $tutorialName]);
}

public function getDefaultTutorials()
{
$aDefaultTutorials = LsDefaultDataSets::getTutorialData();
$result = [];
foreach( $aDefaultTutorials as $aDefaultTutorial){
$oTutorial = new Tutorial();
$oTutorial->setAttributes($aDefaultTutorial);
$result[] = $oTutorial;
}
return $result;
}

public function getActiveTutorials()
{
return self::model()->findAll('active=1');
$aTutorials = self::model()->findAll('active=1');
if(!empty($aTutorials)){
return array_merge($aTutorials, $this->getDefaultTutorials());
}

return $this->getDefaultTutorials();
}

public function setFinished($iUserId)
Expand All @@ -157,13 +184,22 @@ public function setFinished($iUserId)

public function getTutorialDataArray($tutorialName)
{

if ($this->tid === null) { return []; }
$aTutorialEntryRelations = TutorialEntryRelation::model()->findAll('tid=:tid', [':tid'=>$this->tid]);
$aSteps = [];
foreach ($aTutorialEntryRelations as $oTutorialMapEntry) {
$oTutorialEntry = $oTutorialMapEntry->tutorialEntry;
$aSteps[] = $oTutorialEntry->getStepFromEntry();

if ($this->tid === null) {
$defaultEntries = LsDefaultDataSets::getTutorialEntryData();
$this->tid = $tutorialName;
foreach ($defaultEntries[$tutorialName] as $aTutorialMapEntry) {
$oTutorialEntry = new TutorialEntry();
$oTutorialEntry->setAttributes($aTutorialMapEntry, false);
$aSteps[] = $oTutorialEntry->getStepFromEntry();
}
} else {
$aTutorialEntryRelations = TutorialEntryRelation::model()->findAll('tid=:tid', [':tid'=>$this->tid]);
foreach ($aTutorialEntryRelations as $oTutorialMapEntry) {
$oTutorialEntry = $oTutorialMapEntry->tutorialEntry;
$aSteps[] = $oTutorialEntry->getStepFromEntry();
}
}

$aTutorialData = json_decode($this->settings, true);
Expand All @@ -177,11 +213,11 @@ public function getTutorialDataArray($tutorialName)
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Tutorials the static model class
* @return Tutorial the static model class
*/
public static function model($className = __CLASS__)
{
/** @var Tutorials $model */
/** @var Tutorial $model */
$model = parent::model($className);
return $model;
}
Expand Down
2 changes: 1 addition & 1 deletion application/models/TutorialEntry.php
Expand Up @@ -11,7 +11,7 @@
* @property string $settings
*
* The followings are the available model relations:
* @property Tutorials $t
* @property Tutorial $t
*/
class TutorialEntry extends LSActiveRecord
{
Expand Down
2 changes: 1 addition & 1 deletion application/models/TutorialEntryRelation.php
Expand Up @@ -43,7 +43,7 @@ public function relations()
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'tutorials' => array(self::HAS_ONE, 'Tutorials', 'tid', 'together' => true),
'tutorials' => array(self::HAS_ONE, 'Tutorial', 'tid', 'together' => true),
'tutorialEntry' => array(self::HAS_ONE, 'TutorialEntry', 'teid', 'order'=>'ordering ASC', 'together' => true),
);
}
Expand Down
11 changes: 8 additions & 3 deletions application/views/admin/super/_tutorial_menu.php
@@ -1,20 +1,25 @@
<?php
$aTutorials = Tutorials::model()->getActiveTutorials();
$aTutorials = Tutorial::model()->getActiveTutorials();

?>

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-rocket" ></span>
<?php eT('Tutorials');?>
<?php eT('Tutorial');?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu " id="tutorials-dropdown">
<?php foreach($aTutorials as $oTutorial) { ?>
<li>
<a href="#" onclick="window.tourLibrary.triggerTourStart('<?=$oTutorial->name?>')">
<i class="fa <?=$oTutorial->icon?>"></i>&nbsp;<?=gT($oTutorial->title)?>
<i class="fa <?=$oTutorial->icon?>"></i>&nbsp;<?=$oTutorial->title?>
</a>
</li>
<?php } ?>
</ul>
</li>

<script>
console.log(<?=json_encode( array_map(function($tut){return $tut->attributes;}, $aTutorials) )?>);
</script>
2 changes: 1 addition & 1 deletion application/views/admin/tutorials/_form.php
@@ -1,6 +1,6 @@
<?php
/* @var $this TutorialsController */
/* @var $model Tutorials */
/* @var $model Tutorial */
/* @var $form CActiveForm */
?>

Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/tutorials/_search.php
@@ -1,6 +1,6 @@
<?php
/* @var $this TutorialsController */
/* @var $model Tutorials */
/* @var $model Tutorial */
/* @var $form CActiveForm */
?>

Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/tutorials/_view.php
@@ -1,6 +1,6 @@
<?php
/* @var $this TutorialsController */
/* @var $data Tutorials */
/* @var $data Tutorial */
?>

<div class="view">
Expand Down
10 changes: 5 additions & 5 deletions application/views/admin/tutorials/admin.php
@@ -1,15 +1,15 @@
<?php
/* @var $this TutorialsController */
/* @var $model Tutorials */
/* @var $model Tutorial */

$this->breadcrumbs=array(
'Tutorials'=>array('index'),
'Tutorial'=>array('index'),
'Manage',
);

$this->menu=array(
array('label'=>'List Tutorials', 'url'=>array('index')),
array('label'=>'Create Tutorials', 'url'=>array('create')),
array('label'=>'List Tutorial', 'url'=>array('index')),
array('label'=>'Create Tutorial', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
Expand All @@ -26,7 +26,7 @@
");
?>

<h1>Manage Tutorials</h1>
<h1>Manage Tutorial</h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
Expand Down
10 changes: 5 additions & 5 deletions application/views/admin/tutorials/create.php
@@ -1,18 +1,18 @@
<?php
/* @var $this TutorialsController */
/* @var $model Tutorials */
/* @var $model Tutorial */

$this->breadcrumbs=array(
'Tutorials'=>array('index'),
'Tutorial'=>array('index'),
'Create',
);

$this->menu=array(
array('label'=>'List Tutorials', 'url'=>array('index')),
array('label'=>'Manage Tutorials', 'url'=>array('admin')),
array('label'=>'List Tutorial', 'url'=>array('index')),
array('label'=>'Manage Tutorial', 'url'=>array('admin')),
);
?>

<h1>Create Tutorials</h1>
<h1>Create Tutorial</h1>

<?php $this->renderPartial('_form', array('model'=>$model)); ?>
2 changes: 1 addition & 1 deletion application/views/admin/tutorials/index.php
Expand Up @@ -20,7 +20,7 @@
<div class="container-fluid ls-space padding left-50 right-50">
<div class="ls-flex-column ls-space padding left-35 right-35">
<div class="col-12 h1 pagetitle">
<?php eT('Tutorials')?>
<?php eT('Tutorial')?>
</div>
<div class="col-12">
<a class="btn btn-primary pull-right col-xs-6 col-sm-3 col-md-2" id="createnewtutorial" >
Expand Down

0 comments on commit eabc4e7

Please sign in to comment.