Ejemplo n.º 1
0
 /**
  * doExecute
  *
  * @return  bool
  */
 protected function doExecute()
 {
     $table = $this->getArgument(0);
     if (!$table) {
         throw new \InvalidArgumentException('No table');
     }
     $db = Ioc::getDatabase();
     $columns = $db->getTable($table)->getColumnDetails();
     if ($file = $this->getOption('o')) {
         if ($file == 1) {
             $file = '/form/fields/' . $table . '.php.tpl';
         }
         $file = new \SplFileInfo(WINDWALKER_TEMP . '/' . ltrim($file, '/\\'));
         if (!is_dir($file)) {
             Folder::create($file->getPath());
         }
         $output = '';
         foreach ($columns as $column) {
             $output .= $this->handleColumn($column) . "\n";
         }
         file_put_contents($file->getPathname(), $output);
         $this->out()->out('File output to: ' . $file->getPathname());
     } else {
         $this->out()->out('Start Generate Fields')->out('--------------------------------------------------')->out()->out();
         foreach ($columns as $column) {
             $this->out($this->handleColumn($column));
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $user = $this->input->getVar('registration');
     $user = new Data($user);
     $session = Ioc::getSession();
     $session['register.form.data'] = $user;
     $trans = Ioc::getDatabase()->getTransaction()->start();
     try {
         $this->validate($user);
         // User
         $user = $this->createUser($user);
         // Blog
         $blogCtrl = $this->createBlog($user);
         // Articles
         $this->createDefaultArticle($blogCtrl);
     } catch (ValidFailException $e) {
         $trans->rollback();
         $this->setRedirect(Router::buildHttp('user:registration'), $e->getMessage(), 'danger');
         return false;
     } catch (\Exception $e) {
         $trans->rollback();
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('user:registration'), 'Register fail', 'danger');
         return false;
     }
     $trans->commit();
     $session->remove('register.form.data');
     // OK let's login
     User::makeUserLogin($user->id);
     $this->setRedirect(Router::buildHttp('user:login'), 'Register success.', 'success');
     return true;
 }
Ejemplo n.º 3
0
 /**
  * getItems
  *
  * @return  \stdClass[]
  */
 protected function getItems()
 {
     $db = Ioc::getDatabase();
     $query = $this->get('query', $this->get('sql'));
     if (is_callable($query)) {
         $handler = $query;
         $query = $db->getQuery(true);
         call_user_func($handler, $query, $this);
     }
     if (!$query) {
         return array();
     }
     return (array) $db->setQuery($query)->loadAll();
 }
Ejemplo n.º 4
0
    /**
     * Execute the controller.
     *
     * @return  mixed Return executed result.
     *
     * @throws  \LogicException
     * @throws  \RuntimeException
     */
    public function execute()
    {
        $query = $this->input->getString('query');
        $query = trim($query);
        if (!$query) {
            return;
        }
        $queries = explode(' ', $query);
        $mapper = new DataMapper('users');
        $conditions = [];
        $q = Ioc::getDatabase()->getQuery(true);
        foreach ($queries as $query) {
            if (!trim($query)) {
                continue;
            }
            $query = $q->quote('%' . $query . '%');
            $conditions[] = 'username LIKE ' . $query;
            $conditions[] = 'fullname LIKE ' . $query;
            $conditions[] = 'email LIKE ' . $query;
        }
        $conditions = new QueryElement('()', $conditions, ' OR ');
        $users = $mapper->find([(string) $conditions], 'username', 0, 10);
        $suggestions = [];
        $tmpl = <<<VALUE
<div>
\t<img width="48" height="48" class="find-author-avatar pull-left" src="%s" alt=""/>
\t<div class="find-author-name">%s <small>%s</small></div>
\t<small>%s</small>
\t<div class="clearfix"></div>
</div>
VALUE;
        foreach ($users as $user) {
            $suggestions[] = ['value' => sprintf($tmpl, UserHelper::getAvatar($user->id), $user->fullname, $user->username, $user->email), 'data' => $user->username];
        }
        $response = new Response();
        $response->setBody(json_encode(['suggestions' => $suggestions]));
        $response->setMimeType('text/json');
        $response->respond();
        exit;
        return true;
    }
Ejemplo n.º 5
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $user = User::get($this->input->get('user_id'));
     $blog = $this->input->getVar('blog');
     $blog = new Data($blog);
     $blog->params = $this->input->getByPath('blog.params', array(), null);
     $isNew = !$blog->id;
     $blog->state = 1;
     $blog->alias = OutputFilter::stringURLSafe($blog->alias);
     if ($isNew) {
         $blog->params['css'] = $this->getDefaultCss();
     }
     if (!$this->validate($blog)) {
         return false;
     }
     $trans = Ioc::getDatabase()->getTransaction()->start();
     try {
         $blog->params = json_encode($blog->params);
         $this->blog = (new DataMapper('blogs'))->saveOne($blog, 'id');
         if ($isNew) {
             $author['user'] = $user->id;
             $author['blog'] = $this->blog->id;
             $author['owner'] = 1;
             $author['admin'] = 1;
             $this->author = (new DataMapper('authors'))->createOne($author);
         }
         $trans->commit();
     } catch (\Exception $e) {
         $trans->rollback();
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('admin:blog', ['id' => $blog->id ?: '']), 'Save fail', 'danger');
         return true;
     }
     $this->setRedirect(Router::buildHttp('admin:blogs'), 'Save Success', 'success');
     return true;
 }
Ejemplo n.º 6
0
 /**
  * getItems
  *
  * @return  \stdClass[]
  */
 protected function getItems()
 {
     $db = Ioc::getDatabase();
     $query = $db->getQuery(true);
     $table = $this->get('table', $this->table);
     if (!$table) {
         return array();
     }
     if ($this->get('published')) {
         $query->where($query->quoteName($this->get('stateField', 'state')) . ' >= 1');
     }
     if ($ordering = $this->get('ordering', $this->ordering)) {
         $query->order($ordering);
     }
     $select = $this->get('select', '*');
     $query->select($select)->from($table);
     $this->postQuery($query);
     $postQuery = $this->get('postQuery');
     if (is_callable($postQuery)) {
         call_user_func($postQuery, $query, $this);
     }
     return (array) $db->setQuery($query)->loadAll();
 }
Ejemplo n.º 7
0
 /**
  * getMaxOrder
  *
  * @param integer $blogId
  *
  * @return  mixed
  */
 protected function getMaxOrder($blogId)
 {
     $db = Ioc::getDatabase();
     return $db->setQuery('SELECT max(ordering) FROM categories WHERE blog = ' . $blogId)->loadResult();
 }