Initial Commit
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
class App_Service_VariabiliSito
|
||||
{
|
||||
const VARIABILI_SITO_REGISTRY_NAME = 'VARIABILI_SITO';
|
||||
|
||||
protected $_genericModel;
|
||||
protected $_variabili;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->_genericModel = new Application_Model_Generic();
|
||||
$this->initialize();
|
||||
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
{
|
||||
|
||||
if (Zend_Registry::isRegistered(self::VARIABILI_SITO_REGISTRY_NAME)){
|
||||
$this->_variabili = Zend_Registry::get(self::VARIABILI_SITO_REGISTRY_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
$tmp = $this->_genericModel->getList('VariabiliSito');
|
||||
$variabili = array();
|
||||
|
||||
foreach($tmp as $key => $val){
|
||||
$tipo = explode('_',$val['Nome'])[0];
|
||||
switch($tipo){
|
||||
case'I':
|
||||
$variabili[$val['Nome']] = $val['ValoreInteger'];
|
||||
break;
|
||||
case'D':
|
||||
$variabili[$val['Nome']] = $val['ValoreDouble'];
|
||||
break;
|
||||
case'S':
|
||||
$variabili[$val['Nome']] = $val['ValoreString'];
|
||||
break;
|
||||
case'TJ':
|
||||
$variabili[$val['Nome']] = Zend_Json::decode($val['ValoreString']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_variabili = $variabili;
|
||||
Zend_Registry::set(self::VARIABILI_SITO_REGISTRY_NAME, $this->_variabili);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
return $this->_variabili[$key];
|
||||
}
|
||||
|
||||
public function set($key,$value){
|
||||
|
||||
$tipo = explode('_',$key)[0];
|
||||
switch($tipo){
|
||||
case'I':
|
||||
$data = array('ValoreInteger'=>$value);
|
||||
break;
|
||||
case'D':
|
||||
$data = array('ValoreDouble'=>$value);
|
||||
break;
|
||||
case'T':
|
||||
$data = array('ValoreString'=>$value);
|
||||
break;
|
||||
case'TJ':
|
||||
$data = array('ValoreString'=>Zend_Json::encode($value));
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Tipo del valore da inserire non specificato");
|
||||
break;
|
||||
}
|
||||
|
||||
if(array_key_exists($key,$this->_variabili)) //update
|
||||
$this->_genericModel->updateWhere('VariabiliSito',"Nome = '$key'",$data);
|
||||
else //Inserimento
|
||||
$this->_genericModel->insert('VariabiliSito',array_merge(array('Nome'=>$key),$data));
|
||||
|
||||
$this->_variabili[$key] = $value;
|
||||
Zend_Registry::set(self::VARIABILI_SITO_REGISTRY_NAME, $this->_variabili);
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return $this->_variabili;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user