Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. $form['filter'] = array(
  2. '#type' => 'fieldset',
  3. '#collapsible' => TRUE,
  4. '#collapsed' => FALSE,
  5. '#title' => t('Filtres')
  6. );
  7.  
  8. $form['filter']['filter_mail'] = array(
  9. '#type' => 'textfield',
  10. '#title' => t('Email'),
  11. '#size' => 15,
  12. );
  13. $form['filter']['submit'] = array(
  14. '#type' => 'submit',
  15. '#value' => t('Filtrer'),
  16. '#submit' => array('modulename_people_search_submit'),
  17. );
  18.  
  19. // BUILD HEADER ARRAY
  20. $header = array(
  21. array('data' => t('Nom'), 'field' => 'nom.field_profile_nom_value'),
  22. array('data' => t('Prénom'), 'field' => 'prenom.field_profile_prenom_value'),
  23. array('data' => t('Email'), 'field' => 'u.mail'),
  24. );
  25.  
  26. // BUILD QUERY
  27. $query = db_select('users', 'u')->extend('PagerDefault')->extend('TableSort');
  28.  
  29. $query->leftJoin('field_data_field_profile_nom', 'nom', 'u.uid = nom.entity_id');
  30. $query->leftJoin('field_data_field_profile_prenom', 'prenom', 'u.uid = prenom.entity_id');
  31.  
  32. $query->condition('u.uid', 0, '>');
  33.  
  34. // GET CONDITIONAL FILTER VALUE
  35. if(isset($form_state['filters']['mail'])) {
  36. $query->condition('u.mail', '%' . db_like($form_state['filters']['mail']) . '%', 'LIKE');
  37. $exportMail = $form_state['filters']['mail'];
  38. }
  39.  
  40. // FIELDS
  41. $query->fields('u', array('uid', 'mail', 'login', 'status'))
  42. ->fields('nom', array('field_profile_nom_value'))
  43. ->fields('prenom', array('field_profile_prenom_value'));
  44.  
  45. // GET RESULTS
  46. $result = $query->limit(30)->orderByHeader($header)->execute();
  47.  
  48. // BUILD DATA ARRAY
  49. $rows = array();
  50. foreach($result as $data){
  51. $rows[] = array(
  52. $data->field_profile_nom_value,
  53. $data->field_profile_prenom_value,
  54. $data->mail,
  55. );
  56. }
  57.  
  58. // ASSEMBLE DATA IN TABLE
  59. $form['table'] = array(
  60. '#theme' => 'table',
  61. '#header' => $header,
  62. '#rows' => $rows,
  63. '#empty' => t('Aucun résultat.')
  64. );
  65.  
  66. // ADD PAGER
  67. $form['pager'] = array('#markup' => theme('pager'));
  68. return $form;
  69.  
  70. function modulename_people_search_submit($form, &$form_state) {
  71. $form_state['filters']['mail'] = $form_state['values']['filter_mail'];
  72. $form_state['rebuild'] = TRUE;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement