twigDisplay.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Grav\Plugin;
  3. use Grav\Common\Data;
  4. use Grav\Common\Plugin;
  5. use Grav\Common\Grav;
  6. use Grav\Common\Uri;
  7. use Grav\Common\Taxonomy;
  8. use Grav\Common\Page\Page;
  9. use RocketTheme\Toolbox\Event\Event;
  10. class twigDisplay extends \Twig_Extension
  11. {
  12. public function getName()
  13. {
  14. return 'ExampleTwigExtension';
  15. }
  16. public function getFunctions(): array
  17. {
  18. return [
  19. new \Twig_SimpleFunction('getJson', [$this, 'getJson'])
  20. ];
  21. }
  22. public function getJson()
  23. {
  24. $grav = Grav::instance();
  25. $debugger = $grav['debugger'];
  26. $page = $grav['page'];
  27. $pages = $page->evaluate(['@page.children' => '/coalitions']);
  28. // initialiser l'objet
  29. $data = array();
  30. $i = 0;
  31. $a = 0;
  32. foreach ($pages as $key => $coa) {
  33. $header = $coa->header();
  34. $url = $coa->url();
  35. /*dump(st'01/01/'+$header->info['date']))*/
  36. if(isset($header->member)){
  37. $coa_object = array(
  38. 'lane' => $i,
  39. 'title' => $coa->title(),
  40. 'coa_name' => $header->info['orga'],
  41. 'start' => strtotime('01/01/'.$header->info['date'])*1000,
  42. 'end' => strtotime(date("Y"))*1000,
  43. 'activist' => array()
  44. );
  45. if (isset($header->member)) {
  46. foreach ($header->member as $member) {
  47. if (strtotime($member["free"]) != "") {
  48. $f = strtotime($member["free"]);
  49. }else{
  50. $f = strtotime(date("Y"));
  51. }
  52. $member_array = array(
  53. 'id' => $member["membre"],
  54. 'start' => strtotime($member['prison'])*1000,
  55. 'end' => $f*1000,
  56. 'url' => $url,
  57. 'lane' => $i,
  58. 'pos' => $a
  59. );
  60. array_push($coa_object['activist'], $member_array);
  61. $a ++;
  62. }
  63. }
  64. array_push($data, $coa_object);
  65. $i ++;
  66. /*$debugger->addMessage($coa->header());*/
  67. }
  68. }
  69. return $data;
  70. }
  71. }