tmgmt_handler_field_tmgmt_job_item_count.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @file
  4. * Contains the tmgmt_handler_field_tmgmt_job_item_count field handler.
  5. */
  6. /**
  7. * Field handler to show the amount of job items per job.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class tmgmt_handler_field_tmgmt_job_item_count extends views_handler_field {
  12. /**
  13. * @var views_plugin_query_default
  14. */
  15. var $query;
  16. function option_definition() {
  17. $options = parent::option_definition();
  18. $options['state'] = array('default' => '');
  19. return $options;
  20. }
  21. function options_form(&$form, &$form_state) {
  22. parent::options_form($form, $form_state);
  23. $options = array('' => t('- All -'));
  24. $options += tmgmt_job_item_states();
  25. $form['state'] = array(
  26. '#title' => t('Job item status'),
  27. '#description' => t('Count only job items of a certain status.'),
  28. '#type' => 'select',
  29. '#options' => $options,
  30. '#default_value' => $this->options['state'],
  31. );
  32. }
  33. function use_group_by() {
  34. return FALSE;
  35. }
  36. function query() {
  37. $this->ensure_my_table();
  38. // Therefore construct the join.
  39. $join = new views_join();
  40. $join->definition['left_table'] = $this->table_alias;
  41. $join->definition['left_field'] = $this->real_field;
  42. $join->definition['table'] = 'tmgmt_job_item';
  43. $join->definition['field'] = 'tjid';
  44. $join->definition['type'] = 'LEFT';
  45. if (!empty($this->options['state'])) {
  46. $join->extra = array(array(
  47. 'field' => 'state',
  48. 'value' => $this->options['state']
  49. ));
  50. }
  51. $join->construct();
  52. // Add the join to the tmgmt_job_item table.
  53. $this->table_alias = $this->query->add_table('tmgmt_job_item', $this->relationship, $join);
  54. // And finally add the count of the job items field.
  55. $params = array('function' => 'count');
  56. $this->field_alias = $this->query->add_field($this->table_alias, 'tjiid', NULL, $params);
  57. $this->add_additional_fields();
  58. }
  59. }