Skip to content

Commit

Permalink
Dev: changes to make nested menues and finally adding new custom menues
Browse files Browse the repository at this point in the history
  • Loading branch information
markusfluer committed Jul 16, 2017
1 parent 25b0ed9 commit 267c097
Show file tree
Hide file tree
Showing 29 changed files with 1,866 additions and 986 deletions.
4 changes: 2 additions & 2 deletions application/controllers/SurveymenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function actionCreate()
{
$model->attributes=$_POST['Surveymenu'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
$this->redirect(array('index'));
}

$this->render('create',array(
Expand All @@ -95,7 +95,7 @@ public function actionUpdate($id)
{
$model->attributes=$_POST['Surveymenu'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
$this->redirect(array('index'));
}

$this->render('update',array(
Expand Down
138 changes: 137 additions & 1 deletion application/controllers/admin/SurveymenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,142 @@

class SurveymenuController extends Survey_Common_Action
{

/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function update($id=0)
{
if($id != 0)
$model = $this->loadModel($id);
else
$model = new Surveymenu();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

$success = false;
if(Yii::app()->request->isPostRequest)
{
$aSurveymenu = Yii::app()->request->getPost('Surveymenu', []);
if($aSurveymenu['id'] == ''){
unset($aSurveymenu['id']);
$aSurveymenu['created_at'] = date('Y-m-d H:i:s');
$aSurveymenu['parent_id'] = (int) $aSurveymenu['parent_id'];
if($aSurveymenu['parent_id'] > 0)
$aSurveymenu['level'] = ((Surveymenu::model()->findByPk($aSurveymenu['parent_id'])->level)+1);
}

$model->setAttributes($aSurveymenu);
if($model->save()){
$model->id = $model->getPrimaryKey();
$success = true;
}
}


return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array(
'data' => [
'success'=> $success,
'redirect' => $this->getController()->createUrl('admin/menus/sa/view'),
'debug' => [$model, $_POST],
'debugErrors' => $model->getErrors(),
'settings' => array(
'extrasettings' => false,
'parseHTML' => false,
)
]
),
false,
false
);

}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function delete($id)
{
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('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 Surveymenu the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=Surveymenu::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param Surveymenu $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='surveymenu-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}

public function index()
{
$this->getController()->redirect(array('admin/menus/sa/view'));
Expand All @@ -24,7 +160,7 @@ public function getsurveymenuform($menuid=null){
$model = Surveymenu::model()->findByPk(((int) $menuid));
} else
{
$model = Surveymenu::model();
$model = new Surveymenu();
}
$user = Yii::app()->session['loginID'];
return Yii::app()->getController()->renderPartial('/admin/surveymenu/_form', array('model'=>$model, 'user'=>$user));
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ private function _exportarchive($iSurveyID, $bSendToBrowser=TRUE)
unlink($sLSTFileName);
}

if ( $survey->hasTimingsTable ) {
if ( isset($survey->hasTimingsTable ) ) {
getXMLDataSingleTable($iSurveyID, 'survey_' . $iSurveyID . '_timings', 'Timings', 'timings', $sLSIFileName);
$this->_addToZip($zip, $sLSIFileName, 'survey_' . $iSurveyID . '_timings.lsi');
unlink($sLSIFileName);
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function view($surveyid, $gid, $qid)
$aData = array();

// Init general variables
$aData['surveyid'] = $iSurveyID = $surveyid;
$aData['surveyid'] = $iSurveyID = (int) $surveyid;
$aData['gid'] = $gid;
$aData['qid'] = $qid;
$survey = Survey::model()->findByPk($iSurveyID);
Expand Down
35 changes: 26 additions & 9 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public function editsurveysettings($iSurveyID)
$iSurveyID = (int) $iSurveyID;
$survey = Survey::model()->findByPk($iSurveyID);


if (is_null($iSurveyID) || !$iSurveyID)
$this->getController()->error('Invalid survey ID');

Expand Down Expand Up @@ -1074,6 +1075,10 @@ public function editlocalsettings($iSurveyID)
$aData['surveyid'] = $iSurveyID = sanitize_int($iSurveyID);
$survey = Survey::model()->findByPk($iSurveyID);
$aData['oSurvey'] = $survey;
$this->getController()->redirect(
Yii::app()->createUrl('admin/survey/sa/rendersidemenulink', ['surveyid' => $iSurveyID, 'subaction' => 'generalsettings'])
);
return;

if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
{
Expand Down Expand Up @@ -2086,19 +2091,31 @@ function insert($iSurveyID=null)
}

// Figure out destination
if (App()->request->getPost('saveandclose'))

if($createSample)
{
if($createSample) {
$this->getController()->redirect(array("admin/questions/sa/view/surveyid/{$iNewSurveyid}/gid/{$iNewGroupID}/qid/{$iNewQuestionID}"));
}
else {
$this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iNewSurveyid));
}
$redirecturl = $this->getController()->createUrl(
"admin/questions/sa/view/",
['surveyid' => $iNewSurveyid, 'gid'=>$iNewGroupID, 'qid' =>$iNewQuestionID]
);
}
else
else
{
$this->getController()->redirect(array('admin/survey/sa/editlocalsettings/surveyid/' . $iNewSurveyid));
$redirecturl = $this->getController()->createUrl(
'admin/survey/sa/view/',
['surveyid'=>$iNewSurveyid]
);
}
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array(
'data' => array(
'redirecturl' => $redirecturl,
)
),
false,
false
);

}
}
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/update/updatedb_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {

function createSurveyMenuTable293($oDB) {
$oDB->createCommand()->createTable('{{surveymenu}}', array(
"id" => "int NOT NULL ",
"id" => "int NOT NULL AUTO_INCREMENT",
"parent_id" => "int DEFAULT NULL",
"survey_id" => "int DEFAULT NULL",
"order" => "int DEFAULT '0'",
Expand Down Expand Up @@ -355,7 +355,7 @@ function createSurveyMenuTable293($oDB) {
);

$oDB->createCommand()->createTable('{{surveymenu_entries}}', array(
"id" => "int NOT NULL ",
"id" => "int NOT NULL AUTO_INCREMENT",
"menu_id" => "int DEFAULT NULL",
"order" => "int DEFAULT '0'",
"name" => "character varying(255) NOT NULL DEFAULT ''",
Expand Down
48 changes: 34 additions & 14 deletions application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,15 @@ private function _parseSurveyMenuData($dataAttribute)
return (object) ($aData);
}

private function _createSurveymenuArray($aSurveyMenuObjects)
private function _createSurveymenuArray($oSurveyMenuObjects)
{
//Posibility to add more languages to the database is given, so it is possible to add a call by language
//Also for peripheral menues we may add submenus someday.
$aResultCollected = [];
foreach($aSurveyMenuObjects as $aSurveyMenuObject){
foreach($oSurveyMenuObjects as $oSurveyMenuObject){
$entries = [];
$defaultMenuEntries = $aSurveyMenuObject->surveymenuEntries;
$defaultMenuEntries = $oSurveyMenuObject->surveymenuEntries;
$submenus = $this->_getSurveymenuSubmenus($oSurveyMenuObject);
foreach($defaultMenuEntries as $menuEntry){
$aEntry = $menuEntry->attributes;
//Skip menu if no permission
Expand All @@ -641,36 +642,54 @@ private function _createSurveymenuArray($aSurveyMenuObjects)
) {continue;}
//parse the render part of the data attribute
$oDataAttribute = $this->_parseSurveyMenuData($menuEntry->data);

if($oDataAttribute->noRender){continue;}

$aEntry['link'] = $aEntry['menu_link']
? App()->getController()->createUrl($aEntry['menu_link'],$oDataAttribute->aLinkCreator)
: App()->getController()->createUrl("admin/survey/sa/rendersidemenulink",['surveyid' => $this->sid, 'subaction' => $aEntry['name'] ]);
$aEntry['link_external'] = $oDataAttribute->linkExternal;
$aEntry['debugData'] = $oDataAttribute;
$entries[] = $aEntry;
$entries[$aEntry['id']] = $aEntry;
}
$aResultCollected[] = [
"title" => $aSurveyMenuObject->title,
"description" => $aSurveyMenuObject->description,
$aResultCollected[$oSurveyMenuObject->id] = [
"title" => $oSurveyMenuObject->title,
"description" => $oSurveyMenuObject->description,
"entries" => $entries,
"submenus" => $submenus
];
}
return $aResultCollected;
}

private function _getSurveymenuSubmenus($oParentSurveymenu){
$criteria=new CDbCriteria;
$criteria->condition='survey_id=:surveyid';
$criteria->condition.=' AND parent_id=:parentid';
$criteria->condition.=' AND level=:level';
$criteria->params = [
':surveyid' => $oParentSurveymenu->survey_id,
':parentid' => $oParentSurveymenu->id,
':level'=> ($oParentSurveymenu->level+1)
];

$oDefaultMenus = Surveymenu::model()->findAll($criteria);

$aResultCollected = $this->_createSurveymenuArray($oDefaultMenus);
return $aResultCollected;
}

private function _getDefaultSurveyMenus($position='')
{
$criteria=new CDbCriteria;
$criteria->condition='survey_id=NULL';
if($position != ''){
$criteria->condition='position=:position';
$criteria->condition='survey_id IS NULL AND parent_id IS NULL';

if($position != '')
{
$criteria->condition.=' AND position=:position';
$criteria->params=array(':position'=>$position);
}
$oDefaultMenus = Surveymenu::model()->findAll($criteria);

$oDefaultMenus = Surveymenu::model()->findAll($criteria);
$aResultCollected = $this->_createSurveymenuArray($oDefaultMenus);

return $aResultCollected;
Expand All @@ -689,7 +708,8 @@ public function getSurveyMenus($position=''){
$aThisSurveyMenues = $this->_createSurveymenuArray($this->surveymenus);
//merge them
$aSurveyMenus = $aDefaultSurveyMenus + $aThisSurveyMenues;

// var_dump($aDefaultSurveyMenus);
// var_dump($aThisSurveyMenues);
//soon to come => Event to add menus for plugins

return $aSurveyMenus;
Expand Down Expand Up @@ -749,7 +769,7 @@ public function deleteSurvey($iSurveyID, $recursive=true)
Yii::app()->db->createCommand()->dropTable($this->responsesTableName);
}
//delete the survey_$iSurveyID_timings table
if ($this->hasTimingsTable) {
if (isset($this->hasTimingsTable)) {
Yii::app()->db->createCommand()->dropTable($this->timingsTableName);
}
//delete the tokens_$iSurveyID table
Expand Down

0 comments on commit 267c097

Please sign in to comment.