/** * @param mixed $id * @throws Logic_WebService_Element_Service_Exception * @return Base_Db_Table_Row */ public function getService($id) { $results = is_integer($id) ? $this->_model->getService($id) : $this->_model->getServiceByHash($id); if (!$results) { throw new Logic_WebService_Element_Service_Exception('Nie ma takiej uslugi #' . $id, 406); } $this->_params = $results; return $results; }
protected function _setupValidators() { $rowSet = $this->_service->findDependentRowset('WsServiceValidator', null, $this->_service->select()->where('ghost = ?', 'FALSE')); foreach ($rowSet as $row) { if (class_exists($row->validator_name)) { $validator = $this->_createValidatorInstance($row->validator_name, $row->getValidatorParams()); } $this->addValidator($validator); } }
/** * @param string $hash * @throws Logic_WebService_Element_Client_Exception * @return Base_Db_Table_Row */ public function checkHash($hash) { if (empty($hash)) { throw new Logic_WebService_Element_Client_Exception('Nieprawidlowy parametr hash: ' . $hash, 401); } $results = $this->_model->getClientByHash($hash); if (!$results) { throw new Logic_WebService_Element_Client_Exception('Nie znaleziono klienta o podanym parametrze hash: ' . $hash, 402); } $this->_params = $results; return $results; }
/** * Testuje limit dubli dla zadanego uzytkownika dla uslugi dla klienta * * @param Base_Model_Table $model * @param integer $recipientId * @param Logic_WebService_Element_Content $content * @throws Logic_WebService_Exception * @return void */ public function checkByContent(Base_Model_Table $model, $recipientId, Logic_WebService_Element_Content $content) { $clientParams = $this->_client->getParams(); $serviceParams = $this->_service->getParams(); $counterContent = $model->getCounterWithContent('day', $recipientId, $clientParams->id, $serviceParams->id, $content->getHash()); if ($counterContent && $serviceParams->limit_day_duplicate) { $validatorDay = new Logic_Validate_ExpiryDay(); if ($serviceParams->limit_day_duplicate <= $counterContent->subcounter && !$validatorDay->isValid($counterContent->count_at_first)) { throw new Logic_WebService_Exception('Osiagnieto limit dzienny dubli (' . $serviceParams->limit_day_duplicate . ') na usluge ' . $serviceParams->service_name . ' dla klienta ' . $clientParams->client_name, 432); } } }
public function removeAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); try { $this->_model->softDelete($this->_model->getAdapter()->quoteInto('id = ?', $id)); $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Logic_Ws_Exception $e) { $this->_helper->error(MSG_ERROR, $e); } }
/** * @return void */ public function detailsAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); $data = array(); try { $data = $this->_model->getSmsWithService($id); } catch (Logic_Ws_Sms_Exception $e) { $this->_helper->messenger('error', MSG_ERROR, $e); $this->_helper->redirector('index'); return; } $this->view->data = $data; }
/** * Dodaje szablon do bazy szablonow * * Jezeli juz istnieje szablon o zadanej nazwie, porownuje hash md5 nowej tresci z hashem md5 ostatniej wersji * szablonu z baza. Jezeli sie roznia, dodaje $content jako najnowsza wersje szablonu o $this->_name. * Jezeli szablon o zadanej nazwie nie istnieje, dodaje $content jako nowy szablon. * * @param string $content * @param mixed $attachments * @throws Logic_WebService_Element_Template_Exception * @return Logic_WebService_Element_Template_Abstract */ public function addTemplate($content, $attachments = null) { $insert = array('ws_client_id' => $this->_ownerID, 'template_name' => $this->_name, 'template_content' => $content, 'template_content_hash' => md5($content)); $newest = $this->_model->getTemplateNewestByNameAndOwner($this->_name, $this->_ownerID); if ($newest) { // dodaje nowa wersje juz istniejacej templatki if (md5($content) == $newest->template_content_hash) { // throw new Logic_WebService_Element_Template_Exception('Zawartosc szablonu nie zmienila sie - aktualna wersja: ' . $newest->template_name . ' v.' . $newest->version_num . ' ' . $newest->created_at, 443); // zakomentowano 9.12.2010 // drobny ficzer ;] $this->addMessage('Zawartosc szablonu nie zmienila sie - aktualna wersja: ' . $newest->template_name . ' v.' . $newest->version_num . ' ' . $newest->created_at); $this->setHash(md5($content)); return $this; } else { $insert['version_num'] = $newest->version_num + 1; } } $this->_id = $this->_model->addTemplate($insert); $this->_content = $content; if ($attachments) { $model = new WsTemplateAttachment(); $attachmentsCheck = $attachments->getAttachments(); $hashesCheck = $attachments->getHashes(); if (empty($attachmentsCheck) && !empty($hashesCheck)) { throw new Logic_WebService_Exception('Podano hash\'e MD5 zamiast zalacznikow', 448); } $model->addAttachment($this->_id, $attachments->mapToModel()); } return $this; }
public function ghostUpdate($data, $where) { $select = $this->select(); foreach ($where as $k => $v) { $select->where($k, $v); } $old = $this->fetchRow($select); if ($old) { $old = $old->toArray(); $new = array_merge($old, $data); foreach ($new as $k => &$row) { if (is_bool($row)) { if ($row) { $row = 't'; } else { $row = 'f'; } } } parent::update(array('ghost' => 't'), array('id = ?' => $old['id'])); unset($new['id']); unset($new['last_change']); parent::insert($new); return true; } else { return 0; } }
/** * @return void */ public function editAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); $form = new Logic_Ws_Sms_Blacklist_Form_Generic(); if ($request->isPost()) { if ($form->isValid($request->getPost())) { try { $values = $form->getValues(); if (!empty($values['ws_service_id'])) { foreach ($values['ws_service_id'] as $service) { $val['ws_service_id'] = $service; $val['number_comment'] = $values['number_comment']; $val['phone_number'] = $values['phone_number']; $this->_model->editBlackList($id, $val); } } else { $this->_model->editBlackList($id, $values); } $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Logic_Exception $e) { $this->_helper->messenger->error(); } } } else { $form->setDefaults($this->_model->getRecord($id)); } $this->view->form = $form; }
/** * @return void */ public function editAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); $form = new Logic_Ws_Sms_RecipientDeveloper_Form_Generic(); if ($request->isPost()) { if ($form->isCancelled($this->getRequest()->getPost())) { $this->_helper->redirector('index', null, null); return; } if ($form->isValid($request->getPost())) { try { $values = $form->getValues(); $this->_model->editRecipientDeveloper($id, $values); $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Logic_Exception $e) { $this->_helper->messenger->error(); } } } else { $form->setDefaults($this->_model->getRecord($id)); } $this->view->form = $form; }
/** * Utworzenie nowej usługi lub nadpis poprzedniej (o ile podano id usługi) * @param array $data * @throws Logic_Exception */ public function createOrUpdateService(array $data, $idService = null) { if (null === $idService) { $row = $this->getModel()->createRow($data); } else { $row = $this->getService($idService); $row->setFromArray($data); } try { $idService = $row->save(); } catch (Exception $e) { throw new Logic_Exception("Cannot save basic service data!", 0, $e); } if ($this->_model->getName() == 'service_sms' && !empty($data['mask'])) { $maskModel = new WsServiceSmsMask(); $maskModel->setMasksForService($idService, $data['mask']); } return $idService; }
public function checkstatusAction() { $this->_helper->getHelper('ViewRenderer')->setNoRender(true); $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); if (empty($id)) { $this->_helper->messenger->error('Nie podano parametru ID'); return null; } try { $smsInfo = $this->_model->getSmsInfo($id); $cfg = Zend_Registry::get('config'); $config = array('throwExceptions' => true, 'clientHash' => $cfg['services']['mrdebug']['hash'], 'serviceHash' => $smsInfo->service_hash); $http = new Zend_Controller_Request_Http(); $host = 'http://' . $http->getServer('HTTP_HOST') . '/ws/'; switch ($values['env_type']) { case '1': $config['wsdl'] = $host . 'sms/?wsdl'; break; default: $config['wsdl'] = $host . 'sms/?wsdl'; } $sms = new SmsSoapClient($config); $sms->registerSmsIDManyRaw($smsInfo->smsid); $response = $sms->getSmsInfoMany(); foreach ($response as $r) { if ($r->errorCode == 0) { $message .= "SMS o ID:" . $r->smsId . " został wysłany"; } else { $message .= "SMS o ID: " . $r->smsId . " nie został wysłany: " . $r->errorMessage . '(' . $r->errorCode . ')'; } } $this->_helper->messenger->info($message); $this->_redirect($this->getRequest()->getHeader('referer')); return; } catch (Exception $ex) { $this->_helper->messenger->error(); $this->_redirect($this->getRequest()->getHeader('referer')); } }
/** * Usuniecie templatki * * @return void */ public function deleteAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); try { $this->_model->deleteTemplate($id); $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Zend_Db_Exception $e) { $this->_helper->messenger->error(); $this->_helper->redirector('index'); } }
/** * @return void */ public function editAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); $form = new Logic_Ws_Service_SaveIP_Form_Generic(); if ($request->isPost()) { if ($form->isCancelled($this->getRequest()->getPost())) { $this->_helper->redirector('index', null, null); return; } if ($form->isValid($request->getPost())) { try { $this->_model->updateIP($form, $id); $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Logic_Ws_Exception $e) { $this->_helper->messenger->error($e->getMessage()); } } } else { $data = array(); try { $data = $this->_model->getIpWithClients(intval($id)); $row = new Row_WsSaveIP(); $ip = str_replace(array('{', '}', ','), array('', '', "\n"), $data['ip']); $data['ip'] = $ip; } catch (Zend_Db_Exception $e) { $this->_helper->messenger->error($e->getMessage()); $this->_helper->redirector('index'); return; } $form->setDefaults($data); } $this->view->form = $form; }
public function permissionsAction() { $request = $this->getRequest(); $id = $request->getParam('id'); $id = $this->_helper->IdConvert->hexToStr($id); if (empty($id)) { $this->_helper->messenger->error('Nie podano parametru ID'); return null; } $clientModel = new WsClient(); $data = $clientModel->findOne($id); $form = new Logic_Ws_Client_Form_Permissions($data->shipping_type); if ($this->getRequest()->isPost()) { if ($form->isCancelled($this->getRequest()->getPost())) { $this->_helper->redirector('index', null, null); return; } if ($form->isValid($request->getPost())) { $post = $request->getPost(); try { $clientModel->updatePermissionsToGroup($form, $id); $this->_helper->messenger("success", 'Zmiany w uprawnieniach zostały zapisane.'); $this->_helper->redirector('index'); return; } catch (Logic_Uzytkownik_Exception $e) { $this->_helper->messenger('error', MSG_ERROR, $e); } } } else { $depTables = array('sms' => 'WsClientHasServiceGroup', 'mail' => 'WsClientHasServiceGroup', 'sset' => 'WsClientHasServiceSet'); foreach ($depTables as $key => $table) { $select = $this->_model->getTableFromString($table)->select()->where('ghost = ?', 'FALSE'); $groups = $data->findDependentRowset($table, null, $select); $form->setDefaults($groups->toArray(), $key); } $limits = $data->findDependentRowset('WsServiceSetLimits'); $form->setLimits($limits->toArray()); } $this->view->form = $form; }
public function removeclientAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); if (empty($id)) { $this->_helper->messenger->error('Nie podano parametru ID'); return $this->_helper->redirector('index'); } try { $db = $this->_model->getDefaultAdapter(); $db->beginTransaction(); $model = new WsClientHasServiceSet(); $model->deleteClient($id); $db->commit(); $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Logic_Ws_Exception $e) { $db->rollBack(); $this->_helper->error(MSG_ERROR, $e); } }
/** * @todo Wysyłka maila * @param type $data */ public function saveFormData($data, Zend_Db_Table_Row $row = null) { $delegation = new DelegationSettlement(); $utils = new Logic_Utilities(); $idConvert = Zend_Controller_Action_HelperBroker::getStaticHelper('IdConvert'); $uri = 'delegations/accept/id_delegation/' . $idConvert->strToHex($data['id_delegation']); $data['id_address_history'] = $this->getCurrentAddress(); //$data['id_address_history'] = $this->addAddressToHistory(); try { $db = Base_Model_Table::getDefaultAdapter(); $db->beginTransaction(); if ($row) { if ($data['id_state'] != Logic_ItemAbstract::STATE_NEW_2) { if ($row->id_state != $data['id_state'] && !($row->id_state == Logic_ItemAbstract::STATE_APPROVED_2 && $data['id_state'] == Logic_ItemAbstract::STATE_NEW_2)) { $row->findParentRow('DelegationSettlement')->setFromArray(array_merge($this->getCurrentValuesIds(), $data))->save(); $this->saveLocations($row->id, $data['departure']); } else { throw new Exception('Krok który próbowałeś zapisać został już wykonany.'); } } else { if (!($row->id_state == Logic_ItemAbstract::STATE_APPROVED_2 && $data['id_state'] == Logic_ItemAbstract::STATE_NEW_2)) { $row->findParentRow('DelegationSettlement')->setFromArray(array_merge($this->getCurrentValuesIds(), $data))->save(); $this->saveLocations($row->id, $data['departure']); } else { throw new Exception('Delegacja została już wysłana do zatwierdzenia.'); } } } else { $idRow = $delegation->createRow(array_merge($this->getCurrentValuesIds(), $data))->save(); $this->saveLocations($idRow, $data['departure']); } $db->commit(); } catch (Exception $exc) { $db->rollBack(); //diee($exc->getTraceAsString()); throw new Exception("Błąd podczas dodawania nowego rozliczenia! Treść: " . $exc->getMessage()); } }
/** * Ładowanie danych do pakietu * @param type $limit */ public function loadPackage($package) { $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); $updloadDir = $config->uploads->destination; if (false === is_readable($fileName = $updloadDir . DIRECTORY_SEPARATOR . $package['file_name']) || false === is_file($fileName)) { throw new Exception("File for packageId = " . $package['id'] . " does not exists or is not readable"); } $serviceSet = new WsServiceSet(); $serviceSetRow = $serviceSet->findOne($package['ws_service_set_id']); $fileHandler = fopen($fileName, 'r'); $dataToSave = array(); $errors = array(); $this->_getDataFromFileByConfig($fileHandler, $serviceSetRow->getDelimiter(), $serviceSetRow->file_type, $dataToSave, $serviceSetRow->message, $errors); $packageDataModel = new WsPackageData(); $packageModel = new WsPackage(); if (false === empty($errors)) { $this->packageError($package['id'], $errors); } Base_Model_Table::getDefaultAdapter()->beginTransaction(); try { foreach ($dataToSave as &$chunk) { $packageDataModel->createRow(array('ws_package_id' => $package['id'], 'tags' => Zend_Json::encode($chunk), 'id_status' => WsPackageStatus::STATUS_READY))->save(); } Base_Model_Table::getDefaultAdapter()->commit(); } catch (Exception $exc) { Base_Model_Table::getDefaultAdapter()->rollBack(); throw new Logic_Exception("Cannot save package data! Error: " . $exc->getMessage(), null, $exc); } fclose($fileHandler); }
function __unset($name) { parent::delete(array('key = ?' => $name)); $this->_cache->remove(__CLASS__ . $name); }
/** * Czyści klucz na podstawie wygenerowanego identyfikatora */ protected function removeCache() { $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); if ($bootstrap) { $cache = $bootstrap->getResource('cachemanager')->getCache('requestcache'); /* @var Zend_Cache_Core $cache */ $cache->remove(Base_Model_Table::buildRequestCacheID($this->getTableClass(), $this->_getPrimaryKey())); } }
public function getObjectTypeId($ObjectType) { $adapter = Base_Model_Table::getDefaultAdapter(); $select = $adapter->select()->from('scan.dictionary', array())->joinLeft('scan.dictionary_entry', 'dictionary_entry.dictionary_id = dictionary.id')->where('dictionary.code = ?', 'typy_obiektow')->where('dictionary_entry.code = ?', $ObjectType); try { $result = $select->query()->fetchAll(); } catch (Exception $e) { throw $e; } if (empty($result) || !isset($result)) { throw new Exception('Nieznany typ obiektu'); } return $result[0]; }
public function __construct($config = array(), $definition = null) { parent::__construct($config, $definition); $db = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('multidb')->getDb('log'); $this->_setAdapter($db); }