Initial Commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
|
||||
class App_Controller_Sections_Section extends Zend_Controller_Action
|
||||
{
|
||||
protected $_sections = [];
|
||||
|
||||
public function __call($methodName, $args)
|
||||
{
|
||||
$actionName = $this->getRequest()->getActionName();
|
||||
$sectionName = null;
|
||||
try {
|
||||
|
||||
if (preg_match("/^list/", $actionName)) {
|
||||
$sectionName = preg_replace("/list/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->lista();
|
||||
}
|
||||
|
||||
if (preg_match("/^get/", $actionName)) {
|
||||
$sectionName = preg_replace("/get/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->get();
|
||||
}
|
||||
|
||||
if (preg_match("/^save|^salva/", $actionName)) {
|
||||
$sectionName = preg_replace("/save|salva/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->save();
|
||||
}
|
||||
|
||||
if (preg_match("/^(?=.*?delete)(?!.*?select).*$/", $actionName)) {
|
||||
$sectionName = preg_replace("/delete/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->delete();
|
||||
}
|
||||
|
||||
if (preg_match("/^deleteselect/", $actionName)) {
|
||||
$sectionName = preg_replace("/deleteselect/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->deleteSelect();
|
||||
}
|
||||
|
||||
if (preg_match("/^(?=.*?setstate)(?!.*?select).*$/", $actionName)) {
|
||||
$sectionName = preg_replace("/setstate/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->setstate();
|
||||
}
|
||||
|
||||
if (preg_match("/^setstateselect/", $actionName)) {
|
||||
$sectionName = preg_replace("/setstateselect/", "", $actionName);
|
||||
return $this->generaSectionClass($sectionName)->setstateSelect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gestisce le funzione custom di un report se vengono separate dal trattino
|
||||
* con la stringa composta cosi: "<sectionName>-<functionName>"
|
||||
*/
|
||||
if (preg_match("/-/", $actionName)) {
|
||||
|
||||
$sectionName = explode('-', $actionName)[0];
|
||||
$functionName = explode('-', $actionName)[1];
|
||||
|
||||
// non funzionante con php 5
|
||||
// [$sectionName, $functionName] = explode('-', $actionName);
|
||||
|
||||
return $this->generaSectionClass($sectionName)->$functionName();
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
try {
|
||||
parent::__call($actionName, null);
|
||||
} catch (Exception $e2) {
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function generaSectionClass($sectionName)
|
||||
{
|
||||
if (!isset($this->_sections[$sectionName])) {
|
||||
$className = $this->getSectionClassName($sectionName);
|
||||
$this->_sections[$sectionName] = new $className($this);
|
||||
}
|
||||
return $this->_sections[$sectionName];
|
||||
}
|
||||
|
||||
private function getSectionClassName($sectionName)
|
||||
{
|
||||
return implode('_', array(
|
||||
'Application',
|
||||
'ControllerSection',
|
||||
ucfirst($this->getRequest()->getModuleName()),
|
||||
ucfirst($this->getRequest()->getControllerName()),
|
||||
ucfirst($sectionName)));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user