primo commit
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage table
|
||||
* @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 table behavior class. It defines the events which are
|
||||
* called by a Table.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
abstract class F0FTableBehavior extends F0FUtilsObservableEvent
|
||||
{
|
||||
/**
|
||||
* This event runs before binding data to the table
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param array &$data The data to bind
|
||||
*
|
||||
* @return boolean True on success
|
||||
*/
|
||||
public function onBeforeBind(&$table, &$data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after binding data to the table
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param object|array &$src The data to bind
|
||||
*
|
||||
* @return boolean True on success
|
||||
*/
|
||||
public function onAfterBind(&$table, &$src)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after loading a record from the database
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param boolean &$result Did the load succeeded?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterLoad(&$table, &$result)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before storing (saving) data to the database
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param boolean $updateNulls Should nulls be saved as nulls (true) or just skipped over (false)?
|
||||
*
|
||||
* @return boolean True to allow saving
|
||||
*/
|
||||
public function onBeforeStore(&$table, $updateNulls)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after storing (saving) data to the database
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow saving without an error
|
||||
*/
|
||||
public function onAfterStore(&$table)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before moving a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param boolean $updateNulls Should nulls be saved as nulls (true) or just skipped over (false)?
|
||||
*
|
||||
* @return boolean True to allow moving
|
||||
*/
|
||||
public function onBeforeMove(&$table, $updateNulls)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after moving a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow moving without an error
|
||||
*/
|
||||
public function onAfterMove(&$table)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before reordering a table
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param string $where The WHERE clause of the SQL query to run on reordering (record filter)
|
||||
*
|
||||
* @return boolean True to allow reordering
|
||||
*/
|
||||
public function onBeforeReorder(&$table, $where = '')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after reordering a table
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow the reordering to complete without an error
|
||||
*/
|
||||
public function onAfterReorder(&$table)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before deleting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record to delete
|
||||
*
|
||||
* @return boolean True to allow the deletion
|
||||
*/
|
||||
public function onBeforeDelete(&$table, $oid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after deleting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record which was deleted
|
||||
*
|
||||
* @return boolean True to allow the deletion without errors
|
||||
*/
|
||||
public function onAfterDelete(&$table, $oid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before hitting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record to hit
|
||||
* @param boolean $log Should we log the hit?
|
||||
*
|
||||
* @return boolean True to allow the hit
|
||||
*/
|
||||
public function onBeforeHit(&$table, $oid, $log)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after hitting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record which was hit
|
||||
*
|
||||
* @return boolean True to allow the hitting without errors
|
||||
*/
|
||||
public function onAfterHit(&$table, $oid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The even which runs before copying a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record being copied
|
||||
*
|
||||
* @return boolean True to allow the copy to take place
|
||||
*/
|
||||
public function onBeforeCopy(&$table, $oid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The even which runs after copying a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record which was copied (not the new one)
|
||||
*
|
||||
* @return boolean True to allow the copy without errors
|
||||
*/
|
||||
public function onAfterCopy(&$table, $oid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before a record is (un)published
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer|array &$cid The PK IDs of the records being (un)published
|
||||
* @param integer $publish 1 to publish, 0 to unpublish
|
||||
*
|
||||
* @return boolean True to allow the (un)publish to proceed
|
||||
*/
|
||||
public function onBeforePublish(&$table, &$cid, $publish)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after the object is reset to its default values.
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow the reset to complete without errors
|
||||
*/
|
||||
public function onAfterReset(&$table)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The even which runs before the object is reset to its default values.
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow the reset to complete
|
||||
*/
|
||||
public function onBeforeReset(&$table)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage table
|
||||
* @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 table behavior class for assets
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FTableBehaviorAssets extends F0FTableBehavior
|
||||
{
|
||||
/**
|
||||
* The event which runs after storing (saving) data to the database
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow saving
|
||||
*/
|
||||
public function onAfterStore(&$table)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
$asset_id_field = $table->getColumnAlias('asset_id');
|
||||
|
||||
if (in_array($asset_id_field, $table->getKnownFields()))
|
||||
{
|
||||
if (!empty($table->$asset_id_field))
|
||||
{
|
||||
$currentAssetId = $table->$asset_id_field;
|
||||
}
|
||||
|
||||
// The asset id field is managed privately by this class.
|
||||
if ($table->isAssetsTracked())
|
||||
{
|
||||
unset($table->$asset_id_field);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the object used for inserting/udpating data to the database
|
||||
$fields = $table->getTableFields();
|
||||
|
||||
// Let's remove the asset_id field, since we unset the property above and we would get a PHP notice
|
||||
if (isset($fields[$asset_id_field]))
|
||||
{
|
||||
unset($fields[$asset_id_field]);
|
||||
}
|
||||
|
||||
// Asset Tracking
|
||||
if (in_array($asset_id_field, $table->getKnownFields()) && $table->isAssetsTracked())
|
||||
{
|
||||
$parentId = $table->getAssetParentId();
|
||||
|
||||
try{
|
||||
$name = $table->getAssetName();
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$table->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
$title = $table->getAssetTitle();
|
||||
|
||||
$asset = JTable::getInstance('Asset');
|
||||
$asset->loadByName($name);
|
||||
|
||||
// Re-inject the asset id.
|
||||
$this->$asset_id_field = $asset->id;
|
||||
|
||||
// Check for an error.
|
||||
$error = $asset->getError();
|
||||
|
||||
// Since we are using JTable, there is no way to mock it and test for failures :(
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($error)
|
||||
{
|
||||
$table->setError($error);
|
||||
|
||||
return false;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// Specify how a new or moved node asset is inserted into the tree.
|
||||
// Since we're unsetting the table field before, this statement is always true...
|
||||
if (empty($table->$asset_id_field) || $asset->parent_id != $parentId)
|
||||
{
|
||||
$asset->setLocation($parentId, 'last-child');
|
||||
}
|
||||
|
||||
// Prepare the asset to be stored.
|
||||
$asset->parent_id = $parentId;
|
||||
$asset->name = $name;
|
||||
$asset->title = $title;
|
||||
|
||||
if ($table->getRules() instanceof JAccessRules)
|
||||
{
|
||||
$asset->rules = (string) $table->getRules();
|
||||
}
|
||||
|
||||
// Since we are using JTable, there is no way to mock it and test for failures :(
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!$asset->check() || !$asset->store())
|
||||
{
|
||||
$table->setError($asset->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// Create an asset_id or heal one that is corrupted.
|
||||
if (empty($table->$asset_id_field) || (($currentAssetId != $table->$asset_id_field) && !empty($table->$asset_id_field)))
|
||||
{
|
||||
// Update the asset_id field in this table.
|
||||
$table->$asset_id_field = (int) $asset->id;
|
||||
|
||||
$k = $table->getKeyName();
|
||||
|
||||
$db = $table->getDbo();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->qn($table->getTableName()))
|
||||
->set($db->qn($asset_id_field).' = ' . (int) $table->$asset_id_field)
|
||||
->where($db->qn($k) . ' = ' . (int) $table->$k);
|
||||
|
||||
$db->setQuery($query)->execute();
|
||||
}
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after binding data to the table
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param object|array &$src The data to bind
|
||||
*
|
||||
* @return boolean True on success
|
||||
*/
|
||||
public function onAfterBind(&$table, &$src)
|
||||
{
|
||||
// Set rules for assets enabled tables
|
||||
if ($table->isAssetsTracked())
|
||||
{
|
||||
// Bind the rules.
|
||||
if (isset($src['rules']) && is_array($src['rules']))
|
||||
{
|
||||
// We have to manually remove any empty value, since they will be converted to int,
|
||||
// and "Inherited" values will become "Denied". Joomla is doing this manually, too.
|
||||
// @todo Should we move this logic inside the setRules method?
|
||||
$rules = array();
|
||||
|
||||
foreach ($src['rules'] as $action => $ids)
|
||||
{
|
||||
// Build the rules array.
|
||||
$rules[$action] = array();
|
||||
|
||||
foreach ($ids as $id => $p)
|
||||
{
|
||||
if ($p !== '')
|
||||
{
|
||||
$rules[$action][$id] = ($p == '1' || $p == 'true') ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$table->setRules($rules);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before deleting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record to delete
|
||||
*
|
||||
* @return boolean True to allow the deletion
|
||||
*/
|
||||
public function onBeforeDelete(&$table, $oid)
|
||||
{
|
||||
// If tracking assets, remove the asset first.
|
||||
if ($table->isAssetsTracked())
|
||||
{
|
||||
$k = $table->getKeyName();
|
||||
|
||||
// If the table is not loaded, let's try to load it with the id
|
||||
if(!$table->$k)
|
||||
{
|
||||
$table->load($oid);
|
||||
}
|
||||
|
||||
// If I have an invalid assetName I have to stop
|
||||
try
|
||||
{
|
||||
$name = $table->getAssetName();
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$table->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do NOT touch JTable here -- we are loading the core asset table which is a JTable, not a F0FTable
|
||||
$asset = JTable::getInstance('Asset');
|
||||
|
||||
if ($asset->loadByName($name))
|
||||
{
|
||||
// Since we are using JTable, there is no way to mock it and test for failures :(
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!$asset->delete())
|
||||
{
|
||||
$table->setError($asset->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
else
|
||||
{
|
||||
// I'll simply return true even if I couldn't load the asset. In this way I can still
|
||||
// delete a broken record
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage table
|
||||
* @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 table behavior class for content History
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.2.0
|
||||
*/
|
||||
class F0FTableBehaviorContenthistory extends F0FTableBehavior
|
||||
{
|
||||
/**
|
||||
* The event which runs after storing (saving) data to the database
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
*
|
||||
* @return boolean True to allow saving without an error
|
||||
*/
|
||||
public function onAfterStore(&$table)
|
||||
{
|
||||
$aliasParts = explode('.', $table->getContentType());
|
||||
$table->checkContentType();
|
||||
|
||||
if (JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
|
||||
{
|
||||
$historyHelper = new JHelperContenthistory($table->getContentType());
|
||||
$historyHelper->store($table);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before deleting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record to delete
|
||||
*
|
||||
* @return boolean True to allow the deletion
|
||||
*/
|
||||
public function onBeforeDelete(&$table, $oid)
|
||||
{
|
||||
$aliasParts = explode('.', $table->getContentType());
|
||||
|
||||
if (JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
|
||||
{
|
||||
$historyHelper = new JHelperContenthistory($table->getContentType());
|
||||
$historyHelper->deleteHistory($table);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage table
|
||||
* @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 table behavior class for tags
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FTableBehaviorTags extends F0FTableBehavior
|
||||
{
|
||||
/**
|
||||
* The event which runs after binding data to the table
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param object|array &$src The data to bind
|
||||
* @param array $options The options of the table
|
||||
*
|
||||
* @return boolean True on success
|
||||
*/
|
||||
public function onAfterBind(&$table, &$src, $options = array())
|
||||
{
|
||||
// Bind tags
|
||||
if ($table->hasTags())
|
||||
{
|
||||
if ((!empty($src['tags']) && $src['tags'][0] != ''))
|
||||
{
|
||||
$table->newTags = $src['tags'];
|
||||
}
|
||||
|
||||
// Check if the content type exists, and create it if it does not
|
||||
$table->checkContentType();
|
||||
|
||||
$tagsTable = clone($table);
|
||||
|
||||
$tagsHelper = new JHelperTags();
|
||||
$tagsHelper->typeAlias = $table->getContentType();
|
||||
|
||||
// TODO: This little guy here fails because JHelperTags
|
||||
// need a JTable object to work, while our is F0FTable
|
||||
// Need probably to write our own F0FHelperTags
|
||||
// Thank you com_tags
|
||||
if (!$tagsHelper->postStoreProcess($tagsTable))
|
||||
{
|
||||
$table->setError('Error storing tags');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs before storing (saving) data to the database
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param boolean $updateNulls Should nulls be saved as nulls (true) or just skipped over (false)?
|
||||
*
|
||||
* @return boolean True to allow saving
|
||||
*/
|
||||
public function onBeforeStore(&$table, $updateNulls)
|
||||
{
|
||||
if ($table->hasTags())
|
||||
{
|
||||
$tagsHelper = new JHelperTags();
|
||||
$tagsHelper->typeAlias = $table->getContentType();
|
||||
|
||||
// TODO: JHelperTags sucks in Joomla! 3.1, it requires that tags are
|
||||
// stored in the metadata property. Not our case, therefore we need
|
||||
// to add it in a fake object. We sent a PR to Joomla! CMS to fix
|
||||
// that. Once it's accepted, we'll have to remove the attrocity
|
||||
// here...
|
||||
$tagsTable = clone($table);
|
||||
$tagsHelper->preStoreProcess($tagsTable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The event which runs after deleting a record
|
||||
*
|
||||
* @param F0FTable &$table The table which calls this event
|
||||
* @param integer $oid The PK value of the record which was deleted
|
||||
*
|
||||
* @return boolean True to allow the deletion without errors
|
||||
*/
|
||||
public function onAfterDelete(&$table, $oid)
|
||||
{
|
||||
// If this resource has tags, delete the tags first
|
||||
if ($table->hasTags())
|
||||
{
|
||||
$tagsHelper = new JHelperTags();
|
||||
$tagsHelper->typeAlias = $table->getContentType();
|
||||
|
||||
if (!$tagsHelper->deleteTagData($table, $oid))
|
||||
{
|
||||
$table->setError('Error deleting Tags');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage table
|
||||
* @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 table behavior dispatcher class
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.1
|
||||
*/
|
||||
class F0FTableDispatcherBehavior extends F0FUtilsObservableDispatcher
|
||||
{
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user