Am displaying list haviing
Date
News Heading
Short Descrption
The list is spread to around 100 pages, having 20 news in each page
Issue is: This is working absolute fine in php 7.3, 7.4 in joomla 3.10 where on clicking url - list is shown spread over multiple pages having sort by date wise as first criteria, latest date of publishing is coming
But when same used on php 8.0.x - its showing incorrectly, where on clicking URL - last page of list having page number 100 is shown first. Now when i add on limitstart=0 in url then its showing correctly as the first page.
Now when i change from descending to ascending - its bringing the content on last page and its opening, but page number is 100 again
Seems like URL when opened is directly taking to last page of news item as published (although no limitstart is mentioned in it), which is incorrect as ideally should open in descending order and open the page having latest one
Below is code of views/list/tmpl/default.php
if(count($this->items) >0){
//$i=1;
foreach($this->items as $newslist)
{
$date = JFactory::getDate($newslist->n_date);
$list .='<h3><strong>'.$newslist->v_heading.'</strong></h3>
<p>'. $date->format('F j, Y').'</p>
<p>'.substr($newslist->v_short_description,0,100).'</p>
<p><i>Know More on:- </i><b><i>'.$newslist->v_heading.'</i></b></p><hr/><br>';
//$i=$i+1;
}
}else{
JError::raiseError(404, "Message");
}
<?php echo $list?>
and for models/list.php this is the function
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query
->select(
$this->getState(
'list.select', 'DISTINCT a.*'
)
);
$query->from('`#__news` AS a');
if (!JFactory::getUser()->authorise('core.edit', 'com_news'))
{
$query->where('a.state = 1');
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
$search = $db->Quote('%' . $db->escape($search, true) . '%');
$query->where('( a.n_heading LIKE ' . $search . ' )');
}
}
/*
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
if ($orderCol && $orderDirn)
{
$query->order($db->escape($orderCol . ' ' . $orderDirn));
}
*/ //Order by date
$query->order ('a.n_date DESC');
$query->order ('a.id DESC');
return $query;
}
This is the code for views/list/view.html.php
public function display($tpl = null)
{
$app = JFactory::getApplication();
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->params = $app->getParams('com_news');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new Exception(implode("\n", $errors));
}
$this->_prepareDocument();
parent::display($tpl);
}
Unsure how to achieve in and why its not working in php 8.0 where url should open the 1st page and not last page
Related
I use RsForm Pro on Joomla CMS, and there I have created a form. In my form, I have 5 sections with a checkbox. I want to display individual sections up to a certain limit (let's say a max of 20 users), after the submission limit has been reached the form section needs to be disabled.
I found a limit for submit form, but if 20 users submit only one section in the form (not for checkbox), another 4 can't be available for other users. In other words, I don't want to disable all sections unless all sections have reached there limit.
This is code for limit submit form:
// Define the maximum number of submissions. For this example we'll use 25.
$max = 25;
// Get a database connection.
$db = JFactory::getDbo();
// Setup the query. This query counts the number of submissions for the current form.
// $formId contains the ID of the current form.
$db->setQuery("SELECT COUNT(`SubmissionId`) FROM #__rsform_submissions WHERE `FormId`='".(int) $formId."'");
$submissions = $db->loadResult();
if ($submissions >= $max) {
$formLayout = 'Sorry, we have no more spaces on this time. Please wait next registration. Thank you!.';
}
EDIT SOLVED:
$limit25 = 25;
$limit21 = 21;
$limit20 = 20;
$db = JFactory::getDbo();
$db->setQuery("SELECT COUNT(`FieldName`) FROM `nqm2i_rsform_submission_values` WHERE `nqm2i_rsform_submission_values`.`FieldName` = 'Bus_Blockchain_March 11th'");
$first_submission_value = $db->loadResult();
if ($first_submission_value >= $limit25) {
echo '<style>.rsform-block-bus-blockchain-march-11th { display:none;}</style>';
}
$db->setQuery("SELECT COUNT(`FieldName`) FROM `nqm2i_rsform_submission_values` WHERE `nqm2i_rsform_submission_values`.`FieldName` = 'Bus_Blockchain_March 13'");
$secont_submission_value = $db->loadResult();
if ($second_submission_value >= $limit25) {
echo '<style>.rsform-block-bus-blockchain-march-13 { display:none;}</style>';
}
$db->setQuery("SELECT COUNT(`FieldName`) FROM `nqm2i_rsform_submission_values` WHERE `nqm2i_rsform_submission_values`.`FieldName` = 'Bus_Blockchain_March 18'");
$third_submission_value = $db->loadResult();
if ($third_submission_value >= $limit25) {
echo '<style>.rsform-block-bus-blockchain-march-18 { display:none;}</style>';
}
$db->setQuery("SELECT COUNT(`FieldName`) FROM `nqm2i_rsform_submission_values` WHERE `nqm2i_rsform_submission_values`.`FieldName` = 'evening_QA'");
$fourth_submission_value = $db->loadResult();
if ($fourth_submission_value >= $limit20) {
echo '<style>.rsform-block-evening-qa { display:none;}</style>';
}
$db->setQuery("SELECT COUNT(`FieldName`) FROM `nqm2i_rsform_submission_values` WHERE `nqm2i_rsform_submission_values`.`FieldName` = 'evening_QA_2'");
$fifth_submission_value = $db->loadResult();
if ($fifth_submission_value >= $limit21) {
echo '<style>.rsform-block-evening-qa-2 { display:none;}</style>';
}
if(
$first_submission_value >= $limit25
&& $secont_submission_value >= $limit25
&& $third_submission_value >= $limit25
&& $fourth_submission_value >= $limit20
&& $fifth_submission_value >= $limit21
) {
$formLayout = 'Sorry, we have no more spaces on this time. Please wait next registration. Thank you!';
}
I see that you have edited your question to reveal your solution. Rather than to ask you to post your solution as an answer (which you should have done), I'll do you one better -- I've taken the time to refactor your code, implement Joomla's query building methods, make it more efficient, cleaner, more direct, and easier to manage.
Most importantly, because all of the database interactions can be performed with a single query, they should be.
Because your field names seamlessly relate to your classnames, a "lookup array" or "mapping array" will allow my snippet to reliably deliver your desired results dynamically. You will never need to adjust more than $formId and $field_maxes.
Code: (tested locally with my own rsform pro table)
$formId = 3; // or whatever the correct formId value is
$field_maxes = [
'Bus_Blockchain_March 11th' => 25,
'Bus_Blockchain_March 13' => 25,
'Bus_Blockchain_March 18' => 25,
'evening_QA' => 20,
'evening_QA_2' => 21
];
$classes_to_hide = []; // initiate as empty array
$formLayout = ''; // initiate as empty string
$db = JFactory::getDbo();
$quoted_fields = implode(',', $db->q(array_keys($field_maxes))); // create quoted comma-separated values
$query = $db->getQuery(true)
->select("FieldName, COUNT(1) AS " . $db->qn("Count"))
->from("#__rsform_submission_values")
->where([
"FormId = " . (int) $formId,
"FieldName IN ($quoted_fields)"
])
->group("FieldName")
->order("FIELD ($quoted_fields)");
// if you wish to see the rendered query, uncomment the next line (do not show to public)
// JFactory::getApplication()->enqueueMessage("<div>" . $query->dump() . "</div>", "notice");
try // listen for syntax errors
{
$db->setQuery($query);
if (!$results = $db->loadAssocList()) // declare and check for empty result set
{
echo "No Results in Form";
}
else
{
foreach ($results as $row) // iterate rows
{
if ($row['Count'] >= $field_maxes[$row['FieldName']]) { // if fieldname has reached limit
$classes_to_hide[] = ".rsform-" . str_replace(['_', ' '], '-', $row['FieldName']);
}
}
if ($tally = sizeof($classes_to_hide)) // declare and check if not empty
{
echo "<style>" , implode(", ", $classes_to_hide) , " {display:none;}</style>"; // apply css styling to one or more designated classes
if ($tally == sizeof($field_maxes)) // if all fieldnames are full
{
$formLayout = 'Sorry, we have no more spaces on this time. Please wait next registration. Thank you!';
}
}
}
}
catch (Exception $e)
{
JFactory::getApplication()->enqueueMessage("Query Syntax Error", "error");
// if you have a syntax error and wish to see the message, uncomment the next line (do not show to public)
//JFactory::getApplication()->enqueueMessage($e->getMessage(), "error");
}
I have a php Code as below but unable to display title with correct php value
For instance on standalone basis it displays correct data as
$this->CatName; - Displays category
$this->prodDet->prod_name; - Displays Product Name
$this->prodDet->v_location; - Displays Location
I want to create a combined title as
Used <catname> <prod_name> for sale in <v_location>
Like
Used Fisher Milk Bottle for sale in Capetown
But when i modify code in
$title = 'Used' ($this->CatName $this->prodDet->prod_name) 'for Sale in' ($this->prodDet->v_location);
It shows syntax error and does not work
Here is complete code
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
/**
* Prepares the document
*
* #return void
*
* #throws Exception
*/
protected function _prepareDocument()
{
$app = JFactory::getApplication();
$menus = $app->getMenu();
$title = null;
$menu = $menus->getActive();
if ($menu) {
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
} else {
$this->params->def('page_heading', JText::_('COM_USEDCAR_DEFAULT_PAGE_TITLE'));
}
$title = $this->params->get('page_title', '');
if (empty($title)) {
$title = $app->get('sitename');
} elseif ($app->get('sitename_pagetitles', 0) == 1) {
$title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
} elseif ($app->get('sitename_pagetitles', 0) == 2) {
$title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}
$title = $this->CatName;
$this->document->setTitle($title);
}
?>
Can any one help how to display correct title
Use the concatenation operator . , read more here
change
$title = 'Used' ($this->CatName $this->prodDet->prod_name) 'for Sale in' ($this->prodDet->v_location);
to
$title = 'Used' . ($this->CatName .' '.$this->prodDet->prod_name). 'for Sale in' . ($this->prodDet->v_location);
Use concatenation(.) operator there like below:-
$title = 'Used '.($this->CatName.' '.$this->prodDet->prod_name).' for Sale in '.($this->prodDet->v_location);
Note:- Also add spaces in between variables and string so that output look bit good.(I have already did that in my solution)
Reference:-String Operators
I have a community site, where people can put up pages, and the url generates from their name. e.g. My Business, becomes my-business. I want to create a way, that if there is another My Business, it will check and make the url my-business-2, my-business-3, etc.
function check_url($url) {
$qry = mysqli_query($this->con, "SELECT * FROM businesses WHERE url LIKE '$url%'");
if(mysqli_num_rows($qry)>0) {
$slugs = array();
while($row = mysqli_fetch_array($qry)) $slugs[] = $row['url'];
if(in_array($url, $slugs)) {
$max = 1;
while(in_array(($url . '-' . ++$max ), $slugs)) $url .= '-' . $max;
}
}
return $url;
}
This is my function, but this still wont work, as if there is a business called My Bus, it will make it my-bus-2, when it would have been unique at my-bus. I have experimented with other functions too, but this one is the closest I got. Can anyone tell me one that works perfectly?
So form my understanding, you are trying to avoid inserting/generating duplicate URL. Output will be something like this -
www.example.com/my-business
www.example.com/my-business-1
www.example.com/my-business-2
www.example.com/my-business-3
...
Try using this function -
function check_url($base_url, $new_url='', $num=0) {
if($new_url == '') {
$new_url = $base_url;
}
$qry = mysqli_query($this->con, "SELECT * FROM businesses WHERE url = '$new_url'");
if(mysqli_num_rows($qry) > 0) {
while($row = mysqli_fetch_array($qry)) {
$num++;
check_url($base_url, $base_url . '-' . $num, $num);
}
}
return $url;
}
Basically, this function will check the database until it finds a valid URL. Each time it will increment the number and recursively call the same function to generate new/valid URL.
Simple and basic!
#SpritsDracula has working code, but his function will query your database each time it executes. That being said, the recursion is a nice concept. Here is a piece of code that will save your the multiple database calls.
function check_url($url) {
$qry = mysqli_query($this->con, "SELECT * FROM businesses WHERE url LIKE '$url%'");
if(mysqli_num_rows($qry)>0) {
$baseUrl = $url;
$slugs = [];
while($row = mysqli_fetch_array($qry)) $slugs[] = $row['url'];
$max = 1;
while(in_array($url, $slugs)) {
$url = $baseUrl . "-" . $max++;
}
}
return $url;
}
I am trying to list a few games, each, on individual pages. While a game page is opened into a new window the head title of page (< title>) is set to games page header (< h1> My Game). Also to list all game types I am using quick tabs.
From 12 types of games only at 2 of them the title is settled correctly and my problem is that I don't know from where it comes. I have tried to var_dump() all the headers and all of them are returning the same thing "Game" not the title/heading from db.
Where should I look or what would be the next step ?
$metaTitle = $page['content']['metatags']['global']['title']['#attached']['metatag_set_preprocess_variable'][0][2];
$metaTitle = str_replace(' | SuperCasino.com', '', $metaTitle);
Where should I look or what would be the next step ?
Here is my preprocess page code
function desktop_preprocess_page(&$vars, $hook) {
if (isset($vars['node_title'])) {
$vars['title'] = $vars['node_title'];
}
// Adding a class to #page in wireframe mode
if (theme_get_setting('wireframe_mode')) {
$vars['classes_array'][] = 'wireframe-mode';
}
// Adding classes wether #navigation is here or not
if (!empty($vars['main_menu']) or !empty($vars['sub_menu'])) {
$vars['classes_array'][] = 'with-navigation';
}
if (!empty($vars['secondary_menu'])) {
$vars['classes_array'][] = 'with-subnav';
}
// Page template suggestions based off of content types
if (isset($vars['theme_hook_suggestions']['node'])) {
$vars['theme_hook_suggestions'][] = 'page__type__'. $vars['node']->type;
$vars['theme_hook_suggestions'][] = "page__node__" . $vars['node']->nid;
}
// Add first/last classes to node listings about to be rendered.
if (isset($vars['page']['content']['system_main']['nodes'])) {
// All nids about to be loaded (without the #sorted attribute).
$nids = element_children($vars['page']['content']['system_main']['nodes']);
// Only add first/last classes if there is more than 1 node being rendered.
if (count($nids) > 1) {
$first_nid = reset($nids);
$last_nid = end($nids);
$first_node = $vars['page']['content']['system_main']['nodes'][$first_nid]['#node'];
$first_node->classes_array = array('first');
$last_node = $vars['page']['content']['system_main']['nodes'][$last_nid]['#node'];
$last_node->classes_array = array('last');
}
}
//var_dump($vars['theme_hook_suggestions']);die();
// Page template suggestions based off URL alias
if (module_exists('path')) {
//$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
$alias = request_path();
if ($alias != $_GET['q']) {
//echo'here';die;
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '__' . str_replace('-','_',$path_part);
$vars['theme_hook_suggestions'][] = $template_filename;
//var_dump($template_filename);
}
}
}
You can use drupal_set_title(YOUR_TITLE) for the different pages.
drupal_set_title($title = NULL, $output = CHECK_PLAIN)
https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_set_title/7
From the theme level, you can use this code in your template.php:
function MYTHEMENAME_preprocess_page(&$vars, $hook) {
$vars['title'] = $custom_title';
$vars['head_title'] = $custom_title;
}
For Drupal 7 its is :
$vars['site_name']
One of my project use solr1.2 and when i use "sort by score" in search function it's not working.I don't know why?
Can any one explain this.I am totally confuse.
my controller where i do :
protected function globalSearch($searchTerm, $productFilter = array())
{
$solrService = $this->get('syd.solr_service');
$solrQuery = new SolrQuery('*:*');
$solrQuery->addField('id')
->addField('first_product_slug')
->addField('first_product_name')
->addField('name')
->addField('slug')
->addField('thumbnail_path')
->addField('product_slug')
->addField('design_category_id')
->addSortField('score', SolrQuery::ORDER_DESC);
$solrQuery->set("group", "true");
$solrQuery->set("group.field", "first_product_id");
$solrQuery->set("group.limit", 4);
if($searchTerm){
$filterQueries = array();
$searchTerms = explode(' ',$searchTerm);
$searchTerms[] = $searchTerm;
$searchTerm = '("' . implode('" OR "', $searchTerms) . '")';
$filterQuery = sprintf(self::SEARCH_STRING, $searchTerm);
$solrQuery->addFilterQuery($filterQuery);
}
if (!empty($productFilter))
{
$productFiltersArr = array();
$productFilterQry = '';
foreach ($productFilter as $productFilterValue )
{
$productFiltersArr[] = 'first_product_slug:' . $productFilterValue;
}
$productFilterQry = implode(' OR ', $productFiltersArr);
$solrQuery->addFilterQuery($productFilterQry);
}
$solrQuery->setRows(1000);
try {
$solrObject = $solrService->query(
'SydPrintBundle:DesignTemplate',
$solrQuery,
SolrService::WRITER_FORMAT_SOLR_OBJECT
);
$templates = $solrObject->offsetGet('grouped')->offsetGet('first_product_id')->offsetGet('groups');
}
catch (\Exception $e) {
$templates = array();
}
if (!$templates) {
if (!empty($searchTerm)) {
$this->setFlash('catalog-message', 'No results found for your search.');
}
return array();
}
if (!$searchTerm) {
if (!empty($searchTerm)) {
$this->setFlash('catalog-message', 'No results found for your search.');
}
return array();
}
return $templates;
}
When you say when i use "sort by score" in search function it's not working I assume you are telling that the results are not sorted by score.
This is because your main query is *:* and you are adding your search terms via a filter query, which won't influence the score. See https://wiki.apache.org/solr/CommonQueryParameters#fq where it says
This parameter can be used to specify a query that can be used to restrict the super set of documents that can be returned, without influencing score.
So if you make the search term filter query as your main query, then you should see results sorted by score.
Update:
Instead of
$solrQuery = new SolrQuery('*:*');
use
$solrQuery = new SolrQuery();
and instead of
$solrQuery->addFilterQuery($filterQuery);
use
$solrQuery->setQuery($filterQuery);