123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- <?php
- // $Id$
- /**
- * @file
- * Non-features part of FGCF
- */
- include_once('fgcf.features.inc');
- /**
- * Helper: get a vocabulary ID from its name.
- *
- * @param string $name
- */
- function _fgcf_get_vocabulary_by_name($name) {
- $vocabularies = taxonomy_get_vocabularies();
- $ret = 0;
- foreach ($vocabularies as $vid => $vocabulary) {
- if (drupal_strtolower($vocabulary->name) == drupal_strtolower($name)) {
- $ret = $vid;
- break;
- }
- }
- return $ret;
- }
- /**
- * Shared filter form for course lists.
- *
- * Filter values are taken from the form logic or, when absent, from the
- * session, in order for them to be persistent across non-form pages.
- *
- * @return array
- */
- function fgcf_filter_form($form_state) {
- $form['filtre'] = array(
- '#title' => t('Filtrer les formations'),
- '#attributes' => array('class' => 'fgcf-filtre'),
- '#type' => 'fieldset',
- '#collapsible' => TRUE,
- );
- $dif = isset($form_state['storage']['dif'])
- ? $form_state['storage']['dif']
- : isset($_SESSION['fgcf']['dif'])
- ? $_SESSION['fgcf']['dif']
- : FALSE;
- $form['filtre']['dif'] = array(
- '#type' => 'checkbox',
- '#default_value' => $dif,
- '#title' => t('Eligibles DIF'),
- );
- $modalite = isset($form_state['storage']['modalite'])
- ? $form_state['storage']['modalite']
- : isset($_SESSION['fgcf']['modalite'])
- ? $_SESSION['fgcf']['modalite']
- : array();
- $form['filtre']['modalite'] = array(
- '#title' => t('Modalité'),
- '#type' => 'checkboxes',
- '#options' => array(
- 'inter' => t('Inter-entreprises'),
- 'intra' => t('Intra-entreprise'),
- 'autres' => t('Autres'),
- ),
- '#default_value' => $modalite,
- );
- $form['filtre']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Appliquer le filtre'),
- );
- return $form;
- }
- function fgcf_init() {
- if (arg(0) == 'fgcf') {
- drupal_add_css(drupal_get_path('module', 'fgcf') .'/theme/css/fgcf.css');
- }
- }
- /**
- * Submit handler for fgcf_filter_form().
- *
- * @param array $form
- * @param array $form_state
- *
- * @return void
- */
- function fgcf_filter_form_submit($form, &$form_state) {
- $form_state['storage']['modalite'] = $form_state['values']['modalite'];
- $form_state['storage']['dif'] = $form_state['values']['dif'];
- $_SESSION['fgcf'] = array(
- 'dif' => $form_state['storage']['dif'],
- 'modalite' => $form_state['storage']['modalite'],
- );
- }
- /**
- * Implements hook_nodeapi().
- *
- * @param object $node
- * @param string $op
- * @param mixed $a3
- * @param mixed $a4
- */
- function fgcf_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
- switch ($op) {
- case 'view':
- if ($a3 /* !teaser */ || !$a4 /* page */) {
- break;
- }
- drupal_add_css(drupal_get_path('module', 'fgcf') .'/theme/css/fgcf.css');
- switch ($node->type) {
- case 'fgcf_prestataire':
- $bc = drupal_get_breadcrumb();
- $bc[] = l(t('Catalogue formations'), 'fgcf');
- $bc[] = l(t('Organismes'), 'fgcf/organisme');
- drupal_set_breadcrumb($bc);
- break;
- case 'fgcf_fiche':
- $nat_config = variable_get('nat_config', NULL);
- $vid = isset($nat_config['types']['fgcf_thematique'])
- ? reset($nat_config['types']['fgcf_thematique'])
- : 0;
- unset($nat_config);
- $taxo2 = array();
- foreach ($node->taxonomy as $tid => $term) {
- if ($term->vid != $vid) {
- $taxo2[$tid] = $term;
- }
- else {
- $node->fgcf_scat = $term; // Single by configuration
- }
- }
- $node->taxonomy = $taxo2;
- unset($taxo2, $tid, $term);
- // Build cat/scat[/scat]* path
- $cats = array();
- $parents = taxonomy_get_parents($node->fgcf_scat->tid);
- foreach ($parents as $tid => $term) {
- $cats[] = $term;
- }
- $cats[] = $node->fgcf_scat;
- $node->content['fgcf_catpath'] = array(
- '#value' => theme('fgcf_thematiques', $cats),
- );
- $bc = drupal_get_breadcrumb();
- $bc[] = l(t('Catalogue formations'), 'fgcf');
- $bc[] = l(t('Thématiques'), 'fgcf/thematique');
- $bc[] = l($cats[0]->description, 'fgcf/thematique/'. $cats[0]->tid);
- $bc[] = l($cats[1]->description, 'fgcf/thematique/'. $cats[1]->tid);
- drupal_set_breadcrumb($bc);
- unset($cats, $parents, $tid, $term);
- break;
- }
- }
- }
- /**
- * Implements hook_perm().
- *
- * @return array
- */
- function fgcf_perm() {
- $ret = array(
- 'access course catalog',
- );
- return $ret;
- }
- /**
- * Implements hook_menu().
- *
- * @return array
- */
- function fgcf_menu() {
- $read_access = array('access course catalog');
- $items = array();
- $items['fgcf'] = array(
- 'title' => 'Catalogue Formations',
- 'page callback' => 'fgcf_page_home',
- 'access arguments' => $read_access,
- 'menu_name' => 'primary-links',
- );
- $items['fgcf/format'] = array(
- 'type' => MENU_CALLBACK,
- 'title' => 'Formations par format',
- 'page callback' => 'fgcf_page_format',
- 'access arguments' => $read_access,
- );
- $items['fgcf/organisme'] = array(
- 'type' => MENU_CALLBACK,
- 'title' => 'Formations par organisme',
- 'page callback' => 'fgcf_page_organisme',
- 'access arguments' => $read_access,
- );
- return $items;
- }
- function fgcf_page_format($format = 0) {
- $bc = drupal_get_breadcrumb();
- $bc[] = l(t('Catalogue formations'), 'fgcf');
- $filter_form = drupal_get_form('fgcf_filter_form');
- $ret = $filter_form;
- $vid = _fgcf_get_vocabulary_by_name('FGCF Format de cours');
- if (empty($format)) {
- $ret .= views_embed_view('fgcf_formats_de_formations', 'default', $vid);
- }
- else {
- $bc[] = l(t('Formats de formation'), 'fgcf/format');
- $term = taxonomy_get_term($format);
- if (!is_object($term) || !isset($term->vid) || $term->vid != $vid) {
- $format = 0;
- }
- $ret .= views_embed_view('fgcf_formations_par_format', 'default', $format);
- }
- drupal_set_breadcrumb($bc);
- return $ret;
- }
- function fgcf_page_organisme() {
- $bc = drupal_get_breadcrumb();
- $bc[] = l(t('Catalogue formations'), 'fgcf');
- drupal_set_breadcrumb($bc);
- $filter_form = drupal_get_form('fgcf_filter_form');
- $ret = $filter_form;
- $ret .= views_embed_view('fgcf_organismes_de_formation');
- return $ret;
- }
- /**
- * Page callback for fgcf.
- *
- * @return string
- */
- function fgcf_page_home() {
- drupal_add_css(drupal_get_path('module', 'fgcf') .'/theme/css/fgcf.css');
- drupal_set_title('Catalogue des formations France Galop');
- $filter_form = drupal_get_form('fgcf_filter_form');
- $ret = theme('fgcf_home', $filter_form);
- return $ret;
- }
- /**
- * Preprocess callback for theme('fgcf_home').
- *
- * @param unknown_type $variables
- *
- * @return void
- */
- function fgcf_preprocess_fgcf_home(&$variables) {
- $variables['app_path'] = url('fgcf');
- }
- /**
- * Implements hook_theme().
- *
- * @param array $existing
- * @param string $type
- * @param string $theme
- * @param string $path
- *
- * @return array
- */
- function fgcf_theme($existing, $type, $theme, $path) {
- $ret = array(
- 'fgcf_home' => array(
- 'arguments' => array('filter_form' => array()),
- 'template' => 'fgcf-home',
- 'path' => $path .'/theme',
- ),
- 'fgcf_thematiques' => array(
- 'arguments' => array('terms' => array()),
- ),
- /*
- 'fgcf_fiche_node_form' => array(
- 'arguments' => array('element' => NULL),
- 'template' => 'fgcf-fiche-node-form',
- 'path' => $path .'/theme',
- ),
- */
- );
- return $ret;
- }
- function fgcf_views_api() {
- $ret = array(
- 'api' => '3.0-alpha1',
- 'path' => drupal_get_path('module', 'fgcf') . '/views',
- );
- return $ret;
- }
- /**
- * Theme function for course themes.
- *
- * @param array $terms
- *
- * @return string
- */
- function theme_fgcf_thematiques($terms) {
- $items = array();
- foreach ($terms as $tid => $term) {
- $items[] = l($term->description, taxonomy_term_path($term));
- }
- // Build cat logo
- $cat_term = reset($terms);
- $nodes = nat_get_nids(array($cat_term->tid), TRUE);
- $cat_node = reset($nodes);
- $node_view = node_build_content($cat_node, FALSE, FALSE);
- $logo = drupal_render($node_view->content['field_fgcf_thematique_logo']);
- array_unshift($items, $logo);
- $ret = '<div class="node-thematique">'. theme('item_list', $items) .'</div>';
- return $ret;
- }
- /*
- function fgcf_features_api() {
- $ret = array(
- // 'fgcf_comp1' => array(
- // 'default_hook' => 'fgcf_comp1_defaults',
- // 'default_file' => FEATURES_DEFAULTS_INCLUDED,
- // 'features_source' => TRUE,
- // // 'file' => drupal_get_path('module', 'fgcf') .'/fgcf.features.inc',
- // ),
- );
- $ret = array(
- 'fgcf' => array(
- 'name' => t('FGCF Comp'),
- 'feature_source' => TRUE,
- 'default_hook' => 'fgcf_default_comp',
- )
- );
- // dsm($ret);
- return $ret;
- }
- function fgcf_fgcf_default_comp() {
- $ret = "Default comp";
- dsm(get_defined_vars(), __FUNCTION__);
- return $ret;
- }
- function fgcf_features_export($data, &$export, $module_name = '') {
- dsm(get_defined_vars());
- $export['features']['fgcf'] = $data;
- // On peut ajouter des entrées à $export['dependencies']
- // $module_name est le module vers lequel on exporte
- return array();
- }
- function fgcf_features_export_options() {
- dsm(get_defined_vars(), __FUNCTION__);
- $options = array(
- 'a', 'b', 'c',
- );
- return $options;
- }
- function fgcf_features_export_render($module_name = '', $data) {
- dsm(get_defined_vars());
- $ret = <<<EOT
- return "rendered $module_name" . var_export($data, TRUE) ;
- EOT;
- return $ret;
- }
- function fgcf_features_export_revert($module) {
- dsm("reverting $module");
- }
- function fgcf_features_export_rebuild($module) {
- dsm("export_rebuilding $module");
- }
- */
- /*
- function fgcf_link($type, $object, $teaser = FALSE) {
- // function fgcf_link_alter(&$links, $node, $comment = NULL) {
- if ($type != 'node' || $teaser) {
- return;
- }
- }
- */
- /*
- function fgcf_preprocess_fgcf_fiche_node_form(&$variables) {
- $element = &$variables['element'];
- $meta = &$element['group_fgcf_fiche_meta'];
- foreach (element_children($meta) as $name) {
- $variables['meta'][$name] = drupal_render($meta[$name]);
- }
- }
- */
- /*
- $x = (object) array(
- // 'nid' => 'new',
- // 'vid' => '32',
- // 'revision_uid' => '1',
- 'type' => 'fgcf_fiche',
- 'language' => '',
- // 'uid' => '1',
- 'status' => '1',
- // 'created' => '1278782394',
- // 'changed' => '1278794808',
- 'comment' => '0',
- 'promote' => '0',
- 'moderate' => '0',
- 'sticky' => '0',
- //'tnid' => '0',
- // 'translate' => '0',
- 'title' => 'Analyse des sols 3',
- 'body' => 'Analyser l\'influence du sol sur les végétaux
- Étudier la biologique du sol, l\'analyse de sol, le travail de sol
- Comprendre et connaître le pouvoir absorbant, point sur les constituants chimiques
- Proposer des solutions liées à l\'eau dans le sol (drainage, irrigation)
- Connaître et proposer les amendements
- Connaître et maîtriser la fertilisation
- ',
- 'teaser' => 'Analyser l\'influence du sol sur les végétaux
- Étudier la biologique du sol, l\'analyse de sol, le travail de sol
- Comprendre et connaître le pouvoir absorbant, point sur les constituants chimiques
- Proposer des solutions liées à l\'eau dans le sol (drainage, irrigation)
- Connaître et proposer les amendements
- Connaître et maîtriser la fertilisation
- ',
- // 'log' => '',
- // 'revision_timestamp' => '1278794708',
- 'format' => '1',
- // 'name' => 'd6root',
- // 'picture' => '',
- // 'data' => 'a:0:{}',
- 'field_fgcf_fiche_organisme' =>
- array (
- 0 =>
- array (
- 'nid' => '16',
- ),
- ),
- 'field_fgcf_fiche_reference' =>
- array (
- 0 =>
- array (
- 'value' => 'EH-EV-03',
- ),
- ),
- 'taxonomy' =>
- array (
- 13 =>
- (object) array(
- 'tid' => '13',
- 'vid' => '1',
- 'name' => 'EV',
- 'description' => 'Espaces Verts',
- 'weight' => '0',
- )),
- );
- $y = node_save($x);
- dsm($x);
- dsm($y);
- */
|