primo commit
This commit is contained in:
30
libraries/f0f/model/field/boolean.php
Normal file
30
libraries/f0f/model/field/boolean.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage model
|
||||
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
// Protect from unauthorized access
|
||||
defined('F0F_INCLUDED') or die;
|
||||
|
||||
/**
|
||||
* FrameworkOnFramework model behavior class
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelFieldBoolean extends F0FModelFieldNumber
|
||||
{
|
||||
/**
|
||||
* Is it a null or otherwise empty value?
|
||||
*
|
||||
* @param mixed $value The value to test for emptiness
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty($value)
|
||||
{
|
||||
return is_null($value) || ($value === '');
|
||||
}
|
||||
}
|
||||
212
libraries/f0f/model/field/date.php
Normal file
212
libraries/f0f/model/field/date.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage model
|
||||
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
// Protect from unauthorized access
|
||||
defined('F0F_INCLUDED') or die;
|
||||
|
||||
/**
|
||||
* FrameworkOnFramework model behavior class
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelFieldDate extends F0FModelFieldText
|
||||
{
|
||||
/**
|
||||
* Returns the default search method for this field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultSearchMethod()
|
||||
{
|
||||
return 'exact';
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a between limits match. When $include is true
|
||||
* the condition tested is:
|
||||
* $from <= VALUE <= $to
|
||||
* When $include is false the condition tested is:
|
||||
* $from < VALUE < $to
|
||||
*
|
||||
* @param mixed $from The lowest value to compare to
|
||||
* @param mixed $to The higherst value to compare to
|
||||
* @param boolean $include Should we include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function between($from, $to, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($from) || $this->isEmpty($to))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '((' . $this->getFieldName() . ' >' . $extra . ' "' . $from . '") AND ';
|
||||
$sql .= '(' . $this->getFieldName() . ' <' . $extra . ' "' . $to . '"))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an outside limits match. When $include is true
|
||||
* the condition tested is:
|
||||
* (VALUE <= $from) || (VALUE >= $to)
|
||||
* When $include is false the condition tested is:
|
||||
* (VALUE < $from) || (VALUE > $to)
|
||||
*
|
||||
* @param mixed $from The lowest value of the excluded range
|
||||
* @param mixed $to The higherst value of the excluded range
|
||||
* @param boolean $include Should we include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function outside($from, $to, $include = false)
|
||||
{
|
||||
if ($this->isEmpty($from) || $this->isEmpty($to))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '((' . $this->getFieldName() . ' <' . $extra . ' "' . $from . '") OR ';
|
||||
$sql .= '(' . $this->getFieldName() . ' >' . $extra . ' "' . $to . '"))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interval date search
|
||||
*
|
||||
* @param string $value The value to search
|
||||
* @param string|array|object $interval The interval. Can be (+1 MONTH or array('value' => 1, 'unit' => 'MONTH', 'sign' => '+'))
|
||||
* @param boolean $include If the borders should be included
|
||||
*
|
||||
* @return string the sql string
|
||||
*/
|
||||
public function interval($value, $interval, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($value) || $this->isEmpty($interval))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$interval = $this->getInterval($interval);
|
||||
|
||||
if ($interval['sign'] == '+')
|
||||
{
|
||||
$function = 'DATE_ADD';
|
||||
}
|
||||
else
|
||||
{
|
||||
$function = 'DATE_SUB';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '(' . $this->getFieldName() . ' >' . $extra . ' ' . $function;
|
||||
$sql .= '(' . $this->getFieldName() . ', INTERVAL ' . $interval['value'] . ' ' . $interval['unit'] . '))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a between limits match. When $include is true
|
||||
* the condition tested is:
|
||||
* $from <= VALUE <= $to
|
||||
* When $include is false the condition tested is:
|
||||
* $from < VALUE < $to
|
||||
*
|
||||
* @param mixed $from The lowest value to compare to
|
||||
* @param mixed $to The higherst value to compare to
|
||||
* @param boolean $include Should we include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function range($from, $to, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($from) && $this->isEmpty($to))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
if ($from)
|
||||
$sql[] = '(' . $this->getFieldName() . ' >' . $extra . ' "' . $from . '")';
|
||||
if ($to)
|
||||
$sql[] = '(' . $this->getFieldName() . ' <' . $extra . ' "' . $to . '")';
|
||||
|
||||
$sql = '(' . implode(' AND ', $sql) . ')';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an interval –which may be given as a string, array or object– into
|
||||
* a standardised hash array that can then be used bu the interval() method.
|
||||
*
|
||||
* @param string|array|object $interval The interval expression to parse
|
||||
*
|
||||
* @return array The parsed, hash array form of the interval
|
||||
*/
|
||||
protected function getInterval($interval)
|
||||
{
|
||||
if (is_string($interval))
|
||||
{
|
||||
if (strlen($interval) > 2)
|
||||
{
|
||||
$interval = explode(" ", $interval);
|
||||
$sign = ($interval[0] == '-') ? '-' : '+';
|
||||
$value = (int) substr($interval[0], 1);
|
||||
|
||||
$interval = array(
|
||||
'unit' => $interval[1],
|
||||
'value' => $value,
|
||||
'sign' => $sign
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$interval = array(
|
||||
'unit' => 'MONTH',
|
||||
'value' => 1,
|
||||
'sign' => '+'
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$interval = (array) $interval;
|
||||
}
|
||||
|
||||
return $interval;
|
||||
}
|
||||
}
|
||||
198
libraries/f0f/model/field/number.php
Normal file
198
libraries/f0f/model/field/number.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage model
|
||||
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
// Protect from unauthorized access
|
||||
defined('F0F_INCLUDED') or die;
|
||||
|
||||
/**
|
||||
* FrameworkOnFramework model behavior class
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelFieldNumber extends F0FModelField
|
||||
{
|
||||
/**
|
||||
* The partial match is mapped to an exact match
|
||||
*
|
||||
* @param mixed $value The value to compare to
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function partial($value)
|
||||
{
|
||||
return $this->exact($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a between limits match. When $include is true
|
||||
* the condition tested is:
|
||||
* $from <= VALUE <= $to
|
||||
* When $include is false the condition tested is:
|
||||
* $from < VALUE < $to
|
||||
*
|
||||
* @param mixed $from The lowest value to compare to
|
||||
* @param mixed $to The higherst value to compare to
|
||||
* @param boolean $include Should we include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function between($from, $to, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($from) || $this->isEmpty($to))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '((' . $this->getFieldName() . ' >' . $extra . ' ' . $from . ') AND ';
|
||||
$sql .= '(' . $this->getFieldName() . ' <' . $extra . ' ' . $to . '))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an outside limits match. When $include is true
|
||||
* the condition tested is:
|
||||
* (VALUE <= $from) || (VALUE >= $to)
|
||||
* When $include is false the condition tested is:
|
||||
* (VALUE < $from) || (VALUE > $to)
|
||||
*
|
||||
* @param mixed $from The lowest value of the excluded range
|
||||
* @param mixed $to The higherst value of the excluded range
|
||||
* @param boolean $include Should we include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function outside($from, $to, $include = false)
|
||||
{
|
||||
if ($this->isEmpty($from) || $this->isEmpty($to))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '((' . $this->getFieldName() . ' <' . $extra . ' ' . $from . ') OR ';
|
||||
$sql .= '(' . $this->getFieldName() . ' >' . $extra . ' ' . $to . '))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an interval match. It's similar to a 'between' match, but the
|
||||
* from and to values are calculated based on $value and $interval:
|
||||
* $value - $interval < VALUE < $value + $interval
|
||||
*
|
||||
* @param integer|float $value The center value of the search space
|
||||
* @param integer|float $interval The width of the search space
|
||||
* @param boolean $include Should I include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause
|
||||
*/
|
||||
public function interval($value, $interval, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($value))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$from = $value - $interval;
|
||||
$to = $value + $interval;
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '((' . $this->getFieldName() . ' >' . $extra . ' ' . $from . ') AND ';
|
||||
$sql .= '(' . $this->getFieldName() . ' <' . $extra . ' ' . $to . '))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a range limits match. When $include is true
|
||||
* the condition tested is:
|
||||
* $from <= VALUE <= $to
|
||||
* When $include is false the condition tested is:
|
||||
* $from < VALUE < $to
|
||||
*
|
||||
* @param mixed $from The lowest value to compare to
|
||||
* @param mixed $to The higherst value to compare to
|
||||
* @param boolean $include Should we include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function range($from, $to, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($from) && $this->isEmpty($to))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
if ($from)
|
||||
$sql[] = '(' . $this->getFieldName() . ' >' . $extra . ' ' . $from . ')';
|
||||
if ($to)
|
||||
$sql[] = '(' . $this->getFieldName() . ' <' . $extra . ' ' . $to . ')';
|
||||
|
||||
$sql = '(' . implode(' AND ', $sql) . ')';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an interval match. It's similar to a 'between' match, but the
|
||||
* from and to values are calculated based on $value and $interval:
|
||||
* $value - $interval < VALUE < $value + $interval
|
||||
*
|
||||
* @param integer|float $value The starting value of the search space
|
||||
* @param integer|float $interval The interval period of the search space
|
||||
* @param boolean $include Should I include the boundaries in the search?
|
||||
*
|
||||
* @return string The SQL where clause
|
||||
*/
|
||||
public function modulo($value, $interval, $include = true)
|
||||
{
|
||||
if ($this->isEmpty($value) || $this->isEmpty($interval))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
|
||||
if ($include)
|
||||
{
|
||||
$extra = '=';
|
||||
}
|
||||
|
||||
$sql = '(' . $this->getFieldName() . ' >' . $extra . ' ' . $value . ' AND ';
|
||||
$sql .= '(' . $this->getFieldName() . ' - ' . $value . ') % ' . $interval . ' = 0)';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
145
libraries/f0f/model/field/text.php
Normal file
145
libraries/f0f/model/field/text.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage model
|
||||
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
// Protect from unauthorized access
|
||||
defined('F0F_INCLUDED') or die;
|
||||
|
||||
/**
|
||||
* FrameworkOnFramework model behavior class
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelFieldText extends F0FModelField
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param F0FDatabaseDriver $db The database object
|
||||
* @param object $field The field informations as taken from the db
|
||||
*/
|
||||
public function __construct($db, $field, $table_alias = false)
|
||||
{
|
||||
parent::__construct($db, $field, $table_alias);
|
||||
|
||||
$this->null_value = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default search method for this field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultSearchMethod()
|
||||
{
|
||||
return 'partial';
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a partial match (search in string)
|
||||
*
|
||||
* @param mixed $value The value to compare to
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function partial($value)
|
||||
{
|
||||
if ($this->isEmpty($value))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return '(' . $this->getFieldName() . ' LIKE ' . $this->_db->quote('%' . $value . '%') . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an exact match (match string)
|
||||
*
|
||||
* @param mixed $value The value to compare to
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function exact($value)
|
||||
{
|
||||
if ($this->isEmpty($value))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return '(' . $this->getFieldName() . ' LIKE ' . $this->_db->quote($value) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy method; this search makes no sense for text fields
|
||||
*
|
||||
* @param mixed $from Ignored
|
||||
* @param mixed $to Ignored
|
||||
* @param boolean $include Ignored
|
||||
*
|
||||
* @return string Empty string
|
||||
*/
|
||||
public function between($from, $to, $include = true)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy method; this search makes no sense for text fields
|
||||
*
|
||||
* @param mixed $from Ignored
|
||||
* @param mixed $to Ignored
|
||||
* @param boolean $include Ignored
|
||||
*
|
||||
* @return string Empty string
|
||||
*/
|
||||
public function outside($from, $to, $include = false)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy method; this search makes no sense for text fields
|
||||
*
|
||||
* @param mixed $value Ignored
|
||||
* @param mixed $interval Ignored
|
||||
* @param boolean $include Ignored
|
||||
*
|
||||
* @return string Empty string
|
||||
*/
|
||||
public function interval($value, $interval, $include = true)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy method; this search makes no sense for text fields
|
||||
*
|
||||
* @param mixed $from Ignored
|
||||
* @param mixed $to Ignored
|
||||
* @param boolean $include Ignored
|
||||
*
|
||||
* @return string Empty string
|
||||
*/
|
||||
public function range($from, $to, $include = false)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy method; this search makes no sense for text fields
|
||||
*
|
||||
* @param mixed $from Ignored
|
||||
* @param mixed $to Ignored
|
||||
* @param boolean $include Ignored
|
||||
*
|
||||
* @return string Empty string
|
||||
*/
|
||||
public function modulo($from, $to, $include = false)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user