PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_contact/views/category/view.html.php

https://github.com/joebushi/joomla
PHP | 151 lines | 96 code | 31 blank | 24 comment | 17 complexity | 7ca0dc18606ac557f62e8056a0f31cee MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Site
  5. * @subpackage Contact
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('_JEXEC') or die;
  11. jimport('joomla.application.component.view');
  12. /**
  13. * @package Joomla.Site
  14. * @subpackage Contacts
  15. */
  16. class ContactViewCategory extends JView
  17. {
  18. function display($tpl = null)
  19. {
  20. $app = &JFactory::getApplication();
  21. $user = &JFactory::getUser();
  22. $uri = &JFactory::getURI();
  23. $model = &$this->getModel();
  24. $document = &JFactory::getDocument();
  25. $pparams = &$app->getParams('com_contact');
  26. // Selected Request vars
  27. $categoryId = JRequest::getVar('catid', 0, '', 'int');
  28. $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
  29. $filter_order = JRequest::getVar('filter_order', 'cd.ordering', '', 'cmd');
  30. $filter_order_Dir = JRequest::getVar('filter_order_Dir', 'ASC', '', 'word');
  31. $pparams->def('display_num', $app->getCfg('list_limit'));
  32. $default_limit = $pparams->def('display_num', 20);
  33. $limit = $app->getUserStateFromRequest('com_contact.'.$this->getLayout().'.limit', 'limit', $default_limit, 'int');
  34. // query options
  35. $options['category_id'] = $categoryId;
  36. $options['limit'] = $limit;
  37. $options['limitstart'] = $limitstart;
  38. $options['order by'] = "$filter_order $filter_order_Dir, cd.ordering";
  39. $categories = $model->getCategories($options);
  40. $contacts = $model->getContacts($options);
  41. $total = $model->getContactCount($options);
  42. // Validate the category.
  43. //add alternate feed link
  44. if ($pparams->get('show_feed_link', 1) == 1)
  45. {
  46. $link = '&format=feed&limitstart=';
  47. $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
  48. $document->addHeadLink(JRoute::_($link.'&type=rss'), 'alternate', 'rel', $attribs);
  49. $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
  50. $document->addHeadLink(JRoute::_($link.'&type=atom'), 'alternate', 'rel', $attribs);
  51. }
  52. //prepare contacts
  53. if ($pparams->get('show_email', 0) == 1) {
  54. jimport('joomla.mail.helper');
  55. }
  56. $k = 0;
  57. for($i = 0; $i < count($contacts); $i++)
  58. {
  59. $contact = &$contacts[$i];
  60. $contact->link = JRoute::_('index.php?option=com_contact&view=contact&id='.$contact->slug.'&catid='.$contact->catslug);
  61. if ($pparams->get('show_email', 0) == 1) {
  62. $contact->email_to = trim($contact->email_to);
  63. if (!empty($contact->email_to) && JMailHelper::isEmailAddress($contact->email_to)) {
  64. $contact->email_to = JHtml::_('email.cloak', $contact->email_to);
  65. } else {
  66. $contact->email_to = '';
  67. }
  68. }
  69. $contact->odd = $k;
  70. $contact->count = $i;
  71. $k = 1 - $k;
  72. }
  73. // find current category
  74. // TODO: Move to model
  75. $category = null;
  76. foreach ($categories as $i => $_cat)
  77. {
  78. if ($_cat->id == $categoryId) {
  79. $category = &$categories[$i];
  80. break;
  81. }
  82. }
  83. if ($category == null) {
  84. $db = &JFactory::getDbo();
  85. $category = &JTable::getInstance('category');
  86. }
  87. $menus = &JSite::getMenu();
  88. $menu = $menus->getActive();
  89. // because the application sets a default page title, we need to get it
  90. // right from the menu item itself
  91. if (is_object($menu)) {
  92. $menu_params = new JParameter($menu->params);
  93. if (!$menu_params->get('page_title')) {
  94. $pparams->set('page_title', $category->title);
  95. }
  96. } else {
  97. $pparams->set('page_title', $category->title);
  98. }
  99. $document->setTitle($pparams->get('page_title'));
  100. // Prepare category description
  101. $category->description = JHtml::_('content.prepare', $category->description);
  102. // table ordering
  103. $lists['order_Dir'] = $filter_order_Dir;
  104. $lists['order'] = $filter_order;
  105. $selected = '';
  106. jimport('joomla.html.pagination');
  107. $pagination = new JPagination($total, $limitstart, $limit);
  108. $this->assignRef('items', $contacts);
  109. $this->assignRef('lists', $lists);
  110. $this->assignRef('pagination', $pagination);
  111. //$this->assignRef('data', $data);
  112. $this->assignRef('category', $category);
  113. $this->assignRef('params', $pparams);
  114. $this->assign('action', str_replace('&', '&amp;', $uri->toString()));
  115. parent::display($tpl);
  116. }
  117. function getItems()
  118. {
  119. }
  120. }