PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/libraries/joomla/database/table/asset.php

https://github.com/joebushi/joomla
PHP | 121 lines | 55 code | 13 blank | 53 comment | 5 complexity | ef77502cca9c566b822297b6a94e2512 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Framework
  5. * @subpackage Database
  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. defined('JPATH_BASE') or die;
  10. jimport('joomla.database.tablenested');
  11. /**
  12. * Table class supporting modified pre-order tree traversal behavior.
  13. *
  14. * @package Joomla.Framework
  15. * @subpackage Database
  16. * @since 1.6
  17. * @link http://docs.joomla.org/JTableAsset
  18. */
  19. class JTableAsset extends JTableNested
  20. {
  21. /**
  22. * The primary key of the asset.
  23. *
  24. * @var int
  25. */
  26. public $id = null;
  27. /**
  28. * The unique name of the asset.
  29. *
  30. * @var string
  31. */
  32. public $name = null;
  33. /**
  34. * The human readable title of the asset.
  35. *
  36. * @var string
  37. */
  38. public $title = null;
  39. /**
  40. * @var string
  41. */
  42. public $rules = null;
  43. /**
  44. * @param database A database connector object
  45. */
  46. public function __construct(&$db)
  47. {
  48. parent::__construct('#__assets', 'id', $db);
  49. }
  50. /**
  51. * Method to load an asset by it's name.
  52. *
  53. * @param string The name of the asset.
  54. *
  55. * @return int
  56. */
  57. public function loadByName($name)
  58. {
  59. // Get the asset id for the asset.
  60. $this->_db->setQuery(
  61. 'SELECT `id`' .
  62. ' FROM `#__assets`' .
  63. ' WHERE `name` = '.$this->_db->Quote($name)
  64. );
  65. $assetId = (int) $this->_db->loadResult();
  66. // Check for a database error.
  67. if ($error = $this->_db->getErrorMsg())
  68. {
  69. $this->setError($error);
  70. return false;
  71. }
  72. return $this->load($assetId);
  73. }
  74. /**
  75. * Asset that the nested set data is valid.
  76. *
  77. * @return boolean True if the instance is sane and able to be stored in the database.
  78. * @since 1.0
  79. * @link http://docs.joomla.org/JTable/check
  80. */
  81. public function check()
  82. {
  83. $this->parent_id = (int) $this->parent_id;
  84. // JTableNested does not allow parent_id = 0, override this.
  85. if ($this->parent_id > 0)
  86. {
  87. $this->_db->setQuery(
  88. 'SELECT COUNT(id)' .
  89. ' FROM '.$this->_db->nameQuote($this->_tbl).
  90. ' WHERE `id` = '.$this->parent_id
  91. );
  92. if ($this->_db->loadResult()) {
  93. return true;
  94. }
  95. else
  96. {
  97. if ($error = $this->_db->getErrorMsg()) {
  98. $this->setError($error);
  99. }
  100. else {
  101. $this->setError('JError_Invalid_parent_id');
  102. }
  103. return false;
  104. }
  105. }
  106. return true;
  107. }
  108. }