/** * Load the application options * * @param string $psOption * @return array */ public static function getZendOptions($psOption = null) { $goOnionApp = Application::getInstance(); if ($goOnionApp && $goOnionApp->get('active')) { $gaZendConfig = $goOnionApp->get('_generalConfig'); } if ($psOption !== null && isset($gaZendConfig[$psOption])) { return $gaZendConfig[$psOption]; } else { return $gaZendConfig; } }
/** * */ public function editAction($pnId = null) { $lnId = $this->request('id', $pnId); $this->_sWindowType = $this->request('w', 'default'); if ($lnId === null) { return $this->redirect()->toRoute($this->_sRoute, array('action' => 'add')); } $loEntity = $this->getEntityManager()->find($this->_sEntityExtended, $lnId); $loEntity->getObject(); $loForm = Application::factory($this->_sForm); $loForm->setObjectManager($this->getEntityManager()); $loForm->setActionType('edit'); $loForm->setEntity($this->_sEntityExtended); $loForm->setRecordId($lnId); $loForm->setForm(); $loForm->setWindowType($this->_sWindowType); $loForm->setCancelBtnType($this->_sWindowType == 'default' ? 'cancel' : 'close'); if (method_exists($this, 'editFormSettings')) { $this->editFormSettings($loForm, $loEntity); } $loForm->setBindOnValidate(false); $loForm->bind($loEntity); $lsSecurity = $this->requestPost('security', null); if ($this->requestIsPost() && $lsSecurity !== null) { if (method_exists($loForm, 'getInputFilter')) { $loForm->setInputFilter($loForm->getInputFilter()); } $loForm->setData($this->requestPost()); $loForm->setEntityData($loEntity); if ($loForm->isValid()) { $loForm->bindValues(); $laPostData = $loForm->getDataForm(); $laFileData = $this->requestFiles()->toArray(); $lbResponse = true; if (method_exists($this, 'editBeforeFlush')) { $lbResponse = $this->editBeforeFlush($laPostData, $laFileData, $loForm, $loEntity); } $loEntityOriginal = clone $loEntity; $loEntityOriginal->set('id', $lnId); $loEntity->populate($laPostData); $loEntity->editValidate(); if ($lbResponse) { $this->getEntityManager()->persist($loEntity); $lbResponse = $this->entityFlush(); if (method_exists($this, 'editAfterFlush')) { $lbResponse = $this->editAfterFlush($laPostData, $laFileData, $loForm, $loEntity, $loEntityOriginal, $lbResponse); } if ($lbResponse) { $lnUserId = $this->getAuthenticatedUser(); $laChanges = $this->checkChangeEntity($loEntityOriginal, $loEntity); Event::log(array('userId' => $lnUserId, 'module' => $this->_sModule, 'action' => 'edit', 'record' => $loEntity->get('id'), 'changes' => $laChanges), 6); $this->flashMessenger()->addMessage(array('id' => $this->get('_sModule') . '-' . microtime(true), 'hidden' => $this->get('_bHiddenPushMessage'), 'push' => $this->get('_bPushMessage'), 'type' => 'success', 'msg' => Translator::i18n('Alterado com sucesso!'))); } } if (method_exists($this, 'editRedirect')) { $lmReturn = $this->editRedirect($loEntity); if ($lmReturn !== false) { return $lmReturn; } } else { if ($this->_sWindowType == 'default') { return $this->redirect()->toRoute($this->_sRoute, array('action' => $this->requestPost('back', 'index'))); } else { return $this->redirect()->toRoute($this->_sRoute, array('action' => 'message')); } } } } if (method_exists($this, 'editFormSettingsAfter')) { $this->editFormSettingsAfter($loForm, $loEntity); } $loView = new ViewModel(array('lsBack' => $this->requestPost('back', 'index'), 'lsTitleS' => $this->_sTitleS, 'lsTitleP' => $this->_sTitleP, 'lsRoute' => $this->_sRoute, 'lnId' => $lnId, 'loForm' => $loForm)); return $this->setResponseType($loView); }
public function sendAction() { $this->_sLayout = 'Frontend'; $this->_sWindowType = 'modal'; $this->_sResponse = 'ajax'; $this->_bPushMessage = true; $lsMsg = null; $loForm = Application::factory('ContactUs\\Form\\ContactUs2Form'); $loForm->setForm(); if ($this->requestIsPost()) { $loForm->setData($this->requestPost()); if ($loForm->isValid()) { $laData = $loForm->getData(); $laMsg = print_r($laData, true); $loSendMail = new SendMail(); try { $loSendMail->send(array($laData['fromMail'], $laData['fromName']), $laData['subject'], $laMsg); $lsMsg = Translator::i18n('Sua mensagem foi enviada com sucesso.'); } catch (Exception $e) { $lsMsg = sprintf('<strong>%s</strong><br/> %s<br/>%s', Translator::i18n('Opa!'), Translator::i18n('Algo de errado aconteceu. Por favor, tente novamente mais tarde.'), $e->getMessage()); } } else { Debug::display('not'); } } else { Debug::display('nao'); } $loView = new ViewModel(array('lsTitle' => $this->_sTitleS, 'lsRoute' => $this->_sRoute, 'loForm' => $loForm)); return $this->setResponseType($loView, $lsMsg); }
/** * * @return \Onion\View\Model\ViewModel */ public function forgottenPasswordAction() { $loForm = Application::factory($this->_sForgotten); $loForm->setObjectManager($this->getEntityManager()); $loForm->setActionType('forgotten'); $loForm->setEntity($this->_sEntity); $loForm->setForm(); $lsSecurity = $this->requestPost('security', null); if ($this->requestIsPost() && $lsSecurity !== null) { $loForm->setInputFilter($loForm->getInputFilter()); $loForm->setData($this->requestPost()); if ($loForm->isValid()) { $laData = $loForm->getDataForm(); $lsEmail = String::escapeString($laData['stEmail']); $loEntityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $loUser = $loEntityManager->getRepository($this->_sEntity)->findOneBy(array('stEmail' => $lsEmail)); $lsPassword = String::generatePassword(); if ($this->sendPasswordByEmail($lsEmail, $lsPassword)) { $loUser->setStPassword($lsPassword); $loEntityManager->persist($loUser); $loEntityManager->flush(); } } } return new ViewModel(array('lsTitle' => $this->_sForgottenTitle, 'lsRoute' => $this->_sRoute, 'loForm' => $loForm)); }
public function indexAction() { $loForm = Application::factory($this->_sForm); $loForm->setObjectManager($this->getEntityManager()); $loForm->setActionType('add'); $loForm->setEntity($this->_sEntityExtended); $loForm->setForm(); $loEntity = null; $this->_sWindowType = $this->request('w', 'default'); $loForm->setWindowType($this->_sWindowType); $loForm->setCancelBtnType($this->_sWindowType == 'default' ? 'none' : 'close'); if (method_exists($this, 'addFormSettings')) { $this->addFormSettings($loForm); } $lsSecurity = $this->requestPost('security', null); if ($this->requestIsPost() && $lsSecurity !== null) { $loEntity = Application::factory($this->_sEntity); $loEntity->getObject(); $loForm->bind($loEntity); if (method_exists($loForm, 'getInputFilter')) { $loForm->setInputFilter($loForm->getInputFilter()); } $loForm->setData($this->requestPost()); if ($loForm->isValid()) { $loEntity->setDefault($this->_sTable); $laPostData = $loForm->getDataForm(); $laFileData = $this->requestFiles()->toArray(); $loEntity->populate($laPostData); $loEntity->addValidate(); $this->getEntityManager()->persist($loEntity); $lbResponse = true; if (method_exists($this, 'addBeforeFlush')) { $lbResponse = $this->addBeforeFlush($laPostData, $laFileData, $loForm, $loEntity); } if ($lbResponse) { $lnUserId = $this->getAuthenticatedUser(); if (null !== $lnUserId) { $loEntity->set('User_id', $lnUserId); } $lbResponse = $this->entityFlush(); if (method_exists($this, 'addAfterFlush')) { $lbResponse = $this->addAfterFlush($laPostData, $laFileData, $loForm, $loEntity, $lbResponse); } if ($lbResponse) { $this->flashMessenger()->addMessage(array('id' => $this->get('_sModule') . '-' . microtime(true), 'hidden' => $this->get('_bHiddenPushMessage'), 'push' => $this->get('_bPushMessage'), 'type' => 'success', 'msg' => Translator::i18n('Registrado com sucesso!'))); } } if (method_exists($this, 'addRedirect')) { return $this->addRedirect(); } else { if ($this->_sWindowType == 'default') { return $this->redirect()->toRoute($this->_sRoute, array('action' => $this->requestPost('back', 'index'))); } else { return $this->redirect()->toRoute($this->_sRoute, array('action' => 'message')); } } } } if (method_exists($this, 'addFormSettingsAfter')) { $this->addFormSettingsAfter($loForm, $loEntity); } $loView = new ViewModel(array('lsBack' => $this->requestPost('back', 'index'), 'lsTitleS' => $this->_sTitleS, 'lsTitleP' => $this->_sTitleP, 'lsRoute' => $this->_sRoute, 'loForm' => $loForm)); return $this->setResponseType($loView); }
/** * * @param int $pnStatus * @param bool $pbActive * @param string $psBack * @param string $psFolderTitle * @return string|\Onion\View\Model\ViewModel */ public function gridx($pnStatus = 0, $pbActive = 1, $psBack = 'index', $psFolderTitle = null) { $loGrid = Application::factory('User\\Grid\\UserGrid'); $lnPage = $this->request('p', 0); $lnRows = $this->request('rows', $loGrid->get('numRows')); $lsOrder = $this->request('ord', $loGrid->get('order')); $lsOrderCol = $this->request('col', $loGrid->get('orderCol')); $lsQuery = $this->request('q', ''); $lsField = $this->request('f', ''); $lsField = $loGrid->isSearchField($lsField) ? $lsField : $loGrid->get('searchFieldDefault'); $lsWhere = ''; if ($loGrid->get('showSearch') && !empty($lsQuery)) { $loSearch = new Search(); $loSearch->set('sSearchFields', $lsField); $lsWhere .= $loSearch->createRLikeQuery('"' . $lsQuery . '"', 'r'); } $laParams = array('status' => $pnStatus, 'active' => $pbActive, 'rows' => $lnRows, 'page' => $lnPage, 'col' => $lsOrderCol, 'ord' => $lsOrder, 'q' => $lsQuery, 'where' => $lsWhere); if (method_exists($this, 'gridBeforeSelect')) { $laParams = $this->gridBeforeSelect($laParams); } $laResult = $this->getEntityManager()->getRepository($this->_sEntityExtended)->getList($laParams, $lbCache = false); if (method_exists($this, 'gridAfterSelect')) { $laResult = $this->gridAfterSelect($laResult); } $laMessages = $this->flashMessenger()->getMessages(); $loGrid->setData($laResult['resultSet'])->setTotalResults($laResult['totalCount'])->setBackTo($psBack)->setMessages($laMessages)->setNumRows($lnRows)->setSearchFieldDefault($lsField)->setSearchQuery($lsQuery)->setOrder($lsOrder)->setOrderCol($lsOrderCol)->setCurrentPage($lnPage); $lsGrid = $loGrid->render($this->_sRoute, $psFolderTitle); if (method_exists($this, 'gridAfterRender')) { $lsGrid = $this->gridAfterRender($lsGrid); } $loView = new ViewModel(); if ($this->isXmlHttpRequest()) { $loView->setTerminal(true); // desabilita o layout $loResponse = $this->getResponse(); $loResponse->setStatusCode(200); $loResponse->setContent($lsGrid); return $loResponse; } else { $loView->setVariables(array('lsGrid' => $lsGrid, 'lsFolder' => '', 'lsTitleP' => ''), true); } return $loView; }
/** * */ public function indexAction() { $loForm = Application::factory($this->_sForm); $loForm->setForm(); $loForm->setWindowType($this->_sWindowType); $loForm->setCancelBtnType($this->_sWindowType == 'default' ? 'none' : 'close'); $loForm->setShowCollapseBtn(true); $loForm->setCollapsed(true); $loForm->setData($this->requestAll()); $lsGrid = $this->grid(0, 1, 'filter'); $loView = new ViewModel(array('loForm' => $loForm, 'lsGrid' => $lsGrid, 'lsTitleS' => $this->_sTitleS, 'lsRoute' => $this->_sRoute, 'lsParams' => $this->_sGetParam)); return $this->setResponseType($loView); }
public function sendMail($paTo, $paMsg) { $loForm = Application::factory($this->_sForm); $loSendMail = new SendMail(); try { $loSendMail->send(null, Translator::i18n('Acesso '), $paMsg, $paTo); $this->flashMessenger()->addMessage(array('id' => $this->get('_sModule') . '-' . microtime(true), 'hidden' => $this->get('_bHiddenPushMessage'), 'push' => $this->get('_bPushMessage'), 'type' => 'success', 'msg' => sprintf("<strong>%s</strong><br/> %s", Translator::i18n('Success!'), Translator::i18n('The message was sent successfully.')))); } catch (Exception $e) { $this->flashMessenger()->addMessage(array('id' => $this->get('_sModule') . '-' . microtime(true), 'hidden' => $this->get('_bHiddenPushMessage'), 'push' => $this->get('_bPushMessage'), 'type' => 'error', 'msg' => sprintf('<strong>%s</strong><br/> %s<br/>%s', Translator::i18n('Ops!'), Translator::i18n('Something wrong has happened. Please, try again later.'), $e->getMessage()))); } }
public function addAfterFlushx($paPostData, $paFileData, $poForm, $poEntity, $pbResponse) { $lnCompanyId = $poEntity->get('id'); $lnUserId = $poEntity->get('User_id'); $lsResource = $this->_sTable; $laContacts = null; $laAddresses = null; if (isset($paPostData['Contacts'])) { $laContacts = $paPostData['Contacts']; } if (isset($paPostData['Addresses'])) { $laAddresses = $paPostData['Addresses']; } if (is_array($laContacts)) { foreach ($laContacts as $lnContactId) { $loContact = Application::factory('Contact\\Entity\\ResourceHasContactBasic'); $loContact->set('stResource', $lsResource); $loContact->set('Resource_id', $lsResource); $loContact->set('Contact_id', $lsResource); $loContact->set('User_id', $lsResource); $this->getEntityManager()->persist($loContact); $this->entityFlush(); } } if (is_array($laAddresses)) { foreach ($laAddresses as $lnAddressId) { $loAddress = Application::factory('Address\\Entity\\ResourceHasAddressBasic'); $loAddress->set('stResource', $lsResource); $loAddress->set('Resource_id', $lsResource); $loAddress->set('Address_id', $lsResource); $loAddress->set('User_id', $lsResource); $this->getEntityManager()->persist($loAddress); $this->entityFlush(); } } }