public function insert(array $data) { $this->_db = CrFramework_Db_Control::getAdapter('write'); $this->setDefaultAdapter($this->_db); //logStd(get_class($this).'->createRow()', 'Write to MASTER:'.$id); return parent::insert($data); }
public function insert($data) { if (empty($data['nazwa']) && empty($data['producent']) && empty($data['termin_licencji']) && empty($data['numer_seryjny'])) { throw new Soft_Validation_Exception('Zadne pole wymagane nie zostalo wypelnione!!!'); } if (empty($data['nazwa'])) { throw new Soft_Validation_Exception('Nie podales nazwy oprogramowania! Pole wymagane!!!'); } if (empty($data['producent'])) { throw new Soft_Validation_Exception('Nie podales producenta oprogramowania! Pole wymagane!!!'); } if (empty($data['nr_seryjny'])) { throw new Soft_Validation_Exception('Nie podales nmeru seryjnego! Pole wymagane!!!'); } if (empty($data['termin_licencji'])) { throw new Soft_Validation_Exception('Nie podales terminu licencji! Pole wymagane!!!'); } if (empty($data['termin_licencji'])) { throw new Soft_Validation_Exception('Nie podales terminu licencji! Pole wymagane!!!'); } if (!eregi('[0-9]', $data['ilosc_stanowisk'])) { throw new Soft_Validation_Exception('Niepoprawna liczba stanowisk!'); } if (!eregi('[0-9-]', $data['termin_licencji'])) { throw new Soft_Validation_Exception('Niepoprawna data!'); } return parent::insert($data); }
/** * Saves the properties to the database. * * This performs an intelligent insert/update, and reloads the * properties with fresh data from the table on success. * * @return int 0 on failure, 1 on success. */ public function save() { // convenience var for the primary key name $primary = $this->_info['primary']; // check the primary key value for insert/update if (empty($this->_data[$primary])) { // no primary key value, must be an insert. // make sure it's null. $this->_data[$primary] = null; // attempt the insert. $result = $this->_table->insert($this->_data); if (is_numeric($result)) { // insert worked, refresh with data from the table $this->_data[$primary] = $result; $this->_refresh(); } // regardless of success return the result return $result; } else { // has a primary key value, update only that key. $where = $this->_db->quoteInto("{$primary} = ?", $this->_data[$primary]); // return the result of the update attempt, // no need to update the row object. $result = $this->_table->update($this->_data, $where); if (is_int($result)) { // update worked, refresh with data from the table $this->_refresh(); } } }
public function insert($data) { if (!$this->ifLogin($data['login'])) { throw new User_Validation_Exception('Podany login istnieje juz w bazie danych! Wybierz inny.'); } if (empty($data['login']) && empty($data['haslo'])) { throw new User_Validation_Exception('Nie podales loginu ani hasla!'); } if (empty($data['login'])) { throw new User_Validation_Exception('Nie podales loginu!'); } if (strlen($data['login']) < 5) { throw new User_Validation_Exception('Login musi skladac sie z co najmniej 5 znakow!'); } if (empty($data['haslo'])) { throw new User_Validation_Exception('Nie podales hasla!'); } if (strlen($data['haslo']) < 5) { throw new User_Validation_Exception('Haslo musi skladac sie z co najmniej 5 znakow!'); } if (!eregi('^[a-zA-z]', $data['login'])) { throw new User_Validation_Exception('Login musi zaczynac sie od litery!'); } return parent::insert($data); }
/** * Inserts a new row. * * @param array $data Column-value pairs. * @return mixed The primary key of the row inserted. */ public function insert(array $data) { $rowMaxSort = $this->fetchRow($this->select()->order('sort DESC')); $maxSort = $rowMaxSort ? (int) $rowMaxSort->sort + 1 : 1; $data['sort'] = $maxSort; return parent::insert($data); }
/** * Add new setting and return ID of the setting */ public function add($setting, $table) { global $logger; $oTable = new Zend_Db_Table($table); $data = array('name' => $setting->name); $result = $oTable->insert($data); $logger->log("Add setting {$table}={$setting->name}", Zend_Log::INFO); return $result; }
public function insert(array $data) { if (empty($data['created_at'])) { $data['created_at'] = date('Y-m-d h:i:s'); } if (empty($data['updated_at'])) { $data['updated_at'] = date('Y-m-d h:i:s'); } return parent::insert($data); }
/** * Create a new message in an existing thread * * @param array $data * @return $id */ public function createMessage(array $data) { $messages_table = new Zend_Db_Table('messages'); $data['date_created'] = date('Y-m-d H:i:s'); $messages_table->insert($data); $threads_table = new Zend_Db_Table('threads'); $thread_data = array('unread' => new Zend_Db_Expr('unread + 1'), 'deleted_from' => 0, 'deleted_to' => 0, 'last_speaker' => $data['user_from']); $where = array('id = ?' => $data['thread_id']); $threads_table->update($thread_data, $where); }
public function insert(&$data) { if (empty($data['nazwa'])) { throw new Hamster_Validation_Exception('Podaj nazwę ankiety.'); } if (strlen($data['nazwa']) < 6) { throw new Hamster_Validation_Exception('Nazwa ankiety musi miec conamniej 6 znaków.'); } return parent::insert($data); }
public function formAction() { $table = new Zend_Db_Table(); $table->setOptions(array('name' => 'test')); $table->setMetadataCacheInClass(true); $data = array('listorder' => '11'); $table->insert($data); Zend_Debug::dump($table); die; }
/** * (non-PHPdoc) * @see models/Sahara/Auth/Sahara_Auth_Session::setup() */ public function setup() { $table = new Zend_Db_Table('users'); $record = $table->fetchRow($table->select()->where('name = ?', $this->_authType->getUsername())->where('namespace = ?', $this->_config->institution)); /* User name exists, so no need to create account. */ if ($record) { return; } $table->insert(array('name' => $this->_authType->getUsername(), 'namespace' => $this->_config->institution, 'persona' => 'USER')); }
/** * Save a new entry * @param array $data * @return int|string */ public function save(array $data) { $table = new Zend_Db_Table('users'); $fields = $table->info(Zend_Db_Table_Abstract::COLS); foreach ($data as $field => $value) { if (!in_array($field, $fields)) { unset($data[$field]); } } return $table->insert($data); }
/** * Register new user with given $id and $password * Returns true in case of success and false if user with given $id already * exists * * @param string $id user identity URL * @param string $password encoded user password * @return bool */ public function addUser($id, $password) { // escaping not required as values are inserted as parameters $user = array('username' => $id, 'password' => $password, 'created' => date('Y-m-d H:i:s'), 'openid' => Zend_OpenId::absoluteURL('/openid/' . $id)); if ($this->hasUser($id)) { return false; } else { $this->_usersTable->insert($user); } return true; }
/** * Save object in DB * * @return HumanHelp_Model_Comment */ public function save() { $table = new Zend_Db_Table('comments'); if (isset($this->_id)) { // Update $table->update($this->_data, $table->getAdapter()->quoteInto('id = ?', $this->_id)); } else { // Insert $table->insert($this->_data); $this->_id = $table->getAdapter()->lastInsertId('comments', 'id'); } return $this; }
public function addAction() { $form = new Application_Model_ContactForm(array('action' => '/contact/add', 'method' => 'POST')); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { $contact = new Zend_Db_Table('contacts'); $data = array('name' => $this->_request->getPost('name'), 'email' => $this->_request->getPost('email'), 'type' => $this->_request->getPost('type')); $contact->insert($data); echo "<p>Contact added!</p>"; } } $this->view->form = $form; }
/** * insert с учётом добавления нового поля в таблицу публикаций * * @param array $data */ public function insert(array $data) { $rowID = parent::insert($data); if ($rowID && 'captcha' != $data['type']) { /* создаём поле в таблице хранения данных */ $modelList = new Modules_Publications_Model_List(); $tableInfo = $modelList->fetchRow($modelList->select()->where('rubric_id = ?', $data['rubric_id'])); $tableName = $tableInfo->table_name; $filedName = $data['name']; $params = array('type' => $this->_convertTypes[$data['type']][0], 'length' => $this->_convertTypes[$data['type']][1], 'null' => true); $_migrationManager = new Modules_Dbmigrations_Framework_Manager(); $_migrationManager->upTo('Modules_Publications_Migrations_CreatePublicationAbstractFieled', array($tableName, $filedName, $params), false); } }
public function insert(array $data, $log = true) { $data['updated_at'] = get_time(); if (is_session('user_id')) { $data['updated_by'] = get_session('user_id'); } parent::insert($data); $id = $this->getAdapter()->lastInsertId(); if ($log) { log_sql($this->_name, $id, 'inserted', $data); set_session('notice', 'new record added'); } return $id; }
public function insert($data) { if (empty($data['e_mail'])) { throw new Respondenci_Exception('Podaj adres e-mail.'); } else { if (!$this->testMail($data['e_mail'])) { throw new Respondenci_Exception('Nieprawidlowy adres! Przyklad prawidlowego adresu: eS.Ka2002@interia.pl '); } else { if (!$this->emailExist($data['e_mail'])) { throw new Respondenci_Exception('Podany adres e-mail istnieje juz w bazie danych.'); } } } return parent::insert($data); }
/** * insert с учётом создания таблицы для хранения данных о публикации * * @param array $data * @return int */ public function insert(array $data) { $rowID = parent::insert($data); if ($rowID) { /* создаём таблицу для хранения данных */ $tableName = $data['table_name']; if (!System_Functions::tableExist($tableName)) { $_migrationManager = new Modules_Dbmigrations_Framework_Manager(); $_migrationManager->upTo('Modules_Publications_Migrations_CreatePublicationAbstractTable', $tableName, false); // Добавляем базовые поля $filedsModel = new Modules_Publications_Model_Fields(); $filedsModel->insert(array('rubric_id' => $rowID, 'name' => 'name', 'title' => 'Название', 'type' => 'text', 'validator' => '.*', 'sort' => 1)); $filedsModel->insert(array('rubric_id' => $rowID, 'name' => 'active', 'title' => 'активно', 'type' => 'checkbox', 'default' => '1', 'sort' => 2)); } } return $rowID; }
protected function saveTagsAndReturnIdMap(array $tags = array()) { $ids = array(); $toAdd = array(); if (!empty($tags)) { $select = $this->_db->select()->from(self::tagsTableName, array('id', 'word'))->where('word IN (?)', $tags); $rows = $this->_db->fetchAll($select); foreach ($rows as $row) { $ids[$row['word']] = $row['id']; } } foreach ($tags as $tag) { if (!array_key_exists($tag, $ids)) { $toAdd[] = $tag; } } $tagTable = new Zend_Db_Table(array('db' => $this->_db, 'name' => self::tagsTableName)); foreach ($toAdd as $newTag) { $ids[$newTag] = $tagTable->insert(array('word' => $newTag)); } return $ids; }
/** * @description operate factor * @param array $params * @param object $table * @param object $config * @param object $controller * @return void * @author Se# * @version 0.0.1 */ protected function _actionFactor() { $params = self::$_info['params']; $controller = self::$_info['controller']; $config = self::$_info['config']; $controller->view->headLink()->appendStylesheet('/css/factors.css'); $data = array(); foreach ($params as $param => $value) { if (strpos($param, 'factor') !== false) { $data[substr($param, 6)] = $value; } } $data['ctime'] = time(); $data['etime'] = time(); $data['votes'] = 0; $table = new Zend_Db_Table(Evil_DB::scope2table('factor')); $table->insert($data); if (isset($config->factor->redirect)) { $controller->_redirect($config->factor->redirect); } $controller->view->result = 'Factor added'; $controller->_redirect('/' . self::$_info['controllerName'] . '/factor/id/' . $params['id']); }
/** * 添加新闻信息 * * @param array $arrayInsert */ public function insert($arrayInsert) { try { //开启事务 $this->getAdapter()->beginTransaction(); //调用父类方法添加 parent::insert($arrayInsert); //根据缓存标识清除缓存的数据 $this->_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(strtolower($this->_name))); //提交查询 $this->getAdapter()->commit(); } catch (Zend_Exception $e) { echo $e->getMessage(); //如果出错则事务回滚 $this->getAdapter()->rollBack(); } }
public function accountAction() { // Leave if not ready if (empty($this->_session->mysql)) { return $this->_helper->redirector->gotoRoute(array('action' => 'db-info')); } $this->view->form = $form = new Install_Form_Account(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Check passwords match $values = $form->getValues(); if ($values['password'] != $values['password_conf']) { $form->addError('Passwords must match.'); return; } // Create account // Connect again try { $config = $this->dbFormToConfig($this->_session->mysql); // Connect! $adapter = Zend_Db::factory($config['adapter'], $config['params']); $adapter->getServerVersion(); } catch (Exception $e) { $form->addError('Adapter Error: ' . $e->getMessage()); //$this->view->code = 1; //$this->view->error = 'Adapter Error: ' . $e->getMessage(); return; } // attempt to disable strict mode try { $adapter->query("SET SQL_MODE = ''"); } catch (Exception $e) { } try { // Preprocess $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings')); $usersTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_users')); $levelTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_authorization_levels')); // Get static salt $staticSalt = $settingsTable->find('core.secret')->current(); if (is_object($staticSalt)) { $staticSalt = $staticSalt->value; } else { if (!is_string($staticSalt)) { $staticSalt = ''; } } // Get superadmin level $superAdminLevel = $levelTable->fetchRow($levelTable->select()->where('flag = ?', 'superadmin')); if (is_object($superAdminLevel)) { $superAdminLevel = $superAdminLevel->level_id; } else { $superAdminLevel = 1; } // Temporarily save pw $originalPassword = $values['password']; // Adjust values $values['salt'] = (string) rand(1000000, 9999999); $values['password'] = md5($staticSalt . $values['password'] . $values['salt']); $values['level_id'] = $superAdminLevel; $values['enabled'] = 1; $values['verified'] = 1; $values['creation_date'] = date('Y-m-d H:i:s'); $values['creation_ip'] = ip2long($_SERVER['REMOTE_ADDR']); $values['displayname'] = $values['username']; // Try to write info to config/auth.php if (!$this->_writeAuthToFile($values['email'], 'seiran', $originalPassword)) { throw new Exception('Unable to write Auth to File'); } // Insert $row = $usersTable->createRow(); $row->setFromArray($values); $row->save(); // First Signup Increment // Engine_Api::_()->getDbtable('statistics', 'core')->increment('user.creations'); // Validate password if ($row->password != md5($staticSalt . $originalPassword . $row->salt)) { throw new Engine_Exception('Error creating password'); } // Log the user into the intaller $auth = Zend_Registry::get('Zend_Auth'); $auth->getStorage()->write($row->user_id); // Try to log the user into socialengine // Note: nasty hack try { $mainSessionName = 'PHPSESSID'; if (empty($_COOKIE[$mainSessionName])) { $mainSessionId = md5(mt_rand(0, time()) . serialize($_SERVER)); setcookie($mainSessionName, $mainSessionId, null, dirname($this->view->baseUrl()), $_SERVER['HTTP_HOST'], false, false); } else { $mainSessionId = $_COOKIE[$mainSessionName]; } $adapter->insert('engine4_core_session', array('id' => $mainSessionId, 'modified' => time(), 'lifetime' => 86400, 'data' => 'Zend_Auth|' . serialize(array('storage' => $row->user_id)))); } catch (Exception $e) { // Silence if (APPLICATION_ENV == 'development') { echo $e->__toString(); } } // Update some other stuff $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings')); // Save site name $row = $settingsTable->find('core.general.site.title')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.general.site.title'; } $row->value = $values['site_title']; $row->save(); // Save email $row = $settingsTable->find('core.license.email')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.license.email'; } if ($row->value != '*****@*****.**') { $row->value = $values['email']; $row->save(); } // Update profile fields try { $fieldValuesTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_user_fields_values')); $fieldValuesTable->insert(array('item_id' => 1, 'field_id' => 1, 'index' => 0, 'value' => 1)); } catch (Exception $e) { } } catch (Exception $e) { $form->addError('Error: ' . $e->getMessage()); return; } // Redirect if successful return $this->_helper->redirector->gotoRoute(array('action' => 'complete')); }
/** * Add files to the List of unused files. * * @param array $hashes array of file hashes. * * @return void. */ public static function addFilesToUnusedFileList($files) { if (count($files) === 0) { return; } $db = Phprojekt::getInstance()->getDb(); $table = new Zend_Db_Table(array('db' => $db, 'name' => 'uploaded_unused_files')); $rows = array(); foreach ($files as $file) { $rows[] = array("created" => new Zend_Db_Expr('NOW()'), "hash" => $file['md5']); } foreach ($rows as $row) { $table->insert($row); } }
private function _saveThemeToDb() { $templates = glob(INSTALL_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . '*.html'); if (empty($templates)) { return false; } $templateTable = new Zend_Db_Table('template'); foreach ($templates as $template) { $name = explode(DIRECTORY_SEPARATOR, $template); $name = str_replace('.html', '', end($name)); $validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'template', 'field' => 'name')); $tmplRow = $templateTable->find($name); if ($tmplRow->count()) { $tmplRow = $tmplRow->current(); $tmplRow->content = file_get_contents($template); $tmplRow->save(); } else { $templateTable->insert(array('name' => $name, 'content' => file_get_contents($template), 'type' => 'typeregular')); } unset($name); } return true; }
public function insert(array $data) { $params = array("data" => $data, "errors" => $this->_errors, "table" => $this->_name, "module" => $this->_module_id, "primary" => $this->_primary); if (isset($this->_use_adapter)) { $params['use_adapter'] = $this->_use_adapter; } else { $params['use_adapter'] = null; } // rethrowing exceptions here because of a weird php issue where the trace isn't getting passed try { $params = Bolts_Plugin::getInstance()->doFilter('db_table_insert', $params); } catch (Exception $e) { throw $e; } if (count($params['errors']) == 0) { $params['insert_id'] = parent::insert($params['data']); Bolts_Plugin::getInstance()->doAction('db_table_post_insert', $params); return $params['insert_id']; } else { $this->_errors = $params['errors']; return false; } }
public function saveUserAttributes(Application_Model_Models_User $user) { $paramsCount = func_num_args(); if ($paramsCount === 1) { list($user) = func_get_args(); $attribs = $user->getAttributes(); } elseif ($paramsCount === 2) { list($user, $attribs) = func_get_args(); } elseif ($paramsCount === 3) { $params = func_get_args(); $user = array_shift($params); $attribs = array($params[0] => $params[1]); unset($params); } $dbTable = new Zend_Db_Table('user_attributes'); $userId = $user->getId(); $dbTable->delete(array('user_id = ?' => $userId)); if (is_array($attribs) && !empty($attribs)) { foreach ($attribs as $name => $value) { $dbTable->insert(array('user_id' => $userId, 'attribute' => $name, 'value' => $value)); } $user->setAttributes($attribs); } return $user; }
/** * Add action */ public function addAction() { // Get the request object $request = $this->getRequest(); $populateWithDefaultValues = true; // Check if a form is sent if ($request->isPost()) { // Get the post data $postData = $request->getPost(); $postData = $this->_parsePostData($postData); if (!isset($postData['form_class']) || isset($postData['form_class']) && $postData['form_class'] == get_class($this->_form)) { $populateWithDefaultValues = false; // Populate the post data to the form $this->_form->populate($postData); if (isset($this->_form->cancel) && $this->_form->cancel->isChecked()) { // Cancel button is pressed $this->_redirect($this->_redirectUrlCancel); } elseif ($this->validateForm($postData)) { // Form is sent try { // Parse the form data $item = $this->_getItem('add'); if (array_key_exists('form_class', $item)) { unset($item['form_class']); } if (array_key_exists('form_name', $item)) { unset($item['form_name']); } // Insert the item $item = $this->_model->insert($item); if (!is_array($item)) { $item = array($item); } switch (count($item)) { case 0: break; case 1: $this->_item = $this->_model->find($item[0])->current(); break; case 2: $this->_item = $this->_model->find($item[0], $item[1])->current(); break; case 3: $this->_item = $this->_model->find($item[0], $item[1], $item[2])->current(); break; case 4: $this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3])->current(); break; case 5: $this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3], $item[4])->current(); break; case 6: $this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3], $item[4], $item[5])->current(); break; case 7: $this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3], $item[4], $item[5], $item[6])->current(); break; } // Actions after the query $this->_afterQuery('add'); $this->_flashMessenger->addMessage('Added the item succesfully.'); // Redirect $this->_redirect($this->_redirectUrlAdd); } catch (Exception $exception) { $this->_form->addErrorMessage($exception->getMessage()); } } } } if ($populateWithDefaultValues) { // Initialize the form with default values $this->_form->populate($this->_getDefaultFormValues()); } // Set the class "error" to subforms with errors // Set the class "error" to subforms with errors if (method_exists($this->_form, 'setErrorClass')) { $this->_form->setErrorClass('error'); } // Parse the form to the view $this->view->form = $this->_form; }
/** * Save a metadata value, will update the row if it exists, otherwise insert. * * @param MetadataDao $metadataDao * @return bool * @throws Zend_Exception */ public function saveMetadataValue($metadataDao) { if (!$metadataDao instanceof MetadataDao) { throw new Zend_Exception('Should be a metadata.'); } $cols = array('metadata_id' => $metadataDao->getKey(), 'itemrevision_id' => $metadataDao->getItemrevisionId()); $data['value'] = $metadataDao->getValue(); $tablename = $this->getTableValueName($metadataDao->getMetadatatype()); $table = new Zend_Db_Table(array('name' => $tablename, 'primary' => 'metadata_id')); if ($this->getMetadataValueExists($metadataDao)) { $wheres = array(); foreach ($cols as $col => $val) { $wheres[$col . '=?'] = $val; } $table->update($data, $wheres); } else { foreach ($cols as $col => $val) { $data[$col] = $val; } $table->insert($data); } return true; }
public function create() { $transaction = array('date' => time()); return parent::insert($transaction); }