本文整理汇总了PHP中JAccessRules::__toString方法的典型用法代码示例。如果您正苦于以下问题:PHP JAccessRules::__toString方法的具体用法?PHP JAccessRules::__toString怎么用?PHP JAccessRules::__toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JAccessRules
的用法示例。
在下文中一共展示了JAccessRules::__toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialPermission
function initialPermission()
{
$component_name = JRequest::getCmd('option');
$db = JFactory::getDBO();
$asset = JTable::getInstance('asset');
// Create an asset object
/*** Component assets ***/
if (!$asset->loadByName($component_name)) {
// The assets entry does not exist: We will create initial rules for all component's actions
// Get root asset
$root = JTable::getInstance('asset');
$root->loadByName('root.1');
// Initialize component asset
$asset->name = $component_name;
$asset->title = $component_name;
$asset->setLocation($root->id, 'last-child');
// father of compontent asset it the root asset
// Create initial component rules and set them into the asset
$initial_rules = $this->_createComponentRules($component_name);
$component_rules = new JAccessRules(json_encode($initial_rules));
$asset->rules = $component_rules->__toString();
// Save the asset into the DB
if (!$asset->check() || !$asset->store()) {
echo $asset->getError();
$this->setError($asset->getError());
return false;
}
} else {
// The assets entry already exists: We will check if it has exactly the actions specified in component's access.xml file
// Get existing DB rules and component's actions from the access.xml file
$existing_rules = new JAccessRules($asset->rules);
$rules_data = $existing_rules->getData();
$component_actions = JAccess::getActions('com_flexicontent', 'component');
// Find any deleted / added actions ...
$db_action_names = array();
foreach ($rules_data as $action_name => $data) {
$db_action_names[] = $action_name;
}
foreach ($component_actions as $action) {
$file_action_names[] = $action->name;
}
$deleted_actions = array_diff($db_action_names, $file_action_names);
$added_actions = array_diff($file_action_names, $db_action_names);
if (count($deleted_actions) || count($added_actions)) {
// We have changes in the component actions
// First merge the existing component (db) rules into the initial rules
$initial_rules = $this->_createComponentRules($component_name);
$component_rules = new JAccessRules(json_encode($initial_rules));
$component_rules->merge($existing_rules);
// Second, check if obsolete rules are contained in the existing component (db) rules, if so create a new rules object without the obsolete rules
if ($deleted_actions) {
$rules_data = $component_rules->getData();
foreach ($deleted_actions as $action_name) {
unset($rules_data[$action_name]);
}
$component_rules = new JAccessRules($rules_data);
}
// Set asset rules
$asset->rules = $component_rules->__toString();
// Save the asset
if (!$asset->check() || !$asset->store()) {
echo $asset->getError();
$this->setError($asset->getError());
return false;
}
}
}
// Load component asset
$component_asset = JTable::getInstance('asset');
$component_asset->loadByName($component_name);
/*** CATEGORY assets ***/
// Get a list com_content categories that do not have assets (or have wrong asset names)
$query = $db->getQuery(true)->select('c.id, c.parent_id, c.title, c.asset_id')->from('#__assets AS se')->join('RIGHT', '#__categories AS c ON se.id=c.asset_id AND se.name=concat("com_content.category.",c.id)')->where('(se.id is NULL OR (c.parent_id=1 AND se.parent_id!=' . (int) $asset->id . ') )')->where('c.extension = ' . $db->quote('com_content'))->order('c.level ASC');
// IMPORTANT create categories asset using increasing depth level, so that get parent assetid will not fail
$db->setQuery($query);
$results = $db->loadObjectList();
if ($db->getErrorNum()) {
echo $db->getErrorMsg();
}
// Add an asset to every category that doesnot have one
if (count($results) > 0) {
foreach ($results as $category) {
$parentId = $this->_getAssetParentId(null, $category);
$name = "com_content.category.{$category->id}";
// Try to load asset for the current CATEGORY ID
$asset_found = $asset->loadByName($name);
if (!$asset_found) {
if ($category->asset_id) {
// asset name not found but category has an asset id set ?, we could delete it here
// but it maybe dangerous to do so ... it might be a legitimate asset_id for something else
}
// Set id to null since we will be creating a new asset on store
$asset->id = null;
// Set asset rules to empty, (DO NOT set any ACTIONS, just let them inherit ... from parent)
$asset->rules = new JAccessRules();
/*if ($parentId == $component_asset->id) {
$actions = JAccess::getActions($component_name, 'category');
$rules = json_decode($component_asset->rules);
foreach ($actions as $action) {
$catrules[$action->name] = $rules->{$action->name};
//.........这里部分代码省略.........