Task.php 3.34 KB
Newer Older
pratik.joshi's avatar
pratik.joshi committed
1 2 3
<?php
/*
 +--------------------------------------------------------------------+
totten's avatar
totten committed
4
 | CiviCRM version 5                                                  |
pratik.joshi's avatar
pratik.joshi committed
5
 +--------------------------------------------------------------------+
Seamus Lee's avatar
Seamus Lee committed
6
 | Copyright CiviCRM LLC (c) 2004-2019                                |
pratik.joshi's avatar
pratik.joshi committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
26
 */
pratik.joshi's avatar
pratik.joshi committed
27 28 29 30

/**
 *
 * @package CRM
Seamus Lee's avatar
Seamus Lee committed
31
 * @copyright CiviCRM LLC (c) 2004-2019
pratik.joshi's avatar
pratik.joshi committed
32 33 34 35
 */

/**
 * class to represent the actions that can be performed on a group of contacts
36
 * used by the search forms.
pratik.joshi's avatar
pratik.joshi committed
37 38
 *
 */
39
class CRM_Mailing_Task extends CRM_Core_Task {
pratik.joshi's avatar
pratik.joshi committed
40

41
  public static $objectType = 'mailing';
pratik.joshi's avatar
pratik.joshi committed
42 43 44

  /**
   * These tasks are the core set of tasks that the user can perform
45
   * on a contact / group of contacts.
pratik.joshi's avatar
pratik.joshi committed
46
   *
47
   * @return array
48
   *   the set of tasks for a group of contacts.
pratik.joshi's avatar
pratik.joshi committed
49
   */
50
  public static function tasks() {
pratik.joshi's avatar
pratik.joshi committed
51
    if (!(self::$_tasks)) {
52 53
      self::$_tasks = [
        self::TASK_PRINT => [
colemanw's avatar
colemanw committed
54
          'title' => ts('Print Mailing Recipients'),
pratik.joshi's avatar
pratik.joshi committed
55 56
          'class' => 'CRM_Mailing_Form_Task_Print',
          'result' => FALSE,
57 58
        ],
      ];
pratik.joshi's avatar
pratik.joshi committed
59

60
      parent::tasks();
pratik.joshi's avatar
pratik.joshi committed
61 62 63 64 65 66
    }

    return self::$_tasks;
  }

  /**
colemanw's avatar
colemanw committed
67
   * Show tasks selectively based on the permission level
68
   * of the user.
pratik.joshi's avatar
pratik.joshi committed
69 70
   *
   * @param int $permission
71
   * @param array $params
pratik.joshi's avatar
pratik.joshi committed
72
   *
73 74
   * @return array
   *   set of tasks that are valid for the user
pratik.joshi's avatar
pratik.joshi committed
75
   */
76 77
  public static function permissionedTaskTitles($permission, $params = []) {
    $tasks = [];
78 79 80

    $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
    return $tasks;
pratik.joshi's avatar
pratik.joshi committed
81 82 83
  }

  /**
84
   * These tasks are the core set of tasks that the user can perform.
85
   * on mailing recipients.
pratik.joshi's avatar
pratik.joshi committed
86 87 88
   *
   * @param int $value
   *
89 90
   * @return array
   *   the set of tasks for a group of mailing recipients
pratik.joshi's avatar
pratik.joshi committed
91
   */
92
  public static function getTask($value) {
pratik.joshi's avatar
pratik.joshi committed
93 94 95
    self::tasks();
    if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
      // make the print task by default
96
      $value = self::TASK_PRINT;
pratik.joshi's avatar
pratik.joshi committed
97
    }
98

99
    return [
pratik.joshi's avatar
pratik.joshi committed
100 101
      self::$_tasks[$value]['class'],
      self::$_tasks[$value]['result'],
102
    ];
pratik.joshi's avatar
pratik.joshi committed
103
  }
104

colemanw's avatar
colemanw committed
105
}