PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/api/ui/widget/assignment_list.class.php

https://github.com/patrickdemond/beartooth
PHP | 165 lines | 97 code | 15 blank | 53 comment | 16 complexity | 2067e8f552d47e111afe9d28ff055e3f MD5 | raw file
  1. <?php
  2. /**
  3. * assignment_list.class.php
  4. *
  5. * @author Patrick Emond <emondpd@mcmaster.ca>
  6. * @filesource
  7. */
  8. namespace beartooth\ui\widget;
  9. use cenozo\lib, cenozo\log, beartooth\util;
  10. /**
  11. * widget assignment list
  12. */
  13. class assignment_list extends \cenozo\ui\widget\site_restricted_list
  14. {
  15. /**
  16. * Constructor
  17. *
  18. * Defines all variables required by the assignment list.
  19. * @author Patrick Emond <emondpd@mcmaster.ca>
  20. * @param array $args An associative array of arguments to be processed by the widget
  21. * @access public
  22. */
  23. public function __construct( $args )
  24. {
  25. parent::__construct( 'assignment', $args );
  26. }
  27. /**
  28. * Processes arguments, preparing them for the operation.
  29. *
  30. * @author Patrick Emond <emondpd@mcmaster.ca>
  31. * @throws exception\notice
  32. * @access protected
  33. */
  34. protected function prepare()
  35. {
  36. parent::prepare();
  37. $interview_id = $this->get_argument( 'interview_id', NULL );
  38. $this->add_column( 'user.name', 'string', 'Operator', true );
  39. $this->add_column( 'site.name', 'string', 'Site', true );
  40. // only add the participant column if we are not restricting by interview
  41. if( is_null( $interview_id ) ) $this->add_column( 'uid', 'string', 'UID' );
  42. $this->add_column( 'calls', 'number', 'Calls' );
  43. $this->add_column( 'start_datetime', 'date', 'Date', true );
  44. $this->add_column( 'start_time', 'time', 'Start Time' );
  45. $this->add_column( 'end_time', 'time', 'End Time' );
  46. $this->add_column( 'status', 'string', 'Status' );
  47. }
  48. /**
  49. * Sets up the operation with any pre-execution instructions that may be necessary.
  50. *
  51. * @author Patrick Emond <emondpd@mcmaster.ca>
  52. * @access protected
  53. */
  54. protected function setup()
  55. {
  56. parent::setup();
  57. foreach( $this->get_record_list() as $record )
  58. {
  59. $db_participant = $record->get_interview()->get_participant();
  60. $participant = sprintf( '%s, %s', $db_participant->last_name, $db_participant->first_name );
  61. // get the status of the last phone call for this assignment
  62. $modifier = lib::create( 'database\modifier' );
  63. $modifier->order_desc( 'end_datetime' );
  64. $modifier->limit( 1 );
  65. $phone_call_list = $record->get_phone_call_list( $modifier );
  66. $status = 0 == count( $phone_call_list ) ? 'no calls made' : $phone_call_list[0]->status;
  67. if( 0 == strlen( $status ) ) $status = 'in progress';
  68. // assemble the row for this record
  69. $this->add_row( $record->id,
  70. array( 'user.name' => $record->get_user()->name,
  71. 'site.name' => $record->get_site()->name,
  72. 'uid' => $db_participant->uid, // only used if not restricting by interview_id
  73. 'calls' => $record->get_phone_call_count(),
  74. 'start_datetime' => $record->start_datetime,
  75. 'start_time' => $record->start_datetime,
  76. 'end_time' => $record->end_datetime,
  77. 'status' => $status ) );
  78. }
  79. }
  80. /**
  81. * Overrides the parent class method since the record count depends on the active role
  82. *
  83. * @author Patrick Emond <emondpd@mcmaster.ca>
  84. * @param database\modifier $modifier Modifications to the list.
  85. * @return int
  86. * @access protected
  87. */
  88. public function determine_record_count( $modifier = NULL )
  89. {
  90. if( !is_null( $this->parent ) )
  91. {
  92. if( 'interview_view' == $this->parent->get_class_name() )
  93. {
  94. // restrict the list to the interview's participant
  95. if( is_null( $modifier ) ) $modifier = lib::create( 'database\modifier' );
  96. $modifier->where(
  97. 'assignment.interview_id', '=', $this->parent->get_record()->id );
  98. }
  99. else
  100. { // if this widget gets parented we need to address that parent here
  101. throw lib::create( 'exception\runtime',
  102. 'Invalid parent type '.$this->parent->get_class_name(),
  103. __METHOD__ );
  104. }
  105. }
  106. // we may be restricting by interview
  107. $interview_id = $this->get_argument( 'interview_id', NULL );
  108. if( !is_null( $interview_id ) )
  109. {
  110. if( is_null( $modifier ) ) $modifier = lib::create( 'database\modifier' );
  111. $modifier->where( 'assignment.interview_id', '=', $interview_id );
  112. }
  113. return parent::determine_record_count( $modifier );
  114. }
  115. /**
  116. * Overrides the parent class method since the record list depends on the active role.
  117. *
  118. * @author Patrick Emond <emondpd@mcmaster.ca>
  119. * @param database\modifier $modifier Modifications to the list.
  120. * @return array( record )
  121. * @access protected
  122. */
  123. public function determine_record_list( $modifier = NULL )
  124. {
  125. if( !is_null( $this->parent ) )
  126. {
  127. if( 'interview_view' == $this->parent->get_class_name() )
  128. {
  129. // restrict the list to the interview's participant
  130. if( is_null( $modifier ) ) $modifier = lib::create( 'database\modifier' );
  131. $modifier->where(
  132. 'assignment.interview_id', '=', $this->parent->get_record()->id );
  133. }
  134. else
  135. { // if this widget gets parented we need to address that parent here
  136. throw lib::create( 'exception\runtime',
  137. 'Invalid parent type '.$this->parent->get_class_name(),
  138. __METHOD__ );
  139. }
  140. }
  141. // we may be restricting by interview
  142. $interview_id = $this->get_argument( 'interview_id', NULL );
  143. if( !is_null( $interview_id ) )
  144. {
  145. if( is_null( $modifier ) ) $modifier = lib::create( 'database\modifier' );
  146. $modifier->where( 'assignment.interview_id', '=', $interview_id );
  147. }
  148. return parent::determine_record_list( $modifier );
  149. }
  150. }