-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsmsconversation.php
177 lines (160 loc) · 5.38 KB
/
smsconversation.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
173
174
175
176
177
<?php
require_once 'smsconversation.civix.php';
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function smsconversation_civicrm_config(&$config) {
if (isset(Civi::$statics[__FUNCTION__])) {
return;
}
Civi::$statics[__FUNCTION__] = 1;
Civi::dispatcher()->addListener('hook_civicrm_post', 'smsconversation_process_inbound',1000);
_smsconversation_civix_civicrm_config($config);
}
function smsconversation_process_inbound($event){
if($event->entity=='Activity' && $event->object->activity_type_id == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Inbound SMS')) {
$activity = civicrm_api('Activity', 'getsingle', array('version'=>'3','id' => $event->id));
$p = new CRM_SmsConversation_Processor($activity);
if ($p) {
$p->inbound();
}
}
// var_dump($event->object->activity_type_id);
// var_dump($event->id);
// $r = new ReflectionObject($event);
// var_dump($r->getProperties());
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function smsconversation_civicrm_install() {
_smsconversation_civix_civicrm_install();
}
/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function smsconversation_civicrm_uninstall() {
// Delete action_type option group
$result = civicrm_api3('OptionGroup', 'get', array(
'name' => "sms_conversation_action_type",
));
if (!empty($result['id'])) {
$result = civicrm_api3('OptionGroup', 'delete', array(
'id' => $result['id'],
));
}
// Delete status_type option group
$result = civicrm_api3('OptionGroup', 'get', array(
'name' => "sms_conversation_status_type",
));
if (!empty($result['id'])) {
$result = civicrm_api3('OptionGroup', 'delete', array(
'id' => $result['id'],
));
}
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function smsconversation_civicrm_enable() {
_smsconversation_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_entityTypes.
*
* @param array $entityTypes
* Registered entity types.
*/
function smsconversation_civicrm_entityTypes(&$entityTypes) {
$entityTypes['CRM_SmsConversation_DAO_Action'] = array (
'name' => 'SmsConversationAction',
'class' => 'CRM_SmsConversation_DAO_Action',
'table' => 'civicrm_sms_conversation_action',
);
$entityTypes['CRM_SmsConversation_DAO_Contact'] = array (
'name' => 'SmsConversationContact',
'class' => 'CRM_SmsConversation_DAO_Contact',
'table' => 'civicrm_sms_conversation_contact',
);
$entityTypes['CRM_SmsConversation_DAO_Conversation'] = array (
'name' => 'SmsConversationConversation',
'class' => 'CRM_SmsConversation_DAO_Conversation',
'table' => 'civicrm_sms_conversation',
);
$entityTypes['CRM_SmsConversation_DAO_Question'] = array (
'name' => 'SmsConversationQuestion',
'class' => 'CRM_SmsConversation_DAO_Question',
'table' => 'civicrm_sms_conversation_question',
);
}
function smsconversation_civicrm_summaryActions(&$actions, $contactId){
// If the contact has a mobile phone, start a conversation with them
$count = civicrm_api3('Phone', 'getcount', ['contact_id' => $contactId, 'phone_type_id' => 'Mobile']);
if($count){
$actions['smsconversation'] = [
'title' => 'Start SMS conversation',
'weight' => 999,
'ref' => 'sms-conversation',
'key' => 'sms-conversation',
'href' => CRM_Utils_System::url('civicrm/sms/conversation/schedule', "cid=$contactId"),
];
}
}
function smsconversation_civicrm_searchTasks( $objectName, &$tasks ){
if($objectName == 'contact'){
$tasks[] = [
'title' => 'SMS - schedule a conversation',
'class' => 'CRM_SmsConversation_Form_ScheduleMultiple'
];
}
}
/*function smsconversation_civicrm_tabset($tabsetName, &$tabs, $context) {
// FIXME: For CiviCRM 4.7 we can use this hook instead.
}*/
/**
* Replace the existing activities tab
* @param $tabs
* @param $contactID
*/
function smsconversation_civicrm_tabset ( $tabsetName, &$tabs, $context) {
// ADD the sms conversation tab as a separate tab
if ($tabsetName == 'civicrm/contact/view' && !empty($context['contact_id'])) {
$tabs[] = [
'title' => 'SMS Conversations',
'id' => 'smsconversation',
'class' => 'livePage',
'url' => CRM_Utils_System::url('civicrm/contact/view/smsconversation', "reset=1&cid={$context['contact_id']}"),
'weight' => 50,
'count' => CRM_SmsConversation_BAO_Contact::getConversationCount($context['contact_id']),
];
}
}
function smsconversation_civicrm_navigationMenu(&$menus){
// Find the mailing menu
foreach($menus as &$menu){
if($menu['attributes']['name'] == 'Mailings'){
$nextId = max(array_keys($menu['child']));
$menu['child'][$nextId]=[
'attributes' => array(
'label' => 'SMS Conversations',
'name' => 'SMS Conversations',
'url' => 'civicrm/sms/conversations',
'permission' => 'access CiviMail',
'navID' => $nextId,
'operator' => FALSE,
'separator' => TRUE,
'parentID' => $menu['attributes']['navID'],
'active' => 1
),
];
}
}
}