/** * Build the form object. * * * @param CRM_Core_Form $form * * @return void */ public static function buildQuickForm(&$form) { $toArray = array(); $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc'); $providerSelect = array(); foreach ($providers as $provider) { $providerSelect[$provider['id']] = $provider['title']; } $suppressedSms = 0; //here we are getting logged in user id as array but we need target contact id. CRM-5988 $cid = $form->get('cid'); if ($cid) { $form->_contactIds = array($cid); } $to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE); $form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE); $toSetDefault = TRUE; if (property_exists($form, '_context') && $form->_context == 'standalone') { $toSetDefault = FALSE; } // when form is submitted recompute contactIds $allToSMS = array(); if ($to->getValue()) { $allToPhone = explode(',', $to->getValue()); $form->_contactIds = array(); foreach ($allToPhone as $value) { list($contactId, $phone) = explode('::', $value); if ($contactId) { $form->_contactIds[] = $contactId; $form->_toContactPhone[] = $phone; } } $toSetDefault = TRUE; } //get the group of contacts as per selected by user in case of Find Activities if (!empty($form->_activityHolderIds)) { $extendTargetContacts = 0; $invalidActivity = 0; $validActivities = 0; foreach ($form->_activityHolderIds as $key => $id) { //valid activity check if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $id, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) { $invalidActivity++; continue; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); //target contacts limit check $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID)); if (count($ids) > 1) { $extendTargetContacts++; continue; } $validActivities++; $form->_contactIds = empty($form->_contactIds) ? $ids : array_unique(array_merge($form->_contactIds, $ids)); } if (!$validActivities) { $errorMess = ""; if ($extendTargetContacts) { $errorMess = ts('One selected activity consists of more than one target contact.', array('count' => $extendTargetContacts, 'plural' => '%count selected activities consist of more than one target contact.')); } if ($invalidActivity) { $errorMess = $errorMess ? ' ' : ''; $errorMess .= ts('The selected activity is invalid.', array('count' => $invalidActivity, 'plural' => '%count selected activities are invalid.')); } CRM_Core_Error::statusBounce(ts("%1: SMS Reply will not be sent.", array(1 => $errorMess))); } } if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) { $returnProperties = array('sort_name' => 1, 'phone' => 1, 'do_not_sms' => 1, 'is_deceased' => 1, 'display_name' => 1); list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds, $returnProperties, FALSE, FALSE); // make a copy of all contact details $form->_allContactDetails = $form->_contactDetails; foreach ($form->_contactIds as $key => $contactId) { $value = $form->_contactDetails[$contactId]; //to check if the phone type is "Mobile" $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name'); if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') { //to check for "if the contact id belongs to a specified activity type" $actDetails = CRM_Activity_BAO_Activity::getContactActivity($contactId); if (self::RECIEVED_SMS_ACTIVITY_SUBJECT != CRM_Utils_Array::retrieveValueRecursive($actDetails, 'subject')) { $suppressedSms++; unset($form->_contactDetails[$contactId]); continue; } } if (isset($value['phone_type_id']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) || $value['do_not_sms'] || empty($value['phone']) || !empty($value['is_deceased'])) { //if phone is not primary check if non-primary phone is "Mobile" if (!empty($value['phone']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) && empty($value['is_deceased'])) { $filter = array('do_not_sms' => 0); $contactPhones = CRM_Core_BAO_Phone::allPhones($contactId, FALSE, 'Mobile', $filter); if (count($contactPhones) > 0) { $mobilePhone = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'phone'); $form->_contactDetails[$contactId]['phone_id'] = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'id'); $form->_contactDetails[$contactId]['phone'] = $mobilePhone; $form->_contactDetails[$contactId]['phone_type_id'] = CRM_Utils_Array::value('Mobile', $phoneTypes); } else { $suppressedSms++; unset($form->_contactDetails[$contactId]); continue; } } else { $suppressedSms++; unset($form->_contactDetails[$contactId]); continue; } } if (isset($mobilePhone)) { $phone = $mobilePhone; } elseif (empty($form->_toContactPhone)) { $phone = $value['phone']; } else { $phone = CRM_Utils_Array::value($key, $form->_toContactPhone); } if ($phone) { $toArray[] = array('text' => '"' . $value['sort_name'] . '" (' . $phone . ')', 'id' => "{$contactId}::{$phone}"); } } if (empty($toArray)) { CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid Phone, or communication preferences specify DO NOT SMS, or they are deceased')); } } //activity related variables if (isset($invalidActivity)) { $form->assign('invalidActivity', $invalidActivity); } if (isset($extendTargetContacts)) { $form->assign('extendTargetContacts', $extendTargetContacts); } $form->assign('toContact', json_encode($toArray)); $form->assign('suppressedSms', $suppressedSms); $form->assign('totalSelectedContacts', count($form->_contactIds)); $form->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE); CRM_Mailing_BAO_Mailing::commonCompose($form); if ($form->_single) { // also fix the user context stack if ($form->_context) { $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); } else { $url = CRM_Utils_System::url('civicrm/contact/view', "&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity"); } $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); $form->addDefaultButtons(ts('Send SMS'), 'upload', 'cancel'); } else { $form->addDefaultButtons(ts('Send SMS'), 'upload'); } $form->addFormRule(array('CRM_Contact_Form_Task_SMSCommon', 'formRule'), $form); }
/** * Returns all the rows in the given offset and rowCount. * * @param string $action * The action being performed. * @param int $offset * The row number to start from. * @param int $rowCount * The number of rows to return. * @param string $sort * The sql string that describes the sort order. * @param string $output * What should the result set include (web/email/csv). * * @return array * rows in the given offset and rowCount */ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_activityClause); $rows = array(); $mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs(); $accessCiviMail = CRM_Core_Permission::check('access CiviMail'); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); //get all activity types $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE); while ($result->fetch()) { $row = array(); // ignore rows where we dont have an activity id if (empty($result->activity_id)) { continue; } // the columns we are interested in foreach (self::$_properties as $property) { if (isset($result->{$property})) { $row[$property] = $result->{$property}; } } $contactId = CRM_Utils_Array::value('contact_id', $row); if (!$contactId) { $contactId = CRM_Utils_Array::value('source_contact_id', $row); } $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $targetID); $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $assigneeID); list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $sourceID, TRUE); $row['source_contact_name'] = implode(',', array_values($row['source_contact_name'])); $row['source_contact_id'] = implode(',', $row['source_contact_id']); if ($this->_context == 'search') { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->activity_id; } $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $accessMailingReport = FALSE; $activityTypeId = $row['activity_type_id']; if ($row['activity_is_test']) { $row['activity_type'] = $row['activity_type'] . " (test)"; } $bulkActivityTypeID = CRM_Utils_Array::key('Bulk Email', $activityTypes); $row['mailingId'] = ''; if ($accessCiviMail && ($mailingIDs === TRUE || in_array($result->source_record_id, $mailingIDs)) && $bulkActivityTypeID == $activityTypeId) { $row['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector"); $row['recipients'] = ts('(recipients)'); $row['target_contact_name'] = ''; $row['assignee_contact_name'] = ''; $accessMailingReport = TRUE; } $activityActions = new CRM_Activity_Selector_Activity($result->contact_id, NULL); $actionLinks = $activityActions->actionLinks($activityTypeId, CRM_Utils_Array::value('source_record_id', $row), $accessMailingReport, CRM_Utils_Array::value('activity_id', $row), $this->_key, $this->_compContext); $row['action'] = CRM_Core_Action::formLink($actionLinks, NULL, array('id' => $result->activity_id, 'cid' => $contactId, 'cxt' => $this->_context), ts('more'), FALSE, 'activity.selector.row', 'Activity', $result->activity_id); //carry campaign to selector. $row['campaign'] = CRM_Utils_Array::value($result->activity_campaign_id, $allCampaigns); $row['campaign_id'] = $result->activity_campaign_id; if ($engagementLevel = CRM_Utils_Array::value('activity_engagement_level', $row)) { $row['activity_engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel); } //Check if recurring activity $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($row['activity_id'], 'civicrm_activity'); $row['repeat'] = ''; if ($repeat) { $row['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])); } $rows[] = $row; } return $rows; }
/** * Delete the activity. * * @param array $params * @param bool $moveToTrash * * @return mixed */ public static function deleteActivity(&$params, $moveToTrash = FALSE) { // CRM-9137 if (!empty($params['id']) && !is_array($params['id'])) { CRM_Utils_Hook::pre('delete', 'Activity', $params['id'], $params); } else { CRM_Utils_Hook::pre('delete', 'Activity', NULL, $params); } $transaction = new CRM_Core_Transaction(); if (is_array(CRM_Utils_Array::value('source_record_id', $params))) { $sourceRecordIds = implode(',', $params['source_record_id']); } else { $sourceRecordIds = CRM_Utils_Array::value('source_record_id', $params); } $result = NULL; if (!$moveToTrash) { if (!isset($params['id'])) { if (is_array($params['activity_type_id'])) { $activityTypes = implode(',', $params['activity_type_id']); } else { $activityTypes = $params['activity_type_id']; } $query = "DELETE FROM civicrm_activity WHERE source_record_id IN ({$sourceRecordIds}) AND activity_type_id IN ( {$activityTypes} )"; $dao = CRM_Core_DAO::executeQuery($query); } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $result = $activity->delete(); // CRM-8708 $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); // CRM-13994 delete activity entity_tag $query = "DELETE FROM civicrm_entity_tag WHERE entity_table = 'civicrm_activity' AND entity_id = {$activity->id}"; $dao = CRM_Core_DAO::executeQuery($query); } } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->is_deleted = 1; $result = $activity->save(); // CRM-4525 log activity delete $logMsg = 'Case Activity deleted for'; $msgs = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $sourceContactId = self::getActivityContact($activity->id, $sourceID); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } // get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } // get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID); if (!empty($assigneeContactIds)) { $msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity if ($result) { $activityRecent = array('id' => $activity->id, 'type' => 'Activity'); CRM_Utils_Recent::del($activityRecent); } $transaction->commit(); if (isset($activity)) { // CRM-8708 $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); CRM_Utils_Hook::post('delete', 'Activity', $activity->id, $activity); } return $result; }
/** * Function to get Case Activities * * @param int $caseID case id * @param array $params posted params * @param int $contactID contact id * * @param null $context * @param null $userID * @param null $type * * @return returns case activities * * @static */ static function getCaseActivity($caseID, &$params, $contactID, $context = NULL, $userID = NULL, $type = NULL) { $values = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); // CRM-5081 - formatting the dates to omit seconds. // Note the 00 in the date format string is needed otherwise later on it thinks scheduled ones are overdue. $select = "SELECT count(ca.id) as ismultiple, ca.id as id,\n ca.activity_type_id as type,\n ca.activity_type_id as activity_type_id,\n cc.sort_name as reporter,\n cc.id as reporter_id,\n acc.sort_name AS assignee,\n acc.id AS assignee_id,\n DATE_FORMAT(IF(ca.activity_date_time < NOW() AND ca.status_id=ov.value,\n ca.activity_date_time,\n DATE_ADD(NOW(), INTERVAL 1 YEAR)\n ), '%Y%m%d%H%i00') as overdue_date,\n DATE_FORMAT(ca.activity_date_time, '%Y%m%d%H%i00') as display_date,\n ca.status_id as status,\n ca.subject as subject,\n ca.is_deleted as deleted,\n ca.priority_id as priority,\n ca.weight as weight,\n GROUP_CONCAT(ef.file_id) as attachment_ids "; $from = "\n FROM civicrm_case_activity cca\n INNER JOIN civicrm_activity ca ON ca.id = cca.activity_id\n INNER JOIN civicrm_activity_contact cac ON cac.activity_id = ca.id AND cac.record_type_id = {$sourceID}\n INNER JOIN civicrm_contact cc ON cc.id = cac.contact_id\n INNER JOIN civicrm_option_group cog ON cog.name = 'activity_type'\n INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id\n AND cov.value = ca.activity_type_id AND cov.is_active = 1\n LEFT JOIN civicrm_entity_file ef on ef.entity_table = 'civicrm_activity' AND ef.entity_id = ca.id\n LEFT OUTER JOIN civicrm_option_group og ON og.name = 'activity_status'\n LEFT OUTER JOIN civicrm_option_value ov ON ov.option_group_id=og.id AND ov.name = 'Scheduled'\n LEFT JOIN civicrm_activity_contact caa\n ON caa.activity_id = ca.id AND caa.record_type_id = {$assigneeID}\n LEFT JOIN civicrm_contact acc ON acc.id = caa.contact_id "; $where = 'WHERE cca.case_id= %1 AND ca.is_current_revision = 1'; if (!empty($params['reporter_id'])) { $where .= " AND cac.contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer'); } if (!empty($params['status_id'])) { $where .= " AND ca.status_id = " . CRM_Utils_Type::escape($params['status_id'], 'Integer'); } if (!empty($params['activity_deleted'])) { $where .= " AND ca.is_deleted = 1"; } else { $where .= " AND ca.is_deleted = 0"; } if (!empty($params['activity_type_id'])) { $where .= " AND ca.activity_type_id = " . CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'); } if (!empty($params['activity_date_low'])) { $fromActivityDate = CRM_Utils_Type::escape(CRM_Utils_Date::processDate($params['activity_date_low']), 'Date'); } if (!empty($params['activity_date_high'])) { $toActivityDate = CRM_Utils_Type::escape(CRM_Utils_Date::processDate($params['activity_date_high']), 'Date'); $toActivityDate = $toActivityDate ? $toActivityDate + 235959 : NULL; } if (!empty($fromActivityDate)) { $where .= " AND ca.activity_date_time >= '{$fromActivityDate}'"; } if (!empty($toActivityDate)) { $where .= " AND ca.activity_date_time <= '{$toActivityDate}'"; } // hack to handle to allow initial sorting to be done by query if (CRM_Utils_Array::value('sortname', $params) == 'undefined') { $params['sortname'] = NULL; } if (CRM_Utils_Array::value('sortorder', $params) == 'undefined') { $params['sortorder'] = NULL; } $sortname = CRM_Utils_Array::value('sortname', $params); $sortorder = CRM_Utils_Array::value('sortorder', $params); $groupBy = " GROUP BY ca.id "; if (!$sortname and !$sortorder) { // CRM-5081 - added id to act like creation date $orderBy = " ORDER BY overdue_date ASC, display_date DESC, weight DESC"; } else { $sort = "{$sortname} {$sortorder}"; $sort = CRM_Utils_Type::escape($sort, 'String'); $orderBy = " ORDER BY {$sort} "; if ($sortname != 'display_date') { $orderBy .= ', display_date DESC'; } } $page = CRM_Utils_Array::value('page', $params); $rp = CRM_Utils_Array::value('rp', $params); if (!$page) { $page = 1; } if (!$rp) { $rp = 10; } $start = ($page - 1) * $rp; $query = $select . $from . $where . $groupBy . $orderBy; $params = array(1 => array($caseID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); $params['total'] = $dao->N; //FIXME: need to optimize/cache these queries $limit = " LIMIT {$start}, {$rp}"; $query .= $limit; //EXIT; $dao = CRM_Core_DAO::executeQuery($query, $params); $activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, TRUE); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $activityPriority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); $url = CRM_Utils_System::url("civicrm/case/activity", "reset=1&cid={$contactID}&caseid={$caseID}", FALSE, NULL, FALSE); $contextUrl = ''; if ($context == 'fulltext') { $contextUrl = "&context={$context}"; } $editUrl = "{$url}&action=update{$contextUrl}"; $deleteUrl = "{$url}&action=delete{$contextUrl}"; $restoreUrl = "{$url}&action=renew{$contextUrl}"; $viewTitle = ts('View this activity.'); $statusTitle = ts('Edit status'); $emailActivityTypeIDs = array('Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'), 'Inbound Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Inbound Email', 'name')); $emailActivityTypeIDs = array('Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'), 'Inbound Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Inbound Email', 'name')); $caseDeleted = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseID, 'is_deleted'); // define statuses which are handled like Completed status (others are assumed to be handled like Scheduled status) $compStatusValues = array(); $compStatusNames = array('Completed', 'Left Message', 'Cancelled', 'Unreachable', 'Not Required'); foreach ($compStatusNames as $name) { $compStatusValues[] = CRM_Core_OptionGroup::getValue('activity_status', $name, 'name'); } $contactViewUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid=", FALSE, NULL, FALSE); $hasViewContact = CRM_Core_Permission::giveMeAllACLs(); $clientIds = self::retrieveContactIdsByCaseId($caseID); if (!$userID) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); } while ($dao->fetch()) { $allowView = self::checkPermission($dao->id, 'view', $dao->activity_type_id, $userID); $allowEdit = self::checkPermission($dao->id, 'edit', $dao->activity_type_id, $userID); $allowDelete = self::checkPermission($dao->id, 'delete', $dao->activity_type_id, $userID); //do not have sufficient permission //to access given case activity record. if (!$allowView && !$allowEdit && !$allowDelete) { continue; } $values[$dao->id]['id'] = $dao->id; $values[$dao->id]['type'] = $activityTypes[$dao->type]['label']; $reporterName = $dao->reporter; if ($hasViewContact) { $reporterName = '<a href="' . $contactViewUrl . $dao->reporter_id . '">' . $dao->reporter . '</a>'; } $values[$dao->id]['reporter'] = $reporterName; $targetNames = CRM_Activity_BAO_ActivityContact::getNames($dao->id, $targetID); $targetContactUrls = $withContacts = array(); foreach ($targetNames as $targetId => $targetName) { if (!in_array($targetId, $clientIds)) { $withContacts[$targetId] = $targetName; } } foreach ($withContacts as $cid => $name) { if ($hasViewContact) { $name = '<a href="' . $contactViewUrl . $cid . '">' . $name . '</a>'; } $targetContactUrls[] = $name; } $values[$dao->id]['with_contacts'] = implode('; ', $targetContactUrls); $values[$dao->id]['display_date'] = CRM_Utils_Date::customFormat($dao->display_date); $values[$dao->id]['status'] = $activityStatus[$dao->status]; //check for view activity. $subject = empty($dao->subject) ? '(' . ts('no subject') . ')' : $dao->subject; if ($allowView) { $url = CRM_Utils_System::url('civicrm/case/activity/view', array('cid' => $contactID, 'aid' => $dao->id)); $subject = '<a class="crm-popup medium-popup" href="' . $url . '" title="' . $viewTitle . '">' . $subject . '</a>'; } $values[$dao->id]['subject'] = $subject; // add activity assignee to activity selector. CRM-4485. if (isset($dao->assignee)) { if ($dao->ismultiple == 1) { if ($dao->reporter_id != $dao->assignee_id) { $values[$dao->id]['reporter'] .= $hasViewContact ? ' / ' . "<a href='{$contactViewUrl}{$dao->assignee_id}'>{$dao->assignee}</a>" : ' / ' . $dao->assignee; } $values[$dao->id]['assignee'] = $dao->assignee; } else { $values[$dao->id]['reporter'] .= ' / ' . ts('(multiple)'); } } // FIXME: Why are we not using CRM_Core_Action for these links? This is too much manual work and likely to get out-of-sync with core markup. $url = ""; $css = 'class="action-item crm-hover-button"'; $additionalUrl = "&id={$dao->id}"; if (!$dao->deleted) { //hide edit link of activity type email.CRM-4530. if (!in_array($dao->type, $emailActivityTypeIDs)) { //hide Edit link if activity type is NOT editable (special case activities).CRM-5871 if ($allowEdit) { $url = '<a ' . $css . ' href="' . $editUrl . $additionalUrl . '">' . ts('Edit') . '</a> '; } } if ($allowDelete) { $url .= ' <a ' . str_replace('action-item', 'action-item small-popup', $css) . ' href="' . $deleteUrl . $additionalUrl . '">' . ts('Delete') . '</a>'; } } elseif (!$caseDeleted) { $url = ' <a ' . $css . ' href="' . $restoreUrl . $additionalUrl . '">' . ts('Restore') . '</a>'; $values[$dao->id]['status'] = $values[$dao->id]['status'] . '<br /> (deleted)'; } //check for operations. if (self::checkPermission($dao->id, 'Move To Case', $dao->activity_type_id)) { $url .= ' <a ' . $css . ' href="#" onClick="Javascript:fileOnCase( \'move\',' . $dao->id . ', ' . $caseID . ', this ); return false;">' . ts('Move To Case') . '</a> '; } if (self::checkPermission($dao->id, 'Copy To Case', $dao->activity_type_id)) { $url .= ' <a ' . $css . ' href="#" onClick="Javascript:fileOnCase( \'copy\',' . $dao->id . ',' . $caseID . ', this ); return false;">' . ts('Copy To Case') . '</a> '; } // if there are file attachments we will return how many and, if only one, add a link to it if (!empty($dao->attachment_ids)) { $attachmentIDs = explode(',', $dao->attachment_ids); $values[$dao->id]['no_attachments'] = count($attachmentIDs); if ($values[$dao->id]['no_attachments'] == 1) { // if there is only one it's easy to do a link - otherwise just flag it $attachmentViewUrl = CRM_Utils_System::url("civicrm/file", "reset=1&eid=" . $dao->id . "&id=" . $dao->attachment_ids, FALSE, NULL, FALSE); $url .= " <a href='{$attachmentViewUrl}' ><span class='icon paper-icon'></span></a>"; } } $values[$dao->id]['links'] = $url; $values[$dao->id]['class'] = ""; if (!empty($dao->priority)) { if ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Urgent', 'name')) { $values[$dao->id]['class'] = $values[$dao->id]['class'] . "priority-urgent "; } elseif ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Low', 'name')) { $values[$dao->id]['class'] = $values[$dao->id]['class'] . "priority-low "; } } if (CRM_Utils_Array::crmInArray($dao->status, $compStatusValues)) { $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-completed"; } else { if (CRM_Utils_Date::overdue($dao->display_date)) { $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-overdue"; } else { $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-scheduled"; } } 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>'; } } $dao->free(); return $values; }
/** * Process activity creation. * * @param array $params * Associated array of submitted values. * * @return self|null|object */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } // Save static tags. CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); // Save free tags. if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 if (!empty($params['is_multi_activity'])) { $this->_activityIds[] = $activity->id; } else { $this->_activityId = $activity->id; } // create follow up activity if needed $followupStatus = ''; $followupActivity = NULL; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (Civi::settings()->get('activity_assignee_notification')) { $activityIDs = array($activity->id); if ($followupActivity) { $activityIDs = array_merge($activityIDs, array($followupActivity->id)); } $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { $mailToContacts = array(); // Build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } $sent = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts); if ($sent) { $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // Also send email to follow-up activity assignees if set if ($followupActivity) { $mailToFollowupContacts = array(); foreach ($assigneeContacts as $values) { if ($values['activity_id'] == $followupActivity->id) { $mailToFollowupContacts[$values['email']] = $values; } } $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts); if ($sentFollowup) { $mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); } } } // set status message $subject = ''; if (!empty($params['subject'])) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }
function &getActivity($clientID, $activityDAO, &$activityTypeInfo) { if (empty($this->_redactionStringRules)) { $this->_redactionStringRules = array(); } $activity = array(); $activity['fields'] = array(); if ($clientID) { $clientID = CRM_Utils_Type::escape($clientID, 'Integer'); if (!in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) { $activity['editURL'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"); } else { $activity['editURL'] = ''; } $client = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name'); // add Client SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($client, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($client => 'name_' . rand(10000, 100000))); $clientSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name'); if (!array_key_exists($clientSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$clientSortName] = $this->_redactionStringRules[$client]; } } $activity['fields'][] = array('label' => 'Client', 'value' => $this->redact($client), 'type' => 'String'); } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); if (!empty($activityDAO->targetID)) { // Re-lookup the target ID since the DAO only has the first recipient if there are multiple. // Maybe not the best solution. $targetNames = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID); $processTarget = FALSE; $label = ts('With Contact(s)'); if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) { $processTarget = TRUE; $label = ts('Recipient'); } if (!$processTarget) { foreach ($targetNames as $targetID => $targetName) { if ($targetID != $clientID) { $processTarget = TRUE; break; } } } if ($processTarget) { $targetRedacted = array(); foreach ($targetNames as $targetID => $target) { // add Recipient SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($target, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($target => 'name_' . rand(10000, 100000))); $targetSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name'); if (!array_key_exists($targetSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$targetSortName] = $this->_redactionStringRules[$target]; } } $targetRedacted[] = $this->redact($target); } $activity['fields'][] = array('label' => $label, 'value' => implode('; ', $targetRedacted), 'type' => 'String'); } } // Activity Type info is a special field $activity['fields'][] = array('label' => ts('Activity Type'), 'value' => $activityTypeInfo['label'], 'type' => 'String'); $activity['fields'][] = array('label' => ts('Subject'), 'value' => htmlspecialchars($this->redact($activityDAO->subject)), 'type' => 'Memo'); $creator = $this->getCreatedBy($activityDAO->id); // add Creator to the strings to be redacted across the case session if (!array_key_exists($creator, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($creator => 'name_' . rand(10000, 100000))); } $activity['fields'][] = array('label' => ts('Created By'), 'value' => $this->redact($creator), 'type' => 'String'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID); $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'display_name'); // add Reporter SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($reporter, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($reporter => 'name_' . rand(10000, 100000))); $reporterSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'sort_name'); if (!array_key_exists($reporterSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$reporterSortName] = $this->_redactionStringRules[$reporter]; } } $activity['fields'][] = array('label' => ts('Reported By'), 'value' => $this->redact($reporter), 'type' => 'String'); if (!empty($activityDAO->assigneeID)) { //allow multiple assignee contacts.CRM-4503. $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE); foreach ($assignee_contact_names as &$assignee) { // add Assignee to the strings to be redacted across the case session $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($assignee => 'name_' . rand(10000, 100000))); $assignee = $this->redact($assignee); } $assigneeContacts = implode(', ', $assignee_contact_names); $activity['fields'][] = array('label' => ts('Assigned To'), 'value' => $assigneeContacts, 'type' => 'String'); } if ($activityDAO->medium_id) { $activity['fields'][] = array('label' => ts('Medium'), 'value' => CRM_Core_OptionGroup::getLabel('encounter_medium', $activityDAO->medium_id, FALSE), 'type' => 'String'); } $activity['fields'][] = array('label' => ts('Location'), 'value' => $activityDAO->location, 'type' => 'String'); $activity['fields'][] = array('label' => ts('Date and Time'), 'value' => $activityDAO->activity_date_time, 'type' => 'Date'); $activity['fields'][] = array('label' => ts('Details'), 'value' => $this->redact(CRM_Utils_String::stripAlternatives($activityDAO->details)), 'type' => 'Memo'); // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg if ($activityDAO->duration) { $activity['fields'][] = array('label' => ts('Duration'), 'value' => $activityDAO->duration . ' ' . ts('minutes'), 'type' => 'Int'); } $activity['fields'][] = array('label' => ts('Status'), 'value' => CRM_Core_OptionGroup::getLabel('activity_status', $activityDAO->status_id), 'type' => 'String'); $activity['fields'][] = array('label' => ts('Priority'), 'value' => CRM_Core_OptionGroup::getLabel('priority', $activityDAO->priority_id), 'type' => 'String'); //for now empty custom groups $activity['customGroups'] = $this->getCustomData($clientID, $activityDAO, $activityTypeInfo); return $activity; }
/** * Process the form after the input has been submitted and validated. */ public function postProcess() { // Clear any formRule errors from Email form in case they came back here via Cancel button $this->controller->resetPage('Email'); $params = $this->exportValues(); $this->_contacts = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); // Get assignee contacts. if (!empty($params['assigned_to'])) { foreach ($this->_activityHolderIds as $key => $id) { $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $assigneeID)); $this->_contacts = array_merge($this->_contacts, $ids); } } // Get target contacts. if (!empty($params['with_contact'])) { foreach ($this->_activityHolderIds as $key => $id) { $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID)); $this->_contacts = array_merge($this->_contacts, $ids); } } // Get 'Added by' contacts. if (!empty($params['created_by'])) { parent::setContactIDs(); if (!empty($this->_contactIds)) { $this->_contacts = array_merge($this->_contacts, $this->_contactIds); } } $this->_contacts = array_unique($this->_contacts); // Bounce to pick option if no contacts to send to. if (empty($this->_contacts)) { $urlParams = "_qf_PickOption_display=true&qfKey={$params['qfKey']}"; $urlRedirect = CRM_Utils_System::url('civicrm/activity/search', $urlParams); CRM_Core_Error::statusBounce(ts('It appears you have no contacts with email addresses from the selected recipients.'), $urlRedirect); } $this->set('contacts', $this->_contacts); }
static function recentApplicationActivities($limit = 10) { $recentActivities = array(); $customTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'application_case', 'table_name', 'name'); //Retrieve top $limit(as total activity count) recent activities $query = CRM_Case_BAO_Case::getCaseActivityQuery($type = 'any', NULL, $condition = "AND c_type.name = 'Application' AND t_act.desired_date <= CURRENT_TIMESTAMP "); $query .= "LIMIT 0, {$limit}"; $query = str_replace('ORDER BY case_activity_date ASC', 'ORDER BY case_activity_date DESC', $query); $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $query = "SELECT vacancy_id FROM {$customTableName} WHERE entity_id = {$dao->case_id}"; $ctDAO = CRM_Core_DAO::executeQuery($query); $ctDAO->fetch(); $vacancyDAO = new self(); $vacancyDAO->id = $ctDAO->vacancy_id; $vacancyDAO->find(TRUE); //Applicant contact link $applicant = "<a href='" . CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}") . "'>{$dao->sort_name}</a>"; //Position link $position = "<a href='" . CRM_Utils_System::url('civicrm/case/pipeline', "reset=1&vid={$vacancyDAO->id}") . "'>{$vacancyDAO->position}</a>"; //Case Activity Source link $sourceID = civicrm_api3('OptionValue', 'getvalue', array('option_group_id' => 'activity_contacts', 'name' => 'Activity Source', 'return' => 'value')); $sourceContact = CRM_Activity_BAO_ActivityContact::getNames($dao->case_activity_id, $sourceID); $sourceContactID = key($sourceContact); $source = "<a href='" . CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$sourceContactID}") . "'>{$sourceContact[$sourceContactID]}</a>"; switch ($dao->case_activity_type_name) { case 'Open Case': $recentActivities[] = array('activity' => "{$applicant} applied for {$position}", 'time' => $dao->case_activity_date); break; case 'Comment': $recentActivities[] = array('activity' => "{$source} commented on {$position}", 'time' => $dao->case_activity_date); break; case 'Phone Call': case 'Meeting': case 'Follow up': $recentActivities[] = array('activity' => "{$source} had a {$dao->case_activity_type_name} with {$applicant} (vis-a-vis {$position})", 'time' => $dao->case_activity_date); break; case 'Email': $recentActivities[] = array('activity' => "{$source} sent email to {$applicant}", 'time' => $dao->case_activity_date); break; case 'Change Case Status': $subject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $dao->case_activity_id, 'subject'); $subject = str_replace('Assignment status changed', '', $subject); $recentActivities[] = array('activity' => "{$source} changed the status of {$position} {$subject}", 'time' => $dao->case_activity_date); break; case 'Evaluation': $subject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $dao->case_activity_id, 'subject'); $recentActivities[] = array('activity' => "{$source} evaluated {$applicant} for {$position}", 'time' => $dao->case_activity_date); break; default: $subject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $dao->case_activity_id, 'subject'); $recentActivities[] = array('activity' => "{$position}: {$dao->case_activity_type_name} for {$applicant}", 'time' => $dao->case_activity_date); break; } } return $recentActivities; }
/** * Process activity creation * * @param array $params associated array of submitted values * @access protected */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 if (CRM_Utils_Array::value('is_multi_activity', $params)) { $this->_activityIds[] = $activity->id; } else { $this->_activityId = $activity->id; } // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sending a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $ics = new CRM_Activity_BAO_ICalendar($activity); $ics->addAttachment($attachments, $mailToContacts); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $ics->cleanup(); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message $subject = ''; if (CRM_Utils_Array::value('subject', $params)) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }