0

コンポーネント用のプラグインを作成しています。このコンポーネントには、列id, name,を含むテーブル "#__radiocatalog_item" があり、列descriptionを参照する必要がありますname。このために、私はこのプラグインを書きました:

<?php

defined('JPATH_BASE') or die;

require_once JPATH_ADMINISTRATOR.'/components/com_finder/helpers/indexer/adapter.php';

class PlgFinderRadioitem extends FinderIndexerAdapter
{
   protected $context = 'Radioitem';
   protected $extension = 'com_radiocatalog';
   protected $layout = 'item';
   protected $type_title = 'item';
   protected $table = '#__radiocatalog_item';
   protected $state_field = 'parent';
   protected $autoloadLanguage = true;

   protected function setup()
        {
           return true;
        }


   public function onFinderDelete($context, $table)
   {
      if ($context == 'com_radiocatalog.item')
      {
         $id = $table->id;
      }
      elseif ($context == 'com_finder.index')
      {
         $id = $table->id;
      }
      else
      {
         return true;
      }

      return $this->remove($id);
   }

   public function onFinderChangeState($context, $pks, $value)
   {
      if ($context == 'com_radiocatalog.item')
      {
         $this->itemStateChange($pks, $value);
      }

      if ($context == 'com_plugins.plugin' && $value === 0)
      {
         $this->pluginDisable($pks);
      }
   }

   protected function index(FinderIndexerResult $item, $format = 'html')
   {
      if (JComponentHelper::isEnabled($this->extension) == false)
      {
         return;
      }

      $item->url = $this->getURL($item->id, 'com_radiocatalog&layout=item', $this->layout);
      $item->route = 'index.php?option=com_radiocatalog&view=item&layout=item&id='.$item->id;
      $item->addTaxonomy('Type', 'Radioitems');
      $item->addTaxonomy('Language', $item->language);
      $this->indexer->index($item);      
   }

   protected function getListQuery($sql = null)
   {
      $db = JFactory::getDbo();
      $sql = $sql instanceof JDatabaseQuery ? $sql : $db->getQuery(true);
      $sql->select('a.id as id, a.name as title, a.description as description');
      $sql->from('#__radiocatalog_item AS a');

      return $sql;
   }

   protected function getStateQuery()
   {
      $sql = $this->db->getQuery(true);
      $sql->select($this->db->quoteName('a.id'));
      $sql->select($this->db->quoteName('a.name').' as title');
      $sql->from($this->db->quoteName('#__radiocatalog_item') . ' AS a');
      return $sql;
   }
}
?>

完全なインデックス作成後、サイトでの検索が機能しません。

4

1 に答える 1