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 &&
182 $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) {