/[drupal]/contributions/modules/upcomingorg/upcomingorg.inc
ViewVC logotype

Contents of /contributions/modules/upcomingorg/upcomingorg.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sun Sep 4 10:57:41 2005 UTC (4 years, 2 months ago) by sjaensch
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-4-6
Changes since 1.8: +3 -3 lines
File MIME type: text/x-php
guess what, the return value of node_save() changed again
1 <?php
2 /* $Id: upcomingorg.inc,v 1.8 2005/09/01 22:23:41 sjaensch Exp $ */
3
4
5 function upcomingorg_save_event($event) {
6 global $user;
7
8 if ($event['id']) {
9 $query = 'SELECT nid FROM {upcomingorg_event} WHERE event_id='.intval($event['id']);
10 $nid = db_result(db_query($query));
11 }
12
13 if ($nid) {
14 $node = node_load($nid);
15 $op = 'update'; // FIXME: for debug output, remove later
16 }
17 else {
18 $node = new StdClass();
19 $node->uid = $user->uid;
20 $node->type = variable_get('upcomingorg_event_nodetype', '');
21 $node->created = strtotime($event['date_posted']);
22 // The following is copied from node_validate()
23 $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
24 $node->status = in_array('status', $node_options);
25 $node->moderate = in_array('moderate', $node_options);
26 $node->promote = in_array('promote', $node_options);
27 $node->sticky = in_array('sticky', $node_options);
28 $node->revision = in_array('revision', $node_options);
29 $op = 'add'; // FIXME: for debug output, remove later
30 }
31
32 $node->title = $event['name'];
33 $node->changed = time();
34 $node->event_id = $event['id'];
35 $fields = array('metro_id', 'venue_nid', 'user_id', 'category_id', 'description', 'tags', 'personal', 'selfpromotion', 'event_start', 'event_end', 'is_imported');
36 foreach ($fields as $field) {
37 $node->$field = $event[$field];
38 }
39
40 // Should we call node_validate()? If so: $node->created has to be set again after validating,
41 // since node_validate() overwrites it for users without node administration privileges
42 node_save($node);
43 #echo "<!-- Saved node {$node->nid} for event $event[id] ($op) -->\n";
44 return $node->nid;
45 } // function location_add_event
46
47
48 function upcomingorg_save_venue($venue) {
49 global $user;
50
51 if ($venue['id']) {
52 $query = 'SELECT nid FROM {upcomingorg_venue} WHERE venue_id='.intval($venue['id']);
53 $nid = db_result(db_query($query));
54 }
55
56 if ($nid) {
57 // update the already-imported venue
58 $node = node_load($nid);
59 }
60 else {
61 $node = new StdClass();
62 $node->type = variable_get('upcomingorg_venue_nodetype', '');
63 $node->uid = $user->uid;
64 $node->title = $venue['name'];
65 $node->location = array();
66 // The following is copied from node_validate()
67 $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
68 $node->status = in_array('status', $node_options);
69 $node->moderate = in_array('moderate', $node_options);
70 $node->promote = in_array('promote', $node_options);
71 $node->sticky = in_array('sticky', $node_options);
72 $node->revision = in_array('revision', $node_options);
73 }
74
75 $node->location['name'] = $venue['name'];
76 $node->location['street'] = $venue['address'];
77 $node->location['city'] = $venue['city'];
78 $node->location['postal_code'] = $venue['zip'];
79
80 $node->changed = time();
81 $node->venue_id = $venue['id'];
82 $fields = array('user_id', 'description', 'url', 'phone', 'private', 'is_imported');
83 foreach ($fields as $field) {
84 $node->$field = $venue[$field];
85 }
86
87 node_save($node);
88 echo "<!-- Saved node {$node->nid} for venue $venue[id] -->\n";
89 return $node->nid;
90 }
91
92
93 function upcomingorg_save_category($category)
94 {
95 db_query("INSERT INTO {upcomingorg_category} (category_id, name, description) VALUES (%d, '%s', '%s')", $category['id'], $category['name'], $category['description']);
96 }

  ViewVC Help
Powered by ViewVC 1.1.2