system/modules/pct_customelements/PCT/CustomElements/Core/Controller.php line 85

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao Open Source CMS
  4.  * 
  5.  * Copyright (C) 2005-2013 Leo Feyer
  6.  * 
  7.  * @copyright    Tim Gatzky 2016
  8.  * @author        Tim Gatzky <info@tim-gatzky.de>
  9.  * @package        pct_customelements
  10.  * @subpackage    pct_customelements_plugin_customcatalog
  11.  */
  12. /**
  13.  * Namespace
  14.  */
  15. namespace PCT\CustomElements\Core;
  16. /**
  17.  * Imports
  18.  */
  19. use \PCT\CustomElements\Plugins\CustomCatalog\Helper\QueryBuilder as QueryBuilder;
  20. /**
  21.  * Class file
  22.  * Controller
  23.  * Provide general methods to access any object or modify it
  24.  */
  25. abstract class Controller
  26. {
  27.     /**
  28.      * Data array
  29.      * @var array
  30.      */
  31.     protected $arrData = array();
  32.     
  33.     /**
  34.      * Custom modified array
  35.      * @var array
  36.      */
  37.     protected $arrModified = array();
  38.     
  39.     /**
  40.      * Reference object
  41.      * @var object
  42.      */
  43.     protected $objOrigin null;
  44.     
  45.     /**
  46.      * Model object
  47.      * @var object
  48.      */
  49.     protected $objModel;
  50.     /**    
  51.      * The Session object
  52.      */
  53.     protected $Session null;
  54.     
  55.     
  56.     /**
  57.      * Getters
  58.      * @param string
  59.      * @return mixed
  60.      */
  61.     public function get($strKey)
  62.     {
  63.         if( \property_exists($this,$strKey) )
  64.         {
  65.             return $this->{$strKey};
  66.         }
  67.         else if(isset($this->arrData[$strKey]))
  68.         {
  69.             return $this->arrData[$strKey];
  70.         }
  71.         else{}
  72.     }
  73.     
  74.     
  75.     /**
  76.      * Setters
  77.      * @param string
  78.      * @param mixed
  79.      */
  80.     public function set($strKey$varValue)
  81.     {
  82.         if(array_key_exists($strKey$this->arrData))
  83.         {
  84.             $this->arrData[$strKey] = $varValue;
  85.             return;
  86.         }
  87.         $this->{$strKey} = $varValue;
  88.     }
  89.     
  90.     /**
  91.      * Set data array
  92.      * @param array
  93.      */
  94.     public function setData($arrData$blnDirectAccessible=true)
  95.     {
  96.         if(!is_array($arrData))
  97.         {
  98.             return;
  99.         }
  100.         
  101.         $this->arrData $arrData;
  102.         
  103.         // make object accessible
  104.         if($blnDirectAccessible)
  105.         {
  106.             foreach($arrData as $k => $v)
  107.             {
  108.                 $this->{$k} = $v;
  109.             }
  110.         }
  111.     }
  112.     
  113.     
  114.     /**
  115.      * Return the data array
  116.      * @param array
  117.      */
  118.     public function getData()
  119.     {
  120.         return $this->arrData;
  121.     }
  122.     
  123.     
  124.     /**
  125.      * Return the modified array
  126.      * @return array
  127.      */
  128.     public function getModified()
  129.     {
  130.         return $this->get('arrModified');
  131.     }
  132.     
  133.     
  134.     /**
  135.      * Set a variable or flag to be modified
  136.      * @param string
  137.      */
  138.     public function setModified($strKey)
  139.     {
  140.         $arrModified $this->getModified();
  141.         $arrModified[$strKey] = true;
  142.         $this->set('arrModified',$arrModified);
  143.     }
  144.     
  145.     
  146.     /**
  147.      * Return true/false if a key is set
  148.      * @param string
  149.      * @return boolean
  150.      */
  151.     protected function isModified($strKey)
  152.     {
  153.         $arrModified $this->getModified();
  154.         if(array_key_exists($strKey$arrModified))
  155.         {
  156.             return true;
  157.         }
  158.         return false;
  159.     }
  160.     
  161.     
  162.     /**
  163.      * Add a new flag to the modfied array
  164.      * @param string
  165.      */
  166.     public function markAsModified($strKey)
  167.     {
  168.         $this->setModified($strKey);
  169.     }
  170.     
  171.     /**
  172.      * Return the table of the customcatalog
  173.      * @return string
  174.      */
  175.     public function getTable()
  176.     {
  177.         return ($this->get('mode') == 'new' $this->get('tableName') : $this->get('existingTable') );
  178.     }
  179.     
  180.     
  181.     /**
  182.      * Set a model
  183.      * @param object
  184.      */
  185.     public function setModel($objModel)
  186.     {
  187.         $this->objModel $objModel;
  188.     }
  189.     
  190.     
  191.     /**
  192.      * Return the model
  193.      * @return object
  194.      */
  195.     public function getModel()
  196.     {
  197.         return $this->objModel;
  198.     }
  199.     
  200.     /**
  201.      * Set the orgin
  202.      * @param object Origin
  203.      */
  204.     public function setOrigin($objOrigin)
  205.     {
  206.         $this->set('objOrigin',$objOrigin);
  207.     }
  208.     
  209.     
  210.     /**
  211.      * Get the reference model object
  212.      * @return object
  213.      */
  214.     public function getOrigin()
  215.     {
  216.         return $this->get('objOrigin');
  217.     }
  218. }