本文整理汇总了PHP中JTable::getTree方法的典型用法代码示例。如果您正苦于以下问题:PHP JTable::getTree方法的具体用法?PHP JTable::getTree怎么用?PHP JTable::getTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JTable
的用法示例。
在下文中一共展示了JTable::getTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBeforeDelete
/**
* onBeforeDelete method. Hook for chidlren model.
*
* @param JTable $table The table object.
*
* @return boolean
*/
protected function onBeforeDelete($table)
{
$user = JFactory::getUser();
if (!$user->authorise('k2.category.delete', 'com_k2.category.' . $table->id)) {
$this->setError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'));
return false;
}
// Check that the category is trashed
if ($table->state != -1) {
$this->setError(JText::sprintf('K2_CATEGORY_IS_NOT_TRASHED', $table->title));
return false;
}
// Check for categories that are not trashed in the tree
$tree = $table->getTree($table->id);
foreach ($tree as $category) {
if ($category->state != -1) {
$this->setError(JText::sprintf('K2_COULD_NOT_DELETE_CATEGORY_BECAUSE_IT_CONTAINS_NON_TRASHED_CATEGORIES', $table->title));
return false;
}
}
// Ensure the category and it's children do not contain any items
$model = K2Model::getInstance('Items');
$model->setState('category', $table->id);
$count = $model->countRows();
if ($count) {
$this->setError(JText::sprintf('K2_COULD_NOT_DELETE_CATEGORY_BECAUSE_IT_CONTAINS_ITEMS', $table->title));
return false;
}
return true;
}