Skip to content

Commit

Permalink
integrating the pixie query builder project step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
isocroft committed Feb 16, 2017
1 parent 165a55f commit 4c10c91
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 42 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ _Thanks to **Micheal Akpobome**, **Shuaib Afegbua**, **Abraham Yusuf**, **Stephe

## Minimum Requirements (Running Jollof)

- Have PHP 5.3.8 and above Installed
* Have PHP 5.3.8 and above Installed

- Have Composer 1.0.0 and above Installed
1. Have the PHP *mb_string* extension enabled
2. Have the PHP *openssl* extension enabled
3. Have the PHP *pdo_mysql* extension enabled
4. Have the PHP *pdo_sqlite* extension enabled
5. Have the PHP *sockets* extension enabled
6. Have the PHP *zip* extension enabled
7. Have the PHP *curl* extension enabled

- Have NPM 4.2.0 and above Installed
* Have Composer 1.0.0 and above Installed

* Have Npm 4.2.0 and above Installed


## Trademarks
Expand Down
66 changes: 60 additions & 6 deletions models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ protected static function setInstance(Model $m, array $scma){

if(!isset(static::$instance)){

$name = get_class($m);

$m->$schema = $scma;

$m->builder = $app->getBuilder($m->getAttributes());
$m->builder = $app->getBuilder($m->getAttributes(), $name);

static::$instance = unserialize(
sprintf('O:%d:"%s":0:{}', strlen(get_called_class()), get_class($m))
sprintf('O:%d:"%s":0:{}', strlen(get_called_class()), $name)
);

static::$class = get_class(static::$instance);
Expand Down Expand Up @@ -227,6 +229,39 @@ public static function whereBy(array $clause, array $cols = array('*')){
return static::$instance->get($cols, $clause)->exec();
}


/**
* Retrieves the very first tuple/row from a Model table
* based on conditions.
*
*
* @param void
* @return void
*/

public static function first(array $clause, array $cols = array('*')){

$attrs = static::$instance->getAttributes();

return static::$instance->get($cols, $clause)->exec(1);
}

/**
* Retrieves distinct columns from a Model table
*
*
*
* @param void
* @return void
*/

public static function fetchDistinct(array $cols = array('*')){

$attrs = static::$instance->getAttributes();

return static::$instance->get($cols, array())->distinct()->exec();
}

/**
*
*
Expand All @@ -236,7 +271,7 @@ public static function whereBy(array $clause, array $cols = array('*')){
* @return
*/

public static function fetchAllWith($modelName, array $clause){
public static function fetchAllWith($modelName, array $clause){

return static::$instance->get(array('*'), $clause)->with($modelName)->exec();
}
Expand All @@ -255,7 +290,7 @@ public static function updateById($id = ''){

$attr = static::$instance->getAttributes();
$clause = array();
$clause[$attr['key']] = array('=' =>$id);
$clause[$attr['key']] = array('=' => $id);

return static::$instance->let(array('*'), $clause)->exec(0);
}
Expand Down Expand Up @@ -303,15 +338,34 @@ public static function findById($id = ''){
*
*
*
* @param array $clause
* @param integer $limit
* @param integer $offset
* @return array
* @api
*/

public static function fetchAll($limit = -1, $offset = -1){
public static function fetchAll(array $clause, $limit = -1, $offset = -1){

return static::$instance->get(array('*'), $clause)->exec($limit, $offset);
}

/**
* Retrieves all tuples/rows in an ordered manner
* from the Model table.
*
*
* @param array $clause -
* @param array $orderCols -
* @param integer $limit -
* @param integer $offset -
* @return array
* @api
*/

public static function fetchAllOrdered(array $clause, array $orderCols = array(), $limit = -1, $offset = -1){

return static::$instance->get(array('*'))->exec($limit, $offset);
return static::$instance->get(array('*'), $clause)->ordering($orderCols, true)->exec($limit, $offset);
}

/**
Expand Down
1 change: 1 addition & 0 deletions system/base/class_maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"\\Providers\\Tools\\ArgvOutput" => $compDir . "/providers/Tools/ArgvOutput",
"\\Providers\\Tools\\Console" => $compDir . "/providers/Tools/Console",
"\\Providers\\Tools\\JollofSecureHeaders" => $compDir . "/providers/Tools/JollofSecureHeaders",
"\\Providers\\Tools\\SchemaObject" => $compDir . "/providers/Tools/SchemaObject",
"\\Providers\\Tools\\SecureHeaders" => $compDir . "/providers/Tools/SecureHeaders",
"\\Providers\\Tools\\AuthContext" => $compDir . "/providers/Tools/AuthContext",
"\\Providers\\Tools\\InputFilter" => $compDir . "/providers/Tools/InputFilter",
Expand Down
20 changes: 16 additions & 4 deletions system/base/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ function starts_with($str, $begin, $ignorecase = FALSE){
$slen = strlen($str);
$sub = substr($str, 0, $len);
if((gettype($str) == 'string' && gettype($begin) == 'string') && ($slen > $len)){
if($ignorecase){
$begin = strtolower($begin);
$sub = strtolower($sub);
}
if($ignorecase){
$begin = strtolower($begin);
$sub = strtolower($sub);
}
if(strcmp($sub, $begin) == 0){
return TRUE;
}else{
Expand Down Expand Up @@ -564,6 +564,18 @@ function custom_session_id($native = FALSE){
}
}

if(!function_exists('is_multi_array')){
function is_multi_array($array){
$result = false;
$filtered;
if(count($array) != count($array, COUNT_RECURSIVE)){
$filtered = array_filter($array, 'is_array');
$result = is_array(current($array)) || (count($filtered) > 0);
}
return $result;
}
}

if(! function_exists('is_binary_file') ){
function is_binary_file($file, $asString=FALSE){
$out = array();
Expand Down
9 changes: 5 additions & 4 deletions system/base/providers/Core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,14 @@ public function exposeEnvironment($root){
*
*
*
* @param
* @return
* @param array $atrribs
* @param string $modelName
* @return \Providers\Core\QueryBuilder
*/

public function getBuilder(array $attribs){
public function getBuilder(array $attribs, $modelName){

return $this->dbservice->getBuilder($attribs);
return $this->dbservice->getBuilder($attribs, $modelName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Providers\Core\DBConnection;

class MySqlConnectionAdapter{
class MySqlConnectionAdapter extends BaseConnectionAdapter{

public function __construct($dbName = NULL, $unixSocket = NULL){

Expand Down
14 changes: 14 additions & 0 deletions system/base/providers/Core/DBConnection/PgSqlConnectionAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Providers\Core\DBConnection;

class PgSqlConnectionAdapter extends BaseConnectionAdapter{

public function __construct($dbName = NULL, $unixSocket = NULL){

parent::__construct();
}
}

?>

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Providers\Core\DBConnection;

class SqlLiteConnectionAdapter extends BaseConnectionAdapter{

public function __construct($dbName = NULL, $unixSocket = NULL){

parent::__construct();
}
}

?>

4 changes: 2 additions & 2 deletions system/base/providers/Core/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class QueryBuilder {
* @api
*/

public function __construct(PDO $connection, array $paramTypes){
public function __construct(PDO $connection, array $paramTypes, $modelName){

$this->extender = new QueryExtender($connection, $paramTypes);
$this->extender = new QueryExtender($connection, $paramTypes, $modelName);

}

Expand Down
Loading

0 comments on commit 4c10c91

Please sign in to comment.