public static function pushMessages() { $laMessages = ''; if (PUSH_MESSAGE) { $loContainer = $_SESSION['FlashMessenger']; if (is_object($loContainer)) { if ($loContainer->offsetExists('default')) { $loNamespace = $loContainer->offsetget('default'); if (!$loNamespace->isEmpty()) { $laMsgs = array_reverse($loNamespace->toArray(), true); foreach ($laMsgs as $lnKey => $laMessage) { if ($laMessage['push']) { $laMessages[$lnKey] = $laMessage; if ($loNamespace->offsetExists($lnKey)) { $loNamespace->offsetUnset($lnKey); } } } } } } } return Json::encode($laMessages); }
/** * * @return \Onion\Mvc\Controller\unknown */ public function searchAction() { $this->_sResponse = 'json'; $lsFilter = $this->request('filter', null); $lsTerm = $this->request('term', null); $lsField = $this->request('field', null); $laResponse = array(); $laFilter = json_decode(base64_decode($lsFilter), true); $laWhere[] = isset($laFilter['where']) ? $laFilter['where'] : ""; $loSearch = new Search(); $loSearch->set('sSearchFields', "a.{$lsField}"); $laWhere[] = $loSearch->createRLikeQuery('"' . $lsTerm . '"', 'r'); $laParams = array('status' => 0, 'active' => 1, 'rows' => $this->_nSearchGridNumRows, 'col' => "a.{$lsField}", 'ord' => 'ASC', 'q' => $lsTerm, 'where' => $laWhere); //Debug::display($laParams); $laEntity = $this->getEntityManager()->getRepository($this->_sEntity)->search($laParams); if (isset($laEntity['resultSet']) && is_array($laEntity['resultSet'])) { foreach ($laEntity['resultSet'] as $laItem) { $lsReturnValue = ""; $laSearchLabelField = explode("|", $this->_sSearchLabelField); if (is_array($laSearchLabelField)) { $lsPipe = ""; foreach ($laSearchLabelField as $lsFieldName) { if (method_exists($this, 'formatFieldToGrid')) { $lsContentField = $this->formatFieldToGrid($lsFieldName, $laItem[$lsFieldName]); } else { $lsContentField = $laItem[$lsFieldName]; } $lsReturnValue .= $lsPipe . $lsContentField; $lsPipe = " | "; } } $laResponse[] = array('id' => $laItem['id'], 'value' => $lsReturnValue); } } $loView = new ViewModel(); return $this->setResponseType($loView, Json::encode($laResponse)); }
/** * * @param string $psOption * @return string Json */ public static function getAppOptionsJson($psOption = null) { return Json::endoce(self::getAppOptions($psOption)); }
/** * Retorna a Mensagem no padrão da Aplicação * * @param string $psLabel * @param string $psType * @return object encode json */ public static function getMessage($psLabel, $psType, $paParams = null) { try { switch (strtoupper($psType)) { case 'ERROR': case 'SUCCESS': case 'NOTLOGED': case 'FORBIDDEN': if (strtoupper($psType) != 'SUCCESS') { Event::log(array("userId" => null, "class" => "Util", "method" => "getMessage", 'Mensagem' => $psLabel, 'Tipo' => strtoupper($psType)), Event::ERR); } $mensagem = Json::encode(array('mensagem' => array('label' => $psLabel, 'type' => strtoupper($psType), 'params' => $paParams))); break; default: throw new Exception("Tipo de mensagem " . $psType . " não está definido!"); break; } return $mensagem; } catch (Zend_Exception $e) { die($e->__toString()); } }
/** * * @return string */ public function response() { if ($this->_sResoponseType == 'json') { header("Content-Type: application/json"); return Json::encode($this->_aResponse); } elseif ($this->_sResoponseType == 'stream') { header("Content-type: text/event-stream"); $lsResponse = Json::encode($this->_aResponse); return "data: " . $lsResponse . "\n\n"; } else { Debug::display($this->_aResponse); } }
/** * * @return \Onion\Mvc\Controller\unknown */ public function isLogedAction() { $this->set('_sResponse', 'json'); $lnUserId = $this->getAuthenticatedUser(); $loView = new ViewModel(); return $this->setResponseType($loView, Json::encode(array('userId' => $lnUserId))); }
/** * * @return object */ public function generatePasswordAction() { $lsPassword = String::generatePassword(); $loView = new ViewModel(); $loView->setTerminal(true); // desabilita o layout $loResponse = $this->getResponse(); $loResponse->setStatusCode(200); $loResponse->setContent(Json::encode($lsPassword)); return $loResponse; }
/** * * @return \Onion\Mvc\Controller\unknown */ public function pushAction() { $this->set('_sResponse', 'stream'); $laMessages = ''; if (PUSH_MESSAGE && isset($_SESSION['FlashMessenger'])) { $loContainer = $_SESSION['FlashMessenger']; if (is_object($loContainer)) { if ($loContainer->offsetExists('default')) { $loNamespace = $loContainer->offsetget('default'); if (!$loNamespace->isEmpty()) { $laMsgs = array_reverse($loNamespace->toArray(), true); foreach ($laMsgs as $lnKey => $laMessage) { if ($laMessage['push']) { $laMessages[$lnKey] = $laMessage; if ($loNamespace->offsetExists($lnKey)) { $loNamespace->offsetUnset($lnKey); } } } } } } } $loView = new ViewModel(); $lsMessages = Json::encode($laMessages); return $this->setResponseType($loView, $lsMessages); }
/** * event: gera log de sistema, gravando em banco, arquivo, firebug ou exibindo na tela * * @param string|array $pmParam - array __FILE__,__METHOD__,__LINE__ ... * @param int $pnPriority - EMERG = 0; ALERT = 1; CRIT = 2; ERR = 3; WARN = 4; NOTICE = 5; INFO = 6; DEBUG = 7; * @param string $psOutput - força o nome da tabela ou posfixo do arquivo a ser gravado * @param string $psType - força o tipo de saída: DB ou STREAM */ public static function log($pmParam, $pnPriority = 7, $psOutput = null, $psType = null, $pbSave = false) { $laConfig = Config::getAppOptions(); $laLog = $laConfig['log']['log']['events']; $laDb = $laConfig['db'][APP_ENV]; $lsLogDir = $laConfig['log']['log']['logDir']; $lsTable = $laLog['table']; $lsFilePosfix = "_" . $laLog['fileName']; $lsLine = ""; $lsId = null; if (Util::toBoolean($laLog['enable']) || $pbSave) { $lsIP = $_SERVER['REMOTE_ADDR']; $lsType = $laLog['output']; if ($psType != null) { $lsType = $psType; } if (is_array($pmParam)) { foreach ($pmParam as $lsKey => $lsItem) { if (strtolower($lsKey) == 'userid') { $lsId = $lsItem; continue; } } } $laData = array(); switch ($lsType) { case "DB": if ($psOutput != null) { $lsTable = $psOutput; } $loDb = new Adapter($laDb); $lsLine = Json::encode($pmParam); $lsServer = Json::encode($_SERVER); $laExtra = array('stIP' => 'stIP', 'txtServer' => 'txtServer'); $laData = array('stIP' => $lsIP, 'txtServer' => $lsServer); if ($lsId !== null) { $laExtra['User_id'] = 'User_id'; $laData['User_id'] = $lsId; } $laColumnMap = array('timestamp' => 'dtInsert', 'priority' => 'stPriority', 'message' => 'stMsg', 'extra' => $laExtra); $loWriter = new Writer\Db($loDb, $lsTable, $laColumnMap); break; case "STREAM": $lsLine .= "\t" . $lsIP; if (is_array($pmParam)) { foreach ($pmParam as $lsKey => $lsItem) { $lsLine .= "\t" . $lsItem; if (strtolower($lsKey) == 'userid') { $lsId = $lsItem; } } } else { $lsLine .= "\t" . $pmParam; } if ($psOutput != null) { $lsFilePosfix = "_" . $psOutput; } if (file_exists($lsLogDir)) { $loWriter = new Writer\Stream($lsLogDir . DS . date("Y-m-d") . $lsFilePosfix . ".log"); } break; } $loLogger = new Logger(); $loLogger->addWriter($loWriter); $loLogger->log($pnPriority, $lsLine, $laData); } }
/** */ public static function loadAppJson() { $laOnionApp = Onion\Register::getApplicationArray(); //Debug::displayD($gaOnionApp, true); header('Content-type: application/json'); echo Json::encode($gaOnionApp); exit(200); }
/** * * @return \Onion\Mvc\Controller\unknown */ public function getValuesAction() { $lnId = $this->request('id', null); $lsResponse = ''; $this->set('_bPushMessage', true); $this->set('_sResponse', 'ajax'); if ($lnId !== null) { $loEntity = $this->getEntityManager()->find($this->_sEntity, $lnId); if ($loEntity !== null) { $lnTotal = $loEntity->get('numPrice') - $loEntity->get('numDiscount'); $laResponse = array('Id' => $loEntity->get('id'), 'Name' => $loEntity->get('stName'), 'OldPrice' => $loEntity->get('numOldPrice'), 'Price' => $loEntity->get('numPrice'), 'Discount' => $loEntity->get('numDiscount'), 'Amount' => 1, 'Total' => $lnTotal); $lsResponse = Json::encode($laResponse); } } else { $this->flashMessenger()->addMessage(array('id' => $this->get('_sModule') . '-' . microtime(true), 'hidden' => $this->get('_bHiddenPushMessage'), 'push' => $this->get('_bPushMessage'), 'type' => 'danger', 'msg' => Translator::i18n('Não foi passado nenhum id de destinatário!'))); } $loView = new ViewModel(); return $this->setResponseType($loView, $lsResponse); }
/** */ public static function showDebug() { $laConfig = Config::getAppOptions(); $laDebug = $laConfig['log']['debug']['PHP']; if (Util::toBoolean($laDebug['enable']) && $laDebug['output'] == "BUFFER") { $loBuffer = Session::getRegister("DEBUG"); echo '<pre style="margin:50px;"><code><fieldset><legend>Onion Debug:</legend>'; if (is_array($loBuffer)) { foreach ($loBuffer as $lsItem) { self::displayDebug(Json::decode($lsItem)); echo "<br/><hr/><br/>"; } } echo '</fieldset></code></pre>'; } Session::clearRegister("DEBUG"); }
/** */ public static function log($poCredentials, $psMsg = "OK") { $laConfig = Config::getAppOptions(); $laLog = $laConfig['log']['log']['access']; $laDb = $laConfig['db'][APP_ENV]; $lnId = null; $lsUsername = null; $lnGroupId = null; if (is_object($poCredentials)) { $lnId = $poCredentials->getId(); $lsUsername = $poCredentials->getUsername(); $lnGroupId = $poCredentials->getUserGroupId(); } else { $lsUsername = $poCredentials; } $lsIp = $_SERVER['REMOTE_ADDR']; $lsSession = session_id(); if (Util::toBoolean($laLog['enable'])) { if ($laLog['output'] == "DB") { $loDb = new Adapter($laDb); $laServer = $_SERVER; $laServer['ACCESS_MSG'] = $psMsg; $lsServer = Json::encode($laServer); $laExtra = array('stSession' => 'stSession', 'stIP' => 'stIP', 'txtServer' => 'txtServer'); $laData = array('stSession' => $lsSession, 'stIP' => $lsIp, 'txtServer' => $lsServer); if ($lnId !== null) { $laExtra['User_id'] = 'User_id'; $laData['User_id'] = $lnId; } $laColumnMap = array('timestamp' => 'dtInsert', 'priority' => 'stPriority', 'message' => 'txtCredentials', 'extra' => $laExtra); $laCredential = array('user' => $lsUsername, 'group' => $lnGroupId); $lsCredential = Json::encode($laCredential); $loWriter = new Writer\Db($loDb, $laLog['table'], $laColumnMap); $loLogger = new Logger(); $loLogger->addWriter($loWriter); $loLogger->info($lsCredential, $laData); } else { $laMessage = array('stIP' => $lsIp, 'stSession' => $lsSession, 'userId' => $lnId, 'user' => $lsUsername, 'group' => $lnGroupId); Event::log($laMessage, Event::INFO, $laLog['fileName'], "STREAM", true); } } }