/** * Run the page. * * This method is called after the page is created. */ public function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $entityBlock = array('contact_id' => $contactId); $phones = CRM_Core_BAO_Phone::getValues($entityBlock); if (!empty($phones)) { foreach ($phones as $key => &$value) { $value['location_type'] = $locationTypes[$value['location_type_id']]; $value['phone_type'] = $phoneTypes[$value['phone_type_id']]; } } $contact = new CRM_Contact_BAO_Contact(); $contact->id = $contactId; $contact->find(TRUE); $privacy = array(); foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) { if (isset($contact->{$name})) { $privacy[$name] = $contact->{$name}; } } $this->assign('contactId', $contactId); $this->assign('phone', $phones); $this->assign('privacy', $privacy); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * AllPhones() method - get all Phones for our contact, with primary Phone first */ public function testAllPhones() { $contactParams = array('first_name' => 'Alan', 'last_name' => 'Smith', 'phone-1' => '(415) 222-1011 x 221', 'phone-2' => '(415) 222-5432'); $contactId = Contact::createIndividual($contactParams); $Phones = CRM_Core_BAO_Phone::allPhones($contactId); $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.'); $firstPhoneValue = array_slice($Phones, 0, 1); // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location // type for first phone and sets that to primary. $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} )."); $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.'); Contact::delete($contactId); }
static function relatedContactInfo($contactId) { $return = array(); if (empty($contactId)) { return $return; } $phone = CRM_Core_BAO_Phone::allPhones($contactId, TRUE, NULL, array('is_primary' => 1)); $contactSubType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $contactType = CRM_Contact_BAO_ContactType::getLabel($contactSubType[0]); $gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'PCP_Supporter_Profile', 'id', 'name'); $updateURL = CRM_Utils_System::url('civicrm/profile/edit', "reset=1&gid={$gid}&cid={$contactId}"); // $updateURL =CRM_Utils_System::url('civicrm/pcp/support', "action=browse&component=event&id={$params['pcpId']}"); $return = array('name' => CRM_Contact_BAO_Contact::displayName($contactId), 'type' => $contactType, 'email' => CRM_Contact_BAO_Contact::getPrimaryEmail($contactId), 'phone' => !empty($phone) && isset($phone[1]['phone']) ? $phone[1]['phone'] : NULL, 'action' => "<a href={$updateURL}>Update Contact Information</a>"); return $return; }
/** * takes an associative array and creates a contact object * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * @param int $locationId * @param int $phoneId * @param bool $isPrimary Has any previous entry been marked as isPrimary? * * @return object CRM_Core_BAO_Phone object on success, null otherwise * @access public * @static */ function add(&$params, &$ids, $locationId, $phoneId, &$isPrimary) { if (!CRM_Core_BAO_Phone::dataExists($params, $locationId, $phoneId, $ids)) { return null; } $phone =& new CRM_Core_DAO_Phone(); $phone->id = CRM_Utils_Array::value($phoneId, $ids['location'][$locationId]['phone']); $phone->phone = $params['location'][$locationId]['phone'][$phoneId]['phone']; if (empty($phone->phone)) { $phone->delete(); return null; } $phone->location_id = $params['location'][$locationId]['id']; $phone->phone_type = $params['location'][$locationId]['phone'][$phoneId]['phone_type']; $phone->mobile_provider_id = CRM_Utils_Array::value('mobile_provider_id', $params['location'][$locationId]['phone'][$phoneId]); // set this object to be the value of isPrimary and make sure no one else can be isPrimary $phone->is_primary = $isPrimary; $isPrimary = false; return $phone->save(); }
/** * 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); }
/** * Ensure that civicrm_contact.modified_date is updated when manipulating an email. */ public function testTimestampsPhone() { $test = $this; $this->_testTimestamps(array('INSERT' => function ($contactId) use($test) { $params = array('phone' => '202-555-1000', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId); CRM_Core_BAO_Phone::add($params); $test->assertDBQuery('202-555-1000', 'SELECT phone FROM civicrm_phone WHERE contact_id = %1 ORDER BY id DESC LIMIT 1', array(1 => array($contactId, 'Integer'))); }, 'UPDATE' => function ($contactId) use($test) { CRM_Core_DAO::executeQuery('UPDATE civicrm_phone SET phone = "202-555-2000" WHERE contact_id = %1', array(1 => array($contactId, 'Integer'))); }, 'DELETE' => function ($contactId) use($test) { CRM_Core_DAO::executeQuery('DELETE FROM civicrm_phone WHERE contact_id = %1', array(1 => array($contactId, 'Integer'))); })); }
/** * Send the sms message to a specific contact. * * @param int $toID * The contact id of the recipient. * @param $tokenText * @param array $smsParams * The params used for sending sms. * @param int $activityID * The activity ID that tracks the message. * @param int $userID * * @return bool|PEAR_Error * true on success or PEAR_Error object */ public static function sendSMSMessage($toID, &$tokenText, $smsParams = array(), $activityID, $userID = NULL) { $toDoNotSms = ""; $toPhoneNumber = ""; if ($smsParams['To']) { $toPhoneNumber = trim($smsParams['To']); } elseif ($toID) { $filters = array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0); $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($toID, FALSE, 'Mobile', $filters); // To get primary mobile phonenumber,if not get the first mobile phonenumber if (!empty($toPhoneNumbers)) { $toPhoneNumerDetails = reset($toPhoneNumbers); $toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumerDetails); // Contact allows to send sms $toDoNotSms = 0; } } // make sure both phone are valid // and that the recipient wants to receive sms if (empty($toPhoneNumber) or $toDoNotSms) { return PEAR::raiseError('Recipient phone number is invalid or recipient does not want to receive SMS', NULL, PEAR_ERROR_RETURN); } $recipient = $smsParams['To']; $smsParams['contact_id'] = $toID; $smsParams['parent_activity_id'] = $activityID; $providerObj = CRM_SMS_Provider::singleton(array('provider_id' => $smsParams['provider_id'])); $sendResult = $providerObj->send($recipient, $smsParams, $tokenText, NULL, $userID); if (PEAR::isError($sendResult)) { return $sendResult; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); // add activity target record for every sms that is send $activityTargetParams = array('activity_id' => $activityID, 'contact_id' => $toID, 'record_type_id' => $targetID); CRM_Activity_BAO_ActivityContact::create($activityTargetParams); return TRUE; }
/** * @param $mappingID * @param $now * * @throws CRM_Core_Exception */ static function sendMailings($mappingID, $now) { $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); $fromEmailAddress = "{$domainValues['0']} <{$domainValues['1']}>"; $mapping = new CRM_Core_DAO_ActionMapping(); $mapping->id = $mappingID; $mapping->find(TRUE); $actionSchedule = new CRM_Core_DAO_ActionSchedule(); $actionSchedule->mapping_id = $mappingID; $actionSchedule->is_active = 1; $actionSchedule->find(FALSE); $tokenFields = array(); $session = CRM_Core_Session::singleton(); while ($actionSchedule->fetch()) { $extraSelect = $extraJoin = $extraWhere = $extraOn = ''; if ($actionSchedule->from_email) { $fromEmailAddress = "{$actionSchedule->from_name} <{$actionSchedule->from_email}>"; } if ($actionSchedule->record_activity) { if ($mapping->entity == 'civicrm_membership') { $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Membership Renewal Reminder', 'name'); } else { $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Reminder Sent', 'name'); } $activityStatusID = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); } if ($mapping->entity == 'civicrm_activity') { $tokenEntity = 'activity'; $tokenFields = array('activity_id', 'activity_type', 'subject', 'details', 'activity_date_time'); $extraSelect = ', ov.label as activity_type, e.id as activity_id'; $extraJoin = "\nINNER JOIN civicrm_option_group og ON og.name = 'activity_type'\nINNER JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id"; $extraOn = ' AND e.is_current_revision = 1 AND e.is_deleted = 0 '; if ($actionSchedule->limit_to == 0) { $extraJoin = "\nLEFT JOIN civicrm_option_group og ON og.name = 'activity_type'\nLEFT JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id"; } } if ($mapping->entity == 'civicrm_participant') { $tokenEntity = 'event'; $tokenFields = array('event_type', 'title', 'event_id', 'start_date', 'end_date', 'summary', 'description', 'location', 'info_url', 'registration_url', 'fee_amount', 'contact_email', 'contact_phone', 'balance'); $extraSelect = ', ov.label as event_type, ev.title, ev.id as event_id, ev.start_date, ev.end_date, ev.summary, ev.description, address.street_address, address.city, address.state_province_id, address.postal_code, email.email as contact_email, phone.phone as contact_phone '; $extraJoin = "\nINNER JOIN civicrm_event ev ON e.event_id = ev.id\nINNER JOIN civicrm_option_group og ON og.name = 'event_type'\nINNER JOIN civicrm_option_value ov ON ev.event_type_id = ov.value AND ov.option_group_id = og.id\nLEFT JOIN civicrm_loc_block lb ON lb.id = ev.loc_block_id\nLEFT JOIN civicrm_address address ON address.id = lb.address_id\nLEFT JOIN civicrm_email email ON email.id = lb.email_id\nLEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id\n"; if ($actionSchedule->limit_to == 0) { $extraJoin = "\nLEFT JOIN civicrm_event ev ON e.event_id = ev.id\nLEFT JOIN civicrm_option_group og ON og.name = 'event_type'\nLEFT JOIN civicrm_option_value ov ON ev.event_type_id = ov.value AND ov.option_group_id = og.id\nLEFT JOIN civicrm_loc_block lb ON lb.id = ev.loc_block_id\nLEFT JOIN civicrm_address address ON address.id = lb.address_id\nLEFT JOIN civicrm_email email ON email.id = lb.email_id\nLEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id\n"; } } if ($mapping->entity == 'civicrm_membership') { $tokenEntity = 'membership'; $tokenFields = array('fee', 'id', 'join_date', 'start_date', 'end_date', 'status', 'type'); $extraSelect = ', mt.minimum_fee as fee, e.id as id , e.join_date, e.start_date, e.end_date, ms.name as status, mt.name as type'; $extraJoin = ' INNER JOIN civicrm_membership_type mt ON e.membership_type_id = mt.id INNER JOIN civicrm_membership_status ms ON e.status_id = ms.id'; if ($actionSchedule->limit_to == 0) { $extraJoin = ' LEFT JOIN civicrm_membership_type mt ON e.membership_type_id = mt.id LEFT JOIN civicrm_membership_status ms ON e.status_id = ms.id'; } } if ($mapping->entity == 'civicrm_contact') { $tokenEntity = 'contact'; //TODO: get full list somewhere! $tokenFields = array('birth_date', 'last_name'); //TODO: is there anything to add here? } $entityJoinClause = "INNER JOIN {$mapping->entity} e ON e.id = reminder.entity_id"; if ($actionSchedule->limit_to == 0) { $entityJoinClause = "LEFT JOIN {$mapping->entity} e ON e.id = reminder.entity_id"; $extraWhere .= " AND (e.id = reminder.entity_id OR reminder.entity_table = 'civicrm_contact')"; } $entityJoinClause .= $extraOn; $query = "\nSELECT reminder.id as reminderID, reminder.contact_id as contactID, reminder.*, e.id as entityID, e.* {$extraSelect}\nFROM civicrm_action_log reminder\n{$entityJoinClause}\n{$extraJoin}\nWHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL\n{$extraWhere}"; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer'))); while ($dao->fetch()) { $entityTokenParams = array(); foreach ($tokenFields as $field) { if ($field == 'location') { $loc = array(); $stateProvince = CRM_Core_PseudoConstant::stateProvince(); $loc['street_address'] = $dao->street_address; $loc['city'] = $dao->city; $loc['state_province'] = CRM_Utils_Array::value($dao->state_province_id, $stateProvince); $loc['postal_code'] = $dao->postal_code; $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Address::format($loc); } elseif ($field == 'info_url') { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE); } elseif ($field == 'registration_url') { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE); } elseif (in_array($field, array('start_date', 'end_date', 'join_date', 'activity_date_time'))) { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Date::customFormat($dao->{$field}); } elseif ($field == 'balance') { $info = CRM_Contribute_BAO_Contribution::getPaymentInfo($dao->entityID, 'event'); $balancePay = CRM_Utils_Array::value('balance', $info); $balancePay = CRM_Utils_Money::format($balancePay); $entityTokenParams["{$tokenEntity}." . $field] = $balancePay; } elseif ($field == 'fee_amount') { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Money::format($dao->{$field}); } else { $entityTokenParams["{$tokenEntity}." . $field] = $dao->{$field}; } } $isError = 0; $errorMsg = $toEmail = $toPhoneNumber = ''; if ($actionSchedule->mode == 'SMS' or $actionSchedule->mode == 'User_Preference') { $filters = array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0); $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($dao->contactID, FALSE, 'Mobile', $filters); //to get primary mobile ph,if not get a first mobile phONE if (!empty($toPhoneNumbers)) { $toPhoneNumberDetails = reset($toPhoneNumbers); $toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumberDetails); //contact allows to send sms $toDoNotSms = 0; } } if ($actionSchedule->mode == 'Email' or $actionSchedule->mode == 'User_Preference') { $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($dao->contactID); } if ($toEmail || !(empty($toPhoneNumber) or $toDoNotSms)) { $to['email'] = $toEmail; $to['phone'] = $toPhoneNumber; $result = CRM_Core_BAO_ActionSchedule::sendReminder($dao->contactID, $to, $actionSchedule->id, $fromEmailAddress, $entityTokenParams); if (!$result || is_a($result, 'PEAR_Error')) { // we could not send an email, for now we ignore, CRM-3406 $isError = 1; } } else { $isError = 1; $errorMsg = "Couldn\\'t find recipient\\'s email address."; } // update action log record $logParams = array('id' => $dao->reminderID, 'is_error' => $isError, 'message' => $errorMsg ? $errorMsg : "null", 'action_date_time' => $now); CRM_Core_BAO_ActionLog::create($logParams); // insert activity log record if needed if ($actionSchedule->record_activity) { $activityParams = array('subject' => $actionSchedule->title, 'details' => $actionSchedule->body_html, 'source_contact_id' => $session->get('userID') ? $session->get('userID') : $dao->contactID, 'target_contact_id' => $dao->contactID, 'activity_date_time' => date('YmdHis'), 'status_id' => $activityStatusID, 'activity_type_id' => $activityTypeID, 'source_record_id' => $dao->entityID); $activity = CRM_Activity_BAO_Activity::create($activityParams); } } $dao->free(); } }
/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success'); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error'); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } //make sure we should has to have space, CRM-6977 if ($this->_gName == 'from_email_address') { $params['label'] = str_replace('"<', '" <', $params['label']); } } // set value of filter if not present in params if ($this->_id && !array_key_exists('filter', $params)) { if ($this->_gName == 'participant_role') { $params['filter'] = 0; } else { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } } $groupParams = array('name' => $this->_gName); $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); // CRM-11516 if (!empty($params['financial_account_id'])) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']); CRM_Financial_BAO_FinancialTypeAccount::add($params); } CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success'); } }
/** * Pick SMS phone number. * * @param int $smsToContactId * * @return NULL|string */ protected static function pickSmsPhoneNumber($smsToContactId) { $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($smsToContactId, FALSE, 'Mobile', array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0)); //to get primary mobile ph,if not get a first mobile phONE if (!empty($toPhoneNumbers)) { $toPhoneNumberDetails = reset($toPhoneNumbers); $toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumberDetails); return $toPhoneNumber; } return NULL; }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { require_once 'CRM/Core/BAO/Phone.php'; CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName))); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName))); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (CRM_Utils_Array::value('is_default', $params) && in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } else { if ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } } } $groupParams = array('name' => $this->_gName); require_once 'CRM/Core/OptionValue.php'; $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label))); } }
/** * simple helper function to dispatch getCall to lower comm blocks */ function getBlocks(&$params, &$values, &$ids, $blockCount = 0, &$parent) { $parent->address =& CRM_Core_BAO_Address::getValues($params, $values, $ids, $blockCount); $parent->phone =& CRM_Core_BAO_Phone::getValues($params, $values, $ids, $blockCount); $parent->email =& CRM_Core_BAO_Email::getValues($params, $values, $ids, $blockCount); $parent->im =& CRM_Core_BAO_IM::getValues($params, $values, $ids, $blockCount); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { require_once 'CRM/Core/BAO/Phone.php'; CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName))); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName))); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); //set defaultGreeting option in params as per contact type if (CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = CRM_Utils_Array::value('contactOptions', $params); $params['defaultGreeting'] = 1; } $groupParams = array('name' => $this->_gName); require_once 'CRM/Core/OptionValue.php'; $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label))); } }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName))); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName))); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } //make sure we should has to have space, CRM-6977 if ($this->_gName == 'from_email_address') { $params['label'] = str_replace('"<', '" <', $params['label']); } } // set db value of filter in params if filter is non editable if ($this->_id && !array_key_exists('filter', $params) && !$this->_gName == 'participant_role') { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } $groupParams = array('name' => $this->_gName); $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label))); } }
/** * send the sms message to a specific contact * * @param int $toID the contact id of the recipient * @param int $activityID the activity ID that tracks the message * @param array $smsParams the params used for sending sms * * @return boolean true if successfull else false. * @access public * @static */ static function sendSMSMessage($toID, &$tokenText, &$tokenHtml, $smsParams = array(), $activityID) { $toDoNotSms = ""; $toPhoneNumber = ""; if ($smsParams['To']) { $toPhoneNumber = trim($smsParams['To']); } elseif ($toID) { $filters = array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0); $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($toID, FALSE, 'Mobile', $filters); //to get primary mobile ph,if not get a first mobile ph if (!empty($toPhoneNumbers)) { $toPhoneNumerDetails = reset($toPhoneNumbers); $toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumerDetails); //contact allows to send sms $toDoNotSms = 0; } } // make sure both phone are valid // and that the recipient wants to receive sms if (empty($toPhoneNumber) or $toDoNotSms) { return FALSE; } $message = $tokenHtml ? $tokenHtml : $tokenText; $recipient = $smsParams['To']; $smsParams['contact_id'] = $toID; $smsParams['parent_activity_id'] = $activityID; $providerObj = CRM_SMS_Provider::singleton(array('provider_id' => $smsParams['provider_id'])); if (!$providerObj->send($recipient, $smsParams, $message, NULL)) { return FALSE; } // add activity target record for every sms that is send $activityTargetParams = array('activity_id' => $activityID, 'target_contact_id' => $toID); self::createActivityTarget($activityTargetParams); return TRUE; }
static function processNormalization($fromContactId, $toContactId) { $processInfo = array('name' => 0, 'phone' => 0, 'address' => 0); if (empty($fromContactId) || empty($toContactId)) { return $processInfo; } $contactIds = range($fromContactId, $toContactId); $normalization = CRM_Utils_Normalize::singleton(); $formattedContactIds = $formattedPhoneIds = $formattedAddressIds = array(); foreach ($contactIds as $contactId) { $contact = new CRM_Contact_DAO_Contact(); $contact->id = $contactId; if ($contact->find()) { $params = array('id' => $contactId, 'contact_id' => $contactId); $orgContactValues = array(); CRM_Contact_BAO_Contact::retrieve($params, $orgContactValues); //update contacts name fields. $formatNameValues = array(); foreach ($normalization->getNameFields() as $field) { $nameValue = CRM_Utils_Array::value($field, $orgContactValues); if (empty($nameValue)) { continue; } $formatNameValues[$field] = $nameValue; } if (!empty($formatNameValues)) { $formatNameValues['contact_type'] = $orgContactValues['contact_type']; $formattedNameValues = $formatNameValues; //format name values $normalization->normalize_contact($formattedNameValues); //check formatted diff, only update if there is difference. $formatDiff = array_diff($formatNameValues, $formattedNameValues); if (!empty($formatDiff)) { $formattedNameValues['id'] = $formattedNameValues['contact_id'] = $orgContactValues['id']; $formattedNameValues['contact_type'] = $orgContactValues['contact_type']; $contactUpdated = CRM_Contact_BAO_Contact::add($formattedNameValues); if ($contactUpdated->id) { $formattedContactIds[$contactUpdated->id] = $contactUpdated->id; } $contactUpdated->free(); } } //update phone fields. if (isset($orgContactValues['phone']) && is_array($orgContactValues['phone'])) { foreach ($orgContactValues['phone'] as $cnt => $orgPhoneValues) { if (!isset($orgPhoneValues['id']) || empty($orgPhoneValues['id']) || empty($orgPhoneValues['phone'])) { continue; } $formattedPhoneValues = $orgPhoneValues; //format phone fields $normalization->normalize_phone($formattedPhoneValues); //do check for formatted difference, than only update. $formattedDiff = array_diff_assoc($orgPhoneValues, $formattedPhoneValues); if (!empty($formattedDiff)) { $phoneUpdated = CRM_Core_BAO_Phone::add($formattedPhoneValues); if ($phoneUpdated->id) { $formattedPhoneIds[$phoneUpdated->id] = $phoneUpdated->id; } $phoneUpdated->free(); } } } //update address. if (isset($orgContactValues['address']) && is_array($orgContactValues['address'])) { foreach ($orgContactValues['address'] as $cnt => $orgAddressValues) { if (!isset($orgAddressValues['id']) || empty($orgAddressValues['id'])) { continue; } $formattedAddressValues = $orgAddressValues; //format addrees fields $normalization->normalize_address($formattedAddressValues); //do check for formatted difference, than only update. $formattedDiff = array_diff($orgAddressValues, $formattedAddressValues); if (!empty($formattedDiff)) { $addressUpdated = CRM_Core_BAO_Address::add($formattedAddressValues, FALSE); if ($addressUpdated->id) { $formattedAddressIds[$addressUpdated->id] = $addressUpdated->id; } $addressUpdated->free(); } } } } $contact->free(); } $processInfo = array('name' => $formattedContactIds, 'phone' => $formattedPhoneIds, 'address' => $formattedAddressIds); return $processInfo; }