Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.35 KB | None | 0 0
  1. <?php
  2.  
  3. defined('JPATH_BASE') or die;
  4. require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/adapter.php';
  5.  
  6. class PlgFinderDescontosPromocoes extends FinderIndexerAdapter
  7. {
  8. protected $context = 'Promocoes';
  9. protected $extension = 'com_descontos';
  10. protected $layout = 'promocoes';
  11. protected $type_title = 'Promocao';
  12. protected $table = '#__descontos_promocoes';
  13. protected $state_field = 'state';
  14. protected $autoloadLanguage = true;
  15.  
  16. /**
  17. * Method to index an item. The item must be a FinderIndexerResult object.
  18. *
  19. * @param FinderIndexerResult $item The item to index as an FinderIndexerResult object.
  20. * @param string $format The item format. Not used.
  21. *
  22. * @return void
  23. *
  24. * @since 2.5
  25. * @throws Exception on database error.
  26. */
  27. protected function index(FinderIndexerResult $item, $format = 'html')
  28. {
  29. // Check if the extension is enabled.
  30. if (JComponentHelper::isEnabled($this->extension) == false)
  31. {
  32. return;
  33. }
  34.  
  35. $item->setLanguage();
  36.  
  37. // Need to import component route helpers dynamically, hence the reason it's handled here.
  38. $path = JPATH_SITE . '/components/' . $item->extension . '/helpers/route.php';
  39.  
  40. if (is_file($path))
  41. {
  42. include_once $path;
  43. }
  44.  
  45. $extension = ucfirst(substr($item->extension, 4));
  46.  
  47. // Initialize the item parameters.
  48. $registry = new JRegistry;
  49. $registry->loadString($item->params);
  50. $item->params = $registry;
  51.  
  52. $registry = new JRegistry;
  53. $registry->loadString($item->metadata);
  54. $item->metadata = $registry;
  55.  
  56. /*
  57. * Add the meta-data processing instructions based on the category's
  58. * configuration parameters.
  59. */
  60. // Add the meta-author.
  61. $item->metaauthor = $item->metadata->get('author');
  62.  
  63. // Handle the link to the meta-data.
  64. $item->addInstruction(FinderIndexer::META_CONTEXT, 'link');
  65. $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey');
  66. $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc');
  67. $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor');
  68. $item->addInstruction(FinderIndexer::META_CONTEXT, 'author');
  69.  
  70. // Deactivated Methods
  71. // $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias');
  72.  
  73. // // Trigger the onContentPrepare event.
  74. // $item->summary = FinderIndexerHelper::prepareContent($item->summary, $item->params);
  75.  
  76. // // Build the necessary route and path information.
  77. // $item->url = $this->getURL($item->id, $item->extension, $this->layout);
  78.  
  79. // $class = $extension . 'HelperRoute';
  80.  
  81. // if (class_exists($class) && method_exists($class, 'getCategoryRoute'))
  82. // {
  83. // $item->route = $class::getCategoryRoute($item->id, $item->language);
  84. // }
  85. // else
  86. // {
  87. // $item->route = ContentHelperRoute::getCategoryRoute($item->slug, $item->catid);
  88. // }
  89.  
  90. // $item->path = FinderIndexerHelper::getContentPath($item->route);
  91.  
  92. // // Get the menu title if it exists.
  93. // $title = $this->getItemMenuTitle($item->url);
  94.  
  95. // // Adjust the title if necessary.
  96. // if (!empty($title) && $this->params->get('use_menu_title', true))
  97. // {
  98. // $item->title = $title;
  99. // }
  100.  
  101. // Translate the state. Categories should only be published if the parent category is published.
  102. // $item->state = $this->translateState($item->state);
  103.  
  104. // Add the type taxonomy data.
  105. $item->addTaxonomy('Type', 'Promocao');
  106.  
  107. // Add the language taxonomy data.
  108. $item->addTaxonomy('Language', $item->language);
  109.  
  110. // Get content extras.
  111. FinderIndexerHelper::getContentExtras($item);
  112.  
  113. // Index the item.
  114. $this->indexer->index($item);
  115.  
  116.  
  117.  
  118.  
  119. /**
  120. * I have previously tested this function with only the code bellow (still doesn't index anything):
  121. */
  122.  
  123. // if (JComponentHelper::isEnabled($this->extension) == false) {
  124. // return;
  125. // }
  126.  
  127. // $item->url = $this->getURL($item->id, 'com_descontos&layout=promocoes', $this->layout);
  128. // $item->route = 'index.php?option=com_descontos&view=promocoes&layout=promocoes&id='.$item->id;
  129. // $item->addTaxonomy('Type', 'Promocao');
  130. // $item->addTaxonomy('Language', $item->language);
  131. // $this->indexer->index($item);
  132. }
  133.  
  134. /**
  135. * Method to setup the indexer to be run.
  136. *
  137. * @return boolean True on success.
  138. *
  139. * @since 2.5
  140. */
  141. protected function setup()
  142. {
  143. // Load com_content route helper as it is the fallback for routing in the indexer in this instance.
  144. include_once JPATH_SITE . '/components/com_content/helpers/route.php';
  145.  
  146. return true;
  147. }
  148.  
  149. /**
  150. * Method to get the SQL query used to retrieve the list of content items.
  151. *
  152. * @param mixed $query A JDatabaseQuery object or null.
  153. *
  154. * @return JDatabaseQuery A database object.
  155. *
  156. * @since 2.5
  157. */
  158. protected function getListQuery($query = null)
  159. {
  160. $db = JFactory::getDbo();
  161.  
  162. // Check if we can use the supplied SQL query.
  163. $query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
  164. ->select('a.id as id, a.nome as title')
  165. // ->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary')
  166. // ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering')
  167. // ->select('a.created_by_alias, a.modified, a.modified_by')
  168. // ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
  169. // ->select('a.state AS state, a.created AS start_date, a.params')
  170. // ->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');
  171.  
  172. // // Handle the alias CASE WHEN portion of the query.
  173. // $case_when_item_alias = ' CASE WHEN ';
  174. // $case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
  175. // $case_when_item_alias .= ' THEN ';
  176. // $a_id = $query->castAsChar('a.id');
  177. // $case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
  178. // $case_when_item_alias .= ' ELSE ';
  179. // $case_when_item_alias .= $a_id . ' END as slug';
  180. // $query->select($case_when_item_alias);
  181.  
  182. // $case_when_category_alias = ' CASE WHEN ';
  183. // $case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
  184. // $case_when_category_alias .= ' THEN ';
  185. // $c_id = $query->castAsChar('c.id');
  186. // $case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':');
  187. // $case_when_category_alias .= ' ELSE ';
  188. // $case_when_category_alias .= $c_id . ' END as catslug';
  189. // $query->select($case_when_category_alias)
  190.  
  191. ->from('#__descontos_promocoes AS a');
  192. // ->join('LEFT', '#__categories AS c ON c.id = a.catid');
  193.  
  194. return $query;
  195. }
  196. }
  197.  
  198. artur@artur-desktop:/var/www/10contos$ php5 cli/finder_indexer.php
  199. Smart Search INDEXER
  200. ============================
  201.  
  202. Starting Indexer
  203. Setting up Finder plugins
  204. Setup 9 items in 0.072 seconds.
  205. * Processed batch 1 in 0.021 seconds.
  206. Total Processing Time: 0.094 seconds.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement