Exemplo n.º 1
0
 public function onSave()
 {
     parent::onSave();
     // save Groups field
     $data = $this->getData();
     \Meta\Db::saveAssociated('user_groups', 'user_id', $this->getRecordId(), 'group_id', $data['groups']);
 }
Exemplo n.º 2
0
 public function onSave()
 {
     parent::onSave();
     // save the Pages field
     $data = $this->getData();
     \Meta\Db::saveAssociated('group_pages', 'group_id', $this->getRecordId(), 'page', $data['pages']);
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 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());
     }
 }
Exemplo n.º 6
0
 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()));
 }
Exemplo n.º 7
0
 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));
         }
     }
 }
Exemplo n.º 8
0
 public static function getGroupPages($groupId)
 {
     return Db::query("SELECT page FROM group_pages WHERE group_id = ?", array($groupId))->fetchAll(\PDO::FETCH_COLUMN);
 }
Exemplo n.º 9
0
 public function createOptionsTable()
 {
     Db::execute('create table options (id serial primary key auto_increment, name varchar(255), value longtext);');
 }
Exemplo n.º 10
0
 /**
  * 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));
 }
Exemplo n.º 11
0
 public function onDelete()
 {
     \Meta\Db::delete($this->table, array('id' => $_GET['id']));
     \Meta\Flash::success(t('Record deleted'));
     redirect(current_path());
 }