Skip to content

Commit

Permalink
Put the query into the model
Browse files Browse the repository at this point in the history
  • Loading branch information
coolcat-creations committed Jun 14, 2018
1 parent 2334e0d commit 573517a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
10 changes: 7 additions & 3 deletions administrator/components/com_content/models/articles.php
Expand Up @@ -188,7 +188,7 @@ protected function getListQuery()
'list.select',
'DISTINCT a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.modified, a.ordering, a.featured, a.language, a.hits' .
', a.publish_up, a.publish_down'
', a.publish_up, a.publish_down, c.parent_id, p.title'
)
);
$query->from('#__content AS a');
Expand All @@ -205,10 +205,14 @@ protected function getListQuery()
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');

// Join over the categories.
$query->select('c.title AS category_title')
// Join over the categories and parent categories.
$query->select('c.title AS category_title, c.parent_id AS parent_category_id')
->join('LEFT', '#__categories AS c ON c.id = a.catid');

// Join over parent category title
$query->select('p.title AS parent_category_title')
->join('LEFT', '#__categories AS p ON p.id = c.parent_id');

// Join over the users for the author.
$query->select('ua.name AS author_name')
->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
Expand Down
Expand Up @@ -138,13 +138,6 @@
$canEditOwn = $user->authorise('core.edit.own', 'com_content.article.' . $item->id) && $item->created_by == $userId;
$canChange = $user->authorise('core.edit.state', 'com_content.article.' . $item->id) && $canCheckin;

$db = JFactory::getDbo();
$catid = $item->catid;
$db->setQuery("SELECT cat.parent_id FROM #__categories cat WHERE cat.id='$catid'");
$parent_catid = $db->loadResult();
$db->setQuery("SELECT cat.title FROM #__categories cat WHERE cat.id='$parent_catid'");
$parent_cattitle = $db->loadResult();

?>
<tr class="row<?php echo $i % 2; ?>" sortable-group-id="<?php echo $item->catid; ?>">
<td class="order nowrap center hidden-phone">
Expand Down Expand Up @@ -200,34 +193,44 @@
<div class="small">
<?php echo JText::_('JCATEGORY') . ':' ?>

<?php if ($parent_cattitle != 'ROOT') : ?>
<?php if ($canEdit || $canEditOwn) : ?>
<?php if ($item->parent_category_title != 'ROOT') : ?>

<?php if ($canEdit || $canEditOwn) : ?>

<a class="hasTooltip"
href="<?php echo JRoute::_('index.php?option=com_categories&task=category.edit&id=' . $item->parent_category_id . '&extension=com_content'); ?>"
title="<?php echo JText::_('JACTION_EDIT') . ' ' . JText::_('JCATEGORY'); ?>">

<?php endif ?>

<?php echo '' . $item->parent_category_title . ''; ?>

<?php if ($canEdit || $canEditOwn) : ?>

</a>

<a class="hasTooltip"
href="<?php echo JRoute::_('index.php?option=com_categories&task=category.edit&id=' . $parent_catid . '&extension=com_content'); ?>"
title="<?php echo JText::_('JACTION_EDIT') . ' ' . JText::_('JCATEGORY'); ?>">
<?php endif ?>
<?php endif; ?>

<?php echo '' . $parent_cattitle . ''; ?>
<?php echo ' » '; ?>

<?php endif; ?>

<?php if ($canEdit || $canEditOwn) : ?>
</a>

<?php echo ' » '; ?>
<a class="hasTooltip"
href="<?php echo JRoute::_('index.php?option=com_categories&task=category.edit&id=' . $item->catid . '&extension=com_content'); ?>"
title="<?php echo JText::_('JACTION_EDIT') . ' ' . JText::_('JCATEGORY'); ?>">

<?php endif; ?>
<?php endif; ?>
<?php endif; ?>

<?php echo $this->escape($item->category_title); ?>

<?php if ($canEdit || $canEditOwn) : ?>

<?php if ($canEdit || $canEditOwn) : ?>
<a class="hasTooltip"
href="<?php echo JRoute::_('index.php?option=com_categories&task=category.edit&id=' . $item->catid . '&extension=com_content'); ?>"
title="<?php echo JText::_('JACTION_EDIT') . ' ' . JText::_('JCATEGORY'); ?>">
<?php endif; ?>
</a>

<?php echo $this->escape($item->category_title); ?>
<?php if ($canEdit || $canEditOwn) : ?>
</a>
<?php endif; ?>
<?php endif; ?>

</div>
</div>
</td>
Expand Down

0 comments on commit 573517a

Please sign in to comment.