Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/emran/ssp
Browse files Browse the repository at this point in the history
  • Loading branch information
emran committed Sep 20, 2014
2 parents 4f9f82c + 045d6b3 commit 21abb63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ So due to allow complex query, I have changed the [SSP class](https://github.com
$joinQuery = "FROM `{$table}` AS `c` LEFT JOIN `currency_names` AS `cn` ON (`cn`.`id` = `c`.`id_currency`)";
$extraCondition = "`id_client`=".$ID_CLIENT_VALUE;

$Ssp = new Libs_SSP();
echo json_encode(
$Ssp::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraCondition)
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraCondition)
);

Expand Down
32 changes: 16 additions & 16 deletions ssp.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static function order ( $request, $columns, $isJoin = false )

if ( isset($request['order']) && count($request['order']) ) {
$orderBy = array();
$dtColumns = Libs_SSP::pluck( $columns, 'dt' );
$dtColumns = SSP::pluck( $columns, 'dt' );

for ( $i=0, $ien=count($request['order']) ; $i<$ien ; $i++ ) {
// Convert the column index into the column data property
Expand Down Expand Up @@ -147,7 +147,7 @@ static function filter ( $request, $columns, &$bindings, $isJoin = false )
{
$globalSearch = array();
$columnSearch = array();
$dtColumns = Libs_SSP::pluck( $columns, 'dt' );
$dtColumns = SSP::pluck( $columns, 'dt' );

if ( isset($request['search']) && $request['search']['value'] != '' ) {
$str = $request['search']['value'];
Expand All @@ -158,7 +158,7 @@ static function filter ( $request, $columns, &$bindings, $isJoin = false )
$column = $columns[ $columnIdx ];

if ( $requestColumn['searchable'] == 'true' ) {
$binding = Libs_SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$binding = SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$globalSearch[] = ($isJoin) ? $column['db']." LIKE ".$binding : "`".$column['db']."` LIKE ".$binding;
}
}
Expand All @@ -174,7 +174,7 @@ static function filter ( $request, $columns, &$bindings, $isJoin = false )

if ( $requestColumn['searchable'] == 'true' &&
$str != '' ) {
$binding = Libs_SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$binding = SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$columnSearch[] = ($isJoin) ? $column['db']." LIKE ".$binding : "`".$column['db']."` LIKE ".$binding;
}
}
Expand Down Expand Up @@ -221,12 +221,12 @@ static function filter ( $request, $columns, &$bindings, $isJoin = false )
static function simple ( $request, $sql_details, $table, $primaryKey, $columns, $joinQuery = NULL, $extraWhere = '')
{
$bindings = array();
$db = Libs_SSP::sql_connect( $sql_details );
$db = SSP::sql_connect( $sql_details );

// Build the SQL query string from the request
$limit = Libs_SSP::limit( $request, $columns );
$order = Libs_SSP::order( $request, $columns, $joinQuery );
$where = Libs_SSP::filter( $request, $columns, $bindings, $joinQuery );
$limit = SSP::limit( $request, $columns );
$order = SSP::order( $request, $columns, $joinQuery );
$where = SSP::filter( $request, $columns, $bindings, $joinQuery );

// IF Extra where set then set and prepare query
if($extraWhere){
Expand All @@ -236,7 +236,7 @@ static function simple ( $request, $sql_details, $table, $primaryKey, $columns,
// Main query to actually get the data
if($joinQuery){

$col = Libs_SSP::pluck($columns, 'db', $joinQuery);
$col = SSP::pluck($columns, 'db', $joinQuery);

$query = "SELECT SQL_CALC_FOUND_ROWS ".implode(", ", $col)."
$joinQuery
Expand All @@ -245,24 +245,24 @@ static function simple ( $request, $sql_details, $table, $primaryKey, $columns,
$order
$limit";
}else{
$query = "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", Libs_SSP::pluck($columns, 'db'))."`
$query = "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", SSP::pluck($columns, 'db'))."`
FROM `$table`
$where
$extraWhere
$order
$limit";
}

$data = Libs_SSP::sql_exec( $db, $bindings,$query);
$data = SSP::sql_exec( $db, $bindings,$query);

// Data set length after filtering
$resFilterLength = Libs_SSP::sql_exec( $db,
$resFilterLength = SSP::sql_exec( $db,
"SELECT FOUND_ROWS()"
);
$recordsFiltered = $resFilterLength[0][0];

// Total data set length
$resTotalLength = Libs_SSP::sql_exec( $db,
$resTotalLength = SSP::sql_exec( $db,
"SELECT COUNT(`{$primaryKey}`)
FROM `$table`"
);
Expand All @@ -276,7 +276,7 @@ static function simple ( $request, $sql_details, $table, $primaryKey, $columns,
"draw" => intval( $request['draw'] ),
"recordsTotal" => intval( $recordsTotal ),
"recordsFiltered" => intval( $recordsFiltered ),
"data" => Libs_SSP::data_output( $columns, $data, $joinQuery )
"data" => SSP::data_output( $columns, $data, $joinQuery )
);
}

Expand All @@ -303,7 +303,7 @@ static function sql_connect ( $sql_details )
);
}
catch (PDOException $e) {
Libs_SSP::fatal(
SSP::fatal(
"An error occurred while connecting to the database. ".
"The error reported by the server was: ".$e->getMessage()
);
Expand Down Expand Up @@ -346,7 +346,7 @@ static function sql_exec ( $db, $bindings, $sql=null )
$stmt->execute();
}
catch (PDOException $e) {
Libs_SSP::fatal( "An SQL error occurred: ".$e->getMessage() );
SSP::fatal( "An SQL error occurred: ".$e->getMessage() );
}

// Return all
Expand Down

0 comments on commit 21abb63

Please sign in to comment.