Esempio n. 1
1
 /**
  * Perform the SQL queries needed for an server-side processing requested,
  * utilising the helper functions of this class, limit(), order() and
  * filter() among others. The returned array is ready to be encoded as JSON
  * in response to an SSP request, or can be modified if needed before
  * sending back to the client.
  *
  *  @param  array $request Data sent to server by DataTables
  *  @param  array $sql_details SQL connection details - see sql_connect()
  *  @param  string $table SQL table to query
  *  @param  string $primaryKey Primary key of the table
  *  @param  array $columns Column information array
  *  @return array          Server-side processing response array
  */
 static function simple($request, $db, $table, $primaryKey, $columns, $myJoin, $myWhere)
 {
     $bindings = array();
     //$db = SSP::sql_connect( $sql_details );
     // Build the SQL query string from the request
     $limit = SSP::limit($request, $columns);
     $order = SSP::order($request, $columns);
     $where = SSP::filter($request, $columns, $bindings, $myWhere);
     // Main query to actually get the data
     $data = SSP::sql_exec($db, $bindings, "SELECT SQL_CALC_FOUND_ROWS " . implode(", ", SSP::pluckAs($columns)) . "\n             FROM {$table}\n             {$myJoin}\n             {$where}\n             {$order}\n             {$limit}");
     // Data set length after filtering
     $resFilterLength = SSP::sql_exec($db, "SELECT FOUND_ROWS()");
     $recordsFiltered = $resFilterLength[0][0];
     //add my initial where clause for correct results
     $dataWhere = $myWhere !== '' ? 'WHERE ' . $myWhere : '';
     // Total data set length
     $resTotalLength = SSP::sql_exec($db, "SELECT COUNT({$primaryKey})\n             FROM {$table}\n             {$myJoin}\n             {$dataWhere}");
     $recordsTotal = $resTotalLength[0][0];
     /*
      * Output
      */
     return array("draw" => intval($request['draw']), "recordsTotal" => intval($recordsTotal), "recordsFiltered" => intval($recordsFiltered), "data" => SSP::data_output($columns, $data));
 }