2 namespace Civi\ActionSchedule
;
6 private static $fields = array(
13 'entity_status_label',
19 public static function create($params) {
20 return new static($params);
23 public function __construct($params) {
24 foreach (self
::$fields as $field) {
25 if (isset($params[$field])) {
26 $this->{$field} = $params[$field];
34 * The basic entity to query (table name).
37 * Ex: 'civicrm_activity', 'civicrm_event'.
42 * The basic entity to query (label).
45 * Ex: 'Activity', 'Event'
50 * Level 1 filter -- the field/option-list to filter on.
53 * Ex: 'activity_type', 'civicrm_event', 'event_template'.
58 * Level 1 filter -- The field label.
61 * Ex: 'Activity Type', 'Event Name', 'Event Template'.
63 public $entity_value_label;
66 * Level 2 filter -- the field/option-list to filter on.
68 * Ex: 'activity_status, 'civicrm_participant_status_type', 'auto_renew_options'.
70 public $entity_status;
73 * Level 2 filter -- the field label.
75 * Ex: 'Activity Status', 'Participant Status', 'Auto Rewnewal Options'.
77 public $entity_status_label;
80 * Date filter -- the field name.
82 * Ex: 'event_start_date'
84 public $entity_date_start;
87 * Date filter -- the field name.
89 * Ex: 'event_end_date'.
91 public $entity_date_end;
94 * Contact selector -- The field/relationship/option-group name.
96 * Ex: 'activity_contacts', 'event_contacts'.
98 public $entity_recipient;
101 * Get a list of value options.
104 * Array(string $value => string $label).
105 * Ex: array(123 => 'Phone Call', 456 => 'Meeting').
107 public function getValueLabels() {
108 return self
::getValueLabelMap($this->entity_value
);
112 * Get a list of status options.
114 * @param string|int $value
115 * The list of status options may be contingent upon the selected filter value.
116 * This is the selected filter value.
118 * Array(string $value => string $label).
119 * Ex: Array(123 => 'Completed', 456 => 'Scheduled').
121 public function getStatusLabels($value) {
122 if ($this->entity_status
=== 'auto_renew_options') {
123 if ($value && \CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType', $value, 'auto_renew')) {
124 return \CRM_Core_OptionGroup
::values('auto_renew_options');
130 return self
::getValueLabelMap($this->entity_status
);
135 * Array(string $fieldName => string $fieldLabel).
137 public function getDateFields() {
138 $dateFieldLabels = array();
139 if (!empty($this->entity_date_start
)) {
140 $dateFieldLabels[$this->entity_date_start
] = ucwords(str_replace('_', ' ', $this->entity_date_start
));
142 if (!empty($this->entity_date_end
)) {
143 $dateFieldLabels[$this->entity_date_end
] = ucwords(str_replace('_', ' ', $this->entity_date_end
));
145 return $dateFieldLabels;
149 * @param bool|NULL $noThanksJustKidding
150 * This is ridiculous and should not exist.
151 * If true, don't do our main job.
153 * array(string $value => string $label).
154 * Ex: array('assignee' => 'Activity Assignee').
156 public function getRecipientTypes($noThanksJustKidding = FALSE) {
157 $entityRecipientLabels = array();
158 switch ($this->entity_recipient
) {
159 case 'activity_contacts':
160 $entityRecipientLabels = \CRM_Core_OptionGroup
::values('activity_contacts');
163 case 'event_contacts':
164 if (!$noThanksJustKidding) {
165 $entityRecipientLabels = \CRM_Core_OptionGroup
::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
171 $entityRecipientLabels +
= array(
172 'manual' => ts('Choose Recipient(s)'),
173 'group' => ts('Select Group'),
175 return $entityRecipientLabels;
178 protected static function getValueLabelMap($name) {
179 static $valueLabelMap = NULL;
180 if ($valueLabelMap === NULL) {
181 $valueLabelMap['activity_type'] = \CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
182 asort($valueLabelMap['activity_type']);
184 $valueLabelMap['activity_status'] = \CRM_Core_PseudoConstant
::activityStatus();
185 $valueLabelMap['event_type'] = \CRM_Event_PseudoConstant
::eventType();
186 $valueLabelMap['civicrm_event'] = \CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
187 $valueLabelMap['civicrm_participant_status_type'] = \CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
188 $valueLabelMap['event_template'] = \CRM_Event_PseudoConstant
::eventTemplates();
189 $valueLabelMap['auto_renew_options'] = \CRM_Core_OptionGroup
::values('auto_renew_options');
190 $valueLabelMap['contact_date_reminder_options'] = \CRM_Core_OptionGroup
::values('contact_date_reminder_options');
191 $valueLabelMap['civicrm_membership_type'] = \CRM_Member_PseudoConstant
::membershipType();
193 $allCustomFields = \CRM_Core_BAO_CustomField
::getFields('');
195 'birth_date' => ts('Birth Date'),
196 'created_date' => ts('Created Date'),
197 'modified_date' => ts('Modified Date'),
199 foreach ($allCustomFields as $fieldID => $field) {
200 if ($field['data_type'] == 'Date') {
201 $dateFields["custom_$fieldID"] = $field['label'];
204 $valueLabelMap['civicrm_contact'] = $dateFields;
207 return $valueLabelMap[$name];