Example #1
0
 public function index()
 {
     $table = new G2_ImprovedDataTable();
     if (isset($_GET['s'])) {
         $where = 'title LIKE \'%' . implode('%', str_split(str_replace(' ', '', $_GET['s']))) . '%\' ';
     } else {
         $where = '';
     }
     //$table->add_query('page', $where.' ORDER BY id DESC');
     $query = "SELECT DISTINCT page.* FROM page INNER JOIN area ON page.id = area.page_id ";
     if ($where) {
         $query .= "WHERE " . $where;
     }
     $table->add_exec_query($query);
     $table->set_fields([['name' => 'title', 'label' => 'Page Title'], ['name' => 'description', 'label' => 'Page description']]);
     $renderer = new G2_DataTable_Renderer('title');
     $renderer->set_function(function ($fieldname, $value, $data) {
         return "<strong>{$value}</strong><br><a href=\"" . BASE_URL . $data['slug'] . "\" target=\"_blank\">View Page</a> | <a href=\"" . PACKAGE_URL . "page/{$data['id']}\">Edit Page</a>";
     });
     $table->add_renderer($renderer);
     if (Permission::has_permission('Delete Pages')) {
         $table->add_function(PACKAGE_URL . 'delete-page/[id]', 'Delete this page');
     }
     echo '<a href="' . PACKAGE_URL . 'posts" class="btn">View Posts</a>';
     echo '<div class="panel"><div class="panel-body"><form action="" method="get"><input name="s" type="text" value="' . $_GET['s'] . '"><button>Search</button></form></div></div>';
     echo $table->render();
 }
Example #2
0
 public function view($args)
 {
     $posttype = array_shift($args);
     if (empty($posttype)) {
         $this->redirect(PACKAGE_URL . 'posts');
     }
     echo '<h1>' . ucfirst($posttype) . '</h1>';
     $model = $this->loadModel('post_model');
     /* @var $model Post_Model */
     $posts = $model->get_posts($posttype);
     if (!empty($posts)) {
         $table = new G2_ImprovedDataTable();
         $table->set_data($posts, 5);
         $fields = $model->get_fields($posttype);
         $table->set_fields($model->get_fields($posttype, true));
         $table->add_function(PACKAGE_URL . "posts/crud/{$posttype}/[id]", 'Edit');
         $table->add_function(PACKAGE_URL . "posts/delete/{$posttype}/[id]", 'Delete');
         echo $table->render();
     } else {
         echo '<p>No Posts Found</p>';
     }
     echo '<a href="' . PACKAGE_URL . "posts/crud/{$posttype}" . '" class="btn btn-default">Add Post</a>';
 }