Custom Joomla 3.4 Finder Plugin Not Displaying in Results

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
Wigman27
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Fri Apr 13, 2012 6:35 am
Location: Lithgow NSW Australia
Contact:

Custom Joomla 3.4 Finder Plugin Not Displaying in Results

Post by Wigman27 » Fri Nov 27, 2015 11:43 pm

I have created a custom finder plugin to reference my custom component content, however, the content indexes as expected but it doesn't show up in the results on the front end.

Have I missed a step?

Code: Select all

class PlgFinderAgshows extends FinderIndexerAdapter
{
	/**
	 * The plugin identifier.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $context = 'Agshows';

	/**
	 * The extension name.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $extension = 'com_agshows';

	/**
	 * The sublayout to use when rendering the results.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $layout = 'show';

	/**
	 * The type of content that the adapter indexes.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $type_title = 'Show';

	/**
	 * The table name.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $table = '#__agshows_shows';


	/**
	 * Load the language file on instantiation.
	 *
	 * @var    boolean
	 * @since  3.1
	 */
	protected $autoloadLanguage = true;
protected function index(FinderIndexerResult $item, $format = 'html')
{
    // Check if the extension is enabled
    if (JComponentHelper::isEnabled($this->extension) == false)
    {
        return;
    }

    $item->setLanguage();

    // Initialize the item parameters.
    $registry = new Registry;
    $registry->loadString($item->params);
    $item->params = $registry;

    // Initialize the item parameters.
    $registry = new Registry;
    $registry->loadString($item->info);
    $item->info = $registry;

    // Trigger the onContentPrepare event.
    $item->description = FinderIndexerHelper::prepareContent($item->description, $item->params);

    // Build the necessary route and path information.
    $item->url = $this->getUrl($item->id, $this->extension, $this->layout);
    $item->route = AgshowsHelperRoute::getShowRoute($item->slug, 0, $item->language);
    $item->path = FinderIndexerHelper::getContentPath($item->route);

    // Get the menu title if it exists.
    $title = $this->getItemMenuTitle($item->url);

    // Adjust the title if necessary.
    if (!empty($title) && $this->params->get('use_menu_title', true))
    {
        $item->title = $title;
    }

    /*
     * Add the meta-data processing instructions based on the contact
     * configuration parameters.
     */
    // Handle the contact position.
    $item->addInstruction(FinderIndexer::META_CONTEXT, 'secretary');

    // Add the type taxonomy data.
    $item->addTaxonomy('Type', 'Show');

    // Add the language taxonomy data.
    $item->addTaxonomy('Language', $item->language);

    // Get content extras.
    FinderIndexerHelper::getContentExtras($item);

    // Index the item.
    $test = $this->indexer->index($item);
}

/**
 * Method to setup the indexer to be run.
 *
 * @return  boolean  True on success.
 *
 * @since   2.5
 */
protected function setup()
{
    // Load dependent classes.
    require_once JPATH_SITE . '/components/com_agshows/helpers/route.php';

    return true;
}

/**
 * Method to get the SQL query used to retrieve the list of content items.
 *
 * @param   mixed  $query  A JDatabaseQuery object or null.
 *
 * @return  JDatabaseQuery  A database object.
 *
 * @since   2.5
 */
protected function getListQuery($query = null)
{
    $db = JFactory::getDbo();

    // Check if we can use the supplied SQL query.
    $query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
        ->select('a.id, a.title, a.alias, a.description, a.details AS info, a.secretary')
        ->select('a.state, a.catid')
        ->select('a.created_by_alias, a.modified, a.modified_by')
        ->select('a.metakey, a.metadesc, a.metadata, a.language')
        ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
        ->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');

    // Handle the alias CASE WHEN portion of the query
    $case_when_item_alias = ' CASE WHEN ';
    $case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
    $case_when_item_alias .= ' THEN ';
    $a_id = $query->castAsChar('a.id');
    $case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
    $case_when_item_alias .= ' ELSE ';
    $case_when_item_alias .= $a_id . ' END as slug';
    $query->select($case_when_item_alias);

    $case_when_category_alias = ' CASE WHEN ';
    $case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
    $case_when_category_alias .= ' THEN ';
    $c_id = $query->castAsChar('c.id');
    $case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':');
    $case_when_category_alias .= ' ELSE ';
    $case_when_category_alias .= $c_id . ' END as catslug';
    $query->select($case_when_category_alias)

        ->select('us.name AS secretary')
        ->from('#__agshows_shows AS a')
        ->join('LEFT', '#__categories AS c ON c.id = a.catid')
        ->join('LEFT', '#__users AS us ON us.id = a.secretary');

    return $query;
}
}
I do have the rest of the standard functions for dealing with saved content and deleted content but they are almost identical to the core components.

I have noticed that the detail hover box doesn't appear on any of my indexed content like it does for articles and contacts. Is this a sign its not indexing properly.

I have debugged as best I can but just can't find whats going on.

Thanks

Lee
Need a website designed? Check out my Australian based web development business www.wigweb.com.au for affordable fixed price packages

itoctopus
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4025
Joined: Mon Nov 25, 2013 4:35 pm
Location: Montreal, Canada
Contact:

Re: Custom Joomla 3.4 Finder Plugin Not Displaying in Result

Post by itoctopus » Sat Nov 28, 2015 2:36 pm

Have you tried printing the query that you have in the getListQuery function and then testing it in phpMyAdmin? Does it return any results? If it does, then try debugging the issue at the layout level.
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter

User avatar
Wigman27
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Fri Apr 13, 2012 6:35 am
Location: Lithgow NSW Australia
Contact:

Re: Custom Joomla 3.4 Finder Plugin Not Displaying in Result

Post by Wigman27 » Sun Nov 29, 2015 8:27 am

Thanks Joomla! Hero,

Yes, it was indexing "properly", however, I accidentally omitted the access column from the database query.. Dir!! So it was saving with an access level of 0 and therefor not returning any results.

New getListQuery function

Code: Select all

protected function getListQuery($query = null)
{
$db = JFactory::getDbo();

// Check if we can use the supplied SQL query.
$query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
    ->select('a.id, a.title, a.alias, a.description, a.details AS info, a.secretary')
    ->select('a.state, a.catid')
    ->select('a.created_by_alias, a.modified, a.modified_by')
    ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access')
    ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
    ->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');

// Handle the alias CASE WHEN portion of the query
$case_when_item_alias = ' CASE WHEN ';
$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
$case_when_item_alias .= ' THEN ';
$a_id = $query->castAsChar('a.id');
$case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
$case_when_item_alias .= ' ELSE ';
$case_when_item_alias .= $a_id . ' END as slug';
$query->select($case_when_item_alias);

$case_when_category_alias = ' CASE WHEN ';
$case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
$case_when_category_alias .= ' THEN ';
$c_id = $query->castAsChar('c.id');
$case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':');
$case_when_category_alias .= ' ELSE ';
$case_when_category_alias .= $c_id . ' END as catslug';
$query->select($case_when_category_alias)

    ->select('us.name AS secretary')
    ->from('#__agshows_shows AS a')
    ->join('LEFT', '#__categories AS c ON c.id = a.catid')
    ->join('LEFT', '#__users AS us ON us.id = a.secretary');

return $query;
All fixed now!
Need a website designed? Check out my Australian based web development business www.wigweb.com.au for affordable fixed price packages


Locked

Return to “Joomla! 3.x Coding”