materio_didactique.module 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function materio_didactique_permission() {
  6. return array(
  7. 'view materio didactique home block' => array(
  8. 'title' => t('view materio didactique home block'),
  9. 'description' => t(''),
  10. ),
  11. 'access materio didactique page' => array(
  12. 'title' => t('access materio didactique page'),
  13. 'description' => t(''),
  14. ),
  15. );
  16. }
  17. /**
  18. * Implements hook_menu().
  19. */
  20. function materio_didactique_menu() {
  21. $items['whoweare'] = array(
  22. 'title' => 'Who we are',
  23. 'page callback' => 'materio_didactique_get_page',
  24. // 'page arguments' => array(),
  25. 'access arguments' => array('access materio didactique page'),
  26. 'type' => MENU_CALLBACK,
  27. 'file' => 'materio_didactique.pages.inc',
  28. );
  29. return $items;
  30. }
  31. /**
  32. * Implements hook_block_info().
  33. */
  34. function materio_didactique_block_info() {
  35. $blocks['materio_didactique_home'] = array(
  36. 'info' => t('Materio didactique home block'),
  37. 'cache' => DRUPAL_NO_CACHE
  38. );
  39. return $blocks;
  40. }
  41. /**
  42. * Implements hook_block_view().
  43. */
  44. function materio_didactique_block_view($delta = '') {
  45. $block = array();
  46. switch ($delta) {
  47. case 'materio_didactique_home':
  48. if(user_access('view materio didactique home block')){
  49. $query = new EntityFieldQuery;
  50. $query
  51. ->entityCondition('entity_type', 'node')
  52. ->propertyCondition('status', 1)
  53. ->entityCondition('bundle', array('didactique'))
  54. ->fieldCondition('field_displayed_in_home', 'value', 1)
  55. ->fieldOrderBy('field_weight', 'value', 'ASC');
  56. $result = $query->execute();
  57. // dsm($result, '$result');
  58. if (isset($result['node'])) {
  59. $block['subject'] = t('Didactique home block');
  60. $block['content'] = theme('materio_didactique_home_block', array('items' => $result['node']));
  61. }
  62. }
  63. break;
  64. }
  65. return $block;
  66. }
  67. /**
  68. * Implements hook_theme().
  69. */
  70. function materio_didactique_theme($existing, $type, $theme, $path) {
  71. return array(
  72. 'materio_didactique_home_block' => array(
  73. 'arguments' => array('items'=>NULL),
  74. 'template' => 'materio-didactique-home-block',
  75. 'path' => drupal_get_path('module', 'materio_didactique').'/templates',
  76. ),
  77. 'materio_didactique_page' => array(
  78. 'arguments' => array('items'=>array()),
  79. 'template' => 'materio-didactique-page',
  80. 'path' => drupal_get_path('module', 'materio_didactique').'/templates',
  81. )
  82. );
  83. }
  84. function template_preprocess_materio_didactique_home_block(&$vars){
  85. // dsm($vars, 'template_preprocess_materio_didactique_home_block | $vars');
  86. $items = array();
  87. foreach ($vars['items'] as $nid => $item) {
  88. $items[] = node_load($nid);
  89. }
  90. $vars['items'] = $items;
  91. }
  92. function template_preprocess_materio_didactique_page(&$vars){
  93. // dsm($vars, 'template_preprocess_materio_didactique_page | $vars');
  94. $items = array();
  95. foreach ($vars['items'] as $nid => $item) {
  96. $items[] = node_load($nid);
  97. }
  98. $vars['items'] = $items;
  99. }