本文整理汇总了PHP中CRM_Core_BAO_File::getEntityFile方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_File::getEntityFile方法的具体用法?PHP CRM_Core_BAO_File::getEntityFile怎么用?PHP CRM_Core_BAO_File::getEntityFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_File
的用法示例。
在下文中一共展示了CRM_Core_BAO_File::getEntityFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fileDisplay
function fileDisplay()
{
// Display evidence file
$postParams = $_POST;
$fileID = CRM_Core_BAO_File::getEntityFile($postParams['entityTable'], $postParams['entityID']);
if ($fileID) {
foreach ($fileID as $k => $v) {
$fileType = $v['mime_type'];
$fid = $v['fileID'];
$eid = $postParams['entityID'];
if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') {
list($path) = CRM_Core_BAO_File::path($fid, $eid, NULL, NULL);
list($imageWidth, $imageHeight) = getimagesize($path);
list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
$url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}", FALSE, NULL, TRUE, TRUE);
$file_url = "\n <a href=\"{$url}\" class='crm-image-popup'>\n <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n </a>";
// for non image files
} else {
$uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fid, 'uri');
$url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}");
$file_url = "<a href=\"{$url}\">{$uri}</a>";
}
if (isset($fid)) {
$deleteurl = "<div class=file-delete><a class='action-item crm-hover-button' href='javascript:void(0)' id=file_{$fid}>Delete Attached File</a></div>";
echo "<div id='del_{$fid}'>{$file_url}{$deleteurl}</div>";
}
}
}
CRM_Utils_System::civiExit();
}
示例2: template
/**
* Fetch the template text/html messages
*/
public static function template()
{
$templateId = CRM_Utils_Type::escape($_POST['tid'], 'Integer');
$messageTemplate = new CRM_Core_DAO_MessageTemplate();
$messageTemplate->id = $templateId;
$messageTemplate->selectAdd();
$messageTemplate->selectAdd('msg_text, msg_html, msg_subject, pdf_format_id');
$messageTemplate->find(TRUE);
$messages = array('subject' => $messageTemplate->msg_subject, 'msg_text' => $messageTemplate->msg_text, 'msg_html' => $messageTemplate->msg_html, 'pdf_format_id' => $messageTemplate->pdf_format_id);
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $templateId);
foreach ((array) $documentInfo as $info) {
list($messages['document_body']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']);
}
CRM_Utils_JSON::output($messages);
}
示例3: run
/**
* run this page (figure out the action needed and perform it).
*
* @return void
*/
function run()
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$session =& CRM_Core_Session::singleton();
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, false, 'text');
$type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, false, 'text');
$options = array();
$session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}");
//get the options if control come from search context, CRM-3711
if (empty($options)) {
$session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}");
}
// FIXME: the below and CRM_Mailing_Form_Test::testMail()
// should be refactored
$fromEmail = null;
$mailing =& new CRM_Mailing_BAO_Mailing();
if (!empty($options)) {
$mailing->id = $options['mailing_id'];
$fromEmail = $options['from_email'];
}
$mailing->find(true);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
if (defined('CIVICRM_MAIL_SMARTY')) {
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
}
// get and format attachments
require_once 'CRM/Core/BAO/File.php';
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $mailing->getReturnProperties();
$params = array('contact_id' => $session->get('userID'));
$details = $mailing->getDetails($params, $returnProperties);
$mime =& $mailing->compose(null, null, null, $session->get('userID'), $fromEmail, $fromEmail, true, $details[0][$session->get('userID')], $attachments);
// there doesn't seem to be a way to get to Mail_Mime's text and HTML
// parts, so we steal a peek at Mail_Mime's private properties, render
// them and exit
// note that preview does not display any attachments
$mime->get();
if ($type == 'html') {
header('Content-Type: text/html; charset=utf-8');
print $mime->_htmlbody;
} else {
header('Content-Type: text/plain; charset=utf-8');
print $mime->_txtbody;
}
exit;
}
示例4: view
/**
* View details of a note
*
* @return void
* @access public
*/
function view()
{
$note = new CRM_Core_DAO_Note();
$note->id = $this->_id;
if ($note->find(TRUE)) {
$values = array();
CRM_Core_DAO::storeValues($note, $values);
$values['privacy'] = CRM_Core_OptionGroup::optionLabel('note_privacy', $values['privacy']);
$this->assign('note', $values);
}
$comments = CRM_Core_BAO_Note::getNoteTree($values['id'], 1);
if (!empty($comments)) {
$this->assign('comments', $comments);
}
// add attachments part
$currentAttachmentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_note', $this->_id);
$this->assign('currentAttachmentInfo', $currentAttachmentInfo);
}
示例5: run
/**
* Run this page (figure out the action needed and perform it).
*
* @return void
*/
public function run()
{
$session = CRM_Core_Session::singleton();
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
$type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
$options = array();
$session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}");
//get the options if control come from search context, CRM-3711
if (empty($options)) {
$session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}");
}
// FIXME: the below and CRM_Mailing_Form_Test::testMail()
// should be refactored
$fromEmail = NULL;
$mailing = new CRM_Mailing_BAO_Mailing();
if (!empty($options)) {
$mailing->id = $options['mailing_id'];
$fromEmail = CRM_Utils_Array::value('from_email', $options);
}
$mailing->find(TRUE);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $mailing->getReturnProperties();
$params = array('contact_id' => $session->get('userID'));
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this));
$mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments);
if ($type == 'html') {
CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
print $mime->getHTMLBody();
} else {
CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
print $mime->getTXTBody();
}
CRM_Utils_System::civiExit();
}
示例6: setDefaultValues
/**
* Set default values for the form.
*
* The default values are retrieved from the database.
*/
public function setDefaultValues()
{
$defaults = $this->_values;
if (empty($defaults['pdf_format_id'])) {
$defaults['pdf_format_id'] = 'null';
}
if (empty($defaults['file_type'])) {
$defaults['file_type'] = 0;
}
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults);
$this->assign('workflow_id', $this->_workflow_id);
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
//set the context for redirection after form submit or cancel
$session = CRM_Core_Session::singleton();
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
// FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm()
if ($this->_action & CRM_Core_Action::UPDATE) {
if ($this->_workflow_id) {
$selectedChild = 'workflow';
} else {
$selectedChild = 'user';
}
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $this->_id, TRUE);
if (!empty($documentInfo)) {
$defaults['file_type'] = 1;
$this->_is_document = TRUE;
$this->assign('attachment', $documentInfo);
}
$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
$cancelURL = str_replace('&', '&', $cancelURL);
$this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
}
return $defaults;
}
示例7: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess($params = null)
{
if ($this->_action & CRM_Core_Action::DELETE) {
$deleteParams = array('id' => $this->_activityId);
CRM_Activity_BAO_Activity::deleteActivity($deleteParams);
CRM_Core_Session::setStatus(ts("Selected Activity has been deleted sucessfully."));
return;
}
// store the submitted values in an array
if (!$params) {
$params = $this->controller->exportValues($this->_name);
}
//set activity type id
if (!CRM_Utils_Array::value('activity_type_id', $params)) {
$params['activity_type_id'] = $this->_activityTypeId;
}
if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) {
$customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity');
}
// store the date with proper format
$params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
// assigning formated value to related variable
if (CRM_Utils_Array::value('target_contact_id', $params)) {
$params['target_contact_id'] = explode(',', $params['target_contact_id']);
} else {
$params['target_contact_id'] = array();
}
if (CRM_Utils_Array::value('assignee_contact_id', $params)) {
$params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']);
} else {
$params['assignee_contact_id'] = array();
}
// get ids for associated contacts
if (!$params['source_contact_id']) {
$params['source_contact_id'] = $this->_currentUserId;
} else {
$params['source_contact_id'] = $this->_submitValues['source_contact_qid'];
}
if (isset($this->_activityId)) {
$params['id'] = $this->_activityId;
}
// add attachments as needed
CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId);
// format target params
if (!$this->_single) {
$params['target_contact_id'] = $this->_contactIds;
}
$activityAssigned = array();
// 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_ActivityAssignment::getAssigneeNames($this->_activityId);
$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);
// 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);
// create follow up activity if needed
$followupStatus = '';
if (CRM_Utils_Array::value('followup_activity_type_id', $params)) {
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
$followupStatus = "A followup activity has been scheduled.";
}
// send copy to assignee contacts.CRM-4509
$mailStatus = '';
$config =& CRM_Core_Config::singleton();
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && $config->activityAssigneeNotification) {
$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 sendig a copy of activity.
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
require_once "CRM/Case/BAO/Case.php";
$result = CRM_Case_BAO_Case::sendActivityCopy(null, $activity->id, $mailToContacts, $attachments, null);
$mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
}
}
// set status message
//.........这里部分代码省略.........
示例8: postProcess
//.........这里部分代码省略.........
// copy back params to original var
$params = $newActParams;
}
foreach ($vvalue as $vkey => $vval) {
if ($vval['actId']) {
// 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', $vval['actId']);
//save free tags
if (isset($params['taglist']) && !empty($params['taglist'])) {
CRM_Core_Form_Tag::postProcess($params['taglist'], $vval['actId'], 'civicrm_activity', $this);
}
}
// update existing case record if needed
$caseParams = $params;
$caseParams['id'] = $vval['case_id'];
if (!empty($caseParams['case_status_id'])) {
$caseParams['status_id'] = $caseParams['case_status_id'];
}
// unset params intended for activities only
unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']);
$case = CRM_Case_BAO_Case::create($caseParams);
// create case activity record
$caseParams = array('activity_id' => $vval['actId'], 'case_id' => $vval['case_id']);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
}
// Insert civicrm_log record for the activity (e.g. store the
// created / edited by contact id and date for the activity)
// Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create()
// send copy to selected contacts.
$mailStatus = '';
$mailToContacts = array();
//CRM-5695
//check for notification settings for assignee contacts
$selectedContacts = array('contact_check');
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) {
$selectedContacts[] = 'assignee_contact_id';
}
foreach ($vvalue as $vkey => $vval) {
foreach ($selectedContacts as $dnt => $val) {
if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) {
if ($val == 'contact_check') {
$mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
} else {
$this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($vval['actId']), TRUE, FALSE);
$mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
}
//build an associative array with unique email addresses.
foreach ($params[$val] as $key => $value) {
if ($val == 'contact_check') {
$id = $key;
} else {
$id = $value;
}
if (isset($id) && array_key_exists($id, $this->_relatedContacts) && isset($this->_relatedContacts[$id]['email'])) {
//if email already exists in array then append with ', ' another role only otherwise add it to array.
if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) {
$caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]);
$mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole;
} else {
$mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id];
}
}
}
}
}
if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
//include attachments while sending a copy of activity.
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $vval['actId']);
$ics = new CRM_Activity_BAO_ICalendar($activity);
$ics->addAttachment($attachments, $mailToContacts);
$result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId, $vval['actId'], $mailToContacts, $attachments, $vval['case_id']);
$ics->cleanup();
if (empty($result)) {
$mailStatus = '';
}
} else {
$mailStatus = '';
}
// create follow up activity if needed
$followupStatus = '';
if (!empty($params['followup_activity_type_id'])) {
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($vval['actId'], $params);
if ($followupActivity) {
$caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $vval['case_id']);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
$followupStatus = ts("A followup activity has been scheduled.");
}
}
CRM_Core_Session::setStatus('', ts("'%1' activity has been %2. %3 %4", array(1 => $this->_activityTypeName, 2 => $recordStatus, 3 => $followupStatus, 4 => $mailStatus)), 'info');
}
}
示例9: run
/**
* run this page (figure out the action needed and perform it).
*
* @return void
*/
function run($id = NULL, $contact_id = NULL, $print = TRUE)
{
if (is_numeric($id)) {
$this->_mailingID = $id;
} else {
$print = TRUE;
$this->_mailingID = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
}
// # CRM-7651
// override contactID from the function level if passed in
if (isset($contactID) && is_numeric($contactID)) {
$this->_contactID = $contactID;
} else {
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
}
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
CRM_Utils_System::permissionDenied();
return;
}
CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
// get and format attachments
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
// get contact detail and compose if contact id exists
if (isset($this->_contactID)) {
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $this->_mailing->getReturnProperties();
$params = array('contact_id' => $this->_contactID);
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = $details[0][$this->_contactID];
} else {
$details = array('test');
}
$mime =& $this->_mailing->compose(NULL, NULL, NULL, 0, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
if (isset($this->_mailing->body_html)) {
$header = 'Content-Type: text/html; charset=utf-8';
$content = $mime->getHTMLBody();
} else {
$header = 'Content-Type: text/plain; charset=utf-8';
$content = $mime->getTXTBody();
}
if ($print) {
header($header);
print $content;
CRM_Utils_System::civiExit();
} else {
return $content;
}
}
示例10: processActivity
/**
* 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 (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, '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];
}
}
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).");
}
}
// 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;
}
}
if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) {
$ics = new CRM_Activity_BAO_ICalendar($followupActivity);
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id);
$ics->addAttachment($attachments, $mailToFollowupContacts);
CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL);
$ics->cleanup();
$mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
}
}
//.........这里部分代码省略.........
示例11: run
/**
* Run this page (figure out the action needed and perform it).
*
* @param int $id
* @param int $contactID
* @param bool $print
* @param bool $allowID
*/
public function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE)
{
if (is_numeric($id)) {
$this->_mailingID = $id;
} else {
$print = TRUE;
$this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
}
// # CRM-7651
// override contactID from the function level if passed in
if (isset($contactID) && is_numeric($contactID)) {
$this->_contactID = $contactID;
} else {
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
}
// mailing key check
if (Civi::settings()->get('hash_mailing_url')) {
$this->_mailing = new CRM_Mailing_BAO_Mailing();
if (!is_numeric($this->_mailingID)) {
$this->_mailing->hash = $this->_mailingID;
} elseif (is_numeric($this->_mailingID)) {
$this->_mailing->id = $this->_mailingID;
// if mailing is present and associated hash is present
// while 'hash' is not been used for mailing view : throw 'permissionDenied'
if ($this->_mailing->find() && CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') && !$allowID) {
CRM_Utils_System::permissionDenied();
return;
}
}
} else {
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
}
if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
CRM_Utils_System::permissionDenied();
return;
}
CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
// get contact detail and compose if contact id exists
$returnProperties = $this->_mailing->getReturnProperties();
if (isset($this->_contactID)) {
// get details of contact with token value including Custom Field Token Values.CRM-3734
$params = array('contact_id' => $this->_contactID);
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = $details[0][$this->_contactID];
$contactId = $this->_contactID;
} else {
// get tokens that are not contact specific resolved
$params = array('contact_id' => 0);
$details = CRM_Utils_Token::getAnonymousTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = CRM_Utils_Array::value(0, $details[0]);
$contactId = 0;
}
$mime =& $this->_mailing->compose(NULL, NULL, NULL, $contactId, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
$title = NULL;
if (isset($this->_mailing->body_html) && empty($_GET['text'])) {
$header = 'text/html; charset=utf-8';
$content = $mime->getHTMLBody();
if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) {
$title = '<head><title>' . $this->_mailing->subject . '</title></head>';
}
} else {
$header = 'text/plain; charset=utf-8';
$content = $mime->getTXTBody();
}
CRM_Utils_System::setTitle($this->_mailing->subject);
if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
CRM_Core_Page_AJAX::returnJsonResponse($content);
}
if ($print) {
CRM_Utils_System::setHttpHeader('Content-Type', $header);
print $title;
print $content;
CRM_Utils_System::civiExit();
} else {
return $content;
}
}
示例12: buildQuickForm
public function buildQuickForm()
{
$session = CRM_Core_Session::singleton();
$this->add('text', 'test_email', ts('Send to This Address'));
$defaults['test_email'] = $session->get('ufUniqID');
$qfKey = $this->get('qfKey');
$this->add('select', 'test_group', ts('Send to This Group'), array('' => ts('- none -')) + CRM_Core_PseudoConstant::group('Mailing'));
$this->setDefaults($defaults);
$this->add('submit', 'sendtest', ts('Send a Test Mailing'));
$name = ts('Next >>');
require_once 'CRM/Mailing/Info.php';
if (CRM_Mailing_Info::workflowEnabled()) {
if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) {
$name = ts('Inform Scheduler');
}
}
//FIXME : currently we are hiding save an continue later when
//search base mailing, we should handle it when we fix CRM-3876
$buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => $name, 'spacing' => ' ', 'isDefault' => true), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel')));
if ($this->_searchBasedMailing && $this->get('ssID')) {
$buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => $name, 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')));
}
$this->addButtons($buttons);
$mailingID = $this->get('mailing_id');
$textFile = $this->get('textFile');
$htmlFile = $this->get('htmlFile');
$this->addFormRule(array('CRM_Mailing_Form_Test', 'testMail'), $this);
$preview = array();
if ($textFile) {
$preview['text_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=text&qfKey={$qfKey}");
}
if ($htmlFile) {
$preview['html_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=html&qfKey={$qfKey}");
}
require_once 'CRM/Core/BAO/File.php';
$preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $mailingID);
$this->assign('preview', $preview);
//Token Replacement of Subject in preview mailing
$options = array();
$prefix = "CRM_Mailing_Controller_Send_{$qfKey}";
if ($this->_searchBasedMailing) {
$prefix = "CRM_Contact_Controller_Search_{$qfKey}";
}
$session->getVars($options, $prefix);
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $options['mailing_id'];
$mailing->find(true);
$fromEmail = $mailing->from_email;
require_once 'CRM/Core/BAO/File.php';
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
$returnProperties = $mailing->getReturnProperties();
$userID = $session->get('userID');
$params = array('contact_id' => $userID);
$details = $mailing->getDetails($params, $returnProperties);
$allDetails =& $mailing->compose(null, null, null, $userID, $fromEmail, $fromEmail, true, $details[0][$userID], $attachments);
$this->assign('subject', $allDetails->_headers['Subject']);
}
示例13: sendToAssignee
/**
* Send activity as attachment.
*
* @param object $activity
* @param array $mailToContacts
* @param array $params
*
* @return bool
*/
public static function sendToAssignee($activity, $mailToContacts, $params = array())
{
if (!CRM_Utils_Array::crmIsEmptyArray($mailToContacts)) {
$clientID = CRM_Utils_Array::value('client_id', $params);
$caseID = CRM_Utils_Array::value('case_id', $params);
$ics = new CRM_Activity_BAO_ICalendar($activity);
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
$ics->addAttachment($attachments, $mailToContacts);
$result = CRM_Case_BAO_Case::sendActivityCopy($clientID, $activity->id, $mailToContacts, $attachments, $caseID);
$ics->cleanup();
return $result;
}
return FALSE;
}
示例14: deliver
/**
* Send the mailing.
*
* @param object $mailer
* A Mail object to send the messages.
*
* @param array $testParams
*
* @return void
*/
public function deliver(&$mailer, $testParams = NULL)
{
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(TRUE);
$mailing->free();
$eq = new CRM_Mailing_Event_BAO_Queue();
$eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$phoneTable = CRM_Core_DAO_Phone::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
$ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as phone\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$emailTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND {$contactTable}.is_opt_out = 0";
if ($mailing->sms_provider_id) {
$query = "\n SELECT {$eqTable}.id,\n {$phoneTable}.phone as phone,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as email\n FROM {$eqTable}\n INNER JOIN {$phoneTable}\n ON {$eqTable}.phone_id = {$phoneTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$phoneTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND ( {$contactTable}.is_opt_out = 0\n OR {$contactTable}.do_not_sms = 0 )";
}
$eq->query($query);
$config = NULL;
if ($config == NULL) {
$config = CRM_Core_Config::singleton();
}
$job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
$fields = array();
if (!empty($testParams)) {
$mailing->subject = ts('[CiviMail Draft]') . ' ' . $mailing->subject;
}
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
CRM_Core_Smarty::registerStringResource();
}
// CRM-12376
// This handles the edge case scenario where all the mails
// have been delivered in prior jobs
$isDelivered = TRUE;
// make sure that there's no more than $config->mailerBatchLimit mails processed in a run
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
// CRM_Utils_System::xMemory( "$mailsProcessed: " );
// }
if ($config->mailerBatchLimit > 0 && self::$mailsProcessed >= $config->mailerBatchLimit) {
if (!empty($fields)) {
$this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
$eq->free();
return FALSE;
}
self::$mailsProcessed++;
$fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email, 'phone' => $eq->phone);
if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
if (!$isDelivered) {
$eq->free();
return $isDelivered;
}
$fields = array();
}
}
$eq->free();
if (!empty($fields)) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
return $isDelivered;
}
示例15: civicrm_api3_mailing_preview
/**
* Preview mailing.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* @throws \API_Exception
*/
function civicrm_api3_mailing_preview($params)
{
civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_Mailing', array('id'), FALSE);
$fromEmail = NULL;
if (!empty($params['from_email'])) {
$fromEmail = $params['from_email'];
}
$session = CRM_Core_Session::singleton();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $params['id'];
$mailing->find(TRUE);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
$returnProperties = $mailing->getReturnProperties();
$contactID = CRM_Utils_Array::value('contact_id', $params);
if (!$contactID) {
$contactID = $session->get('userID');
}
$mailingParams = array('contact_id' => $contactID);
$details = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens());
$mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$contactID], $attachments);
return civicrm_api3_create_success(array('id' => $params['id'], 'contact_id' => $contactID, 'subject' => $mime->_headers['Subject'], 'body_html' => $mime->getHTMLBody(), 'body_text' => $mime->getTXTBody()));
}