PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Taxonomy/Model/Type.php

https://github.com/kareypowell/croogo
PHP | 120 lines | 69 code | 9 blank | 42 comment | 2 complexity | 82080f63005393e16d72434045f39bdb MD5 | raw file
  1. <?php
  2. App::uses('AppModel', 'Model');
  3. /**
  4. * Type
  5. *
  6. * @category Taxonomy.Model
  7. * @package Croogo.Taxonomy.Model
  8. * @version 1.0
  9. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  10. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  11. * @link http://www.croogo.org
  12. */
  13. class Type extends TaxonomyAppModel {
  14. /**
  15. * Model name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Type';
  21. /**
  22. * Behaviors used by the Model
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $actsAs = array(
  28. 'Croogo.Cached' => array(
  29. 'groups' => array(
  30. 'taxonomy',
  31. ),
  32. ),
  33. 'Croogo.Params',
  34. 'Croogo.Trackable',
  35. );
  36. /**
  37. * Validation
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. public $validate = array(
  43. 'title' => array(
  44. 'rule' => array('minLength', 1),
  45. 'message' => 'Title cannot be empty.',
  46. ),
  47. 'alias' => array(
  48. 'isUnique' => array(
  49. 'rule' => 'isUnique',
  50. 'message' => 'This alias has already been taken.',
  51. ),
  52. 'minLength' => array(
  53. 'rule' => array('minLength', 1),
  54. 'message' => 'Alias cannot be empty.',
  55. ),
  56. ),
  57. );
  58. /**
  59. * Model associations: hasAndBelongsToMany
  60. *
  61. * @var array
  62. * @access public
  63. */
  64. public $hasAndBelongsToMany = array(
  65. 'Vocabulary' => array(
  66. 'className' => 'Taxonomy.Vocabulary',
  67. 'joinTable' => 'types_vocabularies',
  68. 'foreignKey' => 'type_id',
  69. 'associationForeignKey' => 'vocabulary_id',
  70. 'unique' => true,
  71. 'conditions' => '',
  72. 'fields' => '',
  73. 'order' => 'Vocabulary.weight ASC',
  74. 'limit' => '',
  75. 'offset' => '',
  76. 'finderQuery' => '',
  77. 'deleteQuery' => '',
  78. 'insertQuery' => '',
  79. ),
  80. );
  81. /**
  82. * Display fields for this model
  83. *
  84. * @var array
  85. */
  86. protected $_displayFields = array(
  87. 'id',
  88. 'title',
  89. 'alias',
  90. 'description',
  91. 'plugin',
  92. );
  93. /**
  94. * Get a list of relevant types for given plugin
  95. */
  96. public function pluginTypes($plugin = null) {
  97. if ($plugin === null) {
  98. $conditions = array();
  99. } elseif ($plugin) {
  100. $conditions = array('plugin' => $plugin);
  101. } else {
  102. $conditions = array(
  103. 'OR' => array(
  104. 'plugin LIKE' => '',
  105. 'plugin' => null,
  106. ),
  107. );
  108. }
  109. return $this->find('list', compact('conditions'));
  110. }
  111. }