Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vnfish_menu() {
- $items['records'] = array(
- 'title' => "Record list",
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('record_list_form'),
- 'access arguments' => array('access content'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => "model/vnfish.model.inc",
- );
- return $items;
- }
- /**
- * Show list of record
- * @return theme
- */
- function record_list_form() {
- drupal_add_css(drupal_get_path('module', 'vnfish') . '/stylecss.css', array('group' => CSS_DEFAULT, 'type' => 'file'));
- // Set header
- $header = array(
- array('data' => t('Title'), 'field' => 'title', 'sort' => 'asc'),
- array('data' => t('Summery'), 'field' => 'summery'),
- array('data' => t('Content'), 'field' => 'content'),
- array('data' => t('Status'), 'field' => 'status'),
- array('data' => t('Created / Modified'), 'field' => 'created'),
- array('data' => t('Action')),
- );
- $header = array(
- 'title' => array('data' => t('Title'), 'field' => 'title'),
- 'summery' => array('data' => t('Summery'), 'field' => 'summery'),
- 'content' => array('data' => t('Content'), 'field' => 'content'),
- 'status' => array('data' => t('Status'), 'field' => 'status'),
- 'status' => array('data' => t('Status'), 'field' => 'status'),
- 'created' => array('data' => t('Created / Modified'), 'field' => 'created'),
- 'operations' => array('data' => t('Operations')),
- );
- // , 'class' => $node->status ? 'published' : 'unpublished'
- // Next create Sql query to be executed which returns the sorted and paged results from the database
- $query = db_select('vnfish', 'a')
- // ->condition('a.status', 1) //Only published nodes, change condition as it suits you
- ->extend('PagerDefault') //Pager Extender
- ->limit(5) //5 results per page
- ->extend('TableSort') //Sorting Extender
- ->orderByHeader($header)//Field to sort on is picked from $header
- ->fields('a', array(
- 'id',
- 'title',
- 'summery',
- 'content',
- 'status',
- 'created',
- 'modified',
- ));
- // The next step is executing the query and collecting the rows from the resultset.
- $results = $query->execute();
- $rows = array();
- $i = 0;
- foreach ($results as $k => $node) {
- $rows[$node->id] = array(
- 'title' => l($node->title, 'records/' . $node->id . '/edit'),
- 'summery' => t($node->summery),
- 'content' => t($node->content),
- 'status' => array('data' => ' ', 'class' => $node->status ? 'published' : 'unpublished'),
- 'created' => array(
- 'data' => $node->modified ? format_date($node->modified) : ($node->created ? format_date($node->created) : "___, __/__/____ - __:__"),
- 'style' => ($node->modified || $node->created) ? "" : "color: silver;"
- ),
- );
- $destination = drupal_get_destination();
- // Build a list of all the accessible operations for the current node.
- $operations = array();
- $operations['edit'] = array(
- 'title' => t('edit'),
- 'href' => 'records/' . $node->id . '/edit',
- // 'query' => $destination,
- );
- $operations['delete'] = array(
- 'title' => t('delete'),
- 'href' => 'records/' . $node->id . '/delete',
- // 'query' => $destination,
- );
- $rows[$node->id]['operations'] = array();
- if (count($operations) > 1) {
- // Render an unordered list of operations links.
- $rows[$node->id]['operations'] = array(
- 'data' => array(
- '#theme' => 'links__node_operations',
- '#links' => $operations,
- '#attributes' => array('class' => array('links', 'inline')),
- ),
- );
- } elseif (!empty($operations)) {
- // Render the first and only operation as a link.
- $link = reset($operations);
- $rows[$node->id]['operations'] = array(
- 'data' => array(
- '#type' => 'link',
- '#title' => $link['title'],
- '#href' => $link['href'],
- '#options' => array('query' => $link['query']),
- ),
- );
- }
- }
- $admin_access = user_access('administer nodes');
- $form['options'] = array(
- '#type' => 'fieldset',
- '#title' => t('Action options'),
- '#attributes' => array('class' => array('container-inline')),
- '#access' => $admin_access,
- );
- $options = array();
- $options['vnfish_record_publish'] = "Publish";
- $options['vnfish_record_unpublish'] = "Unpublish";
- $options['vnfish_record_remove'] = "Remove";
- $form['options']['operation'] = array(
- '#type' => 'select',
- '#title' => t('Operation'),
- '#title_display' => 'invisible',
- '#options' => $options,
- '#default_value' => 'approve',
- );
- $form['options']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Go'),
- '#submit' => array('vnfish_record_update'),
- );
- $form['options']['add'] = array(
- '#type' => 'submit',
- '#value' => t('Add'),
- '#submit' => array('vnfish_form_record_add'),
- );
- $form['ids'] = array(
- '#type' => 'tableselect',
- '#header' => $header,
- '#options' => $rows,
- '#empty' => t('No content available.'),
- );
- $form['pager'] = array('#markup' => theme('pager'));
- // $table_attributes = array('id' => 'my-table');
- //
- // // Then, we create a table from the headers and the result rows with a simple call to theme (or theme_table methods):
- // $html = theme('table', array(
- // 'header' => $header,
- // 'rows' => $rows,
- // 'caption' => 'My Table', //Optional Caption for the table
- // 'sticky' => TRUE, //Optional to indicate whether the table headers should be sticky
- // 'empty' => 'No record created...', //Optional empty text for the table if resultset is empty
- // 'attributes' => $table_attributes, //Separating Rows
- // )
- // );
- //
- // // The final step is to append a pager to the table.
- // $html .= theme('pager', array(
- // 'tags' => array()
- // )
- // );
- // $html .= drupal_render(drupal_get_form("vnfish_form_record_add"));
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement