minor tidy-ups
[civicrm-core.git] / CRM / Case / BAO / Case.php
index 4d245fc12ec955f8e60a4cf0b0e5e489e00ff7c1..6c6601bbd9ad82a93ce819928b5ec920559327e3 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  */
 
 /**
- * This class contains the functions for Case Management
+ * This class contains the functions for Case Management.
  *
  */
 class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
 
   /**
-   * Static field for all the case information that we can potentially export
+   * Static field for all the case information that we can potentially export.
    *
    * @var array
-   * @static
    */
   static $_exportableFields = NULL;
 
   /**
-   *
+   * Class constructor.
    */
   public function __construct() {
     parent::__construct();
@@ -65,17 +64,16 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
   }
 
   /**
-   * Takes an associative array and creates a case object
+   * Create a case object.
    *
-   * the function extract all the params it needs to initialize the create a
+   * The function extracts all the params it needs to initialize the create a
    * case object. the params array could contain additional unused name/value
    * pairs
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
    *
-   * @return CRM_Case_BAO_Case object
-   * @static
+   * @return CRM_Case_BAO_Case
    */
   public static function add(&$params) {
     $caseDAO = new CRM_Case_DAO_Case();
@@ -85,7 +83,7 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
 
   /**
    * Given the list of params in the params array, fetch the object
-   * and store the values in the values array
+   * and store the values in the values array.
    *
    * @param array $params
    *   Input parameters to find object.
@@ -94,8 +92,8 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
    * @param array $ids
    *   The array that holds all the db ids.
    *
-   * @return CRM_Case_BAO_Case|null the found object or null
-   * @static
+   * @return CRM_Case_BAO_Case|null
+   *   The found object or null
    */
   public static function &getValues(&$params, &$values, &$ids) {
     $case = new CRM_Case_BAO_Case();
@@ -111,13 +109,12 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
   }
 
   /**
-   * Takes an associative array and creates a case object
+   * Takes an associative array and creates a case object.
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
+   *   (reference) an assoc array of name/value pairs.
    *
-   * @return CRM_Case_BAO_Case object
-   * @static
+   * @return CRM_Case_BAO_Case
    */
   public static function &create(&$params) {
     $transaction = new CRM_Core_Transaction();
@@ -156,9 +153,10 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
   }
 
   /**
-   * Create case contact record
+   * Create case contact record.
    *
-   * @param array case_id, contact_id
+   * @param array $params
+   *   case_id, contact_id
    *
    * @return object
    */
@@ -198,11 +196,9 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
   }
 
   /**
-   * Delet case contact record
+   * Delete case contact record.
    *
-   * @param int case_id
-   *
-   * @return Void
+   * @param int $caseID
    */
   public static function deleteCaseContact($caseID) {
     $caseContact = new CRM_Case_DAO_CaseContact();
@@ -218,12 +214,18 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
   }
 
   /**
-   * This function is used to convert associative array names to values
-   * and vice-versa.
+   * Convert associative array names to values and vice-versa.
    *
    * This function is used by both the web form layer and the api. Note that
    * the api needs the name => value conversion, also the view layer typically
    * requires value => name conversion
+   *
+   * @param array $defaults
+   * @param string $property
+   * @param array $lookup
+   * @param bool $reverse
+   *
+   * @return bool
    */
   public static function lookupValue(&$defaults, $property, &$lookup, $reverse) {
     $id = $property . '_id';
@@ -260,8 +262,7 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
    * @param array $ids
    *   (reference) the array that holds all the db ids.
    *
-   * @return CRM_Case_BAO_Case object
-   * @static
+   * @return CRM_Case_BAO_Case
    */
   public static function retrieve(&$params, &$defaults, &$ids) {
     $case = CRM_Case_BAO_Case::getValues($params, $defaults, $ids);
@@ -275,7 +276,6 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
    *
-   * @static
    */
   public static function processCaseActivity(&$params) {
     $caseActivityDAO = new CRM_Case_DAO_CaseActivity();
@@ -287,13 +287,12 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
   }
 
   /**
-   * Get the case subject for Activity
+   * Get the case subject for Activity.
    *
    * @param int $activityId
    *   Activity id.
    *
-   * @return  case subject or null
-   * @static
+   * @return string|null
    */
   public static function getCaseSubject($activityId) {
     $caseActivity = new CRM_Case_DAO_CaseActivity();
@@ -308,11 +307,10 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
    * Get the case type.
    *
    * @param int $caseId
-   *
    * @param string $colName
    *
-   * @return  case type
-   * @static
+   * @return string
+   *   case type
    */
   public static function getCaseType($caseId, $colName = 'title') {
     $query = "
@@ -335,8 +333,8 @@ WHERE civicrm_case.id = %1";
    *
    * @param bool $moveToTrash
    *
-   * @return bool is successful
-   * @static
+   * @return bool
+   *   is successful
    */
   public static function deleteCase($caseId, $moveToTrash = FALSE) {
     CRM_Utils_Hook::pre('delete', 'Case', $caseId, CRM_Core_DAO::$_nullArray);
@@ -382,7 +380,7 @@ WHERE civicrm_case.id = %1";
   }
 
   /**
-   * Enable disable case related relationships
+   * Enable disable case related relationships.
    *
    * @param int $caseId
    *   Case id.
@@ -390,7 +388,6 @@ WHERE civicrm_case.id = %1";
    *   Action.
    *
    * @return void
-   * @static
    */
   public static function enableDisableCaseRelationships($caseId, $enable) {
     $contactIds = self::retrieveContactIdsByCaseId($caseId);
@@ -409,13 +406,12 @@ WHERE civicrm_case.id = %1";
   }
 
   /**
-   * Delete the activities related to case
+   * Delete the activities related to case.
    *
    * @param int $activityId
    *   Id of the activity.
    *
    * @return void
-   * @static
    */
   public static function deleteCaseActivity($activityId) {
     $case = new CRM_Case_DAO_CaseActivity();
@@ -450,7 +446,7 @@ WHERE civicrm_case.id = %1";
   }
 
   /**
-   * Look up a case using an activity ID
+   * Look up a case using an activity ID.
    *
    * @param int $activityId
    *
@@ -478,8 +474,6 @@ WHERE civicrm_case.id = %1";
    *   ID of the case.
    *
    * @return array
-   *
-   *
    */
   public static function getContactNames($caseId) {
     $contactNames = array();
@@ -517,7 +511,7 @@ WHERE civicrm_case.id = %1";
   }
 
   /**
-   * Retrieve case_id by contact_id
+   * Retrieve case_id by contact_id.
    *
    * @param int $contactID
    * @param bool $includeDeleted
@@ -525,7 +519,6 @@ WHERE civicrm_case.id = %1";
    * @param null $caseType
    *
    * @return array
-   *
    */
   public static function retrieveCaseIdsByContactId($contactID, $includeDeleted = FALSE, $caseType = NULL) {
     $query = "
@@ -715,8 +708,7 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type'
   }
 
   /**
-   * Retrieve cases related to particular contact or whole contact
-   * used in Dashboad and Tab
+   * Retrieve cases related to particular contact or whole contact used in Dashboard and Tab.
    *
    * @param bool $allCases
    *
@@ -727,8 +719,8 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type'
    *
    * @param string $context
    *
-   * @return array     Array of Cases
-   *
+   * @return array
+   *   Array of Cases
    */
   public static function getCases($allCases = TRUE, $userID = NULL, $type = 'upcoming', $context = 'dashboard') {
     $condition = NULL;
@@ -975,9 +967,9 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    *   Case id.
    * @param int $relationshipID
    *
-   * @return array case role / relationships
+   * @return array
+   *   case role / relationships
    *
-   * @static
    */
   public static function getCaseRoles($contactID, $caseID, $relationshipID = NULL) {
     $query = '
@@ -1038,9 +1030,9 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    * @param int $userID
    * @param null $type
    *
-   * @return array of case activities
+   * @return array
+   *   Array of case activities
    *
-   * @static
    */
   public static function getCaseActivity($caseID, &$params, $contactID, $context = NULL, $userID = NULL, $type = NULL) {
     $values = array();
@@ -1362,7 +1354,7 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
       }
 
       if ($allowEdit) {
-        $values[$dao->id]['status'] = '<a class="crm-activity-status crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . ' crm-activity-change-status crm-editable-enabled" activity_id=' . $dao->id . ' current_status=' . $dao->status . ' case_id=' . $caseID . ' href="#" title=\'' . $statusTitle . '\'>' . $values[$dao->id]['status'] . '</a>';
+        $values[$dao->id]['status'] = '<div class="crmf-status_id crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . ' crm-editable" data-type="select" data-action="create" data-refresh="true">' . $values[$dao->id]['status'] . '</div>';
       }
     }
     $dao->free();
@@ -1378,9 +1370,9 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    * @param bool $skipDetails
    *   If true include details of contacts.
    *
-   * @return array $searchRows array of return properties
+   * @return array
+   *   array of return properties
    *
-   * @static
    */
   public static function getRelatedContacts($caseID, $skipDetails = FALSE) {
     $values = array();
@@ -1572,8 +1564,6 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    *   ID of the activity type.
    *
    * @return array
-   *
-   *
    */
   public static function getCaseActivityCount($caseId, $activityTypeId) {
     $queryParam = array(
@@ -1601,7 +1591,8 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    * @param int $file
    *   Email sent.
    *
-   * @return array|void $activity object of newly creted activity via email@access public
+   * @return array|void
+   *   $activity object of newly creted activity via email
    */
   public static function recordActivityViaEmail($file) {
     if (!file_exists($file) ||
@@ -1692,10 +1683,10 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    *
    * @param string $type
    *
-   * @return array  $activityInfo Array of scheduled activity type and date
+   * @return array
+   *   Array of scheduled activity type and date
    *
    *
-   * @static
    */
   public static function getNextScheduledActivity($cases, $type = 'upcoming') {
     $session = CRM_Core_Session::singleton();
@@ -1731,8 +1722,8 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
   /**
    * Combine all the exportable fields from the lower levels object
    *
-   * @return array array of exportable Fields
-   * @static
+   * @return array
+   *   array of exportable Fields
    */
   public static function &exportableFields() {
     if (!self::$_exportableFields) {
@@ -1762,8 +1753,7 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    * @param int $caseId
    *   Id of the case to restore.
    *
-   * @return true if success.
-   * @static
+   * @return bool
    */
   public static function restoreCase($caseId) {
     //restore activities
@@ -1860,11 +1850,11 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    * @param array $criteriaParams
    *   Given criteria.
    * @param bool $latestDate
-   *   If set newest or oldest date is selceted.
+   *   If set newest or oldest date is selected.
    *
-   * @return returns case activities due dates
+   * @return array
+   *   case activities due dates
    *
-   * @static
    */
   public static function getCaseActivityDates($caseID, $criteriaParams = array(), $latestDate = FALSE) {
     $values = array();
@@ -1872,7 +1862,7 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
     $where = $groupBy = ' ';
 
     if (!$caseID) {
-      return;
+      return NULL;
     }
 
     if ($latestDate) {
@@ -1916,9 +1906,9 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    *   Case role assignee contactId.
    * @param int $contactId
    *
-   * @return void on success creates activity and case activity
+   * @return void
+   *   on success creates activity and case activity
    *
-   * @static
    */
   public static function createCaseRoleActivity($caseId, $relationshipId, $relContactId = NULL, $contactId = NULL) {
     if (!$caseId || !$relationshipId || empty($relationshipId)) {
@@ -2010,13 +2000,13 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
    * @param int $caseId
    *   Case id.
    *
-   * @return array $caseManagerContact array of contact on success otherwise empty
+   * @return array
+   *   array of contact on success otherwise empty
    *
-   * @static
    */
   public static function getCaseManagerContact($caseType, $caseId) {
     if (!$caseType || !$caseId) {
-      return;
+      return NULL;
     }
 
     $caseManagerContact = array();
@@ -2049,13 +2039,16 @@ SELECT civicrm_contact.id as casemanager_id,
   }
 
   /**
-   * Get all cases with no end dates
+   * Get all cases with no end dates.
    *
    * @param array $params
    * @param array $excludeCaseIds
    * @param bool $excludeDeleted
    *
-   * @return array of case and related data keyed on case id
+   * @param bool $includeClosed
+   *
+   * @return array
+   *   Case and related data keyed on case id
    */
   public static function getUnclosedCases($params = array(), $excludeCaseIds = array(), $excludeDeleted = TRUE, $includeClosed = FALSE) {
     //params from ajax call.
@@ -2183,8 +2176,7 @@ LEFT JOIN  civicrm_case_contact ON ( civicrm_case.id = civicrm_case_contact.case
    * @param bool $excludeDeleted
    *   Do not include deleted cases.
    *
-   * @return an array of cases.
-   *
+   * @return array
    */
   public static function getContactCases($contactId, $excludeDeleted = TRUE) {
     $cases = array();
@@ -2227,8 +2219,7 @@ INNER JOIN  civicrm_case_contact ON ( civicrm_case.id = civicrm_case_contact.cas
    * @param bool $excludeDeleted
    *   Do not include deleted cases.
    *
-   * @return an array of related cases.
-   *
+   * @return array
    */
   public static function getRelatedCases($mainCaseId, $contactId, $excludeDeleted = TRUE) {
     //FIXME : do check for permissions.
@@ -2335,6 +2326,9 @@ INNER JOIN  civicrm_case_contact ON ( civicrm_case.id = civicrm_case_contact.cas
    * @see CRM_Dedupe_Merger::cpTables()
    *
    * TODO: use the 3rd $sqls param to append sql statements rather than executing them here
+   *
+   * @param int $mainContactId
+   * @param int $otherContactId
    */
   public static function mergeContacts($mainContactId, $otherContactId) {
     self::mergeCases($mainContactId, NULL, $otherContactId);
@@ -2356,10 +2350,9 @@ INNER JOIN  civicrm_case_contact ON ( civicrm_case.id = civicrm_case_contact.cas
    *
    * @param bool $changeClient
    *
-   * @return integer|NULL
-   * @static
+   * @return int|NULL
    */
-  static function mergeCases(
+  public static function mergeCases(
     $mainContactId, $mainCaseId = NULL, $otherContactId = NULL,
     $otherCaseId = NULL, $changeClient = FALSE) {
     $moveToTrash = TRUE;
@@ -2773,7 +2766,6 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    *   Info of the activity.
    *
    * @return void
-   * @static
    */
   public static function buildPermissionLinks(&$tplParams, $activityParams) {
     $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityParams['source_record_id'],
@@ -2819,8 +2811,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    * @param bool $checkComponent
    *   Do we need to check component enabled.
    *
-   * @return boolean $allow  true/false
-   * @static
+   * @return bool
    */
   public static function checkPermission($activityId, $operation, $actTypeId = NULL, $contactId = NULL, $checkComponent = TRUE) {
     $allow = FALSE;
@@ -3131,7 +3122,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    * @param int $activityID
    *   Activity id.
    *
-   * @return boolean  $isCaseActivity true/false
+   * @return bool
    */
   public static function isCaseActivity($activityID) {
     $isCaseActivity = FALSE;
@@ -3149,8 +3140,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
   /**
    * Get all the case type ids currently in use
    *
-   *
-   * @return array $caseTypeIds
+   * @return array
    */
   public static function getUsedCaseType() {
     static $caseTypeIds;
@@ -3174,8 +3164,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
   /**
    * Get all the case status ids currently in use
    *
-   *
-   * @return array $caseStatusIds
+   * @return array
    */
   public static function getUsedCaseStatuses() {
     static $caseStatusIds;
@@ -3195,6 +3184,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
 
   /**
    * Get all the encounter medium ids currently in use
+   *
    * @return array
    */
   public static function getUsedEncounterMediums() {
@@ -3218,7 +3208,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    *
    * @param int $contactId
    *
-   * @return array $configured
+   * @return array
    */
   public static function isCaseConfigured($contactId = NULL) {
     $configured = array_fill_keys(array('configured', 'allowToAddNewCase', 'redirectToCaseAdmin'), FALSE);
@@ -3265,6 +3255,8 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
 
   /**
    * Used during case component enablement and during ugprade
+   *
+   * @return bool
    */
   public static function createCaseViews() {
     $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
@@ -3299,6 +3291,10 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
 
   /**
    * Helper function, also used by the upgrade in case of error
+   *
+   * @param string $section
+   *
+   * @return string
    */
   public static function createCaseViewsQuery($section = 'upcoming') {
     $sql = "";
@@ -3373,8 +3369,8 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    *
    * @param int $caseId
    *
-   * @return array $clients associated array with client ids
-   * @static
+   * @return array
+   *   associated array with client ids
    */
   public static function getCaseClients($caseId) {
     $clients = array();
@@ -3395,11 +3391,11 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    *
    * @param string $fieldName
    * @param string $context
-   *   : @see CRM_Core_DAO::buildOptionsContext.
+   * @see CRM_Core_DAO::buildOptionsContext
    * @param array $props
-   *   : whatever is known about this dao object.
+   *   Whatever is known about this dao object.
    *
-   * @return Array|bool
+   * @return array|bool
    */
   public static function buildOptions($fieldName, $context = NULL, $props = array()) {
     $className = __CLASS__;
@@ -3412,4 +3408,5 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
     }
     return CRM_Core_PseudoConstant::get($className, $fieldName, $params, $context);
   }
+
 }