242 lines
6.2 KiB
Plaintext
242 lines
6.2 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* Implements hook_init().
|
|
*/
|
|
function clameursmod_init() {
|
|
if ($path = libraries_get_path('jquery.domwindow')) {
|
|
// Do something with the library, knowing the path, for instance:
|
|
drupal_add_js($path . '/jquery.DOMWindow.js');
|
|
}
|
|
drupal_add_js(drupal_get_path('module', 'clameursmod').'/clameursmod.js');
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_menu().
|
|
*/
|
|
function clameursmod_menu() {
|
|
|
|
$items['clameursmod/getemvidfield'] = array(
|
|
'page callback' => '_clameursmod_getemvidfield',
|
|
'page arguments' => array(),
|
|
'access callback' => TRUE,
|
|
'type' => MENU_CALLBACK,
|
|
// 'file' => ,
|
|
);
|
|
|
|
return $items;
|
|
}
|
|
|
|
function _clameursmod_getemvidfield(){
|
|
$data = array();
|
|
$data['test'] = "OK";
|
|
$data['src'] = $_GET['src'];
|
|
|
|
$data['embed'] = theme('video_embed_field_embed_code', array('url'=>$data['src'], 'style'=>'normal'));
|
|
|
|
drupal_json_output($data);
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_entity_info_alter().
|
|
*/
|
|
function clameursmod_entity_info_alter(&$entity_info) {
|
|
$entity_info['node']['view modes']['accueil'] = array(
|
|
'label' => t('Accueil'),
|
|
'custom settings' => TRUE,
|
|
);
|
|
$entity_info['node']['view modes']['attente'] = array(
|
|
'label' => t('attente'),
|
|
'custom settings' => TRUE,
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_block_info().
|
|
*/
|
|
function clameursmod_block_info() {
|
|
$blocks['thematiques'] = array(
|
|
'info' => t('Clameurs thematiques'),
|
|
'cache' => DRUPAL_NO_CACHE
|
|
);
|
|
$blocks['thematiques-anchor-links'] = array(
|
|
'info' => t('Clameurs thematiques anchor links'),
|
|
'cache' => DRUPAL_NO_CACHE
|
|
);
|
|
|
|
return $blocks;
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_block_view().
|
|
*/
|
|
function clameursmod_block_view($delta = '') {
|
|
$block = array();
|
|
|
|
switch ($delta) {
|
|
case 'thematiques':
|
|
$block['subject'] = t('Thématiques');
|
|
$block['content'] = _clameursmod_thematiques();
|
|
break;
|
|
case 'thematiques-anchor-links':
|
|
$block['subject'] = t('Thématiques menu');
|
|
$block['content'] = _clameursmod_thematiques_anchor_links();
|
|
break;
|
|
}
|
|
return $block;
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_theme().
|
|
*/
|
|
function clameursmod_theme($existing, $type, $theme, $path) {
|
|
return array(
|
|
'thematiques' => array(
|
|
'render element' => 'element'
|
|
),
|
|
'thematiques_anchor_links' => array(
|
|
'render element' => 'element'
|
|
),
|
|
);
|
|
}
|
|
|
|
// ________ __ _
|
|
// /_ __/ /_ ___ ____ ___ ____ _/ /_(_)___ ___ _____ _____
|
|
// / / / __ \/ _ \/ __ `__ \/ __ `/ __/ / __ `/ / / / _ \/ ___/
|
|
// / / / / / / __/ / / / / / /_/ / /_/ / /_/ / /_/ / __(__ )
|
|
// /_/ /_/ /_/\___/_/ /_/ /_/\__,_/\__/_/\__, /\__,_/\___/____/
|
|
// /_/
|
|
|
|
function _clameursmod_thematiques(){
|
|
$query = new EntityFieldQuery();
|
|
$query
|
|
->entityCondition('entity_type', 'node')
|
|
->entityCondition('bundle', 'thematique')
|
|
->propertyCondition('status', 1)
|
|
->fieldOrderBy('field_poid', 'value', 'ASC');
|
|
|
|
$result = $query->execute();
|
|
// dsm($result['node'], "result");
|
|
$nids = array_keys($result['node']);
|
|
|
|
$nodes = array();
|
|
foreach ($nids as $nid) {
|
|
$nodes[] = node_load($nid);
|
|
}
|
|
return theme('thematiques', array("items"=>$nodes));
|
|
}
|
|
|
|
|
|
function theme_thematiques($vars){
|
|
$nodes = $vars['items'];
|
|
$rendered = "";
|
|
foreach ($nodes as $key => $node) {
|
|
// dsm($node, 'node');
|
|
switch ($node->workflow) {
|
|
case 7:
|
|
$view_mode = "accueil";
|
|
break;
|
|
default:
|
|
$view_mode = "attente";
|
|
break;
|
|
}
|
|
$entity_view = entity_view('node', array($node), $view_mode);
|
|
$rendered .= render($entity_view);
|
|
}
|
|
return $rendered;
|
|
}
|
|
|
|
// ___ __
|
|
// / | ____ _____/ /_ ____ __________
|
|
// / /| | / __ \/ ___/ __ \/ __ \/ ___/ ___/
|
|
// / ___ |/ / / / /__/ / / / /_/ / / (__ )
|
|
// /_/ |_/_/ /_/\___/_/ /_/\____/_/ /____/
|
|
|
|
function _clameursmod_thematiques_anchor_links(){
|
|
$query = new EntityFieldQuery();
|
|
$query
|
|
->entityCondition('entity_type', 'node')
|
|
->entityCondition('bundle', 'thematique')
|
|
->propertyCondition('status', 1)
|
|
->fieldOrderBy('field_poid', 'value', 'ASC');
|
|
|
|
$result = $query->execute();
|
|
$nids = array_keys($result['node']);
|
|
|
|
$nodes = [];
|
|
foreach ($nids as $nid) {
|
|
$node = node_load($nid);
|
|
// dsm($node);
|
|
$alias = str_replace('/', '-', drupal_get_path_alias('node/'.$nid));
|
|
// get the workflow state ID
|
|
$current_state = workflow_state_load_single($node->workflow);
|
|
// dsm($current_state, 'current_state');
|
|
// $workflow = $current_state->getWorkflow();
|
|
// dsm($workflow, "workflow");
|
|
$scheduled_transitions = WorkflowScheduledTransition::load('node', $nid, NULL, 1);
|
|
$transition = false;
|
|
if(count($scheduled_transitions)){
|
|
// dsm($scheduled_transitions, "scheduled_transitions");
|
|
$transition = $scheduled_transitions[0];
|
|
}
|
|
|
|
$nodes[$nid] = array(
|
|
"alias"=>$alias,
|
|
"title"=>$node->title,
|
|
"wf_sid"=>$node->workflow,
|
|
"wf_stamp"=> $transition ? $transition->scheduled : false,
|
|
"wf_state"=>$current_state->getName(),
|
|
);
|
|
}
|
|
return theme('thematiques_anchor_links', array("items"=>$nodes));
|
|
}
|
|
|
|
function theme_thematiques_anchor_links($vars){
|
|
$list = array(
|
|
'items'=>array(),
|
|
'type'=>'ul',
|
|
'attributes'=>array(
|
|
"class"=>array("thematique-anchor-links")
|
|
)
|
|
);
|
|
|
|
$i=0;
|
|
foreach ($vars["items"] as $nid => $val) {
|
|
// TODO: display the workflow state ID
|
|
$options = array(
|
|
"attributes"=>array(
|
|
"class"=>array("anchor","pos-".$i, $val['wf_state'], 'node-'.$nid),
|
|
),
|
|
"fragment"=>$val['alias'],
|
|
"html"=>true,
|
|
);
|
|
$content = $val['title'];
|
|
if($val["wf_stamp"]){
|
|
$content .= "<span>" . format_date($val["wf_stamp"], 'custom', "d M Y") . "</span>";
|
|
}
|
|
$list['items'][] = l($content, '' , $options);
|
|
$i++;
|
|
}
|
|
|
|
return theme('item_list', $list);
|
|
}
|
|
|
|
function clameursmod_field_attach_view_alter(&$output, $context) {
|
|
if(isset($output['field_emvideo'])){
|
|
$entity = $context['entity'];
|
|
$field_vignette = field_get_items('node', $entity, 'field_vignette');
|
|
// dsm($field_vignette, $entity->title.' : field_vignette');
|
|
if($field_vignette){
|
|
// dsm($output, $entity->title.' : output');
|
|
// dsm($context, $entity->title.' : context');
|
|
$uri = $field_vignette[0]['uri'];
|
|
$output['field_emvideo'][0]['#item']['uri'] = $uri;
|
|
}
|
|
}
|
|
}
|