You are here

sgrid.module in Sortable Grid Views Plugin 6

Same filename and directory in other branches
  1. 7 sgrid.module

File

sgrid.module
View source
<?php

global $base_url;
require_once realpath('./') . '/' . drupal_get_path('module', 'sgrid') . '/sgrid_theme.inc';

/**
* Implementation of hook_views_api().
* @return Array with Views API version.
*/
function sgrid_views_api() {
  return array(
    'api' => 3.0,
  );
}
function sgrid_perm() {
  return array(
    'sort Sortable Grid Views',
  );
}

/**
 * Build the form
 */
function form_save_order($form, $viewname) {
  $form = array();
  $form['viewdisplay'] = array(
    '#type' => 'hidden',
    '#value' => $viewname,
  );
  $form['itemsorder'] = array(
    '#type' => 'textfield',
    '#maxlength' => 1000,
    '#attributes' => array(
      'class' => 'sortorder',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save order'),
  );
  return $form;
}
function form_save_order_submit($form, $form_state) {
  db_query("DELETE FROM {sgrid} WHERE view_display = '%s'", $form_state['values']['viewdisplay']);
  foreach (explode(',', $form_state['values']['itemsorder']) as $index => $name) {
    $nid = substr(strrchr($name, '_'), 1);
    db_query("INSERT INTO {sgrid} (nid, rank, view_display) VALUES (%d, %d, '%s')", $nid, $index, $form_state['values']['viewdisplay']);
  }
}

Functions

Namesort descending Description
form_save_order Build the form
form_save_order_submit
sgrid_perm
sgrid_views_api Implementation of hook_views_api().

Globals

Namesort descending Description
$base_url