created edlp_home, edlp_agenda, edlp_production custom modules
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# @Author: Bachir Soussi Chiadmi <bach>
|
||||
# @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
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
# @Author: Bachir Soussi Chiadmi <bach>
|
||||
# @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
|
||||
@@ -0,0 +1,23 @@
|
||||
# @Author: Bachir Soussi Chiadmi <bach>
|
||||
# @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'
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_agenda\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
|
||||
class AgendaController extends ControllerBase {
|
||||
|
||||
|
||||
private function query() {
|
||||
// @see https://www.webomelette.com/query-entities-using-dates-drupal-8
|
||||
|
||||
$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), '>=')
|
||||
->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"=> "<h2>Agenda</h2>",
|
||||
"next"=>array(
|
||||
"#type"=>"container",
|
||||
"#attributes"=>array(
|
||||
"class"=>['next-event', 'column', 'os-scroll']
|
||||
),
|
||||
"#markup"=>"<h3>Prochaine Date</h3>",
|
||||
"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"=>"<h3>Dates à venir</h3>",
|
||||
"future_events"=>$future_list
|
||||
),
|
||||
"past"=>array(
|
||||
"#type"=>"container",
|
||||
"#attributes"=>array(
|
||||
"class"=>['past-events']
|
||||
),
|
||||
"#markup"=>"<h3>Dates passées</h3>",
|
||||
"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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user