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 $groupNames = civicrm_api3('Group', 'get', $params +
[
55 'check_permissions' => TRUE,
56 'return' => ['title', 'visibility', 'group_type', 'is_hidden'],
58 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
[
69 $emailAdd = civicrm_api3('Email', 'get', [
72 'contact_id' => $contactID,
75 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
[
78 'return' => ['id', 'msg_title'],
79 'workflow_name' => ['IS NULL' => ''],
81 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
82 'entity' => ['contact', 'mailing'],
85 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
[
86 'option_group_id' => "from_email_address",
87 'domain_id' => CRM_Core_Config
::domainID(),
89 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
90 $isMultiLingual = (count($enabledLanguages) > 1);
91 // 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.
92 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()
93 ->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
,
94 []) : CRM_Utils_Token
::getRequiredTokens();
95 $crmMailingSettings = [
96 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
98 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents
),
100 // @todo this is not used in core. Remove once Mosaico no longer depends on it.
101 'testGroupNames' => $groupNames['values'],
102 'headerfooterList' => $headerfooterList['values'],
103 'mesTemplate' => $mesTemplate['values'],
104 'emailAdd' => $emailAdd['values'],
105 'mailTokens' => $mailTokens['values'],
106 'contactid' => $contactID,
107 'requiredTokens' => $requiredTokens,
108 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
109 'disableMandatoryTokensCheck' => (int) Civi
::settings()
110 ->get('disable_mandatory_tokens_check'),
111 'fromAddress' => $fromAddress['values'],
112 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
113 'id' => 'user_contact_id',
116 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
117 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
118 'reportIds' => $reportIds,
119 'enabledLanguages' => $enabledLanguages,
120 'isMultiLingual' => $isMultiLingual,
122 return $crmMailingSettings;
129 public function getInfo() {
131 'name' => 'CiviMail',
132 'translatedName' => ts('CiviMail'),
133 'title' => ts('CiviCRM Mailing Engine'),
135 'showActivitiesInCore' => 1,
140 * Get AngularJS modules and their dependencies.
143 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
144 * @see CRM_Utils_Hook::angularModules
146 public function getAngularModules() {
147 // load angular files only if valid permissions are granted to the user
148 if (!CRM_Core_Permission
::check('access CiviMail')
149 && !CRM_Core_Permission
::check('create mailings')
150 && !CRM_Core_Permission
::check('schedule mailings')
151 && !CRM_Core_Permission
::check('approve mailings')
155 global $civicrm_root;
158 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
159 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
167 public static function workflowEnabled() {
168 $config = CRM_Core_Config
::singleton();
170 // early exit, since not true for most
171 if (!$config->userSystem
->is_drupal ||
172 !function_exists('module_exists')
177 if (!module_exists('rules')) {
181 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
183 return $enableWorkflow && $config->userSystem
->is_drupal
;
188 * @param bool $getAllUnconditionally
189 * @param bool $descriptions
190 * Whether to return permission descriptions
194 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
196 'access CiviMail' => [
197 ts('access CiviMail'),
199 'access CiviMail subscribe/unsubscribe pages' => [
200 ts('access CiviMail subscribe/unsubscribe pages'),
201 ts('Subscribe/unsubscribe from mailing list group'),
203 'delete in CiviMail' => [
204 ts('delete in CiviMail'),
205 ts('Delete Mailing'),
207 'view public CiviMail content' => [
208 ts('view public CiviMail content'),
212 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
213 $permissions['create mailings'] = [
214 ts('create mailings'),
216 $permissions['schedule mailings'] = [
217 ts('schedule mailings'),
219 $permissions['approve mailings'] = [
220 ts('approve mailings'),
224 if (!$descriptions) {
225 foreach ($permissions as $name => $attr) {
226 $permissions[$name] = array_shift($attr);
237 public function getUserDashboardElement() {
238 // no dashboard element for this component
245 public function getUserDashboardObject() {
246 // no dashboard element for this component
254 public function registerTab() {
256 'title' => ts('Mailings'),
267 public function getIcon() {
268 return 'crm-i fa-envelope-o';
275 public function registerAdvancedSearchPane() {
277 'title' => ts('Mailings'),
286 public function getActivityTypes() {
291 * add shortcut to Create New.
294 public function creatNewShortcut(&$shortCuts) {