Created
January 6, 2012 06:13
-
-
Save kumarmanish/1569290 to your computer and use it in GitHub Desktop.
Expose the table to view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implementation of hook_views_data(). | |
*/ | |
function reman_views_data() { | |
$data = array(); | |
// Table names | |
$data['realtsoft_captured_leads'] ['table']['group'] = t('RealTSoft Captured Leads'); | |
$data['realtsoft_licenses'] ['table']['group'] = t('RealTSoft Licenses'); | |
$data['realtsoft_applications'] ['table']['group'] = t('RealTSoft Applications'); | |
$data['realtsoft_applications_licenses'] ['table']['group'] = t('RealTSoft Application to License Mappings'); | |
$data['realtsoft_device_activations'] ['table']['group'] = t('RealTSoft Device Activations'); | |
$data['realtsoft_property_searches'] ['table']['group'] = t('RealTSoft Saved Property Searches'); | |
$data['realtsoft_rets_import_report'] ['table']['group'] = t('RealTSoft RETS Import Records'); | |
$data['realtsoft_activity_log'] ['table']['group'] = t('RealTSoft Activity Log'); | |
// Describe base tables | |
$data['realtsoft_captured_leads']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Captured Leads'), | |
'help' => t("Table containing leads captured through RealTSoft software"), | |
'weight' => -10, | |
); | |
$data['realtsoft_applications']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Applications'), | |
'help' => t("Table containing application instances and configurations for RealTSoft software"), | |
'weight' => -10, | |
); | |
$data['realtsoft_applications_licenses']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Applications-Licenses Mapping'), | |
'help' => t("Table containing application to license mappings for RealTSoft software"), | |
'weight' => -10, | |
); | |
$data['realtsoft_licenses']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Licenses'), | |
'help' => t("Table containing license keys and configurations for RealTSoft products"), | |
'weight' => -10, | |
); | |
$data['realtsoft_device_activations']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Device Activations'), | |
'help' => t("Table containing activation information for RealTSoft software installations"), | |
'weight' => -10, | |
); | |
$data['realtsoft_property_searches']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Device Activations'), | |
'help' => t("Table containing Saved Searches from property search form"), | |
'weight' => -10, | |
); | |
$data['realtsoft_rets_import_report']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft RETS Import Records'), | |
'help' => t("Table containing recods of all mls import and listings modifications details"), | |
'weight' => -10, | |
); | |
$data['realtsoft_activity_log']['table']['base'] = array( | |
'field' => 'id', | |
'title' => t('RealTSoft Activity Log'), | |
'help' => t("Table containing recods of all error and activity information in RTS app"), | |
'weight' => -10, | |
); | |
// JOINs | |
_realtsoft_create_join($data, 'realtsoft_captured_leads', 'office_nid', 'node', 'nid'); | |
_realtsoft_create_join($data, 'realtsoft_captured_leads', 'agent_uid', 'users', 'uid'); | |
_realtsoft_create_join($data, 'realtsoft_licenses', 'office_nid', 'node', 'nid'); | |
_realtsoft_create_join($data, 'realtsoft_licenses', 'id', 'realtsoft_applications_licenses', 'license_id'); | |
_realtsoft_create_join($data, 'realtsoft_licenses', 'id', 'realtsoft_device_activations', 'license_id'); | |
_realtsoft_create_join($data, 'realtsoft_applications', 'id', 'realtsoft_applications_licenses', 'application_id'); | |
// $data['realtsoft_device_activations']['table']['join'] = array( | |
// 'realtsoft_licenses' => array( | |
// 'left_field' => 'id', | |
// 'field' => 'license_id', | |
// ), | |
// ); | |
/** | |
* DESCRIBE FIELDS | |
*/ | |
$data['realtsoft_captured_leads']['id'] = _realtsoft_views_field_number(t('ID'), t('Unique ID of the captured lead.')); | |
$data['realtsoft_captured_leads']['customer_uid'] = _realtsoft_views_field_user(t('Customer UID'), t('Drupal user ID of the customer')); | |
$data['realtsoft_captured_leads']['customer_uid']['relationship']['title'] = t('Customer User Account'); | |
$data['realtsoft_captured_leads']['customer_uid']['relationship']['help'] = t('The user account connected to this captured lead'); | |
_realtsoft_views_field_add_relationship( | |
$data['realtsoft_captured_leads']['customer_uid'], 'users', 'uid', t('Customer User Account'), t('The user account of the customer connected to this captured lead')); | |
$data['realtsoft_captured_leads']['office_nid'] = _realtsoft_views_field_node(t('Office NID'), t('Drupal node ID of the real estate office')); | |
$data['realtsoft_captured_leads']['office_nid']['relationship']['title'] = t('Real Estate Office Node'); | |
$data['realtsoft_captured_leads']['office_nid']['relationship']['help'] = t('The Drupal node representing the real estate office that owns this captured lead'); | |
$data['realtsoft_captured_leads']['agent_uid'] = _realtsoft_views_field_user(t('Agent UID'), t('Drupal user ID of the real estate agent')); | |
_realtsoft_views_field_add_relationship( | |
$data['realtsoft_captured_leads']['agent_uid'], 'users', 'uid', t('Agent User Account'), t('The user account of the real estate agent connected to this captured lead')); | |
$data['realtsoft_captured_leads']['property_id'] = _realtsoft_views_field_node(t('Property NID'), t('Drupal node ID of the property')); | |
$data['realtsoft_captured_leads']['property_id']['relationship']['title'] = t('Property Node'); | |
$data['realtsoft_captured_leads']['property_id']['relationship']['help'] = t('The Drupal node representing the real estate property connected to this captured lead'); | |
$data['realtsoft_captured_leads']['created'] = _realtsoft_views_field_timestamp(t('Captured On'), t('Timestamp when lead was captured')); | |
$data['realtsoft_captured_leads']['ip'] = _realtsoft_views_field_string(t('IP Address'), t('IP address of the device that captured the lead')); | |
$data['realtsoft_captured_leads']['device_type'] = _realtsoft_views_field_string(t('Device Type'), t('The type of device that captured the lead')); | |
$data['realtsoft_captured_leads']['installation_guid'] = _realtsoft_views_field_string(t('Installation GUID'), t('Installation GUID of the application on the device that captured the lead')); | |
$data['realtsoft_captured_leads']['user_agent'] = _realtsoft_views_field_string(t('User Agent'), t('User agent string from the device that captured the lead')); | |
$data['realtsoft_captured_leads']['name'] = _realtsoft_views_field_string(t('Name'), t('First and last name of the captured lead')); | |
$data['realtsoft_captured_leads']['email'] = _realtsoft_views_field_string(t('Email Address'), t('Email address of the captured lead')); | |
$data['realtsoft_captured_leads']['phone'] = _realtsoft_views_field_string(t('Phone'), t('Phone number of the captured lead')); | |
$data['realtsoft_captured_leads']['followup_by_email'] = _realtsoft_views_field_boolean(t('Follow up by email'), t('Boolean - whether or not to follow up by email')); | |
$data['realtsoft_captured_leads']['followup_by_phone'] = _realtsoft_views_field_boolean(t('Follow up by phone'), t('Boolean - whether or not to follow up by phone')); | |
$data['realtsoft_captured_leads']['followup_by_sms'] = _realtsoft_views_field_boolean(t('Follow up by SMS'), t('Boolean - whether or not to follow up by SMS')); | |
$data['realtsoft_captured_leads']['address'] = _realtsoft_views_field_string(t('Address'), t('Street address of the captured lead')); | |
$data['realtsoft_captured_leads']['address2'] = _realtsoft_views_field_string(t('Address Line 2'), t('Street address of the captured lead')); | |
$data['realtsoft_captured_leads']['city'] = _realtsoft_views_field_string(t('City'), t('City of the captured lead')); | |
$data['realtsoft_captured_leads']['province'] = _realtsoft_views_field_string(t('State / Province'), t('State or province of the captured lead')); | |
$data['realtsoft_captured_leads']['postal_code'] = _realtsoft_views_field_string(t('Postal Code'), t('Postal code of the captured lead')); | |
$data['realtsoft_captured_leads']['country'] = _realtsoft_views_field_string(t('Country'), t('Country of the captured lead')); | |
$data['realtsoft_captured_leads']['notes'] = _realtsoft_views_field_string(t('Notes'), t('Notes or additional comments')); | |
$data['realtsoft_captured_leads']['user_comments'] = _realtsoft_views_field_string(t('User Comments'), t('Any comments made by the customer when using the lead capture form')); | |
$data['realtsoft_captured_leads']['page_url'] = _realtsoft_views_field_string(t('Page URL'), t('URL of the page where the form was submitted')); | |
$data['realtsoft_licenses']['id'] = _realtsoft_views_field_number(t('License ID'), t('License ID')); | |
$data['realtsoft_licenses']['license_key'] = _realtsoft_views_field_string(t('License Key'), t('License key')); | |
//$data['realtsoft_licenses']['application_guid'] = _realtsoft_views_field_string(t('Application GUID'), t('Application GUID that the license applies to')); | |
$data['realtsoft_licenses']['created'] = _realtsoft_views_field_timestamp(t('Created'), t('Timestamp the license was created')); | |
$data['realtsoft_licenses']['expiration'] = _realtsoft_views_field_timestamp(t('Expiration'), t('Timestamp the license will expire')); | |
$data['realtsoft_licenses']['office_nid'] = _realtsoft_views_field_node(t('Office Node ID'), t('Node ID of the Real Estate office the license is assigned to')); | |
$data['realtsoft_licenses']['device_max'] = _realtsoft_views_field_number(t('Devices Max'), t('Number of devices that can be activated on this license')); | |
$data['realtsoft_device_activations']['id'] = _realtsoft_views_field_number(t('Activation ID'), t('Unique ID of the activation record')); | |
$data['realtsoft_device_activations']['license_id'] = _realtsoft_views_field_number(t('License ID'), t('License ID')); | |
$data['realtsoft_device_activations']['device_guid'] = _realtsoft_views_field_string(t('Device GUID'), t('Device GUID for the installation')); | |
$data['realtsoft_device_activations']['active'] = _realtsoft_views_field_boolean(t('Active?'), t('Whether or not the activation is active?')); | |
$data['realtsoft_device_activations']['date_activated'] = _realtsoft_views_field_timestamp(t('Date Activated'), t('Timestamp the device was activated')); | |
$data['realtsoft_device_activations']['date_deactivated'] = _realtsoft_views_field_timestamp(t('Date Deactivated'), t('Timestamp the device was deactivated')); | |
$data['realtsoft_device_activations']['activation_method'] = _realtsoft_views_field_string(t('Activation Method'), t('How the device was activated')); | |
$data['realtsoft_device_activations']['notes'] = _realtsoft_views_field_string(t('Notes'), t('Notes')); | |
$data['realtsoft_applications_licenses']['id'] = _realtsoft_views_field_number(t('Application-License ID'), t('Unique numeric ID for the application-license mapping')); | |
$data['realtsoft_applications_licenses']['application_id'] = _realtsoft_views_field_number(t('Application ID'), t('Numeric ID of the application in the application-license mapping')); | |
$data['realtsoft_applications_licenses']['license_id'] = _realtsoft_views_field_number(t('License ID'), t('Numeric ID of the license in the application-license mapping')); | |
$data['realtsoft_applications']['id'] = _realtsoft_views_field_number(t('Application ID'), t('Unique numeric ID for the application')); | |
$data['realtsoft_applications']['application_guid'] = _realtsoft_views_field_string(t('Application GUID'), t('Application GUID')); | |
$data['realtsoft_applications']['platform'] = _realtsoft_views_field_string(t('Platform'), t('Platform for which this application is deployed')); | |
$data['realtsoft_applications']['edition'] = _realtsoft_views_field_string(t('Edition'), t('Edition of this application (e.g., full, lite, etc)')); | |
$data['realtsoft_applications']['current_version'] = _realtsoft_views_field_string(t('Current Version'), t('Current version of this application')); | |
$data['realtsoft_applications']['label'] = _realtsoft_views_field_string(t('Title'), t('Human-readable title describing this application')); | |
$data['realtsoft_applications']['created'] = _realtsoft_views_field_timestamp(t('Created'), t('Timestamp the application was created')); | |
$data['realtsoft_applications']['changed'] = _realtsoft_views_field_timestamp(t('Last Updated'), t('Timestamp the application was last updated')); | |
$data['realtsoft_property_searches']['id'] = _realtsoft_views_field_number(t('Application-License ID'), t('Unique numeric ID for the application-license mapping')); | |
$data['realtsoft_property_searches']['office_nid'] = _realtsoft_views_field_number(t('Application ID'), t('Numeric ID of the application in the application-license mapping')); | |
$data['realtsoft_property_searches']['label'] = _realtsoft_views_field_string(t('Title'), t('Human-readable title describing saved search label')); | |
$data['realtsoft_property_searches']['search_data'] = _realtsoft_views_field_string(t('Title'), t('json encoded search data')); | |
$data['realtsoft_property_searches']['created'] = _realtsoft_views_field_timestamp(t('Created'), t('Timestamp the saved search was created')); | |
$data['realtsoft_rets_import_report']['record_id'] = _realtsoft_views_field_number(t('Record ID'), t('Unique numeric ID for record of the table')); | |
$data['realtsoft_rets_import_report']['office_nid'] = _realtsoft_views_field_number(t('Office NID'), t('Numeric ID the office')); | |
$data['realtsoft_rets_import_report']['con_id'] = _realtsoft_views_field_number(t('Drealty Connection ID'), t('Drealty Connection ID of the active office')); | |
$data['realtsoft_rets_import_report']['properties_attached'] = _realtsoft_views_field_number(t('Properties Attached'), t('Numeric value of the properties attached to the connection')); | |
$data['realtsoft_rets_import_report']['last_imported'] = _realtsoft_views_field_timestamp(t('Last Imported'), t('Timestamp when the last REST import was run')); | |
$data['realtsoft_rets_import_report']['last_import_duration'] = _realtsoft_views_field_number(t('Last Import Duration'), t('Numeric value in seconds, for the duration of last import')); | |
$data['realtsoft_rets_import_report']['properties_added'] = _realtsoft_views_field_number(t('Properties Added'), t('Numeric value of how many properties got added in last run')); | |
$data['realtsoft_rets_import_report']['properties_modified'] = _realtsoft_views_field_number(t('Properties Modified'), t('Numeric value how many properties got modified in last run')); | |
$data['realtsoft_rets_import_report']['created'] = _realtsoft_views_field_timestamp(t('Created'), t('Timestamp this record was saved')); | |
$data['realtsoft_activity_log']['id'] = _realtsoft_views_field_number(t('Activity ID'), t('Unique numeric ID for the error or activty in app')); | |
$data['realtsoft_activity_log']['type'] = _realtsoft_views_field_string(t('Activity or Error Type'), t('Human-readable title describing type of error')); | |
$data['realtsoft_activity_log']['office_nid'] = _realtsoft_views_field_number(t('Office NID'), t('Numeric ID the office where the error belongs to')); | |
$data['realtsoft_activity_log']['created'] = _realtsoft_views_field_timestamp(t('Created'), t('Timestamp the activity or error occured')); | |
$data['realtsoft_activity_log']['device_guid'] = _realtsoft_views_field_string(t('Device GUID'), t('Device GUID for the installation where error occured')); | |
$data['realtsoft_activity_log']['contents'] = _realtsoft_views_field_string(t('Error Content'), t('Entire error content and message')); | |
_realtsoft_views_field_add_relationship( | |
$data['realtsoft_applications_licenses']['license_id'], 'realtsoft_licenses', 'id', t('License')); | |
_realtsoft_views_field_add_relationship( | |
$data['realtsoft_applications_licenses']['application_id'], 'realtsoft_applications', 'id', t('Application')); | |
return $data; | |
} | |
/** | |
* Implements hook_views_data_alter(). | |
*/ | |
function reman_views_data_alter(&$data) { | |
$data['realtsoft_licenses']['application_id'] = array( | |
'title' => t('Applications mapped to a license'), | |
'help' => t('Relate applications to licenses'), | |
'relationship' => array( | |
'handler' => 'views_handler_relationship_license_application_mapping', | |
'label' => t('realtsoft_application'), | |
'base' => 'realtsoft_applications', | |
), | |
'field' => array( | |
'title' => t('All mapped applications'), | |
'help' => t('Display all applications associated with a RealTSoft software license.'), | |
'handler' => 'views_handler_field_license_applications', | |
'no group by' => TRUE, | |
), | |
); | |
// $data['realtsoft_licenses']['application_id'] = array( | |
// 'title' => t('Applications mapped to a license'), | |
// 'help' => t('Relate applications to licenses'), | |
// 'relationship' => array( | |
// 'handler' => 'views_handler_relationship_license_application_mapping', | |
// 'label' => t('realtsoft_application'), | |
// 'base' => 'realtsoft_applications', | |
// ), | |
// 'field' => array( | |
// 'title' => t('All mapped applications'), | |
// 'help' => t('Display all applications associated with a RealTSoft software license.'), | |
// 'handler' => 'views_handler_field_license_applications', | |
// 'no group by' => TRUE, | |
// ), | |
// ); | |
$data['drealty_listing']['mls_address_realtsoft'] = array( | |
'field' => array( | |
'title' => t('RealTSoft MLS Composite Address'), | |
'help' => t('Display a formatted address.'), | |
'handler' => 'views_handler_realtsoft_address_field', | |
), | |
); | |
} | |
function _realtsoft_create_join(&$data, $table, $field, $join_table, $join_field, $create_reverse = TRUE) { | |
$data[$table]['table']['join'][$join_table] = array( | |
'left_field' => $join_field, | |
'field' => $field, | |
); | |
if ($create_reverse) { | |
$data[$join_table]['table']['join'][$table] = array( | |
'left_field' => $field, | |
'field' => $join_field, | |
); | |
} | |
} | |
function _realtsoft_views_field_add_relationship(&$field, $base, $base_field, $title, $help = NULL) { | |
$field['relationship'] = array( | |
'title' => $title, | |
'help' => $help, | |
'base' => $base, | |
'base field' => $base_field, | |
'handler' => 'views_handler_relationship', | |
'label' => $title, | |
); | |
} | |
function _realtsoft_views_field_number($title, $help) { | |
return array( | |
'title' => $title, | |
'help' => $help, | |
'field' => array( | |
'handler' => 'views_handler_field_numeric', | |
'click sortable' => TRUE, | |
), | |
'filter' => array( | |
'handler' => 'views_handler_filter_numeric', | |
), | |
'sort' => array( | |
'handler' => 'views_handler_sort', | |
), | |
); | |
} | |
function _realtsoft_views_field_string($title, $help) { | |
return array( | |
'title' => $title, | |
'help' => $help, | |
'field' => array( | |
'handler' => 'views_handler_field', | |
'click sortable' => TRUE, | |
), | |
'sort' => array( | |
'handler' => 'views_handler_sort', | |
), | |
'filter' => array( | |
'handler' => 'views_handler_filter_string', | |
), | |
'argument' => array( | |
'handler' => 'views_handler_argument_string', | |
), | |
); | |
} | |
function _realtsoft_views_field_boolean($title, $help) { | |
return array( | |
'title' => $title, | |
'help' => $help, | |
'field' => array( | |
'handler' => 'views_handler_field_boolean', | |
'click sortable' => TRUE, | |
), | |
'filter' => array( | |
'handler' => 'views_handler_filter_boolean_operator', | |
'label' => t('Published'), | |
'type' => 'yes-no', | |
), | |
'sort' => array( | |
'handler' => 'views_handler_sort', | |
), | |
); | |
} | |
function _realtsoft_views_field_timestamp($title, $help) { | |
return array( | |
'title' => $title, | |
'help' => $help, | |
'field' => array( | |
'handler' => 'views_handler_field_date', | |
'click sortable' => TRUE, | |
), | |
'sort' => array( | |
'handler' => 'views_handler_sort_date', | |
), | |
'filter' => array( | |
'handler' => 'views_handler_filter_date', | |
), | |
); | |
} | |
function _realtsoft_views_field_node($title, $help) { | |
return array( | |
'title' => $title, | |
'help' => $help, | |
'relationship' => array( | |
'title' => t('Content'), | |
'help' => t('The content to which this field points.'), | |
'base' => 'node', | |
'base field' => 'nid', | |
'handler' => 'views_handler_relationship', | |
'label' => t('Content'), | |
), | |
'field' => array( | |
'handler' => 'views_handler_field_node', | |
'click sortable' => TRUE, | |
), | |
// Information for accepting a nid as an argument | |
'argument' => array( | |
'handler' => 'views_handler_argument_node_nid', | |
'name field' => 'title', // the field to display in the summary. | |
'numeric' => TRUE, | |
'validate type' => 'nid', | |
), | |
'filter' => array( | |
'handler' => 'views_handler_filter_numeric', | |
), | |
'sort' => array( | |
'handler' => 'views_handler_sort', | |
), | |
); | |
} | |
function _realtsoft_views_field_user($title, $help) { | |
return array( | |
'title' => $title, | |
'help' => $help, | |
'relationship' => array( | |
'title' => t('User'), | |
'help' => t('Relate this record to a user.'), | |
'base' => 'users', | |
'base field' => 'uid', | |
'handler' => 'views_handler_relationship', | |
'label' => t('user'), | |
), | |
'filter' => array( | |
'handler' => 'views_handler_filter_numeric', | |
), | |
'argument' => array( | |
'handler' => 'views_handler_argument_numeric', | |
), | |
'field' => array( | |
'handler' => 'views_handler_filter_user_name', | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment