primo commit
This commit is contained in:
213
libraries/f0f/model/behavior.php
Normal file
213
libraries/f0f/model/behavior.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?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. It defines the events which are
|
||||
* called by a Model.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
abstract class F0FModelBehavior extends F0FUtilsObservableEvent
|
||||
{
|
||||
/**
|
||||
* This event runs before saving data in the model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param array &$data The data to save
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeSave(&$model, &$data)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs before deleting a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeDelete(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs before copying a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeCopy(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs before publishing a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforePublish(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs before registering a hit on a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeHit(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs before moving a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeMove(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs before changing the records' order in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeReorder(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs when we are building the query used to fetch a record
|
||||
* list in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The query being built
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeBuildQuery(&$model, &$query)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after saving a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterSave(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after deleting a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterDelete(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after copying a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterCopy(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after publishing a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterPublish(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after registering a hit on a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterHit(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after moving a record in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterMove(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after reordering records in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterReorder(&$model)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after we have built the query used to fetch a record
|
||||
* list in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The query being built
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterBuildQuery(&$model, &$query)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after getting a single item
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FTable &$record The record loaded by this model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterGetItem(&$model, &$record)
|
||||
{
|
||||
}
|
||||
}
|
||||
81
libraries/f0f/model/behavior/access.php
Normal file
81
libraries/f0f/model/behavior/access.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?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 to filter front-end access to items
|
||||
* based on the viewing access levels.
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelBehaviorAccess extends F0FModelBehavior
|
||||
{
|
||||
/**
|
||||
* This event runs after we have built the query used to fetch a record
|
||||
* list in a model. It is used to apply automatic query filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterBuildQuery(&$model, &$query)
|
||||
{
|
||||
// This behavior only applies to the front-end.
|
||||
if (!F0FPlatform::getInstance()->isFrontend())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the name of the access field
|
||||
$table = $model->getTable();
|
||||
$accessField = $table->getColumnAlias('access');
|
||||
|
||||
// Make sure the field actually exists
|
||||
if (!in_array($accessField, $table->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$model->applyAccessFiltering(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The event runs after F0FModel has called F0FTable and retrieved a single
|
||||
* item from the database. It is used to apply automatic filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which was called
|
||||
* @param F0FTable &$record The record loaded from the databae
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterGetItem(&$model, &$record)
|
||||
{
|
||||
if ($record instanceof F0FTable)
|
||||
{
|
||||
$fieldName = $record->getColumnAlias('access');
|
||||
|
||||
// Make sure the field actually exists
|
||||
if (!in_array($fieldName, $record->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the user
|
||||
$user = F0FPlatform::getInstance()->getUser();
|
||||
|
||||
// Filter by authorised access levels
|
||||
if (!in_array($record->$fieldName, $user->getAuthorisedViewLevels()))
|
||||
{
|
||||
$record = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
libraries/f0f/model/behavior/emptynonzero.php
Normal file
32
libraries/f0f/model/behavior/emptynonzero.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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 F0FModelBehaviorEmptynonzero extends F0FModelBehavior
|
||||
{
|
||||
/**
|
||||
* This event runs when we are building the query used to fetch a record
|
||||
* list in a model
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The query being built
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeBuildQuery(&$model, &$query)
|
||||
{
|
||||
$model->setState('_emptynonzero', '1');
|
||||
}
|
||||
}
|
||||
84
libraries/f0f/model/behavior/enabled.php
Normal file
84
libraries/f0f/model/behavior/enabled.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?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 to filter front-end access to items
|
||||
* that are enabled.
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelBehaviorEnabled extends F0FModelBehavior
|
||||
{
|
||||
/**
|
||||
* This event runs after we have built the query used to fetch a record
|
||||
* list in a model. It is used to apply automatic query filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterBuildQuery(&$model, &$query)
|
||||
{
|
||||
// This behavior only applies to the front-end.
|
||||
if (!F0FPlatform::getInstance()->isFrontend())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the name of the enabled field
|
||||
$table = $model->getTable();
|
||||
$enabledField = $table->getColumnAlias('enabled');
|
||||
|
||||
// Make sure the field actually exists
|
||||
if (!in_array($enabledField, $table->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter by enabled fields only
|
||||
$db = F0FPlatform::getInstance()->getDbo();
|
||||
|
||||
// Alias
|
||||
$alias = $model->getTableAlias();
|
||||
$alias = $alias ? $db->qn($alias) . '.' : '';
|
||||
|
||||
$query->where($alias . $db->qn($enabledField) . ' = ' . $db->q(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* The event runs after F0FModel has called F0FTable and retrieved a single
|
||||
* item from the database. It is used to apply automatic filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which was called
|
||||
* @param F0FTable &$record The record loaded from the databae
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterGetItem(&$model, &$record)
|
||||
{
|
||||
if ($record instanceof F0FTable)
|
||||
{
|
||||
$fieldName = $record->getColumnAlias('enabled');
|
||||
|
||||
// Make sure the field actually exists
|
||||
if (!in_array($fieldName, $record->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($record->$fieldName != 1)
|
||||
{
|
||||
$record = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
libraries/f0f/model/behavior/filters.php
Normal file
104
libraries/f0f/model/behavior/filters.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?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 F0FModelBehaviorFilters extends F0FModelBehavior
|
||||
{
|
||||
/**
|
||||
* This event runs after we have built the query used to fetch a record
|
||||
* list in a model. It is used to apply automatic query filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterBuildQuery(&$model, &$query)
|
||||
{
|
||||
$table = $model->getTable();
|
||||
$tableName = $table->getTableName();
|
||||
$tableKey = $table->getKeyName();
|
||||
$db = $model->getDBO();
|
||||
|
||||
$filterzero = $model->getState('_emptynonzero', null);
|
||||
|
||||
$fields = $model->getTableFields();
|
||||
$backlist = $model->blacklistFilters();
|
||||
|
||||
foreach ($fields as $fieldname => $fieldtype)
|
||||
{
|
||||
if (in_array($fieldname, $backlist)) {
|
||||
continue;
|
||||
}
|
||||
$field = new stdClass;
|
||||
$field->name = $fieldname;
|
||||
$field->type = $fieldtype;
|
||||
$field->filterzero = $filterzero;
|
||||
|
||||
$filterName = ($field->name == $tableKey) ? 'id' : $field->name;
|
||||
$filterState = $model->getState($filterName, null);
|
||||
|
||||
$field = F0FModelField::getField($field, array('dbo' => $db, 'table_alias' => $model->getTableAlias()));
|
||||
|
||||
if ((is_array($filterState) && (
|
||||
array_key_exists('value', $filterState) ||
|
||||
array_key_exists('from', $filterState) ||
|
||||
array_key_exists('to', $filterState)
|
||||
)) || is_object($filterState))
|
||||
{
|
||||
$options = new JRegistry($filterState);
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = new JRegistry;
|
||||
$options->set('value', $filterState);
|
||||
}
|
||||
|
||||
$methods = $field->getSearchMethods();
|
||||
$method = $options->get('method', $field->getDefaultSearchMethod());
|
||||
|
||||
if (!in_array($method, $methods))
|
||||
{
|
||||
$method = 'exact';
|
||||
}
|
||||
|
||||
switch ($method)
|
||||
{
|
||||
case 'between':
|
||||
case 'outside':
|
||||
case 'range' :
|
||||
$sql = $field->$method($options->get('from', null), $options->get('to'));
|
||||
break;
|
||||
|
||||
case 'interval':
|
||||
case 'modulo':
|
||||
$sql = $field->$method($options->get('value', null), $options->get('interval'));
|
||||
break;
|
||||
|
||||
case 'exact':
|
||||
case 'partial':
|
||||
case 'search':
|
||||
default:
|
||||
$sql = $field->$method($options->get('value', null));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
$query->where($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
168
libraries/f0f/model/behavior/language.php
Normal file
168
libraries/f0f/model/behavior/language.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?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 to filter front-end access to items
|
||||
* based on the language.
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelBehaviorLanguage extends F0FModelBehavior
|
||||
{
|
||||
/**
|
||||
* This event runs before we have built the query used to fetch a record
|
||||
* list in a model. It is used to blacklist the language filter
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeBuildQuery(&$model, &$query)
|
||||
{
|
||||
if (F0FPlatform::getInstance()->isFrontend())
|
||||
{
|
||||
$model->blacklistFilters('language');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event runs after we have built the query used to fetch a record
|
||||
* list in a model. It is used to apply automatic query filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterBuildQuery(&$model, &$query)
|
||||
{
|
||||
// This behavior only applies to the front-end.
|
||||
if (!F0FPlatform::getInstance()->isFrontend())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the name of the language field
|
||||
$table = $model->getTable();
|
||||
$languageField = $table->getColumnAlias('language');
|
||||
|
||||
// Make sure the access field actually exists
|
||||
if (!in_array($languageField, $table->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure it is a multilingual site and get a list of languages
|
||||
$app = JFactory::getApplication();
|
||||
$hasLanguageFilter = method_exists($app, 'getLanguageFilter');
|
||||
|
||||
if ($hasLanguageFilter)
|
||||
{
|
||||
$hasLanguageFilter = $app->getLanguageFilter();
|
||||
}
|
||||
|
||||
if (!$hasLanguageFilter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$lang_filter_plugin = JPluginHelper::getPlugin('system', 'languagefilter');
|
||||
$lang_filter_params = new JRegistry($lang_filter_plugin->params);
|
||||
|
||||
$languages = array('*');
|
||||
|
||||
if ($lang_filter_params->get('remove_default_prefix'))
|
||||
{
|
||||
// Get default site language
|
||||
$lg = F0FPlatform::getInstance()->getLanguage();
|
||||
$languages[] = $lg->getTag();
|
||||
}
|
||||
else
|
||||
{
|
||||
$languages[] = JFactory::getApplication()->input->getCmd('language', '*');
|
||||
}
|
||||
|
||||
// Filter out double languages
|
||||
$languages = array_unique($languages);
|
||||
|
||||
// And filter the query output by these languages
|
||||
$db = F0FPlatform::getInstance()->getDbo();
|
||||
|
||||
// Alias
|
||||
$alias = $model->getTableAlias();
|
||||
$alias = $alias ? $db->qn($alias) . '.' : '';
|
||||
|
||||
$languages = array_map(array($db, 'quote'), $languages);
|
||||
$query->where($alias . $db->qn($languageField) . ' IN (' . implode(',', $languages) . ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* The event runs after F0FModel has called F0FTable and retrieved a single
|
||||
* item from the database. It is used to apply automatic filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which was called
|
||||
* @param F0FTable &$record The record loaded from the databae
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterGetItem(&$model, &$record)
|
||||
{
|
||||
if ($record instanceof F0FTable)
|
||||
{
|
||||
$fieldName = $record->getColumnAlias('language');
|
||||
|
||||
// Make sure the field actually exists
|
||||
if (!in_array($fieldName, $record->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure it is a multilingual site and get a list of languages
|
||||
$app = JFactory::getApplication();
|
||||
$hasLanguageFilter = method_exists($app, 'getLanguageFilter');
|
||||
|
||||
if ($hasLanguageFilter)
|
||||
{
|
||||
$hasLanguageFilter = $app->getLanguageFilter();
|
||||
}
|
||||
|
||||
if (!$hasLanguageFilter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$lang_filter_plugin = JPluginHelper::getPlugin('system', 'languagefilter');
|
||||
$lang_filter_params = new JRegistry($lang_filter_plugin->params);
|
||||
|
||||
$languages = array('*');
|
||||
|
||||
if ($lang_filter_params->get('remove_default_prefix'))
|
||||
{
|
||||
// Get default site language
|
||||
$lg = F0FPlatform::getInstance()->getLanguage();
|
||||
$languages[] = $lg->getTag();
|
||||
}
|
||||
else
|
||||
{
|
||||
$languages[] = JFactory::getApplication()->input->getCmd('language', '*');
|
||||
}
|
||||
|
||||
// Filter out double languages
|
||||
$languages = array_unique($languages);
|
||||
|
||||
if (!in_array($record->$fieldName, $languages))
|
||||
{
|
||||
$record = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
libraries/f0f/model/behavior/private.php
Normal file
94
libraries/f0f/model/behavior/private.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?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 to filter front-end access to items
|
||||
* craeted by the currently logged in user only.
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelBehaviorPrivate extends F0FModelBehavior
|
||||
{
|
||||
/**
|
||||
* This event runs after we have built the query used to fetch a record
|
||||
* list in a model. It is used to apply automatic query filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which calls this event
|
||||
* @param F0FDatabaseQuery &$query The model which calls this event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterBuildQuery(&$model, &$query)
|
||||
{
|
||||
// This behavior only applies to the front-end.
|
||||
if (!F0FPlatform::getInstance()->isFrontend())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the name of the access field
|
||||
$table = $model->getTable();
|
||||
$createdField = $table->getColumnAlias('created_by');
|
||||
|
||||
// Make sure the access field actually exists
|
||||
if (!in_array($createdField, $table->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the current user's id
|
||||
$user_id = F0FPlatform::getInstance()->getUser()->id;
|
||||
|
||||
// And filter the query output by the user id
|
||||
$db = F0FPlatform::getInstance()->getDbo();
|
||||
|
||||
$alias = $model->getTableAlias();
|
||||
$alias = $alias ? $db->qn($alias) . '.' : '';
|
||||
|
||||
$query->where($alias . $db->qn($createdField) . ' = ' . $db->q($user_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* The event runs after F0FModel has called F0FTable and retrieved a single
|
||||
* item from the database. It is used to apply automatic filters.
|
||||
*
|
||||
* @param F0FModel &$model The model which was called
|
||||
* @param F0FTable &$record The record loaded from the databae
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterGetItem(&$model, &$record)
|
||||
{
|
||||
if ($record instanceof F0FTable)
|
||||
{
|
||||
$keyName = $record->getKeyName();
|
||||
if ($record->$keyName === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$fieldName = $record->getColumnAlias('created_by');
|
||||
|
||||
// Make sure the field actually exists
|
||||
if (!in_array($fieldName, $record->getKnownFields()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = F0FPlatform::getInstance()->getUser()->id;
|
||||
|
||||
if ($record->$fieldName != $user_id)
|
||||
{
|
||||
$record = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
libraries/f0f/model/dispatcher/behavior.php
Normal file
19
libraries/f0f/model/dispatcher/behavior.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?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 dispatcher class
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FModelDispatcherBehavior extends F0FUtilsObservableDispatcher
|
||||
{
|
||||
}
|
||||
353
libraries/f0f/model/field.php
Normal file
353
libraries/f0f/model/field.php
Normal file
@ -0,0 +1,353 @@
|
||||
<?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
|
||||
*/
|
||||
abstract class F0FModelField
|
||||
{
|
||||
protected $_db = null;
|
||||
|
||||
/**
|
||||
* The column name of the table field
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* The column type of the table field
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = '';
|
||||
|
||||
/**
|
||||
* The alias of the table used for filtering
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = false;
|
||||
|
||||
/**
|
||||
* The null value for this type
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $null_value = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param F0FDatabaseDriver $db The database object
|
||||
* @param object $field The field informations as taken from the db
|
||||
* @param string $table_alias The table alias to use when filtering
|
||||
*/
|
||||
public function __construct($db, $field, $table_alias = false)
|
||||
{
|
||||
$this->_db = $db;
|
||||
|
||||
$this->name = $field->name;
|
||||
$this->type = $field->type;
|
||||
$this->filterzero = $field->filterzero;
|
||||
$this->table_alias = $table_alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it a null or otherwise empty value?
|
||||
*
|
||||
* @param mixed $value The value to test for emptiness
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty($value)
|
||||
{
|
||||
return (($value === $this->null_value) || empty($value))
|
||||
&& !($this->filterzero && $value === "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default search method for a field. This always returns 'exact'
|
||||
* and you are supposed to override it in specialised classes. The possible
|
||||
* values are exact, partial, between and outside, unless something
|
||||
* different is returned by getSearchMethods().
|
||||
*
|
||||
* @see self::getSearchMethods()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultSearchMethod()
|
||||
{
|
||||
return 'exact';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the search methods available for this field class,
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchMethods()
|
||||
{
|
||||
$ignore = array('isEmpty', 'getField', 'getFieldType', '__construct', 'getDefaultSearchMethod', 'getSearchMethods');
|
||||
|
||||
$class = new ReflectionClass(__CLASS__);
|
||||
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
$tmp = array();
|
||||
|
||||
foreach ($methods as $method)
|
||||
{
|
||||
$tmp[] = $method->name;
|
||||
}
|
||||
|
||||
$methods = $tmp;
|
||||
|
||||
if ($methods = array_diff($methods, $ignore))
|
||||
{
|
||||
return $methods;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an exact match (equality matching)
|
||||
*
|
||||
* @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 '';
|
||||
}
|
||||
|
||||
if (is_array($value))
|
||||
{
|
||||
$db = F0FPlatform::getInstance()->getDbo();
|
||||
$value = array_map(array($db, 'quote'), $value);
|
||||
|
||||
return '(' . $this->getFieldName() . ' IN (' . implode(',', $value) . '))';
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->search($value, '=');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a partial match (usually: search in string)
|
||||
*
|
||||
* @param mixed $value The value to compare to
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
abstract public function partial($value);
|
||||
|
||||
/**
|
||||
* Perform a between limits match (usually: search for a value between
|
||||
* two numbers or a date between two preset dates). 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
|
||||
*/
|
||||
abstract public function between($from, $to, $include = true);
|
||||
|
||||
/**
|
||||
* Perform an outside limits match (usually: search for a value outside an
|
||||
* area or a date outside a preset period). 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
|
||||
*/
|
||||
abstract public function outside($from, $to, $include = false);
|
||||
|
||||
/**
|
||||
* Perform an interval search (usually: a date interval check)
|
||||
*
|
||||
* @param string $from The value to search
|
||||
* @param string|array|object $interval The interval
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
abstract public function interval($from, $interval);
|
||||
|
||||
/**
|
||||
* Perform a between limits match (usually: search for a value between
|
||||
* two numbers or a date between two preset dates). 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
|
||||
*/
|
||||
abstract public function range($from, $to, $include = true);
|
||||
|
||||
/**
|
||||
* Perform an modulo search
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
abstract public function modulo($from, $interval, $include = true);
|
||||
|
||||
/**
|
||||
* Return the SQL where clause for a search
|
||||
*
|
||||
* @param mixed $value The value to search for
|
||||
* @param string $operator The operator to use
|
||||
*
|
||||
* @return string The SQL where clause for this search
|
||||
*/
|
||||
public function search($value, $operator = '=')
|
||||
{
|
||||
if ($this->isEmpty($value))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return '(' . $this->getFieldName() . ' ' . $operator . ' ' . $this->_db->quote($value) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field name with the given table alias
|
||||
*
|
||||
* @return string The field name
|
||||
*/
|
||||
public function getFieldName()
|
||||
{
|
||||
$name = $this->_db->qn($this->name);
|
||||
|
||||
if ($this->table_alias)
|
||||
{
|
||||
$name = $this->_db->qn($this->table_alias) . '.' . $name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a field Object based on the field column type
|
||||
*
|
||||
* @param object $field The field informations
|
||||
* @param array $config The field configuration (like the db object to use)
|
||||
*
|
||||
* @return F0FModelField The Field object
|
||||
*/
|
||||
public static function getField($field, $config = array())
|
||||
{
|
||||
$type = $field->type;
|
||||
|
||||
$classType = self::getFieldType($type);
|
||||
|
||||
$className = 'F0FModelField' . $classType;
|
||||
|
||||
if (class_exists($className))
|
||||
{
|
||||
if (isset($config['dbo']))
|
||||
{
|
||||
$db = $config['dbo'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$db = F0FPlatform::getInstance()->getDbo();
|
||||
}
|
||||
|
||||
if (isset($config['table_alias']))
|
||||
{
|
||||
$table_alias = $config['table_alias'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$table_alias = false;
|
||||
}
|
||||
|
||||
$field = new $className($db, $field, $table_alias);
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the classname based on the field Type
|
||||
*
|
||||
* @param string $type The type of the field
|
||||
*
|
||||
* @return string the class suffix
|
||||
*/
|
||||
public static function getFieldType($type)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'varchar':
|
||||
case 'text':
|
||||
case 'smalltext':
|
||||
case 'longtext':
|
||||
case 'char':
|
||||
case 'mediumtext':
|
||||
case 'character varying':
|
||||
case 'nvarchar':
|
||||
case 'nchar':
|
||||
$type = 'Text';
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
case 'time':
|
||||
case 'year':
|
||||
case 'timestamp':
|
||||
case 'timestamp without time zone':
|
||||
case 'timestamp with time zone':
|
||||
$type = 'Date';
|
||||
break;
|
||||
|
||||
case 'tinyint':
|
||||
case 'smallint':
|
||||
$type = 'Boolean';
|
||||
break;
|
||||
|
||||
default:
|
||||
$type = 'Number';
|
||||
break;
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
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 '';
|
||||
}
|
||||
}
|
||||
3256
libraries/f0f/model/model.php
Normal file
3256
libraries/f0f/model/model.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user