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 $session = CRM_Core_Session
::singleton();
45 $contactID = $session->get('userID');
49 'options' => ['limit' => 0],
52 $groupNames = civicrm_api3('Group', 'get', $params +
[
54 'check_permissions' => TRUE,
55 'return' => ['title', 'visibility', 'group_type', 'is_hidden'],
57 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
[
68 $emailAdd = civicrm_api3('Email', 'get', [
71 'contact_id' => $contactID,
74 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
[
77 'return' => ['id', 'msg_title'],
78 'workflow_name' => ['IS NULL' => ''],
80 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
81 'entity' => ['contact', 'mailing'],
84 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
[
85 'option_group_id' => "from_email_address",
86 'domain_id' => CRM_Core_Config
::domainID(),
88 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
89 $isMultiLingual = (count($enabledLanguages) > 1);
90 // 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.
91 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()
92 ->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
,
93 []) : CRM_Utils_Token
::getRequiredTokens();
94 $crmMailingSettings = [
95 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
97 'campaignEnabled' => CRM_Core_Component
::isEnabled('CiviCampaign'),
99 // @todo this is not used in core. Remove once Mosaico no longer depends on it.
100 'testGroupNames' => $groupNames['values'],
101 'headerfooterList' => $headerfooterList['values'],
102 'mesTemplate' => $mesTemplate['values'],
103 'emailAdd' => $emailAdd['values'],
104 'mailTokens' => $mailTokens['values'],
105 'contactid' => $contactID,
106 'requiredTokens' => $requiredTokens,
107 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
108 'disableMandatoryTokensCheck' => (int) Civi
::settings()
109 ->get('disable_mandatory_tokens_check'),
110 'fromAddress' => $fromAddress['values'],
111 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
112 'id' => 'user_contact_id',
115 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
116 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
117 'reportIds' => $reportIds,
118 'enabledLanguages' => $enabledLanguages,
119 'isMultiLingual' => $isMultiLingual,
121 return $crmMailingSettings;
128 public function getInfo() {
130 'name' => 'CiviMail',
131 'translatedName' => ts('CiviMail'),
132 'title' => ts('CiviCRM Mailing Engine'),
134 'showActivitiesInCore' => 1,
139 * Get AngularJS modules and their dependencies.
142 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
143 * @see CRM_Utils_Hook::angularModules
145 public function getAngularModules() {
146 // load angular files only if valid permissions are granted to the user
147 if (!CRM_Core_Permission
::check('access CiviMail')
148 && !CRM_Core_Permission
::check('create mailings')
149 && !CRM_Core_Permission
::check('schedule mailings')
150 && !CRM_Core_Permission
::check('approve mailings')
154 global $civicrm_root;
157 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
158 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
166 public static function workflowEnabled() {
167 $config = CRM_Core_Config
::singleton();
169 // early exit, since not true for most
170 if (!$config->userSystem
->is_drupal ||
171 !function_exists('module_exists')
176 if (!module_exists('rules')) {
180 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
182 return $enableWorkflow && $config->userSystem
->is_drupal
;
187 * @param bool $getAllUnconditionally
188 * @param bool $descriptions
189 * Whether to return permission descriptions
193 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
195 'access CiviMail' => [
196 ts('access CiviMail'),
198 'access CiviMail subscribe/unsubscribe pages' => [
199 ts('access CiviMail subscribe/unsubscribe pages'),
200 ts('Subscribe/unsubscribe from mailing list group'),
202 'delete in CiviMail' => [
203 ts('delete in CiviMail'),
204 ts('Delete Mailing'),
206 'view public CiviMail content' => [
207 ts('view public CiviMail content'),
211 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
212 $permissions['create mailings'] = [
213 ts('create mailings'),
215 $permissions['schedule mailings'] = [
216 ts('schedule mailings'),
218 $permissions['approve mailings'] = [
219 ts('approve mailings'),
223 if (!$descriptions) {
224 foreach ($permissions as $name => $attr) {
225 $permissions[$name] = array_shift($attr);
236 public function getUserDashboardElement() {
237 // no dashboard element for this component
244 public function getUserDashboardObject() {
245 // no dashboard element for this component
253 public function registerTab() {
255 'title' => ts('Mailings'),
266 public function getIcon() {
267 return 'crm-i fa-envelope-o';
274 public function registerAdvancedSearchPane() {
276 'title' => ts('Mailings'),
285 public function getActivityTypes() {
290 * add shortcut to Create New.
293 public function creatNewShortcut(&$shortCuts) {