예제 #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']);
 }
예제 #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']);
 }
예제 #3
0
파일: Crud.php 프로젝트: moiseh/codegen
 /**
  * @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;
 }
예제 #4
0
파일: Crud.php 프로젝트: moiseh/codegen
 /**
  * @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;
 }
예제 #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());
     }
 }
예제 #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()));
 }
예제 #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));
         }
     }
 }
예제 #8
0
파일: User.php 프로젝트: moiseh/codegen
 public static function getGroupPages($groupId)
 {
     return Db::query("SELECT page FROM group_pages WHERE group_id = ?", array($groupId))->fetchAll(\PDO::FETCH_COLUMN);
 }
예제 #9
0
 public function createOptionsTable()
 {
     Db::execute('create table options (id serial primary key auto_increment, name varchar(255), value longtext);');
 }
예제 #10
0
파일: Query.php 프로젝트: moiseh/codegen
 /**
  * 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));
 }
예제 #11
0
파일: Crud.php 프로젝트: moiseh/codegen
 public function onDelete()
 {
     \Meta\Db::delete($this->table, array('id' => $_GET['id']));
     \Meta\Flash::success(t('Record deleted'));
     redirect(current_path());
 }