Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. $emptyTextVue = $view->display_handler->get_option('empty');
  2. $emptyText = $view->display_handler->set_option('empty','<div class="ma-classe">Pas images.</div>');
  3.  
  4. $handler->display->display_options['empty']['area']['content'] = 'Pas d'images à afficher.';
  5.  
  6. // Load the view.
  7. $view = views_get_view('VIEW_NAME');
  8. // Set the options for the header text.
  9. // To get an idea of what options are available, set up a view with header text
  10. // and then use the devel module to print out the view definition.
  11. // For example, add a header text area field and print it with
  12. // dpm($view->header['area']); after you have loaded it with views_get_view().
  13. $header_options = array(
  14. 'label' => t('Header text'), // Administrative label. Not really needed here.
  15. 'content' => 'This is the header text content.', // Content of header text.
  16. 'format' => 'filtered_html', // Format of header text.
  17. 'empty' => 1, // Show even when there are no results. Set to zero otherwise.
  18. );
  19. // This adds a header handler for a text area. The table is views because it is not
  20. // a database field. The field is area because it is a text area.
  21. // The header_options are the settings.
  22. $view->add_item('DISPLAY_NAME', 'header', 'views', 'area', $header_options);
  23. // This is the preferred way to get the rendered view.
  24. $output = $view->preview('DISPLAY_NAME');
  25. // If you want you can check for results with this.
  26. if (!empty($view->result)) {
  27. // Do something if there are rows.
  28. }
  29.  
  30. $view->add_item('DISPLAY_NAME', 'footer', 'views', 'area', $footer_options);
  31.  
  32. $view->add_item('DISPLAY_NAME', 'empty', 'views', 'area', $empty_options);
  33.  
  34. /**
  35. * Implementation of hook_views_pre_view().
  36. *
  37. * Change the set filter to be the current Quarter/Year set in the CCS admin area.
  38. */
  39. function courses_db_views_pre_view(&$view, &$display_id, &$args) {
  40. // This is /DEPT/courses
  41. #dpm($view);
  42. if ($view->name == 'departmental_courses') {
  43. $filter =& $view->filter;
  44.  
  45. $fall_tid = 11;
  46. $year_2012_tid = 26;
  47. // We created these _tid variables so that we didn't have to look up the TID
  48. // on every page view by students.
  49. $q = variable_get('ccs_current_quarter_tid', $fall_tid);
  50. $y = variable_get('ccs_current_year_tid', $year_2012_tid);
  51.  
  52. $view->display[$display_id]->handler->options['filters']['field_coursedb_quarter_tid']['value'] = $q;
  53. $view->display[$display_id]->handler->options['filters']['field_coursedb_year_tid']['value'] = $y;
  54. }
  55. if ($view->name == 'courses_for_instructor') {
  56. #dpm($view->display['block']->handler, 'handler');
  57. $quarter = variable_get('ccs_current_quarter', 'Fall');
  58. $year = variable_get('ccs_current_year', '2012');
  59.  
  60. $view->display['block']->handler->options['title'] = t('@quarter @year Instructor of:', array('@quarter' => $quarter, '@year' => $year));
  61. $view->args[0] = $year;
  62. $view->args[1] = $quarter;
  63. #dpm($view->display['block']->handler, 'handler');
  64. }
  65.  
  66. }
  67.  
  68. /**
  69. * Implementation of hook_views_post_execute().
  70. *
  71. * For a view listing of migrated course data, show original legacy
  72. * data in the view header to allow auditing/verification of the
  73. * migrated data.
  74. */
  75. function courses_db_views_post_execute(&$view) {
  76. if ($view->name == 'migration_audits') { # Courses
  77.  
  78. $drupal_nids = array();
  79. if (count($view->result)) {
  80. foreach ($view->result as $i => $node) {
  81. $drupal_nids []= $node->nid;
  82. }
  83. }
  84.  
  85. $ccs_sql = <<<EOFSQL
  86. SELECT mccd.*
  87. FROM ccs_dump.mos_ccs_courses_db mccd
  88. LEFT JOIN ccs_dump.migrate_map_csscourse mmc ON mmc.sourceid1 = mccd.id
  89. WHERE mmc.destid1 IN (:drupal_nids)
  90. EOFSQL;
  91. $result = db_query($ccs_sql, array(':drupal_nids' => $drupal_nids));
  92. $output = '';
  93. foreach ($result as $course) {
  94. #dpm($course);
  95. $title = html_entity_decode($course->course_title, ENT_COMPAT, 'UTF-8');
  96. $instructors = html_entity_decode($course->instructor, ENT_COMPAT, 'UTF-8');
  97. $output .= "<div class="entry">$course->quarter $course->year - $title Instructors:&nbsp;$instructors</div>";
  98. }
  99.  
  100.  
  101. $ccs_values = "<style type="text/css">div.legacy_values { background-color: pink;} div.legacy_values div.entry { padding-bottom: 5px; }</style><div class="legacy_values">$output</div>";
  102. $view->display['page']->handler->handlers['header']['area_1']->options['content'] = $ccs_values;
  103. $view->display['page']->handler->handlers['header']['area_1']->options['empty'] = 0;
  104. }
  105. }
  106.  
  107. $viewname_ag1 = 'Actualites_liste_globale';
  108. $view = views_get_view ($viewname_ag1);
  109. $viewdisplay_ag1 = $view->set_display('block_1');
  110. //$args_ldj1 = $view->set_arguments(array($node->nid));
  111.  
  112. //$emptyTextVue = $view->display_handler->get_option('empty');
  113. $emptyText = $view->display_handler->set_option('empty','<div class="vue-txt-vide">Pas de contenu à afficher pour cette année.</div>');
  114.  
  115. //Code change avec Views3
  116.  
  117. $view->display['block_1']->handler->handlers['header']['area_1']->options['content'] = "texte header embed_views";
  118.  
  119.  
  120.  
  121. //Exécution de le vue
  122. $view->pre_execute();
  123. $view->execute();
  124.  
  125. if (!empty($view->result)) {
  126.  
  127. // S'il y a un resultat on récupère le titre (ajoute tag h3, et le contenu)
  128. $output = '<div id="bloc_actus_globales"><h3 class="classe-h3">'.$view->get_title().'</h3>' .$view->preview($viewdisplay_ag1).'</div>';
  129.  
  130. //Affiche la vue si contenu
  131. print $output;
  132. }
  133. //sinon affiche texte vide
  134. elseif (empty($view->result)) {
  135.  
  136.  
  137. //Formatage du texte vide,ajout du titre de la vue
  138. $outputEmpty = '<div id="bloc_actus_globales"><h3 class="classe-h3">'.$view->get_title().'</h3>'.$emptyText.'</div>';
  139. // $outputEmpty = '<div id="bloc_actus_globales"><h3 class="classe-h3">'.$view->get_title().'</h3>'.$emptyTextVue.'</div>';
  140. // drupal_set_message('$EmptyTextVue : '.$emptyTextVue.'status');
  141. //Affichage du texte vide
  142. print $outputEmpty;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement