-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhero.module
More file actions
219 lines (174 loc) · 5.24 KB
/
Copy pathhero.module
File metadata and controls
219 lines (174 loc) · 5.24 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/*
* igasi
*/
/*
* Function for funcionality contiditional event by capacity
*/
//Update when insert node registration in avalability schedule
function ero_action_insert_registration($nid=NULL)
{
//get parent
$reference_field = "time_of_audit_";
$parent_nid = _ero_er_getparent($reference_field,$nid);
//get field value capacity avalability schedule
$field = "reserved";
$reserved = _get_field_value($field,$parent_nid);
//update avalability schedule
$reserved ++;
$result['update'] = _ero_field_dbupdate($field,$reserved,$parent_nid);
cache_clear_all('field:node:' . $parent_nid, 'cache_field');
$result = array(
'reserved' => $reserved,
'nid' => $nid,
'parent_nid' => $parent_nid,
);
return array('insert_registration' => $result);
}
//Update when delete node registration in avalability schedule
function ero_action_delete_registration($nid=NULL)
{
//get parent
$reference_field = "time_of_audit_";
$parent_nid = _ero_er_getparent($reference_field,$nid);
//get field value capacity avalability schedule
$field = "reserved";
$reserved = _get_field_value($field,$parent_nid);
//update avalability schedule
$reserved --;
$result = _ero_field_dbupdate($field,$reserved,$parent_nid);
cache_clear_all('field:node:' . $parent_nid, 'cache_field');
$result = array(
'reserved' => $reserved,
'nid' => $nid,
'parent_nid' => $parent_nid,
);
return array('delete_registration' => $result);
}
/*
* Auxiliar Functions Active Record for fields
*/
//implements db_insert
function _ero_field_dbinsert($bundle=NULL,$field=NULL,$value=NULL,$nid=NULL)
{
return db_insert('field_data_field_'.$campo)
->fields(array('entity_type'=>'node',
'bundle'=>$bundle,
'deleted'=>0,
'entity_id'=>$nid,
'revision_id'=>$nid,
'language'=>'und',
'delta'=>0,
'field_'.$field.'_value'=>$value,
))
->execute();
}
//implements db_delete
function _ero_field_dbdelete($field=NULL,$nid=NULL){
return db_delete('field_data_field_'.$field)
->condition('entity_id',$nid, '=')
->execute();
}
//implements db_update
function _ero_field_dbupdate($field=NULL,$value=NULL,$nid=NULL){
return db_update('field_data_field_'.$field)
->fields(array('field_'.$field.'_value' => $value))
->condition('entity_id',$nid,'=')
->execute();
}
//implements db_query
function _get_field_value($field=NULL,$nid=NULL){
return db_query("SELECT field_".$field."_value
FROM {field_data_field_".$field."}
WHERE entity_id=:nid",
array(':nid'=>$nid) )-> fetchField();
}
/*
* Auxiliar function for count childs
*/
function _ero_er_count_childs_($reference_field=NULL,$nid=NULL){
$count = 0;
foreach (_ero_er_getallchilds($reference_field,$nid) as $child_nid) {
$count ++;
}
return $count;
}
/*
* functions for get parents and childs
*/
function _ero_er_getparent($reference_field=NULL,$nid=NULL){
return db_query("SELECT field_".$reference_field."_target_id
FROM {field_data_field_".$reference_field."}
WHERE entity_id=:nid",
array(':nid'=>$nid) )-> fetchField();
}
function _ero_er_getallparents($reference_field=NULL,$nid=NULL){
return db_query("SELECT entity_id
FROM {field_data_field_".$reference_field."}
WHERE field_".$referencia."_target_id=:nid",
array(':nid'=>$nid) );
}
function _ero_er_getchild($reference_field=NULL,$nid=NULL){
return db_query("SELECT entity_id
FROM {field_data_field_".$reference_field."}
WHERE field_".$referencia."_target_id=:nid",
array(':nid'=>$nid) )-> fetchField();
}
function _ero_er_getallchilds($reference_field=NULL,$nid=NULL){
return db_query("SELECT entity_id
FROM {field_data_field_".$reference_field."}
WHERE field_".$referencia."_nid=:nid",
array(':nid'=>$nid) );
}
/*
* Implements active record Drupal 7
*/
/*
*Implements db_insert() for entity reference
* $er_id = entity reference id
*/
function _ero_er_dbinsert($bundle=NULL,$field=NULL,$er_id=NULL,$nid=NULL)
{
$result = db_insert('field_data_field_'.$campo)
->fields(array('entity_type'=>'node',
'bundle'=>$bundle,
'deleted'=>0,
'entity_id'=>$nid,
'revision_id'=>$nid,
'language'=>'und',
'delta'=>0,
'field_'.$field.'_target_id'=>$er_id,
))
->execute();
cache_clear_all('field:node:' . $nid, 'cache_field');
return $result;
}
/*
* Implements db_update for entity reference
*/
function _ero_er_dbupdate($field=NULL,$value=NULL,$nid=NULL)
{
return db_update('field_data_field_'.$field)
->fields(array('field_'.$field.'_target_id' => $value))
->condition('entity_id',$nid,'=')
->execute();
}
/*
* Implements db_delete for entity reference
*/
function _ero_er_dbdelete($field=NULL,$nid=NULL)
{
return db_delete('field_data_field_'.$field)
->condition('entity_id',$nid, '=')
->execute();
}
/*
* Implements db_queryt for entity reference
*/
function _ero_er_dbselect($field=NULL, $nid=NULL)
{
return db_query("SELECT field_".$field."_target_id
FROM {field_data_field_".$field."}
WHERE entity_id=:nid",
array(':nid'=>$nid) )-> fetchField();
}