Fix for Manually created Views

  1. function sitehelper_views_tables() {
  2. // view created from email column in users table
  3.   $table = array(
  4. // name of table
  5.     'name' => 'users',
  6.     'provider' => 'internal',
  7.     'join' => array(
  8.       'left' => array(
  9. // all views (currently) must left join to the node table eventually (You can left join to some other table, which then left joins to the node table).
  10.         'table' => 'node',
  11. // Left join means that the two tables have a field in common - the node table uses uid...
  12.         'field' => 'uid'
  13.       ),
  14.       'right' => array(
  15. // and the users table (named earlier in this function) uses uid.
  16.         'field' => 'uid'
  17.       ),
  18.     ),
  19.     'fields' => array(
  20. // The field I want showing up in my view is the mail field in the users table - so I ask for it here.
  21.       'mail' => array(
  22. // This next stuff is what you see when you go to build your view.
  23.         'name' => t('Sitehelper: Email'),
  24.         'sortable' => false,
  25.         'help' => t('This will display the email address of the node creator.'),
  26.       ),
  27.     ),
  28.   );
  29. // I place all the info I just put together into $tables as "users".
  30.   $tables["users"] = $table;
  31. // view from table limiting it to nodes with type 'cinfo' for future use.
  32.   $table = array(
  33.     'name'=> 'node',
  34.     'provider' => 'internal',
  35.     'join' => array(
  36.       'left' => array(
  37.         'table' => 'users',
  38.         'field' => 'uid'
  39.       ),
  40.       'right' => array(
  41.         'field' => 'uid'
  42.       ),
  43.       'extra' => array(
  44.         'type' => 'cinfo'
  45.       ),
  46.     ),
  47.   );
  48.   $tables["node_cinfo_filter"] = $table;
  49. // here's the future use... uses the filtered info then grabs info from the content type cinfo table
  50.   $table = array(
  51.     'name' => 'content_type_cinfo',
  52.     'provider' => 'internal',
  53.     'join' => array(
  54.       'left' => array(
  55.         'table' => 'node_cinfo_filter',
  56.         'field' => 'nid'
  57.       ),
  58.       'right' => array(
  59.         'field' => 'nid'
  60.       ),
  61.     ),
  62.     'fields' => array(
  63.       'field_batch_value' => array(
  64.         'name' => t('Sitehelper: Parent Batch'),
  65.         'sortable' => false,
  66.         'help' => t('Retrieves Batch field for client.'),
  67.       ),
  68.     ),
  69.   );
  70.   $tables["content_type_cinfo"] = $table;
  71. // view created for table 'sitehelper_tracker' - created elsewhere in this module.
  72.   $table = array(
  73.     'name' => 'sitehelper_tracker',
  74.     'provider' => 'internal',
  75.     'join' => array(
  76.       'left' => array(
  77.         'table' => 'node',
  78.         'field' => 'nid'
  79.       ),
  80.       'right' => array(
  81.         'field' => 'nid'
  82.       ),
  83.     ),
  84.     'fields' => array(
  85.       'transaction' => array(
  86.         'name' => t('Sitehelper: Node Changes'),
  87.         'sortable' => false,
  88.         'help' => t('This keeps track of node changes and provides the transaction type.'),
  89.       ),
  90.     ),
  91.     'filters' => array(
  92.       'timestamp' => array(
  93.         'name' => t('Sitehelper: Tracker Time'),
  94.         'operator' => 'views_handler_operator_gtlt',
  95.         'value' => views_handler_filter_date_value_form(),
  96.         'handler' => 'views_handler_filter_timestamp',
  97.         'option' => 'string',
  98.         'help' => t('This filter allows nodes to be filtered by the time of the Sitehelper Tracker.')
  99.           .' '. views_t_strings('filter date'),
  100.       ),
  101.     ),
  102.   );
  103.   $tables["sitehelper_tracker"] = $table;
  104. // view for matrix fields
  105.   foreach (array(1,2,3,4) as $matrixrow) {
  106.     foreach (array(1,2) as $matrixcol) {
  107.       $matrixindex = $matrixrow.'_'.$matrixcol;
  108.       $table = array(
  109.         'name' => 'node_field_matrix_data',
  110.         'provider' => 'internal',
  111.         'join' => array(
  112.           'left' => array(
  113.             'table' => 'node',
  114.             'field' => 'nid'
  115.           ),
  116.           'right' => array(
  117.             'field' => 'nid'
  118.           ),      
  119.           'extra' => array(
  120.             'row' => $matrixrow,
  121.             'col' => $matrixcol
  122.           ),
  123.         ),
  124.         'fields' => array(
  125.           'value' => array(
  126.             'name' => t("Sitehelper: Meter $matrixindex"),
  127.             'sortable' => false,
  128.             'help' => t("This will show the value of meter $matrixindex."),
  129.           ),
  130.         ),
  131.       );
  132.       $tables["node_field_matrix_data_$matrixindex"] = $table;
  133.     }
  134.   }
  135. // views for the individual portions of cck_address
  136.   $table = array(
  137.     'name' => 'content_field_address',
  138.     'provider' => 'internal',
  139.     'join' => array(
  140.       'left' => array(
  141.         'table' => 'node',
  142.         'field' => 'nid'
  143.       ),
  144.       'right' => array(
  145.         'field' => 'nid'
  146.       ),
  147.     ),
  148.     'fields' => array(
  149.       'field_address_street1' => array(
  150.         'name' => t('Sitehelper: Street Address'),
  151.         'sortable' => false,
  152.         'help' => t('This will display the Street Address.'),
  153.       ),
  154.       'field_address_apt' => array(
  155.         'name' => t('Sitehelper: Apt'),
  156.         'sortable' => false,
  157.         'help' => t('This will display the Apt #.'),
  158.       ),
  159.       'field_address_street2' => array(
  160.         'name' => t('Sitehelper: Street Address 2'),
  161.         'sortable' => false,
  162.         'help' => t('This will display the Street Address 2.'),
  163.       ),
  164.       'field_address_city' => array(
  165.         'name' => t('Sitehelper: City'),
  166.         'sortable' => false,
  167.         'help' => t('This will display the City.'),
  168.       ),
  169.       'field_address_state' => array(
  170.         'name' => t('Sitehelper: State'),
  171.         'sortable' => false,
  172.         'help' => t('This will display the State.'),
  173.       ),
  174.       'field_address_zip' => array(
  175.         'name' => t('Sitehelper: Zip'),
  176.         'sortable' => false,
  177.         'help' => t('This will display the Zip Code.'),
  178.       ),
  179.       'field_address_country' => array(
  180.         'name' => t('Sitehelper: Country'),
  181.         'sortable' => false,
  182.         'help' => t('This will display the Country.'),
  183.       ),
  184.     ),
  185.   );
  186.   $tables["content_field_address"] = $table;
  187.   return $tables;
  188. }
  189. // argument created for my sitehelper_tracker table
  190. function sitehelper_views_arguments() {
  191.   $arguments = array(
  192.     'timestamp' => array(
  193.       'name' => t('Sitehelper: Transaction Time'),
  194.       'handler' => 'sitehelper_views_handler_arg_timestamp',
  195.       'help' => t('This argument is a complete date in the form of CCYYMMDD.'),
  196.     ),
  197.   );
  198.   return $arguments;
  199. }
  200.  
  201. function sitehelper_views_handler_arg_timestamp($op, &$query, $argtype, $arg = '') {
  202.   $timezone = _views_get_timezone();
  203.  
  204.   switch($op) {
  205.     case 'summary':
  206.       $query->ensure_table('sitehelper_tracker');
  207.       $query->add_field('timestamp','sitehelper_tracker');
  208.       $fieldinfo['field'] = "DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d')";
  209.       $fieldinfo['fieldname'] = 'name';
  210.       return $fieldinfo;
  211.       break;
  212.     case 'sort':
  213.       $query->add_orderby(NULL, "DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d')", $argtype, 'name');
  214.       break;
  215.     case 'filter':
  216.       $query->add_where("DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d') = '%s'", $arg);
  217.       break;
  218.     case 'link':
  219.       return l(format_date($query->timestamp, 'custom', 'F j, Y'), "$arg/$query->name");
  220.     case 'title':
  221.       return format_date(strtotime($query), 'custom', 'F j, Y');
  222.   }
  223. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.