Nibiru is a rapid prototyping framework written in PHP and based on the MVC design pattern. Now one may say that writing
@@ -55,7 +55,6 @@ Engine Implementation.
Dwoo tempalte eninge tests
Twig tempalte eninge tests
-
Previous version
Version 0.3 beta 04.02.2018
Improved: The Router now accepts actions, either trough the _action as parameter, or on the URL pattern after the controller name Example: http://youdomain/[controllername]/[actionname]/
@@ -65,8 +64,7 @@ Engine Implementation.
The Database access can now be implemented anywhere in your application by adding the namespace to your database accessing Logic: use Nibiru\Factory\Db;
-
-
Update
+
Previous version
Version 0.3.5 beta 14.03.2018
Bugfix on the Router, now the currentPage will be returned correctly.
@@ -75,6 +73,17 @@ Engine Implementation.
Added missing form elements, migration to a Form factory, in order to easy configure and install a form anywhere you like
Minor bugfixing
+
+
Update
+
Version 0.4.0 beta 09.07.2018
+
+
Bugfix on the form classes, now the select option is correctly set back.
+
Update for the database adapter
+
Improvement of the form elements, added onchange on the select boxes, the form tag now can have no element if needed.
+
Implementation of the Postgres and MySQL Adapter with propper Namespacing.
+
Minor bugfixing
+
+
The start is done, have success with PHP prototyping, and always remember to have fun!
Author: Stephan Kasdorf
\ No newline at end of file
diff --git a/application/controller/indexController.php b/application/controller/indexController.php
index 2b9961a..54c12f7 100644
--- a/application/controller/indexController.php
+++ b/application/controller/indexController.php
@@ -33,9 +33,4 @@ class indexController extends View implements IController
{
JsonNavigation::getInstance()->loadJsonNavigationArray();
}
-
- public function formAction( $action = false, $name = "", $type = "", $labeled = false, $data = array() )
- {
- // TODO: Implement formAction() method.
- }
}
\ No newline at end of file
diff --git a/application/model/users.php b/application/model/users.php
index 04bf8dc..f436f49 100644
--- a/application/model/users.php
+++ b/application/model/users.php
@@ -1,6 +1,6 @@
$field)
+ {
+ if(++$i === $numItems)
+ {
+ $fields .= $field . " ";
+ }
+ else
+ {
+ $fields .= $field . ", ";
+ }
+ }
+ return Postgres::query("SELECT " . $fields . "FROM " . self::getTable()['table'] . ";");
+ }
+ catch(\Exception $e)
+ {
+ throw new \Exception(print_r($e, true));
+ }
+
+ }
+
+ public function insertRowsetById($rowset = array(), $id = false)
+ {
+ // TODO: Implement insertRowsetById() method.
+ }
+
+ /**
+ * @desc Selects a Field by max value, or multiple fields by max value, same with min fields.
+ * Both can be combined.
+ * @param string|array $min
+ * @param string|array $max
+ * @return array|mixed
+ */
+ public function selectDatasetByMinMax($min = false, $max = false)
+ {
+ if($min)
+ {
+ $fields = "";
+ if(is_array($min))
+ {
+ $numItems = count($min);
+ $i = 0;
+ foreach ($min as $key=>$item)
+ {
+ if(++$i === $numItems)
+ {
+ $fields .= "MIN(" . $item .") as min_" .$item . " ";
+ }
+ else
+ {
+ $fields .= "MIN(" . $item .") as min_".$item.", ";
+ }
+ }
+ }
+ else
+ {
+ $fields .= "MIN(".$min.") as min_" . $min . " ";
+ }
+ }
+ if($max)
+ {
+ $mfields = "";
+ if(is_array($max))
+ {
+ $numItems = count($max);
+ $y = 0;
+ foreach ($max as $key=>$item)
+ {
+ if(++$y === $numItems)
+ {
+ $mfields .= "MAX(" . $item .") as max_" .$item . " ";
+ }
+ else
+ {
+ $mfields .= "MAX(" . $item .") as max_".$item.", ";
+ }
+ }
+ }
+ else
+ {
+ $mfields .= "MAX(".$max.") as max_" . $max . " ";
+ }
+ }
+ if(!empty($fields))
+ {
+ if(!empty($mfields))
+ {
+ $result = Postgres::query("SELECT " . $fields . ", " . $mfields . " FROM " . self::getTable()['table']);
+ }
+ else
+ {
+ $result = Postgres::query("SELECT " . $fields . " FROM " . self::getTable()['table']);
+ }
+ }
+
+ if(!empty($mfields) && empty($fields))
+ {
+ $result = Postgres::query("SELECT " . $mfields . " FROM " . self::getTable()['table']);
+ }
+ return $result;
+ }
+
+ /**
+ * @desc Gets the next dataset ID for insertation, if the dataset should be iterated and not be related to the last insert id because that one is already
+ * present it can also be iterated
+ * @param bool $iterate
+ * @return int|mixed|null
+ */
+ public function nextInsertIndex($iterate = false)
+ {
+ if(!$iterate)
+ {
+ $cur = array_shift(Postgres::query('SELECT MAX(id) AS id FROM ' . self::getTable()['table'] . ';'));
+ if(empty(array_filter($cur)))
+ {
+ $cur["id"] = 1;
+ }
+ else
+ {
+ $cur["id"]++;
+ }
+ $this->_nextIndex = $cur["id"];
+ }
+ else
+ {
+ $this->_nextIndex++;
+ }
+ return $this->_nextIndex;
+ }
+
+ /**
+ * @desc returns the rowset by the selected field and value array
+ * @param array $fieldValue
+ * @return array|mixed
+ */
+ public function selectRowsetByFieldValue( $fieldValue = array() )
+ {
+ return Postgres::fetchRowInArrayByWhere(self::getTable()['table'], $fieldValue['field'], $fieldValue['value']);
+ }
+
+ /**
+ * @desc selects only one field from the field value array and returns the result
+ * @param array $fieldValue
+ * @return array
+ */
+ public function selectFieldByFieldValue( $fieldValue = array() )
+ {
+ return Postgres::query("SELECT " . $fieldValue['field'] . " FROM " . self::getTable()['table'] . " WHERE " . $fieldValue['field'] . " = '" . $fieldValue['value'] . "';");
+ }
+
+ /**
+ * @desc deletes all content in the table use with caution
+ */
+ public function truncateTable()
+ {
+ Postgres::query('DELETE FROM ' . self::getTable()['table'] . ';');
+ }
+
+ /**
+ * @desc deletes entry by ID from the database
+ * @param bool $id
+ */
+ public function deleteEntryById( $id = false )
+ {
+ if($id)
+ {
+ Postgres::query('DELETE FROM ' . self::getTable()['table'] . ' WHERE id = ' . $id . ';' );
+ }
+ }
+
+ /**
+ * @desc deletes entry by fieldname and value from the database
+ * @param array $fieldValue
+ */
+ public function deleteEntryByFieldValue( $fieldValue = array() )
+ {
+ if(array_key_exists('field', $fieldValue))
+ {
+ Postgres::query("DELETE FROM " . self::getTable()['table'] . " WHERE " . $fieldValue["field"] . " = '" . $fieldValue["value"] . "'" );
+ }
+ }
+
+ /**
+ * @desc Loads the complete Table to an array, only use for small tables, otherwise load the table with its limits.
+ * @param array $sortfield['name'], $sortfield['order'], or as in the followin example:
+ * q
+ * @return array
+ */
+ public function loadTableToArray( $sortfield = array() )
+ {
+ if(sizeof($sortfield)>0)
+ {
+ $name = implode(', ', $sortfield['name']);
+ $result = Postgres::query('SELECT * FROM ' . self::getTable()['table'] . ' ORDER BY ' . $name . ' ' . $sortfield['order']. ';');
+ }
+ else
+ {
+ $result = Postgres::query('SELECT * FROM ' . self::getTable()['table'] . ';');
+ }
+ return $result;
+ }
+
+ public function loadMultithreadCount()
+ {
+ if( $this->_multithreatCount < Postgres::getInstance()->getMultithreading() )
+ {
+ $this->_multithreatCount++;
+ }
+ else
+ {
+ $this->_multithreatCount = 0;
+ }
+ return $this->_multithreatCount;
+ }
+
+ /**
+ * @desc returns the last inserted id from the corresponding table Model
+ * @return mixed
+ */
+ public function getLastInsertID( $sequences = false )
+ {
+
+ try
+ {
+ if(!$sequences)
+ {
+ $result = Postgres::query('SELECT MAX(id) AS id FROM ' . self::getTable()['table'] . ';');
+ return array_shift($result)["id"];
+ }
+ else
+ {
+ //Limbas sequence abfragen
+ Postgres::query('SELECT last_value AS id FROM seq_' . self::getTable()['table'] . '_id ;');
+ return array_shift($result)["id"];
+ }
+ }
+ catch (\Exception $e)
+ {
+ throw new \Exception(print_r($e, true));
+ }
+ }
+
+ /**
+ * @desc gets the row count of a table
+ * @return mixed
+ */
+ public function insertedRowCount()
+ {
+ $result = Postgres::query("SELECT count(*) as sum FROM " . self::getTable()['table'] . ";");
+ return array_shift($result)['sum'];
+ }
+
+ /**
+ * @desc returns all columns as an array from the current table
+ * @return mixed|void
+ */
+ public function getAllColumnsAsArray()
+ {
+ $result = Postgres::query("SELECT * FROM information_schema.columns WHERE table_schema = 'public' AND table_name = '" . self::getTable()['table'] . "';");
+ return $result;
+ }
+}
\ No newline at end of file
diff --git a/core/c/auth.php b/core/c/auth.php
index 3873e92..eeca611 100644
--- a/core/c/auth.php
+++ b/core/c/auth.php
@@ -44,7 +44,9 @@ class Auth extends Controller implements IAuth
$user_password = Pdo::query("SELECT DES_DECRYPT(user_pass, '".Config::getInstance()->getConfig()["SECURITY"]["password_hash"]."') AS pass FROM user WHERE user_login = '".$login."';");
if( $user_password["pass"] == $password )
{
- $_SESSION['auth']['login'] = $login;
+ $session_id = session_id();
+ $_SESSION['auth']['id'] = $session_id;
+ $_SESSION['auth']['login'] = $login;
return true;
}
else
diff --git a/core/c/autoloader.php b/core/c/autoloader.php
index ca65c0b..2eb8456 100644
--- a/core/c/autoloader.php
+++ b/core/c/autoloader.php
@@ -14,7 +14,7 @@ class Autoloader
{
const MY_FILE_NAME = "autoloader.php";
const DB_MODEL_FOLDER = "dbmodel";
- const MODUL_FOLDER = "modul";
+ const MODULE_FOLDER = "module";
private static $_filesInFoler = array();
private static $_instance;
@@ -56,7 +56,33 @@ class Autoloader
*/
private static function _setFilesInFoler( )
{
- $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER] ));
+ $modelFolder = Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::DB_MODEL_FOLDER];
+ if(is_array($modelFolder))
+ {
+ foreach ($modelFolder as $folder)
+ {
+ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . $folder ));
+ foreach ($iterator as $item)
+ {
+ if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!="..")
+ {
+ self::$_filesInFoler[] = $item->getPathName();
+ }
+ }
+ }
+ }
+ else
+ {
+ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . $modelFolder ));
+ foreach ($iterator as $item)
+ {
+ if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!="..")
+ {
+ self::$_filesInFoler[] = $item->getPathName();
+ }
+ }
+ }
+ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS][self::MODULE_FOLDER] ));
foreach ($iterator as $item)
{
if($item->getFileName()!= self::MY_FILE_NAME && $item->getFileName()!="." && $item->getFileName()!="..")
diff --git a/core/c/controller.php b/core/c/controller.php
index 150f9e5..2420572 100644
--- a/core/c/controller.php
+++ b/core/c/controller.php
@@ -142,4 +142,11 @@ class Controller
return $_REQUEST;
}
+ /**
+ * @return mixed
+ */
+ public function getServer()
+ {
+ return $_SERVER;
+ }
}
\ No newline at end of file
diff --git a/core/c/form.php b/core/c/form.php
index 9e214e1..4f32360 100644
--- a/core/c/form.php
+++ b/core/c/form.php
@@ -16,7 +16,9 @@ class Form extends FormAttributes implements IForm
self::FORM_ACTION => '',
self::FORM_TARGET => '',
self::FORM_ATTRIBUTE_ID => '',
- self::FORM_ATTRIBUTE_CLASS => ''
+ self::FORM_ATTRIBUTE_CLASS => '',
+ self::FORM_ENCTYPE => '',
+ self::FORM_ATTRIBUTE_ONSUBMIT => ''
);
public function loadElement( $attributes )
@@ -32,7 +34,7 @@ class Form extends FormAttributes implements IForm
*/
private function _setElement( )
{
- $this->_element = '' . "\n";
+ $this->_element = '' . "\n";
}
}
\ No newline at end of file
diff --git a/core/c/formattributes.php b/core/c/formattributes.php
index a654c7b..6b19087 100755
--- a/core/c/formattributes.php
+++ b/core/c/formattributes.php
@@ -8,25 +8,25 @@ namespace Nibiru\Form;
*/
class FormAttributes
{
-
+
private $_attributes = array();
protected $_element;
-
+
use \Nibiru\Attributes\Form;
-
+
public function __construct( $attributes = false )
{
if($attributes)
{
try {
- if( is_array( $attributes ) )
- {
- $this->_attributes = $attributes;
- }
- else
- {
- throw new \Exception( self::errorMessage( str_replace('.php', '', basename( __FILE__ )), __LINE__ ) );
- }
+ if( is_array( $attributes ) )
+ {
+ $this->_attributes = $attributes;
+ }
+ else
+ {
+ throw new \Exception( self::errorMessage( str_replace('.php', '', basename( __FILE__ )), __LINE__ ) );
+ }
} catch (\Exception $e)
{
self::exceptionMessage( $e );
@@ -41,7 +41,7 @@ class FormAttributes
{
return $this->_attributes;
}
-
+
/**
* @param array $attributes
*/
@@ -58,6 +58,9 @@ class FormAttributes
}
$this->_element = str_replace(' ID', '', $this->_element);
$this->_element = str_replace(' CLASS', '', $this->_element);
+ $this->_element = str_replace(' enctype="ENCTYPE"', '', $this->_element);
+ $this->_element = str_replace(' onsubmit="ONSUBMIT"', '', $this->_element);
+ $this->_element = str_replace(' action="ACTION"', '', $this->_element);
$this->_element = str_replace(' SPEECH', '', $this->_element);
$this->_element = str_replace(' FORM', '', $this->_element);
$this->_element = str_replace(' placeholder="PLACEHOLDER"', '', $this->_element);
@@ -65,6 +68,9 @@ class FormAttributes
$this->_element = str_replace(' value="VALUE"', '', $this->_element);
$this->_element = str_replace(' ', ' ', $this->_element);
$this->_element = str_replace(' type="TYPE"', '', $this->_element);
+ $this->_element = str_replace(' onchange="ONCHANGE"', '', $this->_element);
+ $this->_element = str_replace(' SELECTED', '', $this->_element);
+ $this->_element = str_replace(' CONTEXT', '', $this->_element);
}
/**
diff --git a/core/c/pdo.php b/core/c/pdo.php
index a00a13b..1b0a2a9 100644
--- a/core/c/pdo.php
+++ b/core/c/pdo.php
@@ -33,6 +33,12 @@ final class Pdo extends Mysql implements IPdo
return $result;
}
+ public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TABLE_NAME, $fieldAndValue = array() )
+ {
+ $result = parent::getInstance()->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . "';");
+ return $result->fetchAll();
+ }
+
public static function updateColumnByFieldWhere( $tablename = self::PLACE_TABLE_NAME,
$column_name = IMysql::PLACE_COLUMN_NAME,
$parameter_name = IMysql::PLACE_SEARCH_TERM,
diff --git a/core/c/postgres.php b/core/c/postgres.php
index 3770614..6d1a655 100755
--- a/core/c/postgres.php
+++ b/core/c/postgres.php
@@ -152,4 +152,9 @@ class Postgres extends Odbc implements IPostgres
}
}
+ public static function truncateTable($tablename = IOdbc::PLACE_TABLE_NAME)
+ {
+ \odbc_exec(parent::getInstance( self::getSettingsSection() )->getConn(), "DELETE FROM " . $tablename . ";");
+ }
+
}
\ No newline at end of file
diff --git a/core/c/router.php b/core/c/router.php
index dbc52ca..b430a3b 100755
--- a/core/c/router.php
+++ b/core/c/router.php
@@ -171,7 +171,7 @@ class Router extends Config
public function currentPage()
{
//self::RouterDebug(self::$_cur_page);
- return self::$_cur_page;
+ return self::getCurPage();
}
public static function RouterDebug($value)
diff --git a/core/c/typeoption.php b/core/c/typeoption.php
index dd3841f..d6522d3 100644
--- a/core/c/typeoption.php
+++ b/core/c/typeoption.php
@@ -12,9 +12,11 @@ use Nibiru\Adapter;
class TypeOption extends FormAttributes implements IForm
{
private $_attributes = array(
- self::FORM_VALUE => '',
- self::FORM_ATTRIBUTE_ID => '',
- self::FORM_ATTRIBUTE_CLASS => ''
+ self::FORM_VALUE => '',
+ self::FORM_ATTRIBUTE_ID => '',
+ self::FORM_ATTRIBUTE_CLASS => '',
+ self::FORM_ATTRIBUTE_SELECTED => '',
+ self::FORM_ATTRIBUTE_CONTEXT => ''
);
public function loadElement( $attributes )
@@ -30,9 +32,6 @@ class TypeOption extends FormAttributes implements IForm
*/
private function _setElement( )
{
- $this->_element = '' . "\n";
+ $this->_element = '' . "\n";
}
-
-
-
}
\ No newline at end of file
diff --git a/core/c/typeselect.php b/core/c/typeselect.php
index 4a87c0e..e558f6a 100644
--- a/core/c/typeselect.php
+++ b/core/c/typeselect.php
@@ -12,9 +12,10 @@ use Nibiru\Adapter;
class TypeSelect extends FormAttributes implements IForm
{
private $_attributes = array(
- self::FORM_NAME => '',
- self::FORM_ATTRIBUTE_CLASS => '',
- self::FORM_ATTRIBUTE_ID => ''
+ self::FORM_NAME => '',
+ self::FORM_ATTRIBUTE_CLASS => '',
+ self::FORM_ATTRIBUTE_ID => '',
+ self::FORM_ATTRIBUTE_ONCHANGE => ''
);
public function loadElement( $attributes )
@@ -30,9 +31,6 @@ class TypeSelect extends FormAttributes implements IForm
*/
private function _setElement( )
{
- $this->_element = '' . "\n";
+ $this->_element = '' . "\n";
}
-
-
-
}
\ No newline at end of file
diff --git a/core/f/form.php b/core/f/form.php
index 95fae74..0ab7d18 100644
--- a/core/f/form.php
+++ b/core/f/form.php
@@ -44,7 +44,14 @@ class Form
*/
private static function assambleOptions( $option )
{
- self::$option .= $option;
+ if($option == false)
+ {
+ self::$option = "";
+ }
+ else
+ {
+ self::$option .= $option;
+ }
}
/**
@@ -57,6 +64,14 @@ class Form
return str_replace( 'OPTIONS', self::$option, $select );
}
+ /**
+ * @desc clear all form data in order to build a new one
+ */
+ public static function create()
+ {
+ self::$form = "";
+ }
+
/**
* @desc is used internally for assambly only
* @param $element
@@ -144,7 +159,7 @@ class Form
{
self::setDiv( $div );
}
- self::setElement( new \Nibiru\Form\Form() );
+ self::setElement( new \Sunrise\Form\Form() );
return self::display( self::getElement()->loadElement( $attributes ) );
}
@@ -429,7 +444,7 @@ class Form
}
self::setElement( new TypeSelect() );
self::assamble( self::displaySelect( self::getElement()->loadElement( $attributes ) ) );
-
+ self::assambleOptions( false );
}
/**
diff --git a/core/framework.php b/core/framework.php
index a6103d6..03152c4 100644
--- a/core/framework.php
+++ b/core/framework.php
@@ -7,7 +7,10 @@
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
-session_start();
+if(session_status() == PHP_SESSION_NONE)
+{
+ session_start();
+}
/**
* @desc Nibiru framework functionality
*/
@@ -29,7 +32,8 @@ require_once __DIR__ . '/c/odbc.php';
require_once __DIR__ . '/i/postgres.php';
require_once __DIR__ . '/c/postgres.php';
require_once __DIR__ . '/i/db.php';
-require_once __DIR__ . '/a/db.php';
+require_once __DIR__ . '/a/mysql.db.php';
+require_once __DIR__ . '/a/postgres.db.php';
require_once __DIR__ . '/f/db.php';
/**
* @desc MVC functionality
diff --git a/core/i/db.php b/core/i/db.php
index 2d43019..e2d7301 100644
--- a/core/i/db.php
+++ b/core/i/db.php
@@ -1,5 +1,5 @@