/components/com_weblinks/models/weblink.php

https://bitbucket.org/eternaware/joomus · PHP · 108 lines · 48 code · 13 blank · 47 comment · 7 complexity · 4f905709171cbfaeb52c64a763c16977 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_weblinks
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Weblinks Component Model for a Weblink record
  12. *
  13. * @package Joomla.Site
  14. * @subpackage com_weblinks
  15. * @since 1.5
  16. */
  17. class WeblinksModelWeblink extends JModelItem
  18. {
  19. /**
  20. * Model context string.
  21. *
  22. * @access protected
  23. * @var string
  24. */
  25. protected $_context = 'com_weblinks.weblink';
  26. /**
  27. * Method to auto-populate the model state.
  28. *
  29. * Note. Calling getState in this method will result in recursion.
  30. *
  31. * @since 1.6
  32. */
  33. protected function populateState()
  34. {
  35. $app = JFactory::getApplication();
  36. $params = $app->getParams();
  37. // Load the object state.
  38. $id = $app->input->getInt('id');
  39. $this->setState('weblink.id', $id);
  40. // Load the parameters.
  41. $this->setState('params', $params);
  42. }
  43. /**
  44. * Method to get an object.
  45. *
  46. * @param integer The id of the object to get.
  47. *
  48. * @return mixed Object on success, false on failure.
  49. */
  50. public function &getItem($id = null)
  51. {
  52. if ($this->_item === null)
  53. {
  54. $this->_item = false;
  55. if (empty($id)) {
  56. $id = $this->getState('weblink.id');
  57. }
  58. // Get a level row instance.
  59. $table = JTable::getInstance('Weblink', 'WeblinksTable');
  60. // Attempt to load the row.
  61. if ($table->load($id))
  62. {
  63. // Check published state.
  64. if ($published = $this->getState('filter.published'))
  65. {
  66. if ($table->state != $published) {
  67. return $this->_item;
  68. }
  69. }
  70. // Convert the JTable to a clean JObject.
  71. $properties = $table->getProperties(1);
  72. $this->_item = JArrayHelper::toObject($properties, 'JObject');
  73. }
  74. elseif ($error = $table->getError()) {
  75. $this->setError($error);
  76. }
  77. }
  78. return $this->_item;
  79. }
  80. /**
  81. * Method to increment the hit counter for the weblink
  82. *
  83. * @param int Optional ID of the weblink.
  84. * @return boolean True on success
  85. * @since 1.5
  86. */
  87. public function hit($id = null)
  88. {
  89. if (empty($id)) {
  90. $id = $this->getState('weblink.id');
  91. }
  92. $weblink = $this->getTable('Weblink', 'WeblinksTable');
  93. return $weblink->hit($id);
  94. }
  95. }