diff --git a/location_www.info b/location_www.info new file mode 100755 index 0000000..0dab120 --- /dev/null +++ b/location_www.info @@ -0,0 +1,16 @@ +name = Location www +package = Location +description = Allows you to add a www adress to a location. +dependencies[] = location +core = 7.x +files[] = location_www.module +files[] = location_www.install +files[] = location_www.views.inc + + +; Information added by drupal.org packaging script on 2012-07-25 +version = "7.x-3.0-alpha1" +core = "7.x" +project = "location" +datestamp = "1343220794" + diff --git a/location_www.install b/location_www.install new file mode 100755 index 0000000..dbdbab9 --- /dev/null +++ b/location_www.install @@ -0,0 +1,115 @@ + 'location_www.module {location} supplementary table.', + 'fields' => array( + 'lid' => array( + 'description' => '{location}.lid', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'www' => array( + 'description' => 'www adress', + 'type' => 'varchar', + 'length' => 31, + 'not null' => TRUE, + 'default' => '', + ), + ), + 'primary key' => array('lid'), + ); + + return $schema; +} + +/** + * Implements hook_install(). + */ +function location_www_install() { + // Change weight so we execute after location. + db_update('system') + ->fields(array( + 'weight' => 1, + )) + ->condition('name', 'location_www') + ->condition('type', 'module') + ->execute(); +} + +/** + * Location 3.0 update 1. + * Fix pgsql -- The table definition was broken. + */ +function location_www_update_5300() { + if (!db_table_exists('location_www')) { + $schema['location_www'] = array( + 'description' => 'location_www.module {location} supplementary table.', + 'fields' => array( + 'lid' => array( + 'description' => '{location}.lid', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'www' => array( + 'description' => 'www adress', + 'type' => 'varchar', + 'length' => 31, + 'not null' => TRUE, + 'default' => '', + ), + ), + 'primary key' => array('lid'), + ); + + db_create_table('location_www', $schema['location_www']); + } +} + +/** + * Location 3.0 update 2. + * Change weight of module. + */ +function location_www_update_5301() { + // This update was moved to update 5302. +} + +/** + * Location 3.0 update 2. + * Change weight of module. + */ +function location_www_update_5302() { + // Change weight. + db_update('system') + ->fields(array( + 'weight' => 1, + )) + ->condition('name', 'location_www') + ->condition('type', 'module') + ->execute(); +} + +/** + * Drupal 6 updates. + */ +function location_www_update_6301() { + db_change_field('location_www', 'www', 'www', array( + 'description' => 'www adress', + 'type' => 'varchar', + 'length' => 31, + 'not null' => TRUE, + 'default' => '', + )); +} diff --git a/location_www.module b/location_www.module new file mode 100755 index 0000000..71d3c2a --- /dev/null +++ b/location_www.module @@ -0,0 +1,80 @@ + t('www adress')); + + case 'defaults': + return array( + 'www' => array('default' => '', 'collect' => 0, 'weight' => 30), + ); + + case 'field_expand': + if ($a3 == 'www') { + return array( + '#type' => 'textfield', + '#title' => t('www adress'), + '#size' => 31, + '#maxlength' => 255, + '#description' => NULL, + '#required' => ($a4 == 2), + '#default_value' => $location, + ); + } + break; + + case 'save': + db_delete('location_www') + ->condition('lid', $location['lid']) + ->execute(); + if (!empty($location['www'])) { + db_insert('location_www') + ->fields(array( + 'lid' => $location['lid'], + 'www' => $location['www'], + )) + ->execute(); + } + break; + + case 'load': + $fields = array(); + $www = db_query('SELECT www FROM {location_www} WHERE lid = :lid', array(':lid' => $location['lid']))->fetchField(); + $fields['www'] = $www ? $www : ''; + return $fields; + + case 'delete': + db_delete('location_www') + ->condition('lid', $location['lid']) + ->execute(); + break; + } +} + +/** + * Implements hook_views_api(). + */ +function location_www_views_api() { + return array( + 'api' => 3, + ); +} + +/** + * Implements hook_token_list(). + */ +function location_www_token_list($type = 'all') { + if ($type == 'node' || $type == 'user' || $type == 'all') { + $tokens['location']['location-www_N'] = t('Location www adress (If there are multiple locations per node, N is the iteration, starting with 0)'); + return $tokens; + } +} diff --git a/location_www.views.inc b/location_www.views.inc new file mode 100755 index 0000000..6c792bb --- /dev/null +++ b/location_www.views.inc @@ -0,0 +1,67 @@ + array( + 'left_field' => 'lid', + 'field' => 'lid', + ), + // location_www links to node through location_instance via lid. + 'node' => array( + 'left_table' => 'location_instance', + 'left_field' => 'lid', + 'field' => 'lid', + ), + // location_www links to node_revision through location_instance via lid. + 'node_revision' => array( + 'left_table' => 'location_instance', + 'left_field' => 'lid', + 'field' => 'lid', + ), + // location_www links to users through location_instance via lid. + 'users' => array( + 'left_table' => 'location_instance', + 'left_field' => 'lid', + 'field' => 'lid', + ), + ); + + // ---------------------------------------------------------------- + // location_www table -- fields + + $data['location_www']['www'] = array( + 'title' => t('www'), + 'help' => t('The www number of the selected location.'), + 'field' => array( + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + 'empty field name' => t('None'), + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + 'allow empty' => TRUE, + ), + ); + + return $data; +}