3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This class introduces component to the system and provides all the
14 * information about it. It needs to extend CRM_Core_Component_Info
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 class CRM_Mailing_Info
extends CRM_Core_Component_Info
{
26 protected $keyword = 'mailing';
31 public static function createAngularSettings():array {
33 $reportTypes = ['detail', 'opened', 'bounce', 'clicks'];
34 foreach ($reportTypes as $report) {
35 $rptResult = civicrm_api3('ReportInstance', 'get', [
37 'report_id' => 'mailing/' . $report,
39 if (!empty($rptResult['values'])) {
40 $reportIds[$report] = $rptResult['values'][0]['id'];
44 $config = CRM_Core_Config
::singleton();
45 $session = CRM_Core_Session
::singleton();
46 $contactID = $session->get('userID');
50 'options' => ['limit' => 0],
53 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
[
64 $emailAdd = civicrm_api3('Email', 'get', [
67 'contact_id' => $contactID,
70 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
[
73 'return' => ['id', 'msg_title'],
74 'workflow_name' => ['IS NULL' => ''],
76 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
77 'entity' => ['contact', 'mailing'],
80 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
[
81 'option_group_id' => "from_email_address",
82 'domain_id' => CRM_Core_Config
::domainID(),
84 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
85 $isMultiLingual = (count($enabledLanguages) > 1);
86 // FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
87 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()
88 ->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
,
89 []) : CRM_Utils_Token
::getRequiredTokens();
90 $crmMailingSettings = [
91 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
93 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents
),
95 'headerfooterList' => $headerfooterList['values'],
96 'mesTemplate' => $mesTemplate['values'],
97 'emailAdd' => $emailAdd['values'],
98 'mailTokens' => $mailTokens['values'],
99 'contactid' => $contactID,
100 'requiredTokens' => $requiredTokens,
101 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
102 'disableMandatoryTokensCheck' => (int) Civi
::settings()
103 ->get('disable_mandatory_tokens_check'),
104 'fromAddress' => $fromAddress['values'],
105 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
106 'id' => 'user_contact_id',
109 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
110 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
111 'reportIds' => $reportIds,
112 'enabledLanguages' => $enabledLanguages,
113 'isMultiLingual' => $isMultiLingual,
115 return $crmMailingSettings;
122 public function getInfo() {
124 'name' => 'CiviMail',
125 'translatedName' => ts('CiviMail'),
126 'title' => ts('CiviCRM Mailing Engine'),
128 'showActivitiesInCore' => 1,
133 * Get AngularJS modules and their dependencies.
136 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
137 * @see CRM_Utils_Hook::angularModules
139 public function getAngularModules() {
140 // load angular files only if valid permissions are granted to the user
141 if (!CRM_Core_Permission
::check('access CiviMail')
142 && !CRM_Core_Permission
::check('create mailings')
143 && !CRM_Core_Permission
::check('schedule mailings')
144 && !CRM_Core_Permission
::check('approve mailings')
148 global $civicrm_root;
151 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
152 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
160 public static function workflowEnabled() {
161 $config = CRM_Core_Config
::singleton();
163 // early exit, since not true for most
164 if (!$config->userSystem
->is_drupal ||
165 !function_exists('module_exists')
170 if (!module_exists('rules')) {
174 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
176 return $enableWorkflow && $config->userSystem
->is_drupal
;
181 * @param bool $getAllUnconditionally
182 * @param bool $descriptions
183 * Whether to return permission descriptions
187 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
189 'access CiviMail' => [
190 ts('access CiviMail'),
192 'access CiviMail subscribe/unsubscribe pages' => [
193 ts('access CiviMail subscribe/unsubscribe pages'),
194 ts('Subscribe/unsubscribe from mailing list group'),
196 'delete in CiviMail' => [
197 ts('delete in CiviMail'),
198 ts('Delete Mailing'),
200 'view public CiviMail content' => [
201 ts('view public CiviMail content'),
205 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
206 $permissions['create mailings'] = [
207 ts('create mailings'),
209 $permissions['schedule mailings'] = [
210 ts('schedule mailings'),
212 $permissions['approve mailings'] = [
213 ts('approve mailings'),
217 if (!$descriptions) {
218 foreach ($permissions as $name => $attr) {
219 $permissions[$name] = array_shift($attr);
230 public function getUserDashboardElement() {
231 // no dashboard element for this component
238 public function getUserDashboardObject() {
239 // no dashboard element for this component
247 public function registerTab() {
249 'title' => ts('Mailings'),
260 public function getIcon() {
261 return 'crm-i fa-envelope-o';
268 public function registerAdvancedSearchPane() {
270 'title' => ts('Mailings'),
279 public function getActivityTypes() {
284 * add shortcut to Create New.
287 public function creatNewShortcut(&$shortCuts) {