Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $form['filter'] = array(
- '#type' => 'fieldset',
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#title' => t('Filtres')
- );
- $form['filter']['filter_mail'] = array(
- '#type' => 'textfield',
- '#title' => t('Email'),
- '#size' => 15,
- );
- $form['filter']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Filtrer'),
- '#submit' => array('modulename_people_search_submit'),
- );
- // BUILD HEADER ARRAY
- $header = array(
- array('data' => t('Nom'), 'field' => 'nom.field_profile_nom_value'),
- array('data' => t('Prénom'), 'field' => 'prenom.field_profile_prenom_value'),
- array('data' => t('Email'), 'field' => 'u.mail'),
- );
- // BUILD QUERY
- $query = db_select('users', 'u')->extend('PagerDefault')->extend('TableSort');
- $query->leftJoin('field_data_field_profile_nom', 'nom', 'u.uid = nom.entity_id');
- $query->leftJoin('field_data_field_profile_prenom', 'prenom', 'u.uid = prenom.entity_id');
- $query->condition('u.uid', 0, '>');
- // GET CONDITIONAL FILTER VALUE
- if(isset($form_state['filters']['mail'])) {
- $query->condition('u.mail', '%' . db_like($form_state['filters']['mail']) . '%', 'LIKE');
- $exportMail = $form_state['filters']['mail'];
- }
- // FIELDS
- $query->fields('u', array('uid', 'mail', 'login', 'status'))
- ->fields('nom', array('field_profile_nom_value'))
- ->fields('prenom', array('field_profile_prenom_value'));
- // GET RESULTS
- $result = $query->limit(30)->orderByHeader($header)->execute();
- // BUILD DATA ARRAY
- $rows = array();
- foreach($result as $data){
- $rows[] = array(
- $data->field_profile_nom_value,
- $data->field_profile_prenom_value,
- $data->mail,
- );
- }
- // ASSEMBLE DATA IN TABLE
- $form['table'] = array(
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- '#empty' => t('Aucun résultat.')
- );
- // ADD PAGER
- $form['pager'] = array('#markup' => theme('pager'));
- return $form;
- function modulename_people_search_submit($form, &$form_state) {
- $form_state['filters']['mail'] = $form_state['values']['filter_mail'];
- $form_state['rebuild'] = TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement