Permalink
Browse files

Added open Collective to the readme, thanks @monkeywithacupcake. Adde…

…d default selection to adding admin views to component. Update some helper methods, and comments.
  • Loading branch information...
Llewellynvdm committed Dec 19, 2018
1 parent a52d230 commit 279831da3000cd95ec1bb536f872a0ecc3eb9d62

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -23,7 +23,7 @@
abstract class ###Component###Helper
{###ADMIN_GLOBAL_EVENT_HELPER######CUSTOM_HELPER_SCRIPT######BOTH_CUSTOM_HELPER_SCRIPT###
/**
* Load the Component xml manifest.
* Load the Component xml manifest.
**/
public static function manifest()
{
@@ -32,12 +32,12 @@ public static function manifest()
}

/**
* Joomla version object
* Joomla version object
**/
protected static $JVersion;

/**
* set/get Joomla version
* set/get Joomla version
**/
public static function jVersion()
{
@@ -50,7 +50,7 @@ public static function jVersion()
}

/**
* Load the Contributors details.
* Load the Contributors details.
**/
public static function getContributors()
{
@@ -88,7 +88,7 @@ public static function getContributors()
}###HELP###

/**
* Configure the Linkbar.
* Configure the Linkbar.
**/
public static function addSubmenu($submenu)
{
@@ -494,7 +494,7 @@ protected static function filterActions(&$view, &$action, &$targets)
}

/**
* Get any component's model
* Get any component's model
**/
public static function getModel($name, $path = JPATH_COMPONENT_ADMINISTRATOR, $component = '###Component###', $config = array())
{
@@ -538,9 +538,9 @@ public static function getModel($name, $path = JPATH_COMPONENT_ADMINISTRATOR, $c
}

/**
* 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_###component###');
@@ -572,7 +572,7 @@ public static function setAsset($id,$table)
$asset->name = $name;
$asset->title = $title;
// get the default asset rules
$rules = self::getDefaultAssetRules('com_###component###',$table);
$rules = self::getDefaultAssetRules('com_###component###', $table, $inherit);
if ($rules instanceof JAccessRules)
{
$asset->rules = (string) $rules;
@@ -600,55 +600,62 @@ public static function setAsset($id,$table)
}

/**
* 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)
{
// 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())
{
// asset already set so use saved rules
$assetId = (int) $db->loadResult();
}
}
// get asset rules
$result = JAccess::getAssetRules($assetId);
if ($result instanceof JAccessRules)
{
// asset alread set so use saved rules
$assetId = (int) $db->loadResult();
$result = JAccess::getAssetRules($assetId);
if ($result instanceof JAccessRules)
$_result = (string) $result;
$_result = json_decode($_result);
foreach ($_result as $name => &$rule)
{
$_result = (string) $result;
$_result = json_decode($_result);
foreach ($_result as $name => &$rule)
$v = explode('.', $name);
if ($view !== $v[0])
{
$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();
}
// remove since it is not part of this view
unset($_result->$name);
}
// check if there are any view values remaining
if (count((array)$_result))
elseif ($inherit)
{
$_result = json_encode($_result);
$_result = array($_result);
// Instantiate and return the JAccessRules object for the asset rules.
$rules = new JAccessRules($_result);

return $rules;
// clear the value since we inherit
$rule = array();
}
return $result;
}
// 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 JAccess::getAssetRules(0);
return $result;
}

/**
@@ -817,11 +824,11 @@ public static function renderBoolButton()
}

/**
* 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)
{
@@ -834,11 +841,11 @@ public static function checkJson($string)
}

/**
* 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)
{
@@ -850,11 +857,11 @@ public static function checkObject($object)
}

/**
* 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)
{
@@ -878,11 +885,11 @@ public static function checkArray($array, $removeEmptyString = false)
}

/**
* 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)
{
@@ -894,10 +901,10 @@ public static function checkString($string)
}

/**
* 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()
{
@@ -919,11 +926,11 @@ public static function isConnected()
}

/**
* 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)
{
@@ -949,11 +956,11 @@ public static function sorten($string, $length = 40, $addTip = true)
}

/**
* 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)
{
@@ -990,11 +997,11 @@ public static function shorten($string, $length = 40, $addTip = true)
}

/**
* 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)
{
@@ -1134,11 +1141,11 @@ public static function replaceNumbers($string)
}

/**
* 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)
{
@@ -1225,9 +1232,9 @@ public static function numberToString($x)
}

/**
* Random Key
* Random Key
*
* @returns a string
* @returns a string
**/
public static function randomkey($size)
{
Oops, something went wrong.

0 comments on commit 279831d

Please sign in to comment.