-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.0.3.7 problem with reviews params
- Loading branch information
1 parent
f7b796a
commit feb552e
Showing
12 changed files
with
752 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/******* | ||
* @package xbBooks | ||
* @filesource site/controllers/bookreviews.php | ||
* @version 1.0.3.7 25th January 2023 | ||
* @author Roger C-O | ||
* @copyright Copyright (c) Roger Creagh-Osborne, 2021 | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
******/ | ||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\MVC\Controller\FormController; | ||
|
||
class XbbooksControllerBookreviews extends FormController { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
<?php | ||
/******* | ||
* @package xbBooks | ||
* @filesource site/models/bookreviews.php | ||
* @version 1.0.3.7 26th January 2023 | ||
* @author Roger C-O | ||
* @copyright Copyright (c) Roger Creagh-Osborne, 2023 | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
******/ | ||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\Factory; | ||
use Joomla\Utilities\ArrayHelper; | ||
use Joomla\CMS\Helper\TagsHelper; | ||
|
||
class XbbooksModelBookreviews extends JModelList { | ||
|
||
public function __construct($config = array()) { | ||
|
||
if (empty($config['filter_fields'])) { | ||
$config['filter_fields'] = array( | ||
'id', 'a.id', | ||
'title', 'booktitle', | ||
'rev_date', 'rating', | ||
'category_title', 'c.title', | ||
'catid', 'a.catid', 'category_id'); | ||
} | ||
|
||
parent::__construct($config); | ||
} | ||
|
||
protected function populateState($ordering = null, $direction = null) { | ||
$app = Factory::getApplication('site'); | ||
// Load the parameters. | ||
$params = $app->getParams(); | ||
$this->setState('params', $params); | ||
|
||
$categoryId = $app->getUserStateFromRequest('catid', 'catid',''); | ||
$app->setUserState('catid', ''); | ||
$this->setState('categoryId',$categoryId); | ||
$tagId = $app->getUserStateFromRequest('tagid', 'tagid',''); | ||
$app->setUserState('tagid', ''); | ||
$this->setState('tagId',$tagId); | ||
|
||
parent::populateState($ordering, $direction); | ||
|
||
//pagination limit | ||
$limit = $this->getUserStateFromRequest($this->context.'.limit', 'limit', 25 ); | ||
$this->setState('limit', $limit); | ||
$this->setState('list.limit', $limit); | ||
$limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', $app->get('start')); | ||
$this->setState('list.start', $limitstart); | ||
|
||
} | ||
|
||
protected function getListQuery() { | ||
// Initialize variables. | ||
$db = Factory::getDbo(); | ||
$query = $db->getQuery(true); | ||
|
||
// Create the base select statement. | ||
$query->select('a.id AS id, a.title AS title, a.alias AS alias, a.summary AS summary, a.catid AS catid, | ||
a.review AS review, a.rating AS rating, a.state AS published, a.reviewer AS reviewer, | ||
a.created_by AS created_by, a.rev_date AS rev_date, a.note as note, a.ordering AS ordering, | ||
a.params AS params, | ||
a.checked_out AS checked_out, a.checked_out_time AS checked_out_time, a.created AS created') | ||
->from($db->quoteName('#__xbbookreviews','a')); | ||
|
||
$query->select('c.title AS category_title') | ||
->join('LEFT', '#__categories AS c ON c.id = a.catid'); | ||
|
||
// Join with books table to get the book title | ||
$query->select($db->quoteName('b.id','bookid').','.$db->quoteName('b.title', 'booktitle')) | ||
->join('LEFT', $db->quoteName('#__xbbooks', 'b') . ' ON b.id = a.book_id'); | ||
|
||
// Filter by search in title/id/summary/biog | ||
$search = $this->getState('filter.search'); | ||
|
||
if (!empty($search)) { | ||
if (stripos($search, 'i:') === 0) { | ||
$query->where($db->quoteName('a.id') . ' = ' . (int) substr($search, 2)); | ||
} elseif (stripos($search,'s:')===0) { | ||
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim(substr($search,2)), true) . '%')); | ||
$query->where('a.review' . ' LIKE ' . $search.' OR a.summary LIKE '.$search); | ||
} elseif (stripos($search,'b:')===0) { | ||
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim(substr($search,2)), true) . '%')); | ||
$query->where('b.title' . ' LIKE ' . $search); | ||
} elseif (stripos($search,':')!= 1) { | ||
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); | ||
$query->where('(a.title LIKE ' . $search .') OR (a.alias LIKE ' . $search .')'); | ||
} | ||
} | ||
|
||
// Filter by published state | ||
$query->where('a.state = 1 '); | ||
|
||
$searchbar = (int)$this->getState('params')['search_bar']; | ||
//if a menu filter is set this takes priority and serch filter field is hidden | ||
|
||
// Filter by category | ||
$categoryId = $this->getState('categoryId'); | ||
$this->setState('categoryId',''); | ||
if (empty($categoryId)) { | ||
$categoryId = $this->getState('params')['menu_category_id']; | ||
} | ||
if (($searchbar==1) && ($categoryId==0)){ | ||
$categoryId = $this->getState('filter.category_id'); | ||
} | ||
if ((is_numeric($categoryId)) && ($categoryId > 0) ){ | ||
$query->where($db->quoteName('a.catid') . ' = ' . (int) $categoryId); | ||
} elseif (is_array($categoryId)) { | ||
$catlist = implode(',', $categoryId); | ||
$query->where($db->quoteName('a.catid') . ' IN ('.$catlist.')'); | ||
} | ||
|
||
//Filter by rating | ||
$ratfilt = $this->getState('filter.ratfilt'); | ||
if (is_numeric($ratfilt)) { | ||
$query->where('a.rating = '.$ratfilt); | ||
} | ||
|
||
//filter by tags | ||
$tagfilt = $this->getState('tagId'); | ||
// $this->setState('tagId',''); | ||
$taglogic = 0; | ||
if (empty($tagfilt)) { //look for menu options | ||
$tagfilt = $this->getState('params')['menu_tag']; | ||
$taglogic = $this->getState('params')['menu_taglogic']; //1=AND otherwise OR | ||
} | ||
if ((!is_array($tagfilt)) && (!empty($tagfilt))) { | ||
$tagfilt = array($tagfilt); | ||
} | ||
|
||
if (($searchbar==1) && (empty($tagfilt))) { | ||
//look for filter options and ignore menu options | ||
$tagfilt = $this->getState('filter.tagfilt'); | ||
$taglogic = $this->getState('filter.taglogic'); //1=AND otherwise OR | ||
} | ||
|
||
if (empty($tagfilt)) { | ||
$subQuery = '(SELECT content_item_id FROM #__contentitem_tag_map | ||
WHERE type_alias LIKE '.$db->quote('com_xbbooks.review').')'; | ||
if ($taglogic === '1') { | ||
$query->where('a.id NOT IN '.$subQuery); | ||
} elseif ($taglogic === '2') { | ||
$query->where('a.id IN '.$subQuery); | ||
} | ||
} else { | ||
$tagfilt = ArrayHelper::toInteger($tagfilt); | ||
$subquery = '(SELECT tmap.tag_id AS tlist FROM #__contentitem_tag_map AS tmap | ||
WHERE tmap.type_alias = '.$db->quote('com_xbbooks.review').' | ||
AND tmap.content_item_id = a.id)'; | ||
switch ($taglogic) { | ||
case 1: //all | ||
for ($i = 0; $i < count($tagfilt); $i++) { | ||
$query->where($tagfilt[$i].' IN '.$subquery); | ||
} | ||
break; | ||
case 2: //none | ||
for ($i = 0; $i < count($tagfilt); $i++) { | ||
$query->where($tagfilt[$i].' NOT IN '.$subquery); | ||
} | ||
break; | ||
default: //any | ||
if (count($tagfilt)==1) { | ||
$query->where($tagfilt[0].' IN '.$subquery); | ||
} else { | ||
$tagIds = implode(',', $tagfilt); | ||
if ($tagIds) { | ||
$subQueryAny = '(SELECT DISTINCT content_item_id FROM #__contentitem_tag_map | ||
WHERE tag_id IN ('.$tagIds.') AND type_alias = '.$db->quote('com_xbbooks.review').')'; | ||
$query->innerJoin('(' . (string) $subQueryAny . ') AS tagmap ON tagmap.content_item_id = a.id'); | ||
} | ||
} | ||
break; | ||
} | ||
} //end if $tagfilt | ||
|
||
// Add the list ordering clause. | ||
$orderCol = $this->state->get('list.ordering', 'rev_date'); | ||
$orderDirn = $this->state->get('list.direction', 'DESC'); | ||
switch($orderCol) { | ||
case 'a.ordering' : | ||
case 'a.catid' : | ||
//needs a menu option to set orderCol to ordering. Also menu option to alllow user to reorder on table | ||
$query->order('category_title '.$orderDirn.', a.ordering'); | ||
break; | ||
case 'category_title': | ||
$query->order('category_title '.$orderDirn.', title'); | ||
break; | ||
default: | ||
$query->order($db->escape($orderCol.' '.$orderDirn)); | ||
break; | ||
} | ||
|
||
$query->group('a.id'); | ||
|
||
return $query; | ||
} | ||
|
||
public function getItems() { | ||
$items = parent::getItems(); | ||
$tagsHelper = new TagsHelper; | ||
foreach ($items as $i=>$item) { | ||
$item->tags = $tagsHelper->getItemTags('com_xbbooks.review' , $item->id); | ||
} | ||
return $items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- xbBooks site/models/forms/filter_bookreviews.xml v1.0.3.7 24th January 2023 --> | ||
<form> | ||
<fields name="filter" addfieldpath="administrator/components/com_xbpeople/models/fields"> | ||
<field | ||
name="search" | ||
type="text" | ||
label="COM_CONTENT_FILTER_SEARCH_DESC" | ||
description="XBBOOKS_SEARCH_REVIEW" | ||
hint="JSEARCH_FILTER" | ||
class="js-stools-search-string" | ||
/> | ||
<field | ||
name="ratfilt" type="rating" | ||
label="XBFILMS_RATING_LABEL" description="XBFILMS_RATING_DESC" | ||
default="" | ||
onchange="this.form.submit();"> | ||
<option value="">XBCULTURE_FILTER_BY_RATING</option> | ||
</field> | ||
<field | ||
name="category_id" type="xbitemcats" | ||
label="JOPTION_FILTER_CATEGORY" | ||
description="JOPTION_FILTER_CATEGORY_DESC" | ||
extension="com_xbbooks" | ||
itemtable="#__xbbookreviews" | ||
multiple="true" | ||
class="multipleCats" | ||
onchange="this.form.submit();" | ||
> | ||
</field> | ||
<field | ||
name="tagfilt" | ||
type="tag" | ||
label="JOPTION_FILTER_TAG" | ||
description="JOPTION_FILTER_TAG_DESC" | ||
multiple="true" | ||
class="multipleTags" | ||
mode="nested" | ||
onchange="this.form.submit();" | ||
/> | ||
<field name="taglogic" | ||
type="radio" | ||
default="0" | ||
label="XBBOOKS_MULTITAG_LBL" | ||
description="XBBOOKS_MULTITAG_DESC" | ||
class="btn-group btn-small radiotop" | ||
showon="show_all:1" | ||
> | ||
<option value="1" onchange="this.form.submit();">XBCULTURE_ALL</option> | ||
<option value="0" onchange="this.form.submit();">XBCULTURE_ANY</option> | ||
<option value="2" onchange="this.form.submit();">XBCULTURE_EXCLUDE</option> | ||
</field> | ||
</fields> | ||
<fields name="list"> | ||
<field name="fullordering" type="hidden" default="" /> | ||
<field | ||
name="limit" | ||
type="limitbox" | ||
class="input-mini" | ||
default="25" | ||
label="COM_CONTENT_LIST_LIMIT" | ||
description="COM_CONTENT_LIST_LIMIT_DESC" | ||
onchange="this.form.submit();" | ||
/> | ||
</fields> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!DOCTYPE html><title></title> |
Oops, something went wrong.