This commit is contained in:
2017-12-27 13:46:56 +01:00
parent 0cc882060c
commit 73d95c3daf
22 changed files with 641 additions and 6 deletions
@@ -0,0 +1,190 @@
<?php defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
/**
* Created by PhpStorm.
* User: imac-3
* Date: 04/06/16
* Time: 14:17
*/
class validation {
private $fieldValue;
private $validations;
private $validation;
private $validationResult;
private $errorMessages = [];
private $validationField;
private $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public function validate( $fieldValue, $validationField = FALSE )
{
$this->setValidationField( $validationField );
$this->setFieldValue( $fieldValue );
$this->handle();
}
public function setValidationField( $validationfield )
{
$this->validationField = $validationfield;
}
public function getErrorMessages()
{
return $this->errorMessages;
}
public function getValidationResult()
{
return $this->validationResult;
}
private function handle()
{
$this->setValidations();
$this->checkValidations();
$this->setValidationResult();
}
private function setValidations()
{
$this->validations = explode( '|', $this->validationField['validations'] );
}
private function setFieldValue( $fieldValue )
{
$this->fieldValue = $fieldValue;
}
private function setValidationResult()
{
if ( count( $this->errorMessages ) == 0 ) return $this->validationResult = TRUE;
$this->validationResult = FALSE;
}
private function checkValidations()
{
foreach ( $this->validations as $this->validation )
{
if ( $this->validation == 'required' ) $this->checkRequired();
if ( $this->validation == 'alpha' ) $this->checkAlfa();
if ( $this->validation == 'alphaNumeric' ) $this->checkAlfanumeric();
if ( $this->validation == 'alphaNumericSpaces' ) $this->checkAlphaNumericSpaces();
if ( $this->validation == 'alphaDash' ) $this->checkAlphaDash();
if ( $this->validation == 'numeric' ) $this->checkNumeric();
if ( $this->validation == 'integer' ) $this->checkInteger();
if ( $this->validation == 'decimal' ) $this->checkDecimal();
if ( $this->validation == 'email' ) $this->checkEmail();
if ( $this->validation == 'unique' ) $this->checkUnique();
if ( substr( $this->validation, 0, 9 ) == 'minlength' ) $this->checkMinlength();
if ( substr( $this->validation, 0, 9 ) == 'maxlength' ) $this->checkMaxlength();
}
}
public function checkRequired()
{
if ( ! $this->fieldValue || empty( $this->fieldValue ) || strlen( $this->fieldValue ) == 0 )
$this->errorMessages[] = 'veld is verplicht';
}
public function checkAlfa()
{
$value = ctype_alpha( $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters toegestaan';
}
public function checkAlfaNumeric()
{
$value = ctype_alnum( (string) $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters en cijfers toegestaan';
return $value;
}
public function checkAlphaNumericSpaces()
{
$value = (bool) preg_match( '/^[A-Z0-9 ]+$/i', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters, cijfers en spaties toegestaan';
}
public function checkAlphaDash()
{
$value = (bool) preg_match( '/^[a-z0-9_-]+$/i', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen letters, cijfers en streepjes toegestaan';
}
public function checkNumeric()
{
$value = (bool) preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen getallen toegestaan';
}
public function checkInteger()
{
$value = (bool) preg_match( '/^[\-+]?[0-9]+$/', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen gehele getallen toegestaan';
}
public function checkDecimal()
{
$value = (bool) preg_match( '/^[\-+]?[0-9]+\.[0-9]+$/', $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'alleen getallen toegestaan';
}
public function checkEmail()
{
if ( ! $this->fieldValue || empty( $this->fieldValue ) || strlen( $this->fieldValue ) == 0 ) return;
$value = (bool) filter_var( $this->fieldValue, FILTER_VALIDATE_EMAIL );
if ( ! $value ) $this->errorMessages[] = 'ongeldig emailadres';
}
public function checkUnique()
{
$recordID = $this->ci->input->post( 'id' );
$model = $this->validationField['model'];
$field = $this->validationField['field'];
$value = $this->ci
->$model
->checkUnique( $recordID, $field, $this->fieldValue );
if ( ! $value ) $this->errorMessages[] = 'invoer moet uniek zijn';
}
private function checkMinlength()
{
$length = explode( '-', $this->validation );
if ( strlen( $this->fieldValue ) < $length[1] )
$this->errorMessages[] = 'moet minimaal uit ' . $length[1] . ' karakters bestaan';
}
private function checkMaxlength()
{
$length = explode( $this->validation, '-' );
if ( strlen( $this->fieldValue ) > $length[1] )
$this->errorMessages[] = 'mag maximaal uit ' . $length[1] . ' karakters bestaan';
}
}
@@ -0,0 +1,91 @@
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Created by PhpStorm.
* User: imac-3
* Date: 26/06/16
* Time: 21:17
*/
require_once( APPPATH . 'libraries/validation/Validation.php' );
class BaseValidation {
protected $validationField;
protected $key;
protected $fieldValue;
protected $errorMessages = [];
protected $validation;
protected $fieldname;
protected $ci;
protected $validationResult;
public function __construct()
{
$this->ci =& get_instance();
$this->validateInput();
}
public function getValidationResult()
{
return $this->validationResult;
}
public function validateInput()
{
$this->loopFields();
}
public function getErrorMessages( )
{
return $this->errorMessages;
}
private function loopFields()
{
foreach ( $this->validationFields as $this->key => $this->validationField )
{
$this->validation = new Validation();
$this->setInputfield();
$this->validateFieldvalue();
$this->setFieldname();
$this->setValidationResult();
$this->setErrorMesagges();
}
}
private function setInputfield()
{
$this->fieldValue = $this->ci->input->post( $this->key );
}
private function validateFieldvalue()
{
$this->validation->validate( $this->fieldValue, $this->validationField );
}
private function setFieldname()
{
$this->fieldname = $this->validationField['fieldname'];
}
private function setErrorMesagges()
{
$this->errorMessages[ $this->fieldname ] = $this->validation->getErrorMessages();
}
private function setValidationResult()
{
if( $this->validationResult === FALSE ) return;
$this->validationResult = $this->validation->getValidationResult();
}
}
@@ -0,0 +1,28 @@
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Created by PhpStorm.
* User: imac-3
* Date: 26/06/16
* Time: 21:13
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class LoginValidation extends BaseValidation {
protected $validationFields = [
'username' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'gebruikersnaam'
],
'password' => [
'validations' => 'required',
'fieldname' => 'wachtwoord'
]
];
public function __construct()
{
parent::__construct();
}
}
@@ -0,0 +1,47 @@
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Created by Pensare Software
* User: Theo Weijmer
* Date: 26/06/16
* Time: 20:39
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class OrganisationValidation extends BaseValidation {
protected $validationFields = [
'brin' => [
'validations' => 'required|alphaNumeric',
'fieldname' => 'brinnummer'
],
'naam' => [
'validations' => 'required',
'fieldname' => 'Organisatienaam'
],
'naamkort' => [
'validations' => 'required',
'fieldname' => 'Organisatienaam (kort)'
],
'vestiging' => [
'validations' => 'required|alphaNumeric|unique',
'fieldname' => 'vestigingsnummer',
'model' => 'organisations_model',
'field' => 'vestiging'
],
'email' => [
'validations' => 'email',
'fieldname' => 'email'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}
@@ -0,0 +1,28 @@
<?php
/**
* Created by PhpStorm.
* User: imac-3
* Date: 26/06/16
* Time: 21:13
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class PasswordRequestValidation extends BaseValidation {
protected $validationFields = [
'username' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'gebruikersnaam'
],
'email' => [
'validations' => 'required|email',
'fieldname' => 'email'
]
];
public function __construct()
{
parent::__construct();
}
}
@@ -0,0 +1,44 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/07/16
* Time: 13:35
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class UserValidation extends BaseValidation {
protected $validationFields = [
'firstname' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'firstname'
],
'lastname' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'lastname'
],
'email' => [
'validations' => 'required|email|unique',
'fieldname' => 'email',
'model' => 'User_model',
'field' => 'email'
],
'username' => [
'validations' => 'required|alphanumeric|minlength-4|unique',
'fieldname' => 'username',
'model' => 'User_model',
'field' => 'username'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}