PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Menus/Model/Menu.php

https://github.com/kareypowell/croogo
PHP | 102 lines | 56 code | 8 blank | 38 comment | 2 complexity | 8cdefe46d5a9732e9c2000a387881029 MD5 | raw file
  1. <?php
  2. App::uses('MenusAppModel', 'Menus.Model');
  3. /**
  4. * Menu
  5. *
  6. * @category Model
  7. * @package Croogo.Menus.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 Menu extends MenusAppModel {
  14. /**
  15. * Model name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Menu';
  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. 'menus',
  31. ),
  32. ),
  33. 'Croogo.Params',
  34. 'Croogo.Publishable',
  35. 'Croogo.Trackable',
  36. );
  37. /**
  38. * Validation
  39. *
  40. * @var array
  41. * @access public
  42. */
  43. public $validate = array(
  44. 'title' => array(
  45. 'rule' => array('minLength', 1),
  46. 'message' => 'Title cannot be empty.',
  47. ),
  48. 'alias' => array(
  49. 'isUnique' => array(
  50. 'rule' => 'isUnique',
  51. 'message' => 'This alias has already been taken.',
  52. ),
  53. 'minLength' => array(
  54. 'rule' => array('minLength', 1),
  55. 'message' => 'Alias cannot be empty.',
  56. ),
  57. ),
  58. );
  59. /**
  60. * Model associations: hasMany
  61. *
  62. * @var array
  63. * @access public
  64. */
  65. public $hasMany = array(
  66. 'Link' => array(
  67. 'className' => 'Menus.Link',
  68. 'foreignKey' => 'menu_id',
  69. 'dependent' => true,
  70. 'conditions' => '',
  71. 'fields' => '',
  72. 'order' => 'Link.lft ASC',
  73. 'limit' => '',
  74. 'offset' => '',
  75. 'exclusive' => '',
  76. 'finderQuery' => '',
  77. 'counterQuery' => '',
  78. ),
  79. );
  80. /**
  81. * beforeDelete callback
  82. */
  83. public function beforeDelete($cascade = true) {
  84. // Set tree scope for Link association
  85. $settings = array(
  86. 'scope' => array($this->Link->alias . '.menu_id' => $this->id),
  87. );
  88. if ($this->Link->Behaviors->loaded('Tree')) {
  89. $this->Link->Behaviors->Tree->setup($this->Link, $settings);
  90. } else {
  91. $this->Link->Behaviors->load('Tree', $settings);
  92. }
  93. }
  94. }