PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/cms/table/contenttype.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 95 lines | 36 code | 10 blank | 49 comment | 8 complexity | d80c30864d0a0229cad6603cf2e1de8b MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Libraries
  4. * @subpackage Table
  5. *
  6. * @copyright Copyright (C) 2005 - 2013 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. * Tags table
  12. *
  13. * @package Joomla.Libraries
  14. * @subpackage Table
  15. * @since 3.1
  16. */
  17. class JTableContenttype extends JTable
  18. {
  19. /**
  20. * Constructor
  21. *
  22. * @param JDatabaseDriver $db A database connector object
  23. *
  24. * @since 3.1
  25. */
  26. public function __construct($db)
  27. {
  28. parent::__construct('#__content_types', 'type_id', $db);
  29. }
  30. /**
  31. * Overloaded check method to ensure data integrity.
  32. *
  33. * @return boolean True on success.
  34. *
  35. * @since 3.1
  36. * @throws UnexpectedValueException
  37. */
  38. public function check()
  39. {
  40. // Check for valid name.
  41. if (trim($this->type_title) == '')
  42. {
  43. throw new UnexpectedValueException(sprintf('The title is empty'));
  44. }
  45. $this->type_title = ucfirst($this->type_title);
  46. if (empty($this->type_alias))
  47. {
  48. throw new UnexpectedValueException(sprintf('The type_alias is empty'));
  49. }
  50. return true;
  51. }
  52. /**
  53. * Overridden JTable::store.
  54. *
  55. * @param boolean $updateNulls True to update fields even if they are null.
  56. *
  57. * @return boolean True on success.
  58. *
  59. * @since 3.1
  60. */
  61. public function store($updateNulls = false)
  62. {
  63. // Verify that the alias is unique
  64. $table = JTable::getInstance('Contenttype', 'JTable');
  65. if ($table->load(array('type_alias' => $this->type_alias)) && ($table->type_id != $this->type_id || $this->type_id == 0))
  66. {
  67. $this->setError(JText::_('COM_TAGS_ERROR_UNIQUE_ALIAS'));
  68. return false;
  69. }
  70. return parent::store($updateNulls);
  71. }
  72. /**
  73. * Method to expand the field mapping
  74. *
  75. * @param boolean $assoc True to return an associative array.
  76. *
  77. * @return mixed Array or object with field mappings. Defaults to object.
  78. *
  79. * @since 3.1
  80. */
  81. public function fieldmapExpand($assoc = true)
  82. {
  83. return $this->fieldmap = json_decode($this->fieldmappings, $assoc);
  84. }
  85. }