From 501796690832d580cf0aea944580ab1aa9368579 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Sat, 6 Jan 2018 11:27:29 +0100 Subject: [PATCH] created edlp_home, edlp_agenda, edlp_production custom modules --- .../figli/edlp_agenda/edlp_agenda.info.yml | 18 +++ .../figli/edlp_agenda/edlp_agenda.module | 9 ++ .../figli/edlp_agenda/edlp_agenda.routing.yml | 23 +++ .../src/Controller/AgendaController.php | 135 ++++++++++++++++++ .../assets/dist/scripts/corpus.min.js | 17 ++- .../edlp_corpus/assets/scripts/corpus.js | 17 ++- .../figli/edlp_corpus/edlp_corpus.info.yml | 8 ++ .../figli/edlp_corpus/edlp_corpus.module | 7 + .../all/modules/figli/edlp_home/edlp_home.inc | 26 ++++ .../figli/edlp_home/edlp_home.info.yml | 18 +++ .../modules/figli/edlp_home/edlp_home.module | 29 ++++ .../figli/edlp_home/edlp_home.routing.yml | 15 ++ .../src/Controller/HomeController.php | 63 ++++++++ .../edlp_home/templates/edlp-home.html.twig | 8 ++ .../edlp_productions.info.yml | 18 +++ .../edlp_productions/edlp_productions.module | 8 ++ .../edlp_productions.routing.yml | 23 +++ .../src/Controller/ProductionsController.php | 44 ++++++ 18 files changed, 478 insertions(+), 8 deletions(-) create mode 100644 sites/all/modules/figli/edlp_agenda/edlp_agenda.info.yml create mode 100644 sites/all/modules/figli/edlp_agenda/edlp_agenda.module create mode 100644 sites/all/modules/figli/edlp_agenda/edlp_agenda.routing.yml create mode 100644 sites/all/modules/figli/edlp_agenda/src/Controller/AgendaController.php create mode 100644 sites/all/modules/figli/edlp_home/edlp_home.inc create mode 100644 sites/all/modules/figli/edlp_home/edlp_home.info.yml create mode 100644 sites/all/modules/figli/edlp_home/edlp_home.module create mode 100644 sites/all/modules/figli/edlp_home/edlp_home.routing.yml create mode 100644 sites/all/modules/figli/edlp_home/src/Controller/HomeController.php create mode 100644 sites/all/modules/figli/edlp_home/templates/edlp-home.html.twig create mode 100644 sites/all/modules/figli/edlp_productions/edlp_productions.info.yml create mode 100644 sites/all/modules/figli/edlp_productions/edlp_productions.module create mode 100644 sites/all/modules/figli/edlp_productions/edlp_productions.routing.yml create mode 100644 sites/all/modules/figli/edlp_productions/src/Controller/ProductionsController.php diff --git a/sites/all/modules/figli/edlp_agenda/edlp_agenda.info.yml b/sites/all/modules/figli/edlp_agenda/edlp_agenda.info.yml new file mode 100644 index 000000000..65bc6b8c8 --- /dev/null +++ b/sites/all/modules/figli/edlp_agenda/edlp_agenda.info.yml @@ -0,0 +1,18 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_corpus.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + + +name: Edlp Agenda +type: module +description: Manage agenda for edlp d8. +core: 8.x +package: Edlp +# dependencies: +# - migrate_drupal +# - migrate_plus +# - migrate_tools diff --git a/sites/all/modules/figli/edlp_agenda/edlp_agenda.module b/sites/all/modules/figli/edlp_agenda/edlp_agenda.module new file mode 100644 index 000000000..9fda04257 --- /dev/null +++ b/sites/all/modules/figli/edlp_agenda/edlp_agenda.module @@ -0,0 +1,9 @@ + +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_corpus.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 diff --git a/sites/all/modules/figli/edlp_agenda/edlp_agenda.routing.yml b/sites/all/modules/figli/edlp_agenda/edlp_agenda.routing.yml new file mode 100644 index 000000000..53be06e3b --- /dev/null +++ b/sites/all/modules/figli/edlp_agenda/edlp_agenda.routing.yml @@ -0,0 +1,23 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_corpus.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + +edlp_agenda.agenda: + path: '/agenda' + defaults: + _controller: '\Drupal\edlp_agenda\Controller\AgendaController::agenda' + _title: 'Agenda' + requirements: + _permission: 'access content' + +edlp_agenda.agendaajax: + path: '/agenda/ajax' + defaults: + _controller: '\Drupal\edlp_agenda\Controller\AgendaController::agendajson' + _title: 'Agenda' + requirements: + _permission: 'access content' diff --git a/sites/all/modules/figli/edlp_agenda/src/Controller/AgendaController.php b/sites/all/modules/figli/edlp_agenda/src/Controller/AgendaController.php new file mode 100644 index 000000000..4ebec91da --- /dev/null +++ b/sites/all/modules/figli/edlp_agenda/src/Controller/AgendaController.php @@ -0,0 +1,135 @@ +setTimezone(new \DateTimeZone(DATETIME_STORAGE_TIMEZONE)); + + $query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('type', 'evenement') + ->condition('field_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '>=') + ->sort('field_date'); + + $this->future_nids = $query->execute(); + $this->future_nodes = entity_load_multiple('node', $this->future_nids); + + $this->next_event = array_shift($this->future_nodes); + + $query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('type', 'evenement') + ->condition('field_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '<') + ->sort('field_date', 'DESC'); + + $this->past_nids = $query->execute(); + $this->past_nodes = entity_load_multiple('node', $this->past_nids); + } + + private function toRenderable(){ + $this->query(); + // + // dpm($this->future_nodes); + // dpm($this->next_event); + /* + @see https://www.drupal8.ovh/index.php/en/tutoriels/339/render-a-node-or-an-entity + */ + + $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node'); + + $future_list = array ( + '#theme' => 'item_list', + '#items' => [], + ); + foreach($this->future_nodes as $node){ + $future_list['#items'][] = $view_builder->view($node, 'teaser'); + } + + $past_list = array ( + '#theme' => 'item_list', + '#items' => [], + ); + foreach($this->past_nodes as $node){ + $past_list['#items'][] = $view_builder->view($node, 'teaser'); + } + + return array( + "#type" => "container", + "#attributes"=>array( + "id"=>['agenda'] + ), + // "#markup"=> "

Agenda

", + "next"=>array( + "#type"=>"container", + "#attributes"=>array( + "class"=>['next-event', 'column', 'os-scroll'] + ), + "#markup"=>"

Prochaine Date

", + "event"=>$view_builder->view($this->next_event, 'default') + ), + "future_past"=>array( + "#type"=>"container", + "#attributes"=>array( + "class"=>['future-past-events', 'column', 'os-scroll'] + ), + "future"=>array( + "#type"=>"container", + "#attributes"=>array( + "class"=>['future-events'] + ), + "#markup"=>"

Dates à venir

", + "future_events"=>$future_list + ), + "past"=>array( + "#type"=>"container", + "#attributes"=>array( + "class"=>['past-events'] + ), + "#markup"=>"

Dates passées

", + "past_events"=>$past_list + ) + ) + ); + + } + + /** + * Display agenda as a page. + * + * @return renderable array + */ + public function agenda() { + return $this->toRenderable(); + } + + /** + * Get agenda data as json through ajax. + * + * @return json + */ + public function agendajson() { + + $response = new JsonResponse(); + $renderable = $this->toRenderable(); + $rendered = render($renderable); + + $response->setData([ + 'test'=>'hello', + 'rendered'=> $rendered + ]); + + return $response; + } + +} diff --git a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js index ea176864b..226f946c7 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js +++ b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js @@ -97,10 +97,9 @@ function onResizeCanvas() { _canvas.width = window.innerWidth; _canvas.height = window.innerHeight; - // - _canvas_props['margin-top'] - _canvas_props['margin-bottom']; - // _canvas.style['margin-top'] = _canvas_props['margin-top']+"px"; - // _canvas.style['margin-bottom'] = _canvas_props['margin-bottom']+"px"; - + for (var i = 0; i < _nodes.length; i++) { + _nodes[i].onResizeCanvas(); + } }; // ___ _ @@ -179,6 +178,16 @@ // // this.draw(); // }; + Node.prototype.onResizeCanvas = function(){ + this.wall_limits = { + top: _canvas_props.margin_top +this.real_radius, + right: _canvas.width -_canvas_props.margin_right -this.real_radius, + bottom: _canvas.height -_canvas_props.margin_bottom -this.real_radius, + left: _canvas_props.margin_left +this.real_radius + } + // TODO: when canvas is smaller what about nodes hors champs, they are coming back alone but it's too long + }; + Node.prototype.onUpdate = function(){ this.checkWallBouncing(); this.updatePos(); diff --git a/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js b/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js index ea176864b..226f946c7 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js +++ b/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js @@ -97,10 +97,9 @@ function onResizeCanvas() { _canvas.width = window.innerWidth; _canvas.height = window.innerHeight; - // - _canvas_props['margin-top'] - _canvas_props['margin-bottom']; - // _canvas.style['margin-top'] = _canvas_props['margin-top']+"px"; - // _canvas.style['margin-bottom'] = _canvas_props['margin-bottom']+"px"; - + for (var i = 0; i < _nodes.length; i++) { + _nodes[i].onResizeCanvas(); + } }; // ___ _ @@ -179,6 +178,16 @@ // // this.draw(); // }; + Node.prototype.onResizeCanvas = function(){ + this.wall_limits = { + top: _canvas_props.margin_top +this.real_radius, + right: _canvas.width -_canvas_props.margin_right -this.real_radius, + bottom: _canvas.height -_canvas_props.margin_bottom -this.real_radius, + left: _canvas_props.margin_left +this.real_radius + } + // TODO: when canvas is smaller what about nodes hors champs, they are coming back alone but it's too long + }; + Node.prototype.onUpdate = function(){ this.checkWallBouncing(); this.updatePos(); diff --git a/sites/all/modules/figli/edlp_corpus/edlp_corpus.info.yml b/sites/all/modules/figli/edlp_corpus/edlp_corpus.info.yml index 541d76002..ac0e4fc7a 100644 --- a/sites/all/modules/figli/edlp_corpus/edlp_corpus.info.yml +++ b/sites/all/modules/figli/edlp_corpus/edlp_corpus.info.yml @@ -1,3 +1,11 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_corpus.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + name: Edlp Corpus type: module description: Creates interactive map of corpus for edlp d8. diff --git a/sites/all/modules/figli/edlp_corpus/edlp_corpus.module b/sites/all/modules/figli/edlp_corpus/edlp_corpus.module index 6ade28d15..5802df061 100644 --- a/sites/all/modules/figli/edlp_corpus/edlp_corpus.module +++ b/sites/all/modules/figli/edlp_corpus/edlp_corpus.module @@ -1,4 +1,11 @@ +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_corpus.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 /** * Implements hook_page_attachments(). diff --git a/sites/all/modules/figli/edlp_home/edlp_home.inc b/sites/all/modules/figli/edlp_home/edlp_home.inc new file mode 100644 index 000000000..157403991 --- /dev/null +++ b/sites/all/modules/figli/edlp_home/edlp_home.inc @@ -0,0 +1,26 @@ +getViewBuilder('node'); + // dpm($vars); + + // render the presentation node + $vars["presentation"] = $view_builder->view($vars["presentation_node"], 'default'); + + // TODO: last fil + + // render the last production node + $vars["last_production"] = $view_builder->view($vars['last_production_node'], 'teaser'); + + // render the next events of agenda as list + $agenda = array ( + '#theme' => 'item_list', + '#items' => [], + ); + foreach($vars['agenda_items'] as $node){ + $agenda['#items'][] = $view_builder->view($node, 'teaser'); + } + $vars['agenda'] = render($agenda); + +} diff --git a/sites/all/modules/figli/edlp_home/edlp_home.info.yml b/sites/all/modules/figli/edlp_home/edlp_home.info.yml new file mode 100644 index 000000000..b53672342 --- /dev/null +++ b/sites/all/modules/figli/edlp_home/edlp_home.info.yml @@ -0,0 +1,18 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_home.info.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + + +name: Edlp Home +type: module +description: Manage home for edlp d8. +core: 8.x +package: Edlp +# dependencies: +# - migrate_drupal +# - migrate_plus +# - migrate_tools diff --git a/sites/all/modules/figli/edlp_home/edlp_home.module b/sites/all/modules/figli/edlp_home/edlp_home.module new file mode 100644 index 000000000..d3529f5b6 --- /dev/null +++ b/sites/all/modules/figli/edlp_home/edlp_home.module @@ -0,0 +1,29 @@ + +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_home.module +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + + +/** + * Implements hook_theme(). + */ +function edlp_home_theme($existing, $type, $theme, $path) { + // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module + + return array( + 'edlp_home' => array( + // 'render element' => '', + 'file' => 'edlp_home.inc', + 'variables' => array( + 'presentation_node' => NULL, + 'last_fil_node' => NULL, + 'last_production_node' => NULL, + 'agenda_items' => NULL + ), + ), + ); +} diff --git a/sites/all/modules/figli/edlp_home/edlp_home.routing.yml b/sites/all/modules/figli/edlp_home/edlp_home.routing.yml new file mode 100644 index 000000000..d07818e96 --- /dev/null +++ b/sites/all/modules/figli/edlp_home/edlp_home.routing.yml @@ -0,0 +1,15 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_home.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + +edlp_home.home: + path: '/home' + defaults: + _controller: '\Drupal\edlp_home\Controller\HomeController::home' + _title: 'Home' + requirements: + _permission: 'access content' diff --git a/sites/all/modules/figli/edlp_home/src/Controller/HomeController.php b/sites/all/modules/figli/edlp_home/src/Controller/HomeController.php new file mode 100644 index 000000000..1896b6a23 --- /dev/null +++ b/sites/all/modules/figli/edlp_home/src/Controller/HomeController.php @@ -0,0 +1,63 @@ +getViewBuilder('node'); + + $contents = array("#theme"=>'edlp_home'); + + // presentation + $query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('nid', 5890); + + $pres_nid = $query->execute(); + $contents["#presentation_node"] = entity_load('node', array_pop($pres_nid)); + + + // TODO: last fil + // $contents["#last_fil_node"] = "Last Fil"; + + // TODO: last production + $query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('type', 'page') + ->condition('field_page_type', array('1168'), 'NOT IN') + ->range(0,1) + ->sort('created', 'DESC'); + + $prod = $query->execute(); + $contents["#last_production_node"] = entity_load('node', array_pop($prod)); + + // agenda + $now = new DrupalDateTime('now'); + $now->setTimezone(new \DateTimeZone(DATETIME_STORAGE_TIMEZONE)); + + $query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('type', 'evenement') + ->condition('field_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '>=') + ->range(0,3) + ->sort('field_date'); + + $events = $query->execute(); + $contents['#agenda_items'] = entity_load_multiple('node', $events); + + return $contents; + } + +} diff --git a/sites/all/modules/figli/edlp_home/templates/edlp-home.html.twig b/sites/all/modules/figli/edlp_home/templates/edlp-home.html.twig new file mode 100644 index 000000000..e89afec7e --- /dev/null +++ b/sites/all/modules/figli/edlp_home/templates/edlp-home.html.twig @@ -0,0 +1,8 @@ + +{{ presentation }} + +{{ last_fil }} + +{{ last_production }} + +{{ agenda }} diff --git a/sites/all/modules/figli/edlp_productions/edlp_productions.info.yml b/sites/all/modules/figli/edlp_productions/edlp_productions.info.yml new file mode 100644 index 000000000..9a8485e1f --- /dev/null +++ b/sites/all/modules/figli/edlp_productions/edlp_productions.info.yml @@ -0,0 +1,18 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_productions.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + + +name: Edlp Productions +type: module +description: Manage productions for edlp d8. +core: 8.x +package: Edlp +# dependencies: +# - migrate_drupal +# - migrate_plus +# - migrate_tools diff --git a/sites/all/modules/figli/edlp_productions/edlp_productions.module b/sites/all/modules/figli/edlp_productions/edlp_productions.module new file mode 100644 index 000000000..55cf52bb2 --- /dev/null +++ b/sites/all/modules/figli/edlp_productions/edlp_productions.module @@ -0,0 +1,8 @@ + +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_productions.module +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 diff --git a/sites/all/modules/figli/edlp_productions/edlp_productions.routing.yml b/sites/all/modules/figli/edlp_productions/edlp_productions.routing.yml new file mode 100644 index 000000000..167d9f11b --- /dev/null +++ b/sites/all/modules/figli/edlp_productions/edlp_productions.routing.yml @@ -0,0 +1,23 @@ +# @Author: Bachir Soussi Chiadmi +# @Date: 13-12-2017 +# @Email: bachir@figureslibres.io +# @Filename: edlp_corpus.routing.yml +# @Last modified by: bach +# @Last modified time: 20-12-2017 +# @License: GPL-V3 + +edlp_productions.productions: + path: '/productions' + defaults: + _controller: '\Drupal\edlp_productions\Controller\ProductionsController::productions' + _title: 'Agenda' + requirements: + _permission: 'access content' + +edlp_productions.productionsajax: + path: '/productions/ajax' + defaults: + _controller: '\Drupal\edlp_productions\Controller\ProductionsController::productionsjson' + _title: 'Agenda' + requirements: + _permission: 'access content' diff --git a/sites/all/modules/figli/edlp_productions/src/Controller/ProductionsController.php b/sites/all/modules/figli/edlp_productions/src/Controller/ProductionsController.php new file mode 100644 index 000000000..12c0e8125 --- /dev/null +++ b/sites/all/modules/figli/edlp_productions/src/Controller/ProductionsController.php @@ -0,0 +1,44 @@ +"Edlp Productions" + ); + } + + /** + * Get agenda data as json through ajax. + * + * @return json + */ + public function productionsjson() { + + $response = new JsonResponse(); + $renderable = array( + "#markup"=>"Edlp Productions" + ); + $rendered = render($renderable); + + $response->setData([ + 'test'=>'hello', + 'rendered'=> $rendered + ]); + + return $response; + } + +}