Skip to content

Commit 1255d16

Browse files
committed
Lookup trigger rules in taxononmy to see if it should be published
1 parent 892d8d8 commit 1255d16

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

os2web_cp_service.module

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,26 @@ function os2web_cs_service_create_case(array $data) {
170170
}
171171
}
172172
else {
173-
$node = node_load(array_pop($nids));
173+
$node = node_load($nids);
174+
}
175+
176+
// See if the triggered rules on the published node, is approved
177+
// in the vocabulary. Otherwise the node will be unpublished.
178+
$vocabulary = taxonomy_vocabulary_machine_name_load('os2web_cp_service_tax_approved_rules');
179+
$approved_rules = taxonomy_get_tree($vocabulary->vid);
180+
$approved = FALSE;
181+
foreach ($data['rules'] as $trigger_rule) {
182+
foreach ($approved_rules as $approved_rule) {
183+
if ($approved_rule->name === $trigger_rule) {
184+
$approved = TRUE;
185+
break;
186+
}
187+
}
174188
}
189+
175190
$node->type = 'os2web_cp_service_cp_case';
176191
$node->uid = 0;
177-
$node->status = 1;
192+
$node->status = $approved;
178193
$node->comment = 0;
179194
$node->promote = 0;
180195
$node->moderate = 0;
@@ -211,6 +226,13 @@ function os2web_cs_service_create_case(array $data) {
211226
}
212227
}
213228
}
229+
230+
unset($node->field_os2web_cp_service_rules[LANGUAGE_NONE]);
231+
foreach ($data['rules'] as $name) {
232+
$term = array_pop(taxonomy_get_term_by_name($name, 'os2web_cp_service_tax_approved_rules'));
233+
$node->field_os2web_cp_service_rules[LANGUAGE_NONE][]['tid'] = $term->tid;
234+
}
235+
214236
try {
215237
node_submit($node);
216238
node_save($node);
@@ -354,9 +376,24 @@ function os2web_cs_service_create_document(array $data) {
354376
else {
355377
$node = node_load(array_pop($nids));
356378
}
379+
380+
// See if the triggered rules on the published node, is approved
381+
// in the vocabulary. Otherwise the node will be unpublished.
382+
$vocabulary = taxonomy_vocabulary_machine_name_load('os2web_cp_service_tax_approved_rules');
383+
$approved_rules = taxonomy_get_tree($vocabulary->vid);
384+
$approved = FALSE;
385+
foreach ($data['rules'] as $trigger_rule) {
386+
foreach ($approved_rules as $approved_rule) {
387+
if ($approved_rule->name === $trigger_rule) {
388+
$approved = TRUE;
389+
break;
390+
}
391+
}
392+
}
393+
357394
$node->type = 'os2web_cp_service_cp_document';
358395
$node->uid = 0;
359-
$node->status = 1;
396+
$node->status = $approved;
360397
$node->comment = 0;
361398
$node->promote = 0;
362399
$node->moderate = 0;
@@ -384,6 +421,13 @@ function os2web_cs_service_create_document(array $data) {
384421
}
385422
}
386423
}
424+
425+
unset($node->field_os2web_cp_service_rules[LANGUAGE_NONE]);
426+
foreach ($data['rules'] as $name) {
427+
$term = array_pop(taxonomy_get_term_by_name($name, 'os2web_cp_service_tax_approved_rules'));
428+
$node->field_os2web_cp_service_rules[LANGUAGE_NONE][]['tid'] = $term->tid;
429+
}
430+
387431
try {
388432
node_submit($node);
389433
node_save($node);

0 commit comments

Comments
 (0)