/public_html/sites/all/modules/civicrm/CRM/Project/BAO/TaskStatus.php

https://github.com/timstephenson/NatureBridge · PHP · 191 lines · 107 code · 35 blank · 49 comment · 19 complexity · 96f7098482ff1fc6b009be796a840dde MD5 · raw file

  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 4.0 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2011 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  10. | CiviCRM is free software; you can copy, modify, and distribute it |
  11. | under the terms of the GNU Affero General Public License |
  12. | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
  13. | |
  14. | CiviCRM is distributed in the hope that it will be useful, but |
  15. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  17. | See the GNU Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU Affero General Public |
  20. | License and the CiviCRM Licensing Exception along |
  21. | with this program; if not, contact CiviCRM LLC |
  22. | at info[AT]civicrm[DOT]org. If you have questions about the |
  23. | GNU Affero General Public License or the licensing of CiviCRM, |
  24. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  25. +--------------------------------------------------------------------+
  26. */
  27. /**
  28. *
  29. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2011
  31. * $Id$
  32. *
  33. */
  34. /**
  35. * this file contains functions to manage and manipulate task status
  36. */
  37. require_once 'CRM/Project/DAO/TaskStatus.php';
  38. class CRM_Project_BAO_TaskStatus {
  39. static function &getTaskStatusInitial( &$controller,
  40. $ret, $reid,
  41. $tet, $teid,
  42. $taskID,
  43. $prefix = 'taskStatus',
  44. $statusDetail = true ) {
  45. $taskStatusID = $controller->get( "{$prefix}ID" );
  46. $taskStatus = $controller->get( $prefix );
  47. if ( ! $taskStatusID ) {
  48. // cache the status
  49. require_once 'CRM/Core/OptionGroup.php';
  50. $status =& CRM_Core_OptionGroup::values( 'task_status', true );
  51. // get the task status object, if not there create one
  52. require_once 'CRM/Project/DAO/TaskStatus.php';
  53. $dao = new CRM_Project_DAO_TaskStatus( );
  54. $dao->responsible_entity_table = $ret;
  55. $dao->responsible_entity_id = $reid;
  56. $dao->target_entity_table = $tet;
  57. $dao->target_entity_id = $teid;
  58. $dao->task_id = $taskID;
  59. if ( ! $dao->find( true ) ) {
  60. $dao->create_date = date( 'YmdHis' );
  61. $dao->status_id = $status['Not Started'];
  62. $dao->save( );
  63. }
  64. if ( $statusDetail && $dao->status_detail ) {
  65. $data =& $controller->container( );
  66. $data['valid'] = unserialize( $dao->status_detail );
  67. }
  68. $controller->set( "{$prefix}ID", $dao->id );
  69. $taskStatus = array_search( $dao->status_id, $status );
  70. $controller->set( $prefix, $taskStatus );
  71. }
  72. $controller->assign( $prefix, $taskStatus );
  73. return array( $taskStatusID, $taskStatus );
  74. }
  75. static function updateTaskStatus( &$form,
  76. $prefix = 'taskStatus',
  77. $statusDetail = true ) {
  78. // update the task record
  79. require_once 'CRM/Project/DAO/TaskStatus.php';
  80. $dao = new CRM_Project_DAO_TaskStatus( );
  81. $dao->id = $form->get( "{$prefix}ID" );
  82. if ( ! $dao->id || ! $dao->find( true ) ) {
  83. CRM_Core_Error::fatal( "The task status table is inconsistent" );
  84. }
  85. $status =& CRM_Core_OptionGroup::values( 'task_status', true );
  86. if ( $form->controller->isApplicationComplete( ) ) {
  87. $dao->status_id = $status['Completed'];
  88. $form->set( $prefix, 'Completed' );
  89. } else {
  90. $dao->status_id = $status['In Progress'];
  91. $form->set( $prefix, 'In Progress' );
  92. }
  93. $dao->create_date = CRM_Utils_Date::isoToMysql( $dao->create_date );
  94. $dao->modified_date = date( 'YmdHis' );
  95. if ( $statusDetail ) {
  96. // now save all the valid values to fool QFC
  97. $data =& $form->controller->container( );
  98. // CRM_Core_Error::debug( 'd', $data );
  99. $dao->status_detail = serialize( $data['valid'] );
  100. }
  101. $dao->save( );
  102. }
  103. static function updateTaskStatusWithValue( &$form,
  104. $value = 'In Progress',
  105. $prefix = 'taskStatus' ) {
  106. // update the task record
  107. require_once 'CRM/Project/DAO/TaskStatus.php';
  108. $dao = new CRM_Project_DAO_TaskStatus( );
  109. $dao->id = $form->get( "{$prefix}ID" );
  110. if ( ! $dao->id || ! $dao->find( true ) ) {
  111. CRM_Core_Error::fatal( "The task status table is inconsistent" );
  112. }
  113. $status =& CRM_Core_OptionGroup::values( 'task_status', true );
  114. $dao->status_id = $status[$value];
  115. $form->set( $prefix, $value );
  116. $dao->create_date = CRM_Utils_Date::isoToMysql( $dao->create_date );
  117. $dao->modified_date = date( 'YmdHis' );
  118. $dao->save( );
  119. }
  120. /**
  121. * Function to set the task status of various tasks
  122. *
  123. * @param array $params associated array
  124. *
  125. * @static
  126. * @return returns task status object
  127. */
  128. static function create( &$params )
  129. {
  130. if (!$params['target_entity_id'] || !$params['responsible_entity_id']
  131. || !$params['task_id'] || ! $params['status_id'] ) {
  132. return null;
  133. }
  134. if (!$params['target_entity_table'] ) {
  135. $params['target_entity_table'] = 'civicrm_contact';
  136. }
  137. if (!$params['responsible_entity_table']) {
  138. $params['responsible_entity_table'] = 'civicrm_contact';
  139. }
  140. require_once 'CRM/Project/DAO/TaskStatus.php';
  141. $dao = new CRM_Project_DAO_TaskStatus( );
  142. $dao->target_entity_id = $params['target_entity_id'];
  143. $dao->responsible_entity_id = $params['responsible_entity_id'];
  144. $dao->target_entity_table = $params['target_entity_table'];
  145. $dao->responsible_entity_table = $params['responsible_entity_table'];
  146. $dao->task_id = $params['task_id'];
  147. if ( $dao->find( true ) ) {
  148. $dao->create_date = CRM_Utils_Date::isoToMysql( $dao->create_date );
  149. } else {
  150. $dao->create_date = date( 'YmdHis' );
  151. }
  152. $dao->modified_date = date( 'YmdHis' );
  153. $dao->status_id = $params['status_id'];
  154. return $dao->save();
  155. }
  156. }