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 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
[
63 $emailAdd = civicrm_api3('Email', 'get', [
66 'contact_id' => $contactID,
69 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
[
72 'return' => ['id', 'msg_title'],
73 'workflow_name' => ['IS NULL' => ''],
75 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
76 'entity' => ['contact', 'mailing'],
79 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
[
80 'option_group_id' => "from_email_address",
81 'domain_id' => CRM_Core_Config
::domainID(),
83 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
84 $isMultiLingual = (count($enabledLanguages) > 1);
85 // 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.
86 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()
87 ->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
,
88 []) : CRM_Utils_Token
::getRequiredTokens();
89 $crmMailingSettings = [
90 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
92 'campaignEnabled' => CRM_Core_Component
::isEnabled('CiviCampaign'),
94 'headerfooterList' => $headerfooterList['values'],
95 'mesTemplate' => $mesTemplate['values'],
96 'emailAdd' => $emailAdd['values'],
97 'mailTokens' => $mailTokens['values'],
98 'contactid' => $contactID,
99 'requiredTokens' => $requiredTokens,
100 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
101 'disableMandatoryTokensCheck' => (int) Civi
::settings()
102 ->get('disable_mandatory_tokens_check'),
103 'fromAddress' => $fromAddress['values'],
104 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
105 'id' => 'user_contact_id',
108 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
109 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
110 'reportIds' => $reportIds,
111 'enabledLanguages' => $enabledLanguages,
112 'isMultiLingual' => $isMultiLingual,
114 return $crmMailingSettings;
121 public function getInfo() {
123 'name' => 'CiviMail',
124 'translatedName' => ts('CiviMail'),
125 'title' => ts('CiviCRM Mailing Engine'),
127 'showActivitiesInCore' => 1,
132 * Get AngularJS modules and their dependencies.
135 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
136 * @see CRM_Utils_Hook::angularModules
138 public function getAngularModules() {
139 // load angular files only if valid permissions are granted to the user
140 if (!CRM_Core_Permission
::check('access CiviMail')
141 && !CRM_Core_Permission
::check('create mailings')
142 && !CRM_Core_Permission
::check('schedule mailings')
143 && !CRM_Core_Permission
::check('approve mailings')
147 global $civicrm_root;
150 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
151 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
159 public static function workflowEnabled() {
160 $config = CRM_Core_Config
::singleton();
162 // early exit, since not true for most
163 if (!$config->userSystem
->is_drupal ||
164 !function_exists('module_exists')
169 if (!module_exists('rules')) {
173 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
175 return $enableWorkflow && $config->userSystem
->is_drupal
;
180 * @param bool $getAllUnconditionally
181 * @param bool $descriptions
182 * Whether to return permission descriptions
186 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
188 'access CiviMail' => [
189 ts('access CiviMail'),
191 'access CiviMail subscribe/unsubscribe pages' => [
192 ts('access CiviMail subscribe/unsubscribe pages'),
193 ts('Subscribe/unsubscribe from mailing list group'),
195 'delete in CiviMail' => [
196 ts('delete in CiviMail'),
197 ts('Delete Mailing'),
199 'view public CiviMail content' => [
200 ts('view public CiviMail content'),
204 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
205 $permissions['create mailings'] = [
206 ts('create mailings'),
208 $permissions['schedule mailings'] = [
209 ts('schedule mailings'),
211 $permissions['approve mailings'] = [
212 ts('approve mailings'),
216 if (!$descriptions) {
217 foreach ($permissions as $name => $attr) {
218 $permissions[$name] = array_shift($attr);
229 public function getUserDashboardElement() {
230 // no dashboard element for this component
237 public function getUserDashboardObject() {
238 // no dashboard element for this component
246 public function registerTab() {
248 'title' => ts('Mailings'),
259 public function getIcon() {
260 return 'crm-i fa-envelope-o';
267 public function registerAdvancedSearchPane() {
269 'title' => ts('Mailings'),
278 public function getActivityTypes() {
283 * add shortcut to Create New.
286 public function creatNewShortcut(&$shortCuts) {