Added open Collective to the readme, thanks @monkeywithacupcake. Added default selection to adding admin views to component. Update some helper methods, and comments.

This commit is contained in:
2018-12-19 06:06:36 +02:00
parent a52d230aeb
commit 279831da30
21 changed files with 581 additions and 533 deletions

View File

@ -4057,7 +4057,7 @@ abstract class ComponentbuilderHelper
}
/**
* Load the Component xml manifest.
* Load the Component xml manifest.
**/
public static function manifest()
{
@ -4066,12 +4066,12 @@ abstract class ComponentbuilderHelper
}
/**
* Joomla version object
* Joomla version object
**/
protected static $JVersion;
/**
* set/get Joomla version
* set/get Joomla version
**/
public static function jVersion()
{
@ -4084,7 +4084,7 @@ abstract class ComponentbuilderHelper
}
/**
* Load the Contributors details.
* Load the Contributors details.
**/
public static function getContributors()
{
@ -4194,7 +4194,7 @@ abstract class ComponentbuilderHelper
}
/**
* Get any component's model
* Get any component's model
**/
public static function getModel($name, $path = JPATH_COMPONENT_SITE, $component = 'Componentbuilder', $config = array())
{
@ -4238,9 +4238,9 @@ abstract class ComponentbuilderHelper
}
/**
* Add to asset Table
* Add to asset Table
*/
public static function setAsset($id,$table)
public static function setAsset($id, $table, $inherit = true)
{
$parent = JTable::getInstance('Asset');
$parent->loadByName('com_componentbuilder');
@ -4257,8 +4257,6 @@ abstract class ComponentbuilderHelper
if ($error)
{
$this->setError($error);
return false;
}
else
@ -4274,7 +4272,7 @@ abstract class ComponentbuilderHelper
$asset->name = $name;
$asset->title = $title;
// get the default asset rules
$rules = self::getDefaultAssetRules('com_componentbuilder',$table);
$rules = self::getDefaultAssetRules('com_componentbuilder', $table, $inherit);
if ($rules instanceof JAccessRules)
{
$asset->rules = (string) $rules;
@ -4302,55 +4300,62 @@ abstract class ComponentbuilderHelper
}
/**
* Gets the default asset Rules for a component/view.
* Gets the default asset Rules for a component/view.
*/
protected static function getDefaultAssetRules($component,$view)
protected static function getDefaultAssetRules($component, $view, $inherit = true)
{
// Need to find the asset id by the name of the component.
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component));
$db->setQuery($query);
$db->execute();
if ($db->loadRowList())
// if new or inherited
$assetId = 0;
// Only get the actual item rules if not inheriting
if (!$inherit)
{
// asset alread set so use saved rules
$assetId = (int) $db->loadResult();
$result = JAccess::getAssetRules($assetId);
if ($result instanceof JAccessRules)
// Need to find the asset id by the name of the component.
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component));
$db->setQuery($query);
$db->execute();
// check that there is a value
if ($db->getNumRows())
{
$_result = (string) $result;
$_result = json_decode($_result);
foreach ($_result as $name => &$rule)
{
$v = explode('.', $name);
if ($view !== $v[0])
{
// remove since it is not part of this view
unset($_result->$name);
}
else
{
// clear the value since we inherit
$rule = array();
}
}
// check if there are any view values remaining
if (count((array)$_result))
{
$_result = json_encode($_result);
$_result = array($_result);
// Instantiate and return the JAccessRules object for the asset rules.
$rules = new JAccessRules($_result);
return $rules;
}
return $result;
// asset already set so use saved rules
$assetId = (int) $db->loadResult();
}
}
return JAccess::getAssetRules(0);
// get asset rules
$result = JAccess::getAssetRules($assetId);
if ($result instanceof JAccessRules)
{
$_result = (string) $result;
$_result = json_decode($_result);
foreach ($_result as $name => &$rule)
{
$v = explode('.', $name);
if ($view !== $v[0])
{
// remove since it is not part of this view
unset($_result->$name);
}
elseif ($inherit)
{
// clear the value since we inherit
$rule = array();
}
}
// check if there are any view values remaining
if (count($_result))
{
$_result = json_encode($_result);
$_result = array($_result);
// Instantiate and return the JAccessRules object for the asset rules.
$rules = new JAccessRules($_result);
// return filtered rules
return $rules;
}
}
return $result;
}
/**
@ -4968,11 +4973,11 @@ abstract class ComponentbuilderHelper
}
/**
* Check if have an json string
* Check if have an json string
*
* @input string The json string to check
* @input string The json string to check
*
* @returns bool true on success
* @returns bool true on success
**/
public static function checkJson($string)
{
@ -4985,11 +4990,11 @@ abstract class ComponentbuilderHelper
}
/**
* Check if have an object with a length
* Check if have an object with a length
*
* @input object The object to check
* @input object The object to check
*
* @returns bool true on success
* @returns bool true on success
**/
public static function checkObject($object)
{
@ -5001,11 +5006,11 @@ abstract class ComponentbuilderHelper
}
/**
* Check if have an array with a length
* Check if have an array with a length
*
* @input array The array to check
* @input array The array to check
*
* @returns bool/int number of items in array on success
* @returns bool/int number of items in array on success
**/
public static function checkArray($array, $removeEmptyString = false)
{
@ -5029,11 +5034,11 @@ abstract class ComponentbuilderHelper
}
/**
* Check if have a string with a length
* Check if have a string with a length
*
* @input string The string to check
* @input string The string to check
*
* @returns bool true on success
* @returns bool true on success
**/
public static function checkString($string)
{
@ -5045,10 +5050,10 @@ abstract class ComponentbuilderHelper
}
/**
* Check if we are connected
* Thanks https://stackoverflow.com/a/4860432/1429677
* Check if we are connected
* Thanks https://stackoverflow.com/a/4860432/1429677
*
* @returns bool true on success
* @returns bool true on success
**/
public static function isConnected()
{
@ -5070,11 +5075,11 @@ abstract class ComponentbuilderHelper
}
/**
* Merge an array of array's
* Merge an array of array's
*
* @input array The arrays you would like to merge
* @input array The arrays you would like to merge
*
* @returns array on success
* @returns array on success
**/
public static function mergeArrays($arrays)
{
@ -5100,11 +5105,11 @@ abstract class ComponentbuilderHelper
}
/**
* Shorten a string
* Shorten a string
*
* @input string The you would like to shorten
* @input string The you would like to shorten
*
* @returns string on success
* @returns string on success
**/
public static function shorten($string, $length = 40, $addTip = true)
{
@ -5141,11 +5146,11 @@ abstract class ComponentbuilderHelper
}
/**
* Making strings safe (various ways)
* Making strings safe (various ways)
*
* @input string The you would like to make safe
* @input string The you would like to make safe
*
* @returns string on success
* @returns string on success
**/
public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
{
@ -5285,11 +5290,11 @@ abstract class ComponentbuilderHelper
}
/**
* Convert an integer into an English word string
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
* Convert an integer into an English word string
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
*
* @input an int
* @returns a string
* @input an int
* @returns a string
**/
public static function numberToString($x)
{
@ -5376,9 +5381,9 @@ abstract class ComponentbuilderHelper
}
/**
* Random Key
* Random Key
*
* @returns a string
* @returns a string
**/
public static function randomkey($size)
{