fgcf.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Non-features part of FGCF
  6. */
  7. include_once('fgcf.features.inc');
  8. /**
  9. * Helper: get a vocabulary ID from its name.
  10. *
  11. * @param string $name
  12. */
  13. function _fgcf_get_vocabulary_by_name($name) {
  14. $vocabularies = taxonomy_get_vocabularies();
  15. $ret = 0;
  16. foreach ($vocabularies as $vid => $vocabulary) {
  17. if (drupal_strtolower($vocabulary->name) == drupal_strtolower($name)) {
  18. $ret = $vid;
  19. break;
  20. }
  21. }
  22. return $ret;
  23. }
  24. /**
  25. * Shared filter form for course lists.
  26. *
  27. * Filter values are taken from the form logic or, when absent, from the
  28. * session, in order for them to be persistent across non-form pages.
  29. *
  30. * @return array
  31. */
  32. function fgcf_filter_form($form_state) {
  33. $form['filtre'] = array(
  34. '#title' => t('Filtrer les formations'),
  35. '#attributes' => array('class' => 'fgcf-filtre'),
  36. '#type' => 'fieldset',
  37. '#collapsible' => TRUE,
  38. );
  39. $dif = isset($form_state['storage']['dif'])
  40. ? $form_state['storage']['dif']
  41. : isset($_SESSION['fgcf']['dif'])
  42. ? $_SESSION['fgcf']['dif']
  43. : FALSE;
  44. $form['filtre']['dif'] = array(
  45. '#type' => 'checkbox',
  46. '#default_value' => $dif,
  47. '#title' => t('Eligibles DIF'),
  48. );
  49. $modalite = isset($form_state['storage']['modalite'])
  50. ? $form_state['storage']['modalite']
  51. : isset($_SESSION['fgcf']['modalite'])
  52. ? $_SESSION['fgcf']['modalite']
  53. : array();
  54. $form['filtre']['modalite'] = array(
  55. '#title' => t('Modalité'),
  56. '#type' => 'checkboxes',
  57. '#options' => array(
  58. 'inter' => t('Inter-entreprises'),
  59. 'intra' => t('Intra-entreprise'),
  60. 'autres' => t('Autres'),
  61. ),
  62. '#default_value' => $modalite,
  63. );
  64. $form['filtre']['submit'] = array(
  65. '#type' => 'submit',
  66. '#value' => t('Appliquer le filtre'),
  67. );
  68. return $form;
  69. }
  70. function fgcf_init() {
  71. if (arg(0) == 'fgcf') {
  72. drupal_add_css(drupal_get_path('module', 'fgcf') .'/theme/css/fgcf.css');
  73. }
  74. }
  75. /**
  76. * Submit handler for fgcf_filter_form().
  77. *
  78. * @param array $form
  79. * @param array $form_state
  80. *
  81. * @return void
  82. */
  83. function fgcf_filter_form_submit($form, &$form_state) {
  84. $form_state['storage']['modalite'] = $form_state['values']['modalite'];
  85. $form_state['storage']['dif'] = $form_state['values']['dif'];
  86. $_SESSION['fgcf'] = array(
  87. 'dif' => $form_state['storage']['dif'],
  88. 'modalite' => $form_state['storage']['modalite'],
  89. );
  90. }
  91. /**
  92. * Implements hook_nodeapi().
  93. *
  94. * @param object $node
  95. * @param string $op
  96. * @param mixed $a3
  97. * @param mixed $a4
  98. */
  99. function fgcf_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  100. switch ($op) {
  101. case 'view':
  102. if ($a3 /* !teaser */ || !$a4 /* page */) {
  103. break;
  104. }
  105. drupal_add_css(drupal_get_path('module', 'fgcf') .'/theme/css/fgcf.css');
  106. switch ($node->type) {
  107. case 'fgcf_prestataire':
  108. $bc = drupal_get_breadcrumb();
  109. $bc[] = l(t('Catalogue formations'), 'fgcf');
  110. $bc[] = l(t('Organismes'), 'fgcf/organisme');
  111. drupal_set_breadcrumb($bc);
  112. break;
  113. case 'fgcf_fiche':
  114. $nat_config = variable_get('nat_config', NULL);
  115. $vid = isset($nat_config['types']['fgcf_thematique'])
  116. ? reset($nat_config['types']['fgcf_thematique'])
  117. : 0;
  118. unset($nat_config);
  119. $taxo2 = array();
  120. foreach ($node->taxonomy as $tid => $term) {
  121. if ($term->vid != $vid) {
  122. $taxo2[$tid] = $term;
  123. }
  124. else {
  125. $node->fgcf_scat = $term; // Single by configuration
  126. }
  127. }
  128. $node->taxonomy = $taxo2;
  129. unset($taxo2, $tid, $term);
  130. // Build cat/scat[/scat]* path
  131. $cats = array();
  132. $parents = taxonomy_get_parents($node->fgcf_scat->tid);
  133. foreach ($parents as $tid => $term) {
  134. $cats[] = $term;
  135. }
  136. $cats[] = $node->fgcf_scat;
  137. $node->content['fgcf_catpath'] = array(
  138. '#value' => theme('fgcf_thematiques', $cats),
  139. );
  140. $bc = drupal_get_breadcrumb();
  141. $bc[] = l(t('Catalogue formations'), 'fgcf');
  142. $bc[] = l(t('Thématiques'), 'fgcf/thematique');
  143. $bc[] = l($cats[0]->description, 'fgcf/thematique/'. $cats[0]->tid);
  144. $bc[] = l($cats[1]->description, 'fgcf/thematique/'. $cats[1]->tid);
  145. drupal_set_breadcrumb($bc);
  146. unset($cats, $parents, $tid, $term);
  147. break;
  148. }
  149. }
  150. }
  151. /**
  152. * Implements hook_perm().
  153. *
  154. * @return array
  155. */
  156. function fgcf_perm() {
  157. $ret = array(
  158. 'access course catalog',
  159. );
  160. return $ret;
  161. }
  162. /**
  163. * Implements hook_menu().
  164. *
  165. * @return array
  166. */
  167. function fgcf_menu() {
  168. $read_access = array('access course catalog');
  169. $items = array();
  170. $items['fgcf'] = array(
  171. 'title' => 'Catalogue Formations',
  172. 'page callback' => 'fgcf_page_home',
  173. 'access arguments' => $read_access,
  174. 'menu_name' => 'primary-links',
  175. );
  176. $items['fgcf/format'] = array(
  177. 'type' => MENU_CALLBACK,
  178. 'title' => 'Formations par format',
  179. 'page callback' => 'fgcf_page_format',
  180. 'access arguments' => $read_access,
  181. );
  182. $items['fgcf/organisme'] = array(
  183. 'type' => MENU_CALLBACK,
  184. 'title' => 'Formations par organisme',
  185. 'page callback' => 'fgcf_page_organisme',
  186. 'access arguments' => $read_access,
  187. );
  188. return $items;
  189. }
  190. function fgcf_page_format($format = 0) {
  191. $bc = drupal_get_breadcrumb();
  192. $bc[] = l(t('Catalogue formations'), 'fgcf');
  193. $filter_form = drupal_get_form('fgcf_filter_form');
  194. $ret = $filter_form;
  195. $vid = _fgcf_get_vocabulary_by_name('FGCF Format de cours');
  196. if (empty($format)) {
  197. $ret .= views_embed_view('fgcf_formats_de_formations', 'default', $vid);
  198. }
  199. else {
  200. $bc[] = l(t('Formats de formation'), 'fgcf/format');
  201. $term = taxonomy_get_term($format);
  202. if (!is_object($term) || !isset($term->vid) || $term->vid != $vid) {
  203. $format = 0;
  204. }
  205. $ret .= views_embed_view('fgcf_formations_par_format', 'default', $format);
  206. }
  207. drupal_set_breadcrumb($bc);
  208. return $ret;
  209. }
  210. function fgcf_page_organisme() {
  211. $bc = drupal_get_breadcrumb();
  212. $bc[] = l(t('Catalogue formations'), 'fgcf');
  213. drupal_set_breadcrumb($bc);
  214. $filter_form = drupal_get_form('fgcf_filter_form');
  215. $ret = $filter_form;
  216. $ret .= views_embed_view('fgcf_organismes_de_formation');
  217. return $ret;
  218. }
  219. /**
  220. * Page callback for fgcf.
  221. *
  222. * @return string
  223. */
  224. function fgcf_page_home() {
  225. drupal_add_css(drupal_get_path('module', 'fgcf') .'/theme/css/fgcf.css');
  226. drupal_set_title('Catalogue des formations France Galop');
  227. $filter_form = drupal_get_form('fgcf_filter_form');
  228. $ret = theme('fgcf_home', $filter_form);
  229. return $ret;
  230. }
  231. /**
  232. * Preprocess callback for theme('fgcf_home').
  233. *
  234. * @param unknown_type $variables
  235. *
  236. * @return void
  237. */
  238. function fgcf_preprocess_fgcf_home(&$variables) {
  239. $variables['app_path'] = url('fgcf');
  240. }
  241. /**
  242. * Implements hook_theme().
  243. *
  244. * @param array $existing
  245. * @param string $type
  246. * @param string $theme
  247. * @param string $path
  248. *
  249. * @return array
  250. */
  251. function fgcf_theme($existing, $type, $theme, $path) {
  252. $ret = array(
  253. 'fgcf_home' => array(
  254. 'arguments' => array('filter_form' => array()),
  255. 'template' => 'fgcf-home',
  256. 'path' => $path .'/theme',
  257. ),
  258. 'fgcf_thematiques' => array(
  259. 'arguments' => array('terms' => array()),
  260. ),
  261. /*
  262. 'fgcf_fiche_node_form' => array(
  263. 'arguments' => array('element' => NULL),
  264. 'template' => 'fgcf-fiche-node-form',
  265. 'path' => $path .'/theme',
  266. ),
  267. */
  268. );
  269. return $ret;
  270. }
  271. function fgcf_views_api() {
  272. $ret = array(
  273. 'api' => '3.0-alpha1',
  274. 'path' => drupal_get_path('module', 'fgcf') . '/views',
  275. );
  276. return $ret;
  277. }
  278. /**
  279. * Theme function for course themes.
  280. *
  281. * @param array $terms
  282. *
  283. * @return string
  284. */
  285. function theme_fgcf_thematiques($terms) {
  286. $items = array();
  287. foreach ($terms as $tid => $term) {
  288. $items[] = l($term->description, taxonomy_term_path($term));
  289. }
  290. // Build cat logo
  291. $cat_term = reset($terms);
  292. $nodes = nat_get_nids(array($cat_term->tid), TRUE);
  293. $cat_node = reset($nodes);
  294. $node_view = node_build_content($cat_node, FALSE, FALSE);
  295. $logo = drupal_render($node_view->content['field_fgcf_thematique_logo']);
  296. array_unshift($items, $logo);
  297. $ret = '<div class="node-thematique">'. theme('item_list', $items) .'</div>';
  298. return $ret;
  299. }
  300. /*
  301. function fgcf_features_api() {
  302. $ret = array(
  303. // 'fgcf_comp1' => array(
  304. // 'default_hook' => 'fgcf_comp1_defaults',
  305. // 'default_file' => FEATURES_DEFAULTS_INCLUDED,
  306. // 'features_source' => TRUE,
  307. // // 'file' => drupal_get_path('module', 'fgcf') .'/fgcf.features.inc',
  308. // ),
  309. );
  310. $ret = array(
  311. 'fgcf' => array(
  312. 'name' => t('FGCF Comp'),
  313. 'feature_source' => TRUE,
  314. 'default_hook' => 'fgcf_default_comp',
  315. )
  316. );
  317. // dsm($ret);
  318. return $ret;
  319. }
  320. function fgcf_fgcf_default_comp() {
  321. $ret = "Default comp";
  322. dsm(get_defined_vars(), __FUNCTION__);
  323. return $ret;
  324. }
  325. function fgcf_features_export($data, &$export, $module_name = '') {
  326. dsm(get_defined_vars());
  327. $export['features']['fgcf'] = $data;
  328. // On peut ajouter des entrées à $export['dependencies']
  329. // $module_name est le module vers lequel on exporte
  330. return array();
  331. }
  332. function fgcf_features_export_options() {
  333. dsm(get_defined_vars(), __FUNCTION__);
  334. $options = array(
  335. 'a', 'b', 'c',
  336. );
  337. return $options;
  338. }
  339. function fgcf_features_export_render($module_name = '', $data) {
  340. dsm(get_defined_vars());
  341. $ret = <<<EOT
  342. return "rendered $module_name" . var_export($data, TRUE) ;
  343. EOT;
  344. return $ret;
  345. }
  346. function fgcf_features_export_revert($module) {
  347. dsm("reverting $module");
  348. }
  349. function fgcf_features_export_rebuild($module) {
  350. dsm("export_rebuilding $module");
  351. }
  352. */
  353. /*
  354. function fgcf_link($type, $object, $teaser = FALSE) {
  355. // function fgcf_link_alter(&$links, $node, $comment = NULL) {
  356. if ($type != 'node' || $teaser) {
  357. return;
  358. }
  359. }
  360. */
  361. /*
  362. function fgcf_preprocess_fgcf_fiche_node_form(&$variables) {
  363. $element = &$variables['element'];
  364. $meta = &$element['group_fgcf_fiche_meta'];
  365. foreach (element_children($meta) as $name) {
  366. $variables['meta'][$name] = drupal_render($meta[$name]);
  367. }
  368. }
  369. */
  370. /*
  371. $x = (object) array(
  372. // 'nid' => 'new',
  373. // 'vid' => '32',
  374. // 'revision_uid' => '1',
  375. 'type' => 'fgcf_fiche',
  376. 'language' => '',
  377. // 'uid' => '1',
  378. 'status' => '1',
  379. // 'created' => '1278782394',
  380. // 'changed' => '1278794808',
  381. 'comment' => '0',
  382. 'promote' => '0',
  383. 'moderate' => '0',
  384. 'sticky' => '0',
  385. //'tnid' => '0',
  386. // 'translate' => '0',
  387. 'title' => 'Analyse des sols 3',
  388. 'body' => 'Analyser l\'influence du sol sur les végétaux
  389. Étudier la biologique du sol, l\'analyse de sol, le travail de sol
  390. Comprendre et connaître le pouvoir absorbant, point sur les constituants chimiques
  391. Proposer des solutions liées à l\'eau dans le sol (drainage, irrigation)
  392. Connaître et proposer les amendements
  393. Connaître et maîtriser la fertilisation
  394. ',
  395. 'teaser' => 'Analyser l\'influence du sol sur les végétaux
  396. Étudier la biologique du sol, l\'analyse de sol, le travail de sol
  397. Comprendre et connaître le pouvoir absorbant, point sur les constituants chimiques
  398. Proposer des solutions liées à l\'eau dans le sol (drainage, irrigation)
  399. Connaître et proposer les amendements
  400. Connaître et maîtriser la fertilisation
  401. ',
  402. // 'log' => '',
  403. // 'revision_timestamp' => '1278794708',
  404. 'format' => '1',
  405. // 'name' => 'd6root',
  406. // 'picture' => '',
  407. // 'data' => 'a:0:{}',
  408. 'field_fgcf_fiche_organisme' =>
  409. array (
  410. 0 =>
  411. array (
  412. 'nid' => '16',
  413. ),
  414. ),
  415. 'field_fgcf_fiche_reference' =>
  416. array (
  417. 0 =>
  418. array (
  419. 'value' => 'EH-EV-03',
  420. ),
  421. ),
  422. 'taxonomy' =>
  423. array (
  424. 13 =>
  425. (object) array(
  426. 'tid' => '13',
  427. 'vid' => '1',
  428. 'name' => 'EV',
  429. 'description' => 'Espaces Verts',
  430. 'weight' => '0',
  431. )),
  432. );
  433. $y = node_save($x);
  434. dsm($x);
  435. dsm($y);
  436. */