public function onSave() { parent::onSave(); // save Groups field $data = $this->getData(); \Meta\Db::saveAssociated('user_groups', 'user_id', $this->getRecordId(), 'group_id', $data['groups']); }
public function onSave() { parent::onSave(); // save the Pages field $data = $this->getData(); \Meta\Db::saveAssociated('group_pages', 'group_id', $this->getRecordId(), 'page', $data['pages']); }
/** * @return \Meta\Field */ private function getFieldType($info, $params = array()) { if ($info->Key == 'PRI') { return new \Meta\Field\PrimaryKey($params); } list($type, $size) = \Meta\Db::extractType($info->Type); switch ($type) { case 'char': case 'varchar': case 'text': $field = new \Meta\Field\Text($params); break; case 'integer': case 'int': case 'bigint': $field = new \Meta\Field\Integer($params); break; case 'timestamp': case 'datetime': $field = new \Meta\Field\DateTime($params); break; case 'date': $field = new \Meta\Field\Date($params); break; case 'tinyint': $field = new \Meta\Field\Boolean($params); break; } return $field; }
/** * @return \Meta\Column */ private function getColType($info, $params = array()) { if ($info->Key == 'PRI') { return new \Meta\Column\PrimaryKey($params); } list($type, $size) = \Meta\Db::extractType($info->Type); switch ($type) { case 'char': case 'varchar': case 'integer': case 'int': case 'bigint': case 'text': $col = new \Meta\Column($params); break; case 'timestamp': case 'datetime': $col = new \Meta\Column\DateTime($params); break; case 'date': $col = new \Meta\Column\Date($params); break; case 'tinyint': $col = new \Meta\Column\Boolean($params); break; } // some special columns if (in_array($info->Field, array('picture'))) { $col = new \Meta\Column\Image($params); } return $col; }
public static function checkDbTables() { // database tables installer if (!\Meta\Db::tableExists('db_migrations')) { // import the whole initial databse file \Meta\Db::execute(file_get_contents(abspath('sql/database.sql'))); Flash::success(t('Database imported.')); redirect(page_home()); } }
public function onValidated() { $uid = \User\User::logged()->id; $data = $this->getData(); Db::saveSafe('users', $data); Flash::success(t('Profile saved')); // change password $pass = $data['password_new']; if (strlen($pass) > 0) { Db::update('users', array('password' => md5($pass)), array('id' => $uid)); Flash::success(t('Password changed')); } redirect(url(current_path())); }
public static function execute($migrationsInstance) { $executed = Db::query('SELECT alias FROM db_migrations')->fetchAll(\PDO::FETCH_COLUMN); $rc = new \ReflectionClass($migrationsInstance); foreach ($rc->getMethods() as $method) { $method instanceof \ReflectionMethod; // if migration method not executed, run if (!in_array($method->name, $executed)) { // invoke the method try { $method->invoke($migrationsInstance); $failed = false; } catch (\Exception $e) { // when sql error ... $failed = true; } // save flag to migrations table Db::save('db_migrations', array('alias' => $method->name, 'failed' => $failed)); } } }
public static function getGroupPages($groupId) { return Db::query("SELECT page FROM group_pages WHERE group_id = ?", array($groupId))->fetchAll(\PDO::FETCH_COLUMN); }
public function createOptionsTable() { Db::execute('create table options (id serial primary key auto_increment, name varchar(255), value longtext);'); }
/** * Apply search conditions to a query */ public function applySearchFields() { $filter = filter_input(INPUT_GET, 'squery'); if (!$this->searchFields || !$filter) { return; } $conditions = array(); foreach ($this->searchFields as $field) { $conditions[] = $field . ' like ' . Db::quote('%' . $filter . '%'); } $this->whereAnd(implode(' OR ', $conditions)); }
public function onDelete() { \Meta\Db::delete($this->table, array('id' => $_GET['id'])); \Meta\Flash::success(t('Record deleted')); redirect(current_path()); }