Esempio n. 1
0
 /**
  * @return string
  */
 public function get()
 {
     \General\Environment::setContentJson();
     \General\Environment::set();
     \Database\Factory::getInstance()->quoteAll($this->aParams);
     $aRetVal = array();
     if (empty($this->aParams['class'])) {
         $this->aParams['class'] = 'Api';
     }
     if (empty($this->aParams['method'])) {
         $this->aParams['method'] = 'current';
     }
     /*
      * API can call only it's own methods
      */
     $className = '\\Controller\\' . $this->aParams['class'];
     switch ($this->aParams['method']) {
         default:
             $methodName = $this->aParams['method'];
             break;
     }
     if (class_exists($className)) {
         /** @noinspection PhpUndefinedMethodInspection */
         $tObject = $className::getInstance();
         if (method_exists($tObject, $methodName)) {
             $tObject->{$methodName}($this->aParams, $aRetVal);
         }
     }
     return json_encode($aRetVal);
 }
 /**
  * Główny kontroler
  * @return string
  */
 public function get()
 {
     try {
         /**
          * Quotowana tablica request
          * @var array
          */
         $aRequest = $_REQUEST;
         \Database\Factory::getInstance()->quoteAll($aRequest);
         /**
          * Inicjacja szablonu
          * @var \General\Templater
          */
         $template = new \General\Templater('index.html');
         /*
          * Rejestracja listenerów
          */
         \Listeners\Message::getInstance()->register($aRequest, $template);
         if (empty($aRequest['class'])) {
             $aRequest['class'] = 'Frontpage';
         }
         if (empty($aRequest['method'])) {
             $aRequest['method'] = 'render';
         }
         if (!isset($HTTP_RAW_POST_DATA)) {
             $HTTP_RAW_POST_DATA = file_get_contents("php://input");
         }
         $retVal = '';
         $className = '';
         switch ($aRequest['class']) {
             default:
                 $className = '\\Controller\\' . $aRequest['class'];
                 break;
         }
         $methodName = '';
         switch ($aRequest['method']) {
             default:
                 $methodName = $aRequest['method'];
                 break;
         }
         if (class_exists($className)) {
             $tObject = $className::getInstance();
             if (method_exists($tObject, $methodName)) {
                 $tObject->{$methodName}($aRequest, $template);
             }
         }
         \Listeners\LowLevelMessage::getInstance()->register($aRequest, $template);
     } catch (CustomException $e) {
         $template->add('mainContent', \General\Debug::cThrow($e->getMessage(), $e, array('send' => false, 'display' => false)));
     } catch (Exception $e) {
         $template->add('mainContent', \General\Debug::cThrow(null, $e));
     }
     $template->add('chartHead', '');
     $template->add('listeners', '');
     $template->add('menu', '');
     $template->add('mainContent', '');
     $template->add('titleSecond', '');
     $template->add('pageTitle', '{T:Product Name}');
     return (string) $template;
 }
Esempio n. 3
0
 /**
  * @param array $aParams
  */
 public function __construct(array $aParams = null)
 {
     $this->aParams = $aParams;
     $this->db = Factory::getInstance();
     $this->cache = PhpCache::getInstance()->create();
 }
 /**
  * Metoda edytuje dane w tabeli.
  *
  * @param   array   $aParams    Tablica z danymi do edycji bazy
  * @param   int     $$iId       Identyfikator rekordu
  * @return  int     Identyfikator ostatnio zedytowanego rekordu
  * @throws
  * @since   2012-06-19
  * @version 1.0
  */
 public function edit($aParams, $iId)
 {
     $aUpdate = array();
     foreach ($aParams as $sKey => $mValue) {
         if ($mValue === null) {
             continue;
         }
         if (in_array($sKey, $this->tableFields)) {
             switch (gettype($mValue)) {
                 case 'integer':
                 case 'boolean':
                     $aUpdate[$sKey] = '`' . $sKey . '`' . '=' . $mValue;
                     break;
                 case 'string':
                     $aUpdate[$sKey] = '`' . $sKey . '`' . '=' . "'{$mValue}'";
             }
         }
     }
     $sUpdate = implode(',', $aUpdate);
     $sSql = 'UPDATE ' . $this->tableName . ' SET ' . $sUpdate . ' WHERE ' . $this->registryIdField . '=' . $iId;
     $oDatabase = Database::getInstance();
     $oDatabase->execute($sSql);
     $iLastInsertId = $oDatabase->lastUsedID();
     /*
      * Zrzuć cache
      */
     $this->dropCache($iId);
     return $iLastInsertId;
 }
Esempio n. 5
0
 /**
  * @return string
  */
 public function get()
 {
     \General\Environment::setContentHtml();
     \General\Session::start();
     \General\Environment::set();
     /**
      * @var \General\Templater
      */
     $template = new \General\Templater('index.html');
     try {
         \Database\Factory::getInstance()->quoteAll($this->aParams);
         /*
          * Rejestracja listenerów
          */
         \Listeners\Message::getInstance()->register($this->aParams, $template);
         if (empty($this->aParams['class'])) {
             $this->aParams['class'] = 'Overview';
         }
         if (empty($this->aParams['method'])) {
             $this->aParams['method'] = 'render';
         }
         switch ($this->aParams['class']) {
             default:
                 $className = '\\Controller\\' . $this->aParams['class'];
                 break;
         }
         switch ($this->aParams['method']) {
             default:
                 $methodName = $this->aParams['method'];
                 break;
         }
         if (class_exists($className)) {
             /** @noinspection PhpUndefinedMethodInspection */
             $tObject = $className::getInstance();
             if (method_exists($tObject, $methodName)) {
                 $tObject->{$methodName}($this->aParams, $template);
             }
         }
         \Listeners\LowLevelMessage::getInstance()->register($this->aParams, $template);
     } catch (CustomException $e) {
         $template->add('mainContent', Debug::cThrow($e->getMessage(), $e, array('send' => false, 'display' => false)));
     } catch (Exception $e) {
         $template->add('mainContent', Debug::cThrow(null, $e));
     }
     $template->add('chartHead', '');
     $template->add('listeners', '');
     $template->add('menu', '');
     $template->add('mainContent', '');
     $template->add('titleSecond', '');
     $template->add('pageTitle', '{T:Product Name}');
     $sHtml = (string) $template;
     /*
      * Remove all menu-active-* occurences
      */
     $sHtml = preg_replace('!({submenu-active-[^}]*})!', '', $sHtml);
     $sHtml = preg_replace('!({menu-active-[^}]*})!', '', $sHtml);
     /*
      * Add params
      */
     $sHtml = preg_replace_callback('!({params:[^}]*})!', array($this, 'paramsInjecter'), $sHtml);
     return $sHtml;
 }
 public function getHourAggregate($hours = 24, $orderBy = "DESC")
 {
     $retVal = array();
     $cache = \Cache\Factory::getInstance();
     $sModule = get_class($this) . '::getHourAggregate';
     $sProperty = $hours . '|' . $orderBy;
     if (!$cache->check($sModule, $sProperty)) {
         $db = \Database\Factory::getInstance();
         $rResult = $db->execute("select\r\n\t\t\t\t\tstrftime('%Y-%m-%d %H:00:00', `Date`) Date\n\t\t\t\t\t, AVG(Temperature) Temperature\r\n\t\t\t\t\t, AVG(Humidity) Humidity\r\n\t\t\t\t\t, MIN(Temperature) MinTemperature\r\n\t\t\t\t\t, MAX(Temperature) MaxTemperature\r\n\t\t\t\t\t, MIN(Humidity) MinHumidity\r\n\t\t\t\t\t, MAX(Humidity) MaxHumidity\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\t{$this->tableName}\r\n\t\t\t\t\twhere\r\n\t\t\t\t\t\tdatetime(`Date`)>(SELECT DATETIME('now', '-{$hours} hour'))\r\n\t\t\t\t\tgroup by\r\n\t\t\t\t\t\tstrftime('%Y-%m-%d %H:00:00', `Date`)\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\tdatetime(`Date`) {$orderBy}\r\n\t\t\t\t\t");
         while ($tResult = $db->fetchAssoc($rResult)) {
             array_push($retVal, $tResult);
         }
         $cache->set($sModule, $sProperty, $retVal, 3600);
     } else {
         $retVal = $cache->get($sModule, $sProperty);
     }
     return $retVal;
 }