Esempio n. 1
0
 function galleries_table()
 {
     //ajax call function
     if (!$_REQUEST) {
         return false;
     }
     $baseSql = "\n\t\t\tSELECT \n\t\t\t\tCASE g.type \n\t\t\t\t\tWHEN 1 THEN 'Gallery 1'\n\t\t\t\t\tWHEN 2 THEN 'Gallery 2'\n\t\t\t\t\tWHEN 3 THEN 'Gallery 3'\n\t\t\t\t\tWHEN 4 THEN 'Gallery 4'\n\t\t\t\t\tELSE 'Gallery'\n\t\t\t\tEND AS 'Type',\n\t\t\t\tg.gallery_id,\n\t\t\t\tg.gallery_title as 'Title',\n\t\t\t\tg.url as 'URL',\n\t\t\t\tg.category as 'Category',\n\t\t\t\tg.author_id,\n\t\t\t\tg.created as 'Date Created',\n\t\t\t\tu.username as 'Author',\n\t\t\t\t'' as 'Image'\n\t\t\tFROM\n\t\t\t\tgallery g\n\t\t\tLEFT JOIN\n\t\t\t\tusername u\n\t\t\tON\n\t\t\t\tg.user_id = u.id\n\t\t";
     //List all of your columns here
     $columns = array('Title', 'URL', 'Type', 'Category', 'Author', 'Image', 'Date Created');
     $functions = array();
     /*
      * adding functions is not required. This is just a way to run functions on the data if you wish.
      * This will take the target which is the Image row from the query, and change it to the "replace" string.
      * You can use part of the query to build the replace using {} and passing them in the params.
      */
     $functions[] = array('function' => 'editRow', 'target' => 'Image', 'replace' => '<img src="www.mysite.com/{gallery_id}" alt="{Title}">', 'params' => array('gallery_id', 'Title'));
     /*
      * Add this to change the date format. Simply put in the date format
      * of your column in the format_from value, and put the
      * desired date format in the format_to value
      * 20150101 becomes Thu: 01-01-15
      */
     $functions[] = array('function' => 'date_format', 'format_to' => 'D: m-d-y', 'format_from' => 'Ymd', 'columns' => array('Date Created'));
     /*
      * list any columns you want to be "searchable".
      * you can also list non visable data here to be searchable, such as the gallery_id.
      */
     $searchable = array('Title', 'URL', 'Author', 'Category');
     echo json_encode(SSP::buildTable($this->Model, $_REQUEST, $baseSql, $columns, $searchable, $functions));
 }