PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/api/ui/push/participant_edit.class.php

https://github.com/patrickdemond/beartooth
PHP | 93 lines | 60 code | 12 blank | 21 comment | 10 complexity | ca030763b0303da0c07acea981a92ffd MD5 | raw file
  1. <?php
  2. /**
  3. * participant_edit.class.php
  4. *
  5. * @author Patrick Emond <emondpd@mcmaster.ca>
  6. * @filesource
  7. */
  8. namespace beartooth\ui\push;
  9. use cenozo\lib, cenozo\log, beartooth\util;
  10. /**
  11. * push: participant edit
  12. *
  13. * Edit a participant.
  14. */
  15. class participant_edit extends \cenozo\ui\push\participant_edit
  16. {
  17. /**
  18. * This method executes the operation's purpose.
  19. *
  20. * @author Patrick Emond <emondpd@mcmaster.ca>
  21. * @access protected
  22. */
  23. protected function execute()
  24. {
  25. parent::execute();
  26. $record = $this->get_record();
  27. $columns = $this->get_argument( 'columns', array() );
  28. $db_next_of_kin = NULL;
  29. $db_data_collection = NULL;
  30. $found_next_of_kin = false;
  31. $found_data_collection = false;
  32. // process next_of_kin and data_collection columns
  33. foreach( $columns as $column => $value )
  34. {
  35. if( false !== strpos( $column, 'next_of_kin_' ) )
  36. {
  37. // make sure the next of kin entry exists
  38. if( is_null( $db_next_of_kin ) )
  39. {
  40. $db_next_of_kin = $record->get_next_of_kin();
  41. if( is_null( $db_next_of_kin ) )
  42. { // the record doesn't exist, so create it
  43. $db_next_of_kin = lib::create( 'database\next_of_kin' );
  44. $db_next_of_kin->participant_id = $record->id;
  45. }
  46. }
  47. $next_of_kin_column = substr( $column, strlen( 'next_of_kin_' ) );
  48. $db_next_of_kin->$next_of_kin_column = $value;
  49. $found_next_of_kin = true;
  50. }
  51. else if( false !== strpos( $column, 'data_collection_' ) )
  52. {
  53. // make sure the next of kin entry exists
  54. if( is_null( $db_data_collection ) )
  55. {
  56. $db_data_collection = $record->get_data_collection();
  57. if( is_null( $db_data_collection ) )
  58. { // the record doesn't exist, so create it
  59. $db_data_collection = lib::create( 'database\data_collection' );
  60. $db_data_collection->participant_id = $record->id;
  61. }
  62. }
  63. $data_collection_column = substr( $column, strlen( 'data_collection_' ) );
  64. $db_data_collection->$data_collection_column = $value;
  65. $found_data_collection = true;
  66. }
  67. }
  68. if( $found_next_of_kin ) $db_next_of_kin->save();
  69. if( $found_data_collection ) $db_data_collection->save();
  70. // look for columns which will affect queue status
  71. $column_list = array(
  72. 'active',
  73. 'gender',
  74. 'state_id',
  75. 'override_quota' );
  76. foreach( $record->get_cohort()->get_service_list() as $db_service )
  77. $column_list[] = sprintf( '%s_site_id', $db_service->name );
  78. if( array_intersect_key( $columns, array_flip( $column_list ) ) )
  79. $record->update_queue_status();
  80. }
  81. }