PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Taxonomy/Event/TaxonomiesEventHandler.php

https://github.com/kareypowell/croogo
PHP | 104 lines | 77 code | 8 blank | 19 comment | 2 complexity | b68de142319c1cdfde8cc33b1f037252 MD5 | raw file
  1. <?php
  2. App::uses('CakeEventListener', 'Event');
  3. /**
  4. * Taxonomy Event Handler
  5. *
  6. * @category Event
  7. * @package Croogo.Taxonomy.Event
  8. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  9. * @link http://www.croogo.org
  10. */
  11. class TaxonomiesEventHandler implements CakeEventListener {
  12. /**
  13. * implementedEvents
  14. */
  15. public function implementedEvents() {
  16. return array(
  17. 'Croogo.setupAdminData' => array(
  18. 'callable' => 'onSetupAdminData',
  19. ),
  20. 'Controller.Links.setupLinkChooser' => array(
  21. 'callable' => 'onSetupLinkChooser',
  22. ),
  23. );
  24. }
  25. /**
  26. * Setup admin data
  27. */
  28. public function onSetupAdminData($event) {
  29. $View = $event->subject;
  30. if (empty($View->viewVars['vocabularies_for_admin_layout'])) {
  31. $vocabularies = array();
  32. } else {
  33. $vocabularies = $View->viewVars['vocabularies_for_admin_layout'];
  34. }
  35. foreach ($vocabularies as $v) {
  36. $weight = 9999 + $v['Vocabulary']['weight'];
  37. CroogoNav::add('sidebar', 'content.children.taxonomy.children.' . $v['Vocabulary']['alias'], array(
  38. 'title' => $v['Vocabulary']['title'],
  39. 'url' => array(
  40. 'plugin' => 'taxonomy',
  41. 'admin' => true,
  42. 'controller' => 'terms',
  43. 'action' => 'index',
  44. $v['Vocabulary']['id'],
  45. ),
  46. 'weight' => $weight,
  47. ));
  48. };
  49. }
  50. /**
  51. * Setup Link chooser values
  52. *
  53. * @return void
  54. */
  55. public function onSetupLinkChooser($event) {
  56. $this->Vocabulary = ClassRegistry::init('Taxonomy.Vocabulary');
  57. $vocabularies = $this->Vocabulary->find('all', array(
  58. 'joins' => array(
  59. array(
  60. 'table' => 'types_vocabularies',
  61. 'alias' => 'TypesVocabulary',
  62. 'conditions' => 'Vocabulary.id = TypesVocabulary.vocabulary_id'
  63. ),
  64. array(
  65. 'table' => 'types',
  66. 'alias' => 'Type',
  67. 'conditions' => 'TypesVocabulary.type_id = Type.id',
  68. ),
  69. ),
  70. ));
  71. $linkChoosers = array();
  72. foreach ($vocabularies as $vocabulary) {
  73. foreach ($vocabulary['Type'] as $type) {
  74. $title = $type['title'] . ' ' . $vocabulary['Vocabulary']['title'];
  75. $linkChoosers[$title] = array(
  76. 'description' => $vocabulary['Vocabulary']['description'],
  77. 'url' => array(
  78. 'plugin' => 'taxonomy',
  79. 'controller' => 'terms',
  80. 'action' => 'index',
  81. $vocabulary['Vocabulary']['id'],
  82. '?' => array(
  83. 'type' => $type['alias'],
  84. 'chooser' => 1,
  85. 'KeepThis' => true,
  86. 'TB_iframe' => true,
  87. 'height' => 400,
  88. 'width' => 600,
  89. ),
  90. ),
  91. );
  92. }
  93. }
  94. Croogo::mergeConfig('Menus.linkChoosers', $linkChoosers);
  95. }
  96. }