コード例 #1
0
 /**
  * Fetch object based on array of properties.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param array $defaults
  *   (reference ) an assoc array to hold the flattened values.
  *
  * @return CRM_Activity_DAO_Activity
  */
 public static function retrieve(&$params, &$defaults)
 {
     $activity = new CRM_Activity_DAO_Activity();
     $activity->copyValues($params);
     if ($activity->find(TRUE)) {
         $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
         $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
         $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
         $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
         // TODO: at some stage we'll have to deal
         //       with multiple values for assignees and targets, but
         //       for now, let's just fetch first row.
         $defaults['assignee_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $assigneeID);
         $assignee_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID);
         $defaults['assignee_contact_value'] = implode('; ', $assignee_contact_names);
         $sourceContactId = self::getActivityContact($activity->id, $sourceID);
         if ($activity->activity_type_id != CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name')) {
             $defaults['target_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID);
             $target_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID);
             $defaults['target_contact_value'] = implode('; ', $target_contact_names);
         } elseif (CRM_Core_Permission::check('access CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
             $defaults['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$activity->source_record_id}&reset=1&atype={$activity->activity_type_id}&aid={$activity->id}&cid={$sourceContactId}&context=activity");
         } else {
             $defaults['target_contact_value'] = ts('(recipients)');
         }
         $sourceContactId = self::getActivityContact($activity->id, $sourceID);
         $defaults['source_contact_id'] = $sourceContactId;
         if ($sourceContactId && !CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactId, 'is_deleted')) {
             $defaults['source_contact'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactId, 'sort_name');
         }
         // Get case subject.
         $defaults['case_subject'] = CRM_Case_BAO_Case::getCaseSubject($activity->id);
         CRM_Core_DAO::storeValues($activity, $defaults);
         return $activity;
     }
     return NULL;
 }
コード例 #2
0
ファイル: Activity.php プロジェクト: bhirsch/voipdev
 /**
  * Takes a bunch of params that are needed to match certain criteria and
  * retrieves the relevant objects. Typically the valid params are only
  * contact_id. We'll tweak this function to be more full featured over a period
  * of time. This is the inverse function of create. It also stores all the retrieved
  * values in the default array
  *
  * @param array  $params   (reference ) an assoc array of name/value pairs
  * @param array  $defaults (reference ) an assoc array to hold the flattened values
  * @param string $activityType activity type
  *
  * @return object CRM_Core_BAO_Meeting object
  * @access public
  */
 public function retrieve(&$params, &$defaults)
 {
     $activity =& new CRM_Activity_DAO_Activity();
     $activity->copyValues($params);
     if ($activity->find(true)) {
         require_once "CRM/Contact/BAO/Contact.php";
         // TODO: at some stage we'll have to deal
         // TODO: with multiple values for assignees and targets, but
         // TODO: for now, let's just fetch first row
         $defaults['assignee_contact'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id);
         $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id);
         $defaults['assignee_contact_value'] = null;
         foreach ($assignee_contact_names as $key => $name) {
             $defaults['assignee_contact_value'] .= $defaults['assignee_contact_value'] ? "; {$name}" : "{$name}";
         }
         if ($activity->activity_type_id != CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name')) {
             require_once 'CRM/Activity/BAO/ActivityTarget.php';
             $defaults['target_contact'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id);
             $target_contact_names = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id);
             $defaults['target_contact_value'] = null;
             foreach ($target_contact_names as $key => $name) {
                 $defaults['target_contact_value'] .= $defaults['target_contact_value'] ? "; {$name}" : "{$name}";
             }
         } else {
             if (CRM_Core_Permission::check('access CiviMail')) {
                 $defaults['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$activity->source_record_id}&reset=1&atype={$activity->activity_type_id}&aid={$activity->id}&cid={$activity->source_contact_id}&context=activity");
             } else {
                 $defaults['target_contact_value'] = ts('(recipients)');
             }
         }
         if ($activity->source_contact_id) {
             $defaults['source_contact'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $activity->source_contact_id, 'sort_name');
         }
         //get case subject
         require_once "CRM/Case/BAO/Case.php";
         $defaults['case_subject'] = CRM_Case_BAO_Case::getCaseSubject($activity->id);
         CRM_Core_DAO::storeValues($activity, $defaults);
         return $activity;
     }
     return null;
 }