-
Notifications
You must be signed in to change notification settings - Fork 4
/
resource.php
172 lines (156 loc) · 5.43 KB
/
resource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/*-------------------------------------------------------+
| SYSTOPIA Resource Framework |
| Copyright (C) 2021 SYSTOPIA |
| Author: B. Endres ([email protected]) |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/
require_once 'resource.civix.php';
// phpcs:disable
use CRM_Resource_ExtensionUtil as E;
// phpcs:enable
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function resource_civicrm_config(&$config)
{
_resource_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function resource_civicrm_install()
{
_resource_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function resource_civicrm_enable()
{
_resource_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_entityTypes().
*
* Declare entity types provided by this module.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
*/
function resource_civicrm_entityTypes(&$entityTypes)
{
$entityTypes['CRM_Resource_DAO_Resource'] = [
'name' => 'Resource',
'class' => 'CRM_Resource_DAO_Resource',
'table' => 'civicrm_resource',
//'links_callback' => ['CRM_Resource_BAO_Resource::add_resource_links']
];
$entityTypes['CRM_Resource_DAO_ResourceAssignment'] = [
'name' => 'ResourceAssignment',
'class' => 'CRM_Resource_DAO_ResourceAssignment',
'table' => 'civicrm_resource_assignment',
];
$entityTypes['CRM_Resource_DAO_ResourceDemand'] = [
'name' => 'ResourceDemand',
'class' => 'CRM_Resource_DAO_ResourceDemand',
'table' => 'civicrm_resource_demand',
];
$entityTypes['CRM_Resource_DAO_ResourceDemandCondition'] = [
'name' => 'ResourceDemandCondition',
'class' => 'CRM_Resource_DAO_ResourceDemandCondition',
'table' => 'civicrm_resource_demand_condition',
];
$entityTypes['CRM_Resource_DAO_ResourceUnavailability'] = [
'name' => 'ResourceUnavailability',
'class' => 'CRM_Resource_DAO_ResourceUnavailability',
'table' => 'civicrm_resource_unavailability',
];
}
/**
* Add contact summary tab for contact resources
*/
function resource_civicrm_tabset($tabsetName, &$tabs, $context)
{
switch ($tabsetName) {
case 'civicrm/contact/view':
case 'civicrm/eck/entity':
CRM_Resource_UI::addResourceTab($tabs, $tabsetName, $context);
return;
case 'civicrm/event/manage':
CRM_Resource_UI::addEventResourceDemandTab($tabs, $context);
return;
default:
return;
}
}
function resource_civicrm_searchTasks($objectType, &$tasks)
{
// add "Mark as resource" task to contact list
if ($objectType == 'contact') {
// ...but only, if any contact based resource type is active
$contact_based_resource_types = CRM_Resource_Types::getForEntityTable('civicrm_contact');
if (!empty($contact_based_resource_types)) {
$tasks[] = [
'title' => E::ts('Mark as Resource'),
'class' => 'CRM_Resource_Form_Task_CreateContactResource',
'result' => false
];
}
}
}
/**
* Implementation of hook_civicrm_copy
*/
function resource_civicrm_copy($objectName, &$object)
{
if ($objectName == 'Event') {
// we have the new event ID...
$new_event_id = $object->id;
// ...unfortunately, we have to dig up the original event ID:
$callstack = debug_backtrace();
foreach ($callstack as $call) {
if (isset($call['class']) && isset($call['function'])) {
if ($call['class'] == 'CRM_Event_BAO_Event' && $call['function'] == 'copy') {
// this should be it:
$original_event_id = $call['args'][0];
CRM_Resource_BAO_ResourceDemand::copyAllDemands('civicrm_event', $original_event_id, $new_event_id);
break;
}
}
}
}
}
/**
* Implements hook_civicrm_alterAdminPanel().
*/
function resource_civicrm_alterAdminPanel(&$adminPanel) {
// Add a group to the administration console and display items belonging to it.
$values = CRM_Core_Menu::getAdminLinks();
if (!empty($values['CiviResource'])) {
$adminPanel['CiviResource'] = [
'title' => E::ts('CiviResource'),
] + $values['CiviResource'];
}
}
/**
* Implements hook_civicrm_permission().
*/
function resource_civicrm_permission(&$permissions) {
$permissions['access CiviResource'] = [
'label' => E::ts('CiviResource: access CiviResource'),
'description' => E::ts('CiviResource: Allow creating, editing, (un-)assigning resources/resource demands.'),
];
}