/** * Start analyzer * * @param Zend_Db_Table_Abstract $table * * @return array */ public function analyzeTable(Zend_Db_Table_Abstract $table) { $info = $table->info(); $info['uniques'] = array(); unset($info['sequence'], $info['schema'], $info['rowClass'], $info['rowsetClass'], $info['dependentTables'], $info['referenceMap']); $adapter = $table->getAdapter(); foreach ($info['metadata'] as $property => $details) { // match php types $info['phptypes'][$property] = $this->convertMysqlTypeToPhp($details['DATA_TYPE']); // find uniques $tmp = $adapter->fetchRow('DESCRIBE `' . $info['name'] . '` `' . $property . '`;'); if (!empty($tmp['Key']) && $tmp['Key'] != 'MUL') { $info['uniques'][$property] = $property; } } // get f-keys $result = $adapter->fetchAll('SHOW CREATE TABLE `' . $info['name'] . '`'); $query = $result[0]['Create Table']; $lines = explode("\n", $query); $tblinfo = array(); $keys = array(); foreach ($lines as $line) { preg_match('/^\\s*CONSTRAINT `(\\w+)` FOREIGN KEY \\(`(\\w+)`\\) REFERENCES `(\\w+)` \\(`(\\w+)`\\)/', $line, $tblinfo); if (sizeof($tblinfo) > 0) { $keys[] = $tmp = array('key' => $tblinfo[1], 'column' => $tblinfo[2], 'fk_table' => $tblinfo[3], 'fk_column' => $tblinfo[4]); $this->getDependencyChecker()->isChild($info['name'], $tmp['column'], $tmp['key'], $tmp['fk_table'], $tmp['fk_column']); } } $info['foreign_keys'] = $keys; return $info; }
public function setModel(Zend_Db_Table_Abstract $model) { $this->_model = $model; $this->_setPrimaryIndex($this->_model->getPrimaryIndex()); $info = $model->info(); $this->_columns = $info['cols']; }
/** * Creating a query using a Model. * * @param Zend_Db_Table_Abstract $model * @param array $relationmap Relation map for joins * * @return $this */ public function __construct(Zend_Db_Table_Abstract $model, array $relationMap = array()) { $this->_model = $model; $this->_relationMap = $relationMap; $info = $model->info(); $select = $model->select(); $map = $info['referenceMap']; $map = array_merge_recursive($map, $this->_relationMap); if (is_array($map) && count($map) > 0) { $select->setIntegrityCheck(false); $columnsToRemove = array(); foreach ($map as $sel) { if (is_array($sel['columns'])) { $columnsToRemove = array_merge($columnsToRemove, $sel['columns']); } else { $columnsToRemove[] = $sel['columns']; } } $columnsMainTable = array_diff($info['cols'], $columnsToRemove); $select->from($info['name'], $columnsMainTable, $info['schema']); $tAlias = array($info['name'] => 1); $this->_setJoins($info['name'], $map, $select, $tAlias); } else { $select->from($info['name'], $info['cols'], $info['schema']); } parent::__construct($select); return $this; }
/** * Find admin * * @param int $applicationId * @param string $username * @param Admin_Model_Admin $admin * @return boolean */ public function find($applicationId, $username, Admin_Model_Admin $admin) { $select = $this->_dbTable->select(); $select->setIntegrityCheck(false)->from(array('a' => 'admin'), array('a.*'))->joinLeft(array("aa" => "admin_application"), "aa.admin_id = a.id")->where('a.username = ?', $username)->where('aa.application_id = ?', $applicationId); $resultSet = $this->_dbTable->fetchAll($select); if (0 == count($resultSet)) { return false; } //get first row from resultSet $row = $resultSet->current(); $admin->setOptions($row->toArray()); return true; }
public function update($id, $state, $info) { $data = array('state' => $state, 'info' => $info, 'lastupdate' => time()); $found = $this->find($id); if ($found) { $data = array_merge($found, $data); unset($data['id']); $this->dbTable->update($data, array('id = ?' => $id)); } else { $data['id'] = $id; $data['sticked'] = 0; $this->dbTable->insert($data); } }
public function isValid($value) { $db = $this->_model->getAdapter(); $where = $db->quoteInto($this->_field . ' = ?', $value); if (null !== $this->_where) { $where .= " AND {$this->_where}"; } $rows = $this->_model->fetchAll($where); if (count($rows)) { $this->_messages[] = Axis::translate('core')->__("Record %s already exist", $value); return $this->_not; } $this->_messages[] = Axis::translate('core')->__("Record %s doesn't found", $value); return !$this->_not; }
public function insert(array $data) { $date = new Zend_Date(); $data['datebug'] = $date->toString('Y-MM-d'); $data['statut'] = "Non lu"; return parent::insert($data); }
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); $result = $auth->getStorage(); $identity = $auth->getIdentity(); $registry = Zend_Registry::getInstance(); $config = Zend_Registry::get('config'); $module = strtolower($this->_request->getModuleName()); $controller = strtolower($this->_request->getControllerName()); $action = strtolower($this->_request->getActionName()); if ($identity && $identity != "") { $layout = Zend_Layout::getMvcInstance(); $view = $layout->getView(); $view->login = $identity; $siteInfoNamespace = new Zend_Session_Namespace('siteInfoNamespace'); $id = $siteInfoNamespace->userId; $view->firstname = $siteInfoNamespace->Firstname; $username = $siteInfoNamespace->username; $password = $siteInfoNamespace->password; $db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => $config->resources->db->params->host, 'username' => $username, 'password' => $password, 'dbname' => $config->resources->db->params->dbname)); Zend_Db_Table_Abstract::setDefaultAdapter($db); return; } else { $siteInfoNamespace = new Zend_Session_Namespace('siteInfoNamespace'); $siteInfoNamespace->requestURL = $this->_request->getParams(); $this->_request->setModuleName('default'); $this->_request->setControllerName('Auth'); $this->_request->setActionName('login'); } }
public function editarAction() { if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); $ok = true; // disativa todos os precos do salao $modelEspecialidadePreco = new Model_DbTable_EspecialidadePreco(); $modelEspecialidadePreco->update(array('especialidade_preco_ativo' => 0), "salao_id = {$this->_auth->salao_id}"); Zend_Db_Table_Abstract::getDefaultAdapter()->beginTransaction(); foreach ($data['especialidade_preco'] as $key => $value) { if (!empty($value)) { try { $value = str_replace('.', '', $value); $value = str_replace(',', '.', $value); $data_insert = array('especialidade_id' => $key, 'salao_id' => $this->_auth->salao_id, 'especialidade_preco_preco' => $value); $modelEspecialidadePreco->insert($data_insert); } catch (Exception $ex) { $ok = false; $this->_helper->flashMessenger->addMessage(array('danger' => 'Houve um problema ao editar os preços. ' . $ex->getMessage())); Zend_Db_Table_Abstract::getDefaultAdapter()->rollBack(); } } } Zend_Db_Table_Abstract::getDefaultAdapter()->commit(); if ($ok) { $this->_helper->flashMessenger->addMessage(array('success' => 'Preços alterados com sucesso')); } $this->_redirect("/salao/preco"); } }
public function updateStatus($status, $id) { foreach ($status as $key => $val) { $data[$key] = $val; } return parent::update($data, array('user_id = ?' => $id)); }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $row = $this->_checkCeop($this->_data); if (!empty($row)) { $this->_message->addMessage('CEOP iha tiha ona.', App_Message::ERROR); return false; } if (empty($this->_data['id_dec'])) { $history = 'INSERE CEOP-DEC: %s- INSERIDO NOVO CEOP-DEC COM SUCESSO'; $this->_data['fk_id_sysuser'] = Zend_Auth::getInstance()->getIdentity()->id_sysuser; $this->_data['registry_date'] = Zend_Date::now()->toString('yyyy-MM-dd'); } else { $history = 'ALTERA CEOP-DEC: %s DADUS PRINCIPAL - ALTERA CEOP-DEC'; } $id = parent::_simpleSave(); $history = sprintf($history, $id); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
public function __construct() { //set country //lookup country from subdomain // must be format like http://country.site.org $parts = explode('.', $_SERVER['HTTP_HOST']); self::$COUNTRY = $parts[0]; require_once 'settings.php'; $countryLoaded = false; if ($parts[1] == 'trainingdata') { Settings::$DB_DATABASE = Globals::$DB_TABLE_PREFIX . $parts[0]; self::$COUNTRY = $parts[0]; Settings::$COUNTRY_BASE_URL = 'http://' . $parts[0] . '.' . Globals::$DOMAIN; $countryLoaded = true; } error_reporting(E_ALL); // PATH_SEPARATOR = ; for windows, : for *nix $iReturn = ini_set('include_path', Globals::$BASE_PATH . PATH_SEPARATOR . Globals::$BASE_PATH . 'app' . PATH_SEPARATOR . (Globals::$BASE_PATH . 'ZendFramework' . DIRECTORY_SEPARATOR . 'library') . PATH_SEPARATOR . ini_get('include_path')); require_once 'Zend/Loader.php'; if ($countryLoaded) { //fixes mysterious configuration issue require_once 'Zend/Db/Adapter/Pdo/Mysql.php'; require_once 'Zend/Db.php'; //set a default database adaptor $db = Zend_Db::factory('PDO_MYSQL', array('host' => Settings::$DB_SERVER, 'username' => Settings::$DB_USERNAME, 'password' => Settings::$DB_PWD, 'dbname' => Settings::$DB_DATABASE)); require_once 'Zend/Db/Table/Abstract.php'; Zend_Db_Table_Abstract::setDefaultAdapter($db); } }
public function _initDb() { $resource = $this->getPluginResource('db'); $options = $resource->getOptions(); $db = new Zend_Db_Adapter_Pdo_Mysql($options["params"]); Zend_Db_Table_Abstract::setDefaultAdapter($db); }
public function run() { // Lade Konfig $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); Zend_Registry::set('config', $config); // Erstelle DB Adapter $db = Zend_Db::factory($config->db); Zend_Registry::set('db', $db); Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('db')); if (APPLICATION_ENV !== 'production') { $profiler = new Zend_Db_Profiler_Firebug('All Database Queries:'); $profiler->setEnabled(true); $db->setProfiler($profiler); } $resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => APPLICATION_PATH, 'namespace' => '')); $resourceLoader->addResourceType('plugins', 'plugins', 'Plugins'); if (PHP_SAPI != 'cli') { $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new Plugins_Stats()); if (APPLICATION_ENV == 'production') { $front->registerPlugin(new Plugins_Cache()); } } Zend_View_Helper_PaginationControl::setDefaultViewPartial('_partials/controls.phtml'); parent::run(); }
protected function _setupPrimaryKey() { if (empty($this->_primary)) { $this->_primary = 'id'; } parent::_setupPrimaryKey(); }
public function save($doAudit = true) { $field = $this->table->getPrimary(); // make sure data is valid if (!$this->_validated) { $this->validate(); } if ($this->isValidated()) { $this->generateSafeTitle(); if ($this->row->$field) { $this->beforeUpdate(); $this->row->save(); $this->afterUpdate(); } else { $this->beforeInsert(); $this->generateHash(); $this->row->save(); $this->afterInsert(); } return true; } else { return false; } }
/** * @return Zend_Db_Adapter_Abstract */ public function getAdapter() { if (empty($this->adapter)) { $this->adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); } return $this->adapter; }
/** * __construct() - For concrete implementation of Zend_Db_Table * * @param string|array $config string can reference a Zend_Registry key for a db adapter * OR it can reference the name of a table * @param array|Zend_Db_Table_Definition $definition */ public function __construct($config = array(), $definition = null) { if ($definition !== null && is_array($definition)) { $definition = new Zend_Db_Table_Definition($definition); } if (is_string($config)) { if (Zend_Registry::isRegistered($config)) { trigger_error(__CLASS__ . '::' . __METHOD__ . '(\'registryName\') is not valid usage of Zend_Db_Table, ' . 'try extending Zend_Db_Table_Abstract in your extending classes.', E_USER_NOTICE ); $config = array(self::ADAPTER => $config); } else { // process this as table with or without a definition if ($definition instanceof Zend_Db_Table_Definition && $definition->hasTableConfig($config)) { // this will have DEFINITION_CONFIG_NAME & DEFINITION $config = $definition->getTableConfig($config); } else { $config = array(self::NAME => $config); } } } parent::__construct($config); }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $row = $this->_checkDistrict($this->_data); if (!empty($row)) { $this->_message->addMessage('Distritu iha tiha ona.', App_Message::ERROR); return false; } if (empty($this->_data['id_adddistrict'])) { $history = 'INSERE DISTRITU: %s - INSERIDO NOVO DISTRITU'; } else { $history = 'ALTERA DISTRITU: %s - ALTUALIZADO DISTRITO COM SUCESSO'; } $id = parent::_simpleSave(); $history = sprintf($history, $this->_data['District']); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
public function loginAction() { //Desabilita renderização da view $this->_helper->viewRenderer->setNoRender(); //Obter o objeto do adaptador para autenticar usando banco de dados $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); //Seta qual tabela e colunas procurar o usuário $authAdapter->setTableName('usuario')->setIdentityColumn('login')->setCredentialColumn('senha'); //Seta as credenciais com dados vindos do formulário de login $authAdapter->setIdentity($this->_getParam('login'))->setCredential($this->_getParam('senha'))->setCredentialTreatment('MD5(?)'); //Realiza autenticação $result = $authAdapter->authenticate(); //Verifica se a autenticação foi válida if ($result->isValid()) { //Obtém dados do usuário $usuario = $authAdapter->getResultRowObject(); //Armazena seus dados na sessão $storage = Zend_Auth::getInstance()->getStorage(); $storage->write($usuario); //Redireciona para o Index $this->_redirect('index'); } else { $this->_redirect('autenticacao/falha'); } }
public function init() { $this->getHelper('layout')->disableLayout(); $this->_db = Zend_Db_Table_Abstract::getDefaultAdapter(); $cfg = Zend_Registry::get('cfg'); $this->_docsPath = $cfg['docs']['path']; }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { // $row = $this->_checkOcupationTimor( $this->_data ); // // if ( !empty( $row ) ) { // $this->_message->addMessage( 'Okupasaun Timor-Leste iha tiha ona.', App_Message::ERROR ); // return false; // } if (empty($this->_data['id_profocupationtimor'])) { $history = 'INSERE OCUPASAUN TIMOR: %s DADUS PRINCIPAL - INSERE NOVO OCUPASAUN TIMOR'; } else { $history = 'ALTERA Ocupasaun Timor: %s DADUS PRINCIPAL - ALTERA Ocupasaun Timor'; } $id = parent::_simpleSave(); $history = sprintf($history, $this->_data['ocupation_name_timor']); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
public function buildSQl() { $user_id = Zend_Auth::getInstance()->getIdentity()->id; $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $sql = 'select c.id, c.ip, c.message, c.priority, c.id_user, c.logic, c.method, c.id_row, c.created_at from log.contact c '; $where = ' where c.ip != \'\' '; $join = ''; if (isset($this->filterdata['ip']) and $this->filterdata['ip']) { $where .= $db->quoteInto("\n and c.ip = ?\n ", $this->filterdata['ip']); } if (isset($this->filterdata['message']) and $this->filterdata['message']) { $where .= $db->quoteInto("\n and c.message ~* ?\n ", $this->filterdata['message']); } if (isset($this->filterdata['id_user']) and $this->filterdata['id_user']) { $where .= $db->quoteInto("\n and c.id_user = ?\n ", $this->filterdata['id_user']); } $sql .= $join; $sql .= $where; return $sql; }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $this->setValidators(array('_checkScholarityName', '_checkScholarityExternalCode')); if (!parent::isValid()) { return false; } if (empty($this->_data['id_perscholarity'])) { $history = 'INSERE KURSU: %s DADUS PRINCIPAL - INSERE NOVO KURSU'; } else { $history = 'ALTERA KURSU: %s DADUS PRINCIPAL - ALTERA KURSU'; } $id = parent::_simpleSave(); $history = sprintf($history, $this->_data['scholarity']); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $row = $this->_checkNameDepartment($this->_data); if (!empty($row)) { $this->_message->addMessage('Departamentu iha tiha ona.', App_Message::ERROR); return false; } if (empty($this->_data['id_department'])) { $history = 'INSERE DEPARTAMENTU: %s DADUS PRINCIPAL - INSERE NOVO DEPARTAMENTU'; } else { $history = 'ALTERA DEPARTAMENTU: %s DADUS PRINCIPAL - ALTERA DEPARTAMENTU'; } $id = parent::_simpleSave(); $history = sprintf($history, $this->_data['name']); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $row = $this->_checkClassTimor($this->_data); if (!empty($row)) { $this->_message->addMessage('Klase Timor-Leste iha tiha ona.', App_Message::ERROR); return false; } if (empty($this->_data['id_isicclasstimor'])) { $history = 'REJISTRU CLASSE TIMOR: %s-%s'; } else { $history = 'ALTERA CLASSE TIMOR: %s-%s'; } $id = parent::_simpleSave(); $history = sprintf($history, $this->_data['acronym'], $this->_data['name_classtimor']); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
public function indexAction() { $filter = new Zend_Filter_StripTags(); $login = trim($filter->filter($this->_request->getPost('login'))); $senha = trim($filter->filter($this->_request->getPost('senha'))); $uri = str_replace('kahina/', '', base64_decode($this->_request->getParam('u', base64_encode('painel/index')))); if (empty($login) || empty($senha)) { $this->view->message = 'Por favor, informe seu Usuário e Senha.'; return; } else { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('login')->setIdentityColumn('login')->setCredentialColumn('senha'); $authAdapter->setIdentity($this->_getParam('login'))->setCredential($this->_getParam('senha'))->setCredentialTreatment('MD5(?)'); $result = $authAdapter->authenticate(); if ($result->isValid()) { $user = $authAdapter->getResultRowObject(); $storage = My_Auth::getInstance('Painel')->getStorage(); $storage->write($user); $this->_redirect($uri); } else { $this->view->error = 'Você deve informar Login e Senha.'; } } $this->render(); }
public static function setDbAdapter() { $cnf = Zend_Registry::get('cnf'); $db = Zend_Db::factory($cnf->db); Zend_Db_Table_Abstract::setDefaultAdapter($db); Zend_Registry::set('db', $db); }
/** * _getTableFromString * * @param string $tableName * @return Zend_Db_Table_Abstract */ protected function _getTableFromString($tableName) { if ($this->_table instanceof Zend_Db_Table_Abstract) { $tableDefinition = $this->_table->getDefinition(); if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) { return new Zend_Db_Table($tableName, $tableDefinition); } } // assume the tableName is the class name if (!class_exists($tableName)) { try { require_once 'Zend/Loader.php'; Zend_Loader::loadClass($tableName); } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e); } } $options = array(); if ($table = $this->_getTable()) { $options['db'] = $table->getAdapter(); } if (isset($tableDefinition) && $tableDefinition !== null) { $options[Zend_Db_Table_Abstract::DEFINITION] = $tableDefinition; } return new $tableName($options); }
public function updateProfile($data, $user_id) { $value['first_name'] = $data['first_name']; $value['middle_name'] = $data['middle_name']; $value['last_name'] = $data['last_name']; return parent::update($value, array('user_id = ?' => $user_id)); }