Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: refactored the php menucreation system
Provided foundation for top-bar menu rendering
- Loading branch information
Showing
24 changed files
with
892 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
class SurveymenuEntryData extends CFormModel { | ||
|
||
public $rawData = null; | ||
public $render = null; | ||
public $link = "admin/survey/sa/rendersidemenulink"; | ||
public $linkData = array(); | ||
public $linkExternal = false; | ||
public $surveyid = 0; | ||
public $menuEntry = null; | ||
public $isActive = null; | ||
|
||
public function apply($menuEntry, $surveyid){ | ||
$this->surveyid = $surveyid; | ||
$this->menuEntry = $menuEntry; | ||
|
||
$oData = json_decode(stripcslashes($this->menuEntry->data)); | ||
$jsonError = json_last_error(); | ||
if($jsonError){ | ||
$this->rawData = []; | ||
} else { | ||
$this->rawData = $oData; | ||
$this->_parseDataAttribute(); | ||
} | ||
$this->_parseLink(); | ||
} | ||
|
||
public function linkCreator(){ | ||
$returnLink = Yii::app()->getController()->createUrl($this->link, $this->linkData); | ||
return $returnLink; | ||
} | ||
|
||
private function _parseDataAttribute(){ | ||
|
||
$this->isActive = $this->_recursiveIssetWithDefault($this->rawData , array('render','isActive'), 0, $this->isActive); | ||
$this->linkExternal = $this->_recursiveIssetWithDefault($this->rawData , array('render', 'link','external'), 0, $this->linkExternal); | ||
$alinkData = $this->_recursiveIssetWithDefault($this->rawData , array('render', 'link','data'), 0, $this->linkData); | ||
|
||
foreach($alinkData as $key => $value){ | ||
if(is_array($value)){ | ||
$value= $this->_getValueForLinkData($value); | ||
} | ||
$this->linkData[$key] = $value; | ||
} | ||
} | ||
|
||
private function _parseLink(){ | ||
|
||
if(empty($this->menuEntry->menu_link)){ | ||
$this->linkData['subaction'] = $this->menuEntry->name; | ||
$this->linkData['surveyid'] = $this->surveyid; | ||
} else { | ||
$this->link = $this->menuEntry->menu_link; | ||
} | ||
|
||
} | ||
|
||
private function _recursiveIssetWithDefault ($variable, $checkArray, $i=0, $fallback=null) { | ||
$default = null; | ||
if(is_array($variable) && array_key_exists($checkArray[$i], $variable)) | ||
$default = $variable[$checkArray[$i]]; | ||
else if(is_object($variable) && property_exists($variable, $checkArray[$i])) | ||
$default = $variable->{$checkArray[$i]}; | ||
if(!isset($default)) | ||
return $fallback; | ||
|
||
else if(count($checkArray) > $i + 1) | ||
return $this->_recursiveIssetWithDefault($default, $checkArray, $i+1, $fallback); | ||
else | ||
return $default; | ||
|
||
} | ||
|
||
private function _getValueForLinkData($getDataPair) | ||
{ | ||
|
||
$oSurvey = Survey::model()->findByPk($this->surveyid); | ||
list($type,$attribute) = $getDataPair; | ||
$oTypeObject = null; | ||
switch($type){ | ||
case 'survey': | ||
$oTypeObject = &$oSurvey; | ||
break; | ||
case 'template': | ||
$oTypeObject = Template::model()->findByPk($oSurvey->template); | ||
break; | ||
case 'questiongroup': | ||
if(isset($_REQUEST['gid'])){ | ||
$oTypeObject = QuestionGroup::model()->getByPk(((int) $_REQUEST['gid'])); | ||
} | ||
break; | ||
case 'question': | ||
if(isset($_REQUEST['qid'])){ | ||
$oTypeObject = QuestionGroup::model()->getByPk(((int) $_REQUEST['qid'])); | ||
} | ||
break; | ||
} | ||
|
||
$result = $oTypeObject != null ? $oTypeObject->{$attribute} : null; | ||
return $result; | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.