PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Nodes/Event/NodesEventHandler.php

https://github.com/kareypowell/croogo
PHP | 121 lines | 91 code | 8 blank | 22 comment | 6 complexity | 7593b8a69f37df6a83fe96bb0cc00d95 MD5 | raw file
  1. <?php
  2. App::uses('CakeEventListener', 'Event');
  3. /**
  4. * Nodes Event Handler
  5. *
  6. * @category Event
  7. * @package Croogo.Nodes.Event
  8. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  9. * @link http://www.croogo.org
  10. */
  11. class NodesEventHandler implements CakeEventListener {
  12. /**
  13. * implementedEvents
  14. */
  15. public function implementedEvents() {
  16. return array(
  17. 'Croogo.bootstrapComplete' => array(
  18. 'callable' => 'onBootstrapComplete',
  19. ),
  20. 'Croogo.setupAdminData' => array(
  21. 'callable' => 'onSetupAdminData',
  22. ),
  23. 'Controller.Links.setupLinkChooser' => array(
  24. 'callable' => 'onSetupLinkChooser',
  25. ),
  26. );
  27. }
  28. /**
  29. * Setup admin data
  30. */
  31. public function onSetupAdminData($event) {
  32. $View = $event->subject;
  33. if (empty($View->viewVars['types_for_admin_layout'])) {
  34. $types = array();
  35. } else {
  36. $types = $View->viewVars['types_for_admin_layout'];
  37. }
  38. foreach ($types as $t) {
  39. if (!empty($t['Type']['plugin'])) {
  40. continue;
  41. }
  42. CroogoNav::add('sidebar', 'content.children.create.children.' . $t['Type']['alias'], array(
  43. 'title' => $t['Type']['title'],
  44. 'url' => array(
  45. 'plugin' => 'nodes',
  46. 'admin' => true,
  47. 'controller' => 'nodes',
  48. 'action' => 'add',
  49. $t['Type']['alias'],
  50. ),
  51. ));
  52. };
  53. }
  54. /**
  55. * onBootstrapComplete
  56. */
  57. public function onBootstrapComplete($event) {
  58. if (CakePlugin::loaded('Comments')) {
  59. App::uses('Comment', 'Comments.Model');
  60. Croogo::hookBehavior('Node', 'Comments.Commentable');
  61. Croogo::hookComponent('Nodes', 'Comments.Comments');
  62. Croogo::hookModelProperty('Comment', 'belongsTo', array(
  63. 'Node' => array(
  64. 'className' => 'Nodes.Node',
  65. 'foreignKey' => 'foreign_key',
  66. 'counterCache' => true,
  67. 'counterScope' => array(
  68. 'Comment.model' => 'Node',
  69. 'Comment.status' => Comment::STATUS_APPROVED,
  70. ),
  71. ),
  72. ));
  73. }
  74. if (CakePlugin::loaded('Taxonomy')) {
  75. Croogo::hookBehavior('Node', 'Taxonomy.Taxonomizable');
  76. }
  77. if (CakePlugin::loaded('Meta')) {
  78. Croogo::hookBehavior('Node', 'Meta.Meta');
  79. }
  80. }
  81. /**
  82. * Setup Link chooser values
  83. *
  84. * @return void
  85. */
  86. public function onSetupLinkChooser($event) {
  87. $Type = ClassRegistry::init('Taxonomy.Type');
  88. $types = $Type->find('all', array(
  89. 'fields' => array('alias', 'title', 'description'),
  90. ));
  91. $linkChoosers = array();
  92. foreach ($types as $type) {
  93. $linkChoosers[$type['Type']['title']] = array(
  94. 'title' => $type['Type']['title'],
  95. 'description' => $type['Type']['description'],
  96. 'url' => array(
  97. 'plugin' => 'nodes',
  98. 'controller' => 'nodes',
  99. 'action' => 'index',
  100. '?' => array(
  101. 'type' => $type['Type']['alias'],
  102. 'chooser' => 1,
  103. 'KeepThis' => true,
  104. 'TB_iframe' => true,
  105. 'height' => 400,
  106. 'width' => 600
  107. )
  108. )
  109. );
  110. }
  111. Croogo::mergeConfig('Menus.linkChoosers', $linkChoosers);
  112. }
  113. }