Skip to content

Commit

Permalink
Dev: surveymenu edition working
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jul 25, 2017
1 parent eb141e2 commit c030159
Show file tree
Hide file tree
Showing 18 changed files with 357 additions and 311 deletions.
173 changes: 0 additions & 173 deletions application/controllers/SurveymenuController.php

This file was deleted.

2 changes: 1 addition & 1 deletion application/controllers/admin/SurveymenuController.php
Expand Up @@ -79,7 +79,7 @@ public function update($id=0)
'data' => [
'success'=> $success,
'redirect' => $this->getController()->createUrl('admin/menus/sa/view'),
'debug' => [$model, $_POST],
'debug' => [$model,$aSurveymenu, $_POST],
'debugErrors' => $model->getErrors(),
'settings' => array(
'extrasettings' => false,
Expand Down
65 changes: 0 additions & 65 deletions application/controllers/admin/SurveymenuEntryController.php

This file was deleted.

10 changes: 10 additions & 0 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -298,6 +298,16 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {
$oTransaction->commit();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>305),"stg_name='DBVersion'");
}
/**
* Change dbfieldnames to be more functional
*/
if ($iOldDBVersion < 306) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->renameColumn('{{surveymenu_entries}}','order','ordering');
$oDB->createCommand()->renameColumn('{{surveymenu}}','order','ordering');
$oTransaction->commit();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>306),"stg_name='DBVersion'");
}

/**
* Template tables
Expand Down
49 changes: 25 additions & 24 deletions application/models/Surveymenu.php
Expand Up @@ -8,7 +8,7 @@
* @property integer $parent_id
* @property integer $survey_id
* @property integer $user_id
* @property integer $order
* @property integer $ordering
* @property integer $level
* @property string $title
* @property string $description
Expand Down Expand Up @@ -39,12 +39,12 @@ public function rules()
// will receive user inputs.
return array(
array('changed_at', 'required'),
array('parent_id, survey_id, user_id, order, level, changed_by, created_by', 'numerical', 'integerOnly'=>true),
array('parent_id, survey_id, user_id, ordering, level, changed_by, created_by', 'numerical', 'integerOnly'=>true),
array('title, position', 'length', 'max'=>255),
array('description, created_at', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, parent_id, survey_id, user_id, order, level, position, title, description, changed_at, changed_by, created_at, created_by', 'safe', 'on'=>'search'),
array('id, parent_id, survey_id, user_id, ordering, level, position, title, description, changed_at, changed_by, created_at, created_by', 'safe', 'on'=>'search'),
);
}

Expand All @@ -59,7 +59,7 @@ public function relations()
'surveymenuEntries' => array(self::HAS_MANY, 'SurveymenuEntries', 'menu_id'),
'survey' => array(self::BELONGS_TO, 'Survey', 'sid'),
'user' => array(self::BELONGS_TO, 'User', 'uid'),
'parent' => array(self::BELONGS_TO, 'Surveymenu', 'id'),
'parent' => array(self::BELONGS_TO, 'Surveymenu', 'parent_id'),
);
}

Expand Down Expand Up @@ -89,12 +89,12 @@ public function getSurveyIdOptions (){
return $options;
}

public function getNexOrderPosition(){
public function getNexorderingPosition(){
$oSurveymenus = Surveymenu::model()->findAll();
return count($oSurveymenus);
}

public function getOrderOptions (){
public function getorderingOptions (){
$oSurveymenus = Surveymenu::model()->findAll();
$options = [];
for($i=0; $i<=count($oSurveymenus); $i++){
Expand Down Expand Up @@ -124,7 +124,7 @@ public function attributeLabels()
'parent_id' => gT('Parent'),
'survey_id' => gT('Survey'),
'user_id' => gT('User'),
'order' => gT('Order'),
'ordering' => gT('ordering'),
'level' => gT('Level'),
'title' => gT('Title'),
'position' => gT('Position'),
Expand Down Expand Up @@ -190,7 +190,7 @@ public function getColumns(){
'name' => 'description',
),
array(
'name' => 'order',
'name' => 'ordering',
),
array(
'name' => 'level',
Expand All @@ -200,7 +200,7 @@ public function getColumns(){
),
array(
'name' => 'parent_id',
'value' => '$data->parent_id ? $data->parent->title : "<i class=\'fa fa-minus\'></i>"',
'value' => '$data->parent_id ? $data->parent->title." (".$data->parent_id.")" : "<i class=\'fa fa-minus\'></i>"',
'type' => 'raw'
),
array(
Expand Down Expand Up @@ -230,23 +230,24 @@ public function getColumns(){
return $cols;
}

private function _getMaxLevel(){
$aMaxLevel = Surveymenu::model()->findBySql('SELECT MAX(level) as maxLevel FROM {{surveymenu}}');
return $aMaxLevel['maxLevel'];
}

private function _recalculateOrder(){
$models = Surveymenu::model()->findAll();
$maxLevel = $this->_getMaxLevel();
public function onAfterSave($event){
$criteria = new CDbCriteria();

$criteria->addCondition(['position=:position']);
$criteria->addCondition(['ordering'=>':ordering']);
$criteria->addCondition(['id<>:id']);

$criteria->params = ['position' => $this->position, 'ordering' => (int) $this->ordering, 'id'=> (int) $this->id];
$collidingMenu = Surveymenu::model()->find($criteria)->one();
if($collidingMenu){
$collidingMenu->ordering = (((int) $collidingMenu->ordering)+1);
$collidingMenu->save();
}
return parent::onAfterSave($event);

}


public function onAfterSave($event=null){
//$this->_recalculateOrder();
return parent::onAfterSave($event);
}

/**
* @return array
*/
Expand All @@ -262,7 +263,7 @@ public function getShortListColumns(){
'name' => 'description',
),
array(
'name' => 'order',
'name' => 'ordering',
),
array(
'name' => 'position',
Expand Down Expand Up @@ -310,7 +311,7 @@ public function search()
$criteria->compare('parent_id',$this->parent_id);
$criteria->compare('survey_id',$this->survey_id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('order',$this->order);
$criteria->compare('ordering',$this->ordering);
$criteria->compare('level',$this->level);
$criteria->compare('title',$this->title,true);
$criteria->compare('position',$this->position,true);
Expand Down

0 comments on commit c030159

Please sign in to comment.