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

/api/ui/widget/callback_view.class.php

https://github.com/patrickdemond/beartooth
PHP | 143 lines | 84 code | 20 blank | 39 comment | 13 complexity | 4fbff08845372bc145c9b8877230c53f MD5 | raw file
  1. <?php
  2. /**
  3. * callback_view.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 callback view
  12. */
  13. class callback_view extends \cenozo\ui\widget\base_view
  14. {
  15. /**
  16. * Constructor
  17. *
  18. * Defines all variables which need to be set for the associated template.
  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( 'callback', 'view', $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. // add items to the view
  38. $this->add_item( 'uid', 'constant', 'UID' );
  39. $this->add_item( 'phone_id', 'enum', 'Phone Number',
  40. 'Select a specific phone number to call for the callback, or leave this field blank if '.
  41. 'any of the participant\'s phone numbers can be called.' );
  42. $this->add_item( 'datetime', 'datetime', 'Date' );
  43. $this->add_item( 'assignment.user', 'constant', 'Assigned to' );
  44. $this->add_item( 'state', 'constant', 'State',
  45. '(One of reached, not reached, upcoming, assignable, missed, incomplete, assigned '.
  46. 'or in progress)' );
  47. }
  48. /**
  49. * Finish setting the variables in a widget.
  50. *
  51. * @author Patrick Emond <emondpd@mcmaster.ca>
  52. * @access protected
  53. */
  54. protected function setup()
  55. {
  56. $db_assignment = $this->get_record()->get_assignment();
  57. $operation_class_name = lib::get_class_name( 'database\operation' );
  58. // don't allow editing if the callback has been assigned
  59. if( true == $this->get_editable() ) $this->set_editable( is_null( $db_assignment ) );
  60. parent::setup();
  61. $db_participant = lib::create( 'database\participant', $this->get_record()->participant_id );
  62. // determine the time difference: use the first address unless there is a phone number with
  63. // an address
  64. $db_phone = $this->get_record()->get_phone();
  65. $db_address = is_null( $db_phone ) ? NULL : $db_phone->get_address();
  66. if( is_null( $db_address ) ) $db_address = $db_participant->get_first_address();
  67. $time_diff = is_null( $db_address ) ? NULL : $db_address->get_time_diff();
  68. // need to add the participant's timezone information as information to the date item
  69. $site_name = lib::create( 'business\session' )->get_site()->name;
  70. if( is_null( $time_diff ) )
  71. $note = 'The participant\'s time zone is not known.';
  72. else if( 0 == $time_diff )
  73. $note = sprintf( 'The participant is in the same time zone as the %s site.',
  74. $site_name );
  75. else if( 0 < $time_diff )
  76. $note = sprintf( 'The participant\'s time zone is %s hours ahead of %s\'s time.',
  77. $time_diff,
  78. $site_name );
  79. else if( 0 > $time_diff )
  80. $note = sprintf( 'The participant\'s time zone is %s hours behind of %s\'s time.',
  81. abs( $time_diff ),
  82. $site_name );
  83. $this->add_item( 'datetime', 'datetime', 'Date', $note );
  84. // create enum arrays
  85. $modifier = lib::create( 'database\modifier' );
  86. $modifier->where( 'active', '=', true );
  87. $modifier->order( 'rank' );
  88. $phones = array();
  89. foreach( $db_participant->get_phone_list( $modifier ) as $db_phone )
  90. $phones[$db_phone->id] = $db_phone->rank.". ".$db_phone->number;
  91. if( !is_null( $db_assignment ) )
  92. {
  93. $this->set_item( 'assignment.user', $db_assignment->get_user()->name, false );
  94. $this->add_item( 'assignment.start_datetime', 'constant', 'Started' );
  95. $this->set_item( 'assignment.start_datetime',
  96. util::get_formatted_time( $db_assignment->start_datetime ), false );
  97. $this->add_item( 'assignment.end_datetime', 'constant', 'Finished' );
  98. $this->set_item( 'assignment.end_datetime',
  99. util::get_formatted_time( $db_assignment->end_datetime ), false );
  100. }
  101. else
  102. {
  103. $this->set_item( 'assignment.user', 'unassigned', false );
  104. }
  105. $callback_class_name = lib::get_class_name( 'database\callback' );
  106. // set the view's items
  107. $this->set_item( 'uid', $db_participant->uid );
  108. $this->set_item( 'phone_id', $this->get_record()->phone_id, false, $phones );
  109. $this->set_item( 'datetime', $this->get_record()->datetime, true );
  110. $this->set_item( 'state', $this->get_record()->get_state(), false );
  111. // hide the calendar if requested to
  112. $this->set_variable( 'hide_calendar', $this->get_argument( 'hide_calendar', false ) );
  113. $this->set_variable( 'participant_id', $db_participant->id );
  114. // add an action to view the participant's details
  115. $db_operation = $operation_class_name::get_operation( 'widget', 'participant', 'view' );
  116. if( lib::create( 'business\session' )->is_allowed( $db_operation ) )
  117. $this->add_action(
  118. 'view_participant',
  119. 'View Participant',
  120. NULL,
  121. 'View the participant\'s details' );
  122. }
  123. }