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';
32 public function getInfo() {
35 'translatedName' => ts('CiviMail'),
36 'title' => ts('CiviCRM Mailing Engine'),
38 'showActivitiesInCore' => 1,
43 * Get AngularJS modules and their dependencies.
46 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
47 * @see CRM_Utils_Hook::angularModules
49 public function getAngularModules() {
50 // load angular files only if valid permissions are granted to the user
51 if (!CRM_Core_Permission
::check('access CiviMail')
52 && !CRM_Core_Permission
::check('create mailings')
53 && !CRM_Core_Permission
::check('schedule mailings')
54 && !CRM_Core_Permission
::check('approve mailings')
61 $reportTypes = ['detail', 'opened', 'bounce', 'clicks'];
62 foreach ($reportTypes as $report) {
63 $result = civicrm_api3('ReportInstance', 'get', [
65 'report_id' => 'mailing/' . $report,
67 if (!empty($result['values'])) {
68 $reportIds[$report] = $result['values'][0]['id'];
72 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
73 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
74 $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php";
76 $config = CRM_Core_Config
::singleton();
77 $session = CRM_Core_Session
::singleton();
78 $contactID = $session->get('userID');
82 'options' => ['limit' => 0],
85 $groupNames = civicrm_api3('Group', 'get', $params +
[
87 'check_permissions' => TRUE,
88 'return' => ['title', 'visibility', 'group_type', 'is_hidden'],
90 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
[
92 'return' => ['name', 'component_type', 'is_default', 'body_html', 'body_text'],
95 $emailAdd = civicrm_api3('Email', 'get', [
98 'contact_id' => $contactID,
101 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
[
104 'return' => ["id", "msg_title"],
105 'workflow_id' => ['IS NULL' => ""],
107 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
108 'entity' => ['contact', 'mailing'],
111 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
[
112 'option_group_id' => "from_email_address",
113 'domain_id' => CRM_Core_Config
::domainID(),
115 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
116 $isMultiLingual = (count($enabledLanguages) > 1);
117 // 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.
118 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
, []) : CRM_Utils_Token
::getRequiredTokens();
119 CRM_Core_Resources
::singleton()
122 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
124 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents
),
126 // @todo this is not used in core. Remove once Mosaico no longer depends on it.
127 'testGroupNames' => $groupNames['values'],
128 'headerfooterList' => $headerfooterList['values'],
129 'mesTemplate' => $mesTemplate['values'],
130 'emailAdd' => $emailAdd['values'],
131 'mailTokens' => $mailTokens['values'],
132 'contactid' => $contactID,
133 'requiredTokens' => $requiredTokens,
134 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
135 'disableMandatoryTokensCheck' => (int) Civi
::settings()->get('disable_mandatory_tokens_check'),
136 'fromAddress' => $fromAddress['values'],
137 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
138 'id' => 'user_contact_id',
141 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
142 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
143 'reportIds' => $reportIds,
144 'enabledLanguages' => $enabledLanguages,
145 'isMultiLingual' => $isMultiLingual,
155 'delete in CiviMail',
156 'edit message templates',
165 public static function workflowEnabled() {
166 $config = CRM_Core_Config
::singleton();
168 // early exit, since not true for most
169 if (!$config->userSystem
->is_drupal ||
170 !function_exists('module_exists')
175 if (!module_exists('rules')) {
179 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
181 return $enableWorkflow && $config->userSystem
->is_drupal
;
186 * @param bool $getAllUnconditionally
187 * @param bool $descriptions
188 * Whether to return permission descriptions
192 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
194 'access CiviMail' => [
195 ts('access CiviMail'),
197 'access CiviMail subscribe/unsubscribe pages' => [
198 ts('access CiviMail subscribe/unsubscribe pages'),
199 ts('Subscribe/unsubscribe from mailing list group'),
201 'delete in CiviMail' => [
202 ts('delete in CiviMail'),
203 ts('Delete Mailing'),
205 'view public CiviMail content' => [
206 ts('view public CiviMail content'),
210 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
211 $permissions['create mailings'] = [
212 ts('create mailings'),
214 $permissions['schedule mailings'] = [
215 ts('schedule mailings'),
217 $permissions['approve mailings'] = [
218 ts('approve mailings'),
222 if (!$descriptions) {
223 foreach ($permissions as $name => $attr) {
224 $permissions[$name] = array_shift($attr);
235 public function getUserDashboardElement() {
236 // no dashboard element for this component
243 public function getUserDashboardObject() {
244 // no dashboard element for this component
252 public function registerTab() {
254 'title' => ts('Mailings'),
265 public function getIcon() {
266 return 'crm-i fa-envelope-o';
273 public function registerAdvancedSearchPane() {
275 'title' => ts('Mailings'),
284 public function getActivityTypes() {
289 * add shortcut to Create New.
292 public function creatNewShortcut(&$shortCuts) {