mirror of
https://github.com/joomla-extensions/weblinks.git
synced 2025-02-05 02:38:24 +00:00
Group by subcategories on mod_weblinks (#38)
* Group by subcategories on mod_weblinks * BUGFIX: added missing 1-column option. * GroupBySubcategories turned Off by default. * Improved readability of inline php statements.
This commit is contained in:
parent
7faa44cdb8
commit
cff91ba244
@ -120,10 +120,21 @@ class WeblinksModelCategory extends JModelList
|
||||
|
||||
// Filter by category.
|
||||
if ($categoryId = $this->getState('category.id'))
|
||||
{
|
||||
// Group by subcategory
|
||||
if($this->getState('category.group', 0))
|
||||
{
|
||||
$query->select('c.title AS category_title')
|
||||
->where('c.parent_id = ' . (int) $categoryId)
|
||||
->join('LEFT', '#__categories AS c ON c.id = a.catid')
|
||||
->where('c.access IN (' . $groups . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where('a.catid = ' . (int) $categoryId)
|
||||
->join('LEFT', '#__categories AS c ON c.id = a.catid')
|
||||
->where('c.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
// Filter by published category
|
||||
$cpublished = $this->getState('filter.c.published');
|
||||
@ -177,6 +188,16 @@ class WeblinksModelCategory extends JModelList
|
||||
$query->where('(a.title LIKE ' . $search . ')');
|
||||
}
|
||||
|
||||
// If grouping by subcategory, add the subcategory list ordering clause.
|
||||
if($this->getState('category.group', 0))
|
||||
{
|
||||
$query->order(
|
||||
$db->escape(
|
||||
$this->getState('category.ordering', 'c.lft')) . ' ' . $db->escape($this->getState('category.direction', 'ASC')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order(
|
||||
$db->escape(
|
||||
|
@ -5,6 +5,16 @@
|
||||
|
||||
MOD_WEBLINKS="Web Links"
|
||||
MOD_WEBLINKS_FIELD_CATEGORY_DESC="Choose the Web Links category to display."
|
||||
MOD_WEBLINKS_FIELD_GROUPBY_DESC="If set to yes, weblinks will be grouped by subcategories."
|
||||
MOD_WEBLINKS_FIELD_GROUPBY_LABEL="Group By Subcategories"
|
||||
MOD_WEBLINKS_FIELD_GROUPBYSHOWTITLE_DESC="If set to yes, will show groups titles (valid only if grouping)."
|
||||
MOD_WEBLINKS_FIELD_GROUPBYSHOWTITLE_LABEL="Show Group Title"
|
||||
MOD_WEBLINKS_FIELD_GROUPBYORDERING_DESC="Ordering for the subcategories (valid only if grouping)."
|
||||
MOD_WEBLINKS_FIELD_GROUPBYORDERING_LABEL="Group Ordering"
|
||||
MOD_WEBLINKS_FIELD_GROUPBYDIRECTION_DESC="Direction for the subcategories (valid only if grouping)."
|
||||
MOD_WEBLINKS_FIELD_GROUPBYDIRECTION_LABEL="Group Ordering Direction"
|
||||
MOD_WEBLINKS_FIELD_COLUMNS_DESC="When grouping by subcategories, split into # columns."
|
||||
MOD_WEBLINKS_FIELD_COLUMNS_LABEL="Columns"
|
||||
MOD_WEBLINKS_FIELD_COUNT_DESC="Number of Web Links to display."
|
||||
MOD_WEBLINKS_FIELD_COUNT_LABEL="Count"
|
||||
MOD_WEBLINKS_FIELD_COUNTCLICKS_DESC="If set to yes, the number of times the link has been clicked will be recorded."
|
||||
|
@ -57,6 +57,9 @@ class ModWeblinksHelper
|
||||
|
||||
$catid = (int) $params->get('catid', 0);
|
||||
$model->setState('category.id', $catid);
|
||||
$model->setState('category.group', $params->get('groupby', 0));
|
||||
$model->setState('category.ordering', $params->get('groupby_ordering', 'c.lft'));
|
||||
$model->setState('category.direction', $params->get('groupby_direction', 'ASC'));
|
||||
|
||||
// Create query object
|
||||
$db = JFactory::getDbo();
|
||||
|
@ -26,6 +26,69 @@
|
||||
required="true"
|
||||
label="JCATEGORY"
|
||||
description="MOD_WEBLINKS_FIELD_CATEGORY_DESC" />
|
||||
<field
|
||||
name="groupby"
|
||||
type="radio"
|
||||
class="btn-group btn-group-yesno"
|
||||
default="0"
|
||||
label="MOD_WEBLINKS_FIELD_GROUPBY_LABEL"
|
||||
description="MOD_WEBLINKS_FIELD_GROUPBY_DESC">
|
||||
<option
|
||||
value="1">JYES</option>
|
||||
<option
|
||||
value="0">JNO</option>
|
||||
</field>
|
||||
<field
|
||||
name="groupby_showtitle"
|
||||
type="radio"
|
||||
class="btn-group btn-group-yesno"
|
||||
default="1"
|
||||
label="MOD_WEBLINKS_FIELD_GROUPBYSHOWTITLE_LABEL"
|
||||
description="MOD_WEBLINKS_FIELD_GROUPBYSHOWTITLE_DESC">
|
||||
<option
|
||||
value="1">JYES</option>
|
||||
<option
|
||||
value="0">JNO</option>
|
||||
</field>
|
||||
<field
|
||||
name="groupby_ordering"
|
||||
type="list"
|
||||
default="c.lft"
|
||||
label="MOD_WEBLINKS_FIELD_GROUPBYORDERING_LABEL"
|
||||
description="MOD_WEBLINKS_FIELD_GROUPBYORDERING_DESC">
|
||||
<option
|
||||
value="c.title">JGLOBAL_TITLE</option>
|
||||
<option
|
||||
value="c.lft">MOD_WEBLINKS_FIELD_VALUE_ORDER</option>
|
||||
</field>
|
||||
<field
|
||||
name="groupby_direction"
|
||||
type="list"
|
||||
default="asc"
|
||||
label="MOD_WEBLINKS_FIELD_GROUPBYDIRECTION_LABEL"
|
||||
description="MOD_WEBLINKS_FIELD_GROUPBYDIRECTION_DESC">
|
||||
<option
|
||||
value="asc">MOD_WEBLINKS_FIELD_VALUE_ASCENDING</option>
|
||||
<option
|
||||
value="desc">MOD_WEBLINKS_FIELD_VALUE_DESCENDING</option>
|
||||
</field>
|
||||
<field
|
||||
name="groupby_columns"
|
||||
type="list"
|
||||
default="3"
|
||||
label="MOD_WEBLINKS_FIELD_COLUMNS_LABEL"
|
||||
description="MOD_WEBLINKS_FIELD_COLUMNS_DESC">
|
||||
<option
|
||||
value="1">1</option>
|
||||
<option
|
||||
value="2">2</option>
|
||||
<option
|
||||
value="3">3</option>
|
||||
<option
|
||||
value="4">4</option>
|
||||
<option
|
||||
value="6">6</option>
|
||||
</field>
|
||||
<field
|
||||
name="count"
|
||||
type="text"
|
||||
|
@ -9,10 +9,36 @@
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
?>
|
||||
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
|
||||
<?php
|
||||
foreach ($list as $item) :
|
||||
if($params->get('groupby', 0)) :
|
||||
|
||||
$cats = array();
|
||||
$cols = $params->get('groupby_columns', 3);
|
||||
|
||||
foreach ($list as $l)
|
||||
$cats[] = array('catid' => $l->catid, 'title' => $l->category_title);
|
||||
|
||||
$cats = array_values(array_map('unserialize', array_unique(array_map('serialize', $cats))));
|
||||
|
||||
foreach ($cats as $k => $cat) :
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ($list as $item)
|
||||
if ($item->catid == $cat['catid'])
|
||||
$items[] = $item;
|
||||
?>
|
||||
<?php if($cols > 1) : ?>
|
||||
<?php if($k % $cols == 0) : ?>
|
||||
<div class="row row-fluid">
|
||||
<?php endif; ?>
|
||||
<div class="span<?php echo (12 / $cols); ?>">
|
||||
<?php endif; ?>
|
||||
<?php if($params->get('groupby_showtitle', 1)) : ?>
|
||||
<h4><?php echo htmlspecialchars($cat['title']); ?></h4>
|
||||
<?php endif; ?>
|
||||
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
|
||||
<?php foreach ($items as $item) : ?>
|
||||
<li>
|
||||
<?php
|
||||
$link = $item->link;
|
||||
@ -49,7 +75,54 @@ defined('_JEXEC') or die;
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php if($cols > 1) : ?>
|
||||
</div>
|
||||
<?php if(($k + 1) % $cols == 0 || $k == count($cats) - 1) : ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<ul class="weblinks<?php echo $moduleclass_sfx; ?>">
|
||||
<?php foreach ($list as $item) : ?>
|
||||
<li>
|
||||
<?php
|
||||
$link = $item->link;
|
||||
|
||||
switch ($params->get('target', 3))
|
||||
{
|
||||
case 1:
|
||||
// Open in a new window
|
||||
echo '<a href="' . $link . '" target="_blank" rel="' . $params->get('follow', 'nofollow') . '">' .
|
||||
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// Open in a popup window
|
||||
echo "<a href=\"#\" onclick=\"window.open('" . $link . "', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\">" .
|
||||
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Open in parent window
|
||||
echo '<a href="' . $link . '" rel="' . $params->get('follow', 'nofollow') . '">' .
|
||||
htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</a>';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($params->get('description', 0))
|
||||
{
|
||||
echo nl2br($item->description);
|
||||
}
|
||||
|
||||
if ($params->get('hits', 0))
|
||||
{
|
||||
echo '(' . $item->hits . ' ' . JText::_('MOD_WEBLINKS_HITS') . ')';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user