/[drupal]/contributions/modules/rsvp/rsvp_dateconnector.module
ViewVC logotype

Contents of /contributions/modules/rsvp/rsvp_dateconnector.module

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


Revision 1.2 - (show annotations) (download) (as text)
Sun Jan 11 07:59:39 2009 UTC (10 months, 2 weeks ago) by ulf1
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.1: +3 -3 lines
File MIME type: text/x-php
Merge from DRUPAL-6--1-0
1 <?php
2 // $Id: rsvp_dateconnector.module,v 1.1.2.1 2008/12/05 06:56:59 ulf1 Exp $
3
4 class RsvpDateConnectorImpl extends RsvpConnectorImpl {
5
6 //returns a date as int in unix form (and converted to UTC).
7 function convert_date2UTCUnix($dateAsString, $timezone, $date_type)
8 {
9 //1) convert input date into DateTime
10 $date = date_make_date($dateAsString, $timezone, $date_type);
11
12 //2) convert DateTime into UTC
13 date_timezone_set($date, timezone_open('UTC'));
14
15 //3) convert DateTime into Unix
16 return intval(date_convert($date, DATE_OBJECT, DATE_UNIX));
17 }
18
19 function get_datecount($node, $field) {
20 $fld = $node->$field;
21
22 return count($fld);
23 }
24
25 //returns startdate as unix timestamp in utc
26 function get_startdate($node, $field, $pos) {
27 $fld = $node->$field;
28
29 $timezoneName_db = $this->get_offset_db($node, $field, $pos);
30
31 $date = $this->convert_date2UTCUnix($fld[$pos]['value'], $timezoneName_db, $fld[$pos]['date_type']);
32 return $date;
33 }
34
35 //returns startdate as string in local timezone
36 function get_startdateAsString($node, $field, $pos) {
37
38 $fld = $node->$field;
39
40 $timezoneName_db = $this->get_offset_db($node, $field, $pos);
41 //$timezoneName_target = $this->get_offset($node, $field, $pos);
42
43 //1) convert input date into DateTime
44 $date = date_make_date($fld[$pos]['value'], $timezoneName_db, $fld[$pos]['date_type']);
45
46 //2) convert DateTime into target timezone
47 $timezone_target = date_default_timezone();
48
49 date_timezone_set($date, $timezone_target);
50
51 //3) convert DateTime into String
52 $format = date_formatter_format('default', $field);
53 $out = date_format_date($date, 'custom', $format);
54 return $out;
55 }
56
57 //returns enddate as unix timestamp in utc
58 function get_enddate($node, $field, $pos) {
59 $fld = $node->$field;
60
61 //if no "toDate" is set, return the "StartDate" of the event instead.
62 if (!isset($fld[$pos]['value2'])) {
63 return $this->get_startdate($node, $field, $pos);
64 }
65
66 $timezoneName_db = $this->get_offset_db($node, $field, $pos);
67
68
69 $date = $this->convert_date2UTCUnix($fld[$pos]['value2'], $timezoneName_db, $fld[$pos]['date_type']);
70 return $date;
71 }
72
73 //returns the position for a particular hash, or -1 if invalid hash
74 function get_posByHash($node, $field, $hash) {
75 $fld = $node->$field;
76
77 $count = $this->get_datecount($node, $field);
78
79 for ($i = 0; $i < $count; $i++) {
80 $unixdate = $this->get_startdate($node, $field, $i);
81 if ($unixdate == $hash) {
82 return $i;
83 }
84 }
85 return -1;
86 }
87
88 /*
89 * PRIVATE METHOD. Do not use outside. Return type is based on used connector.
90 * returns time zone offset according to Date API.
91 */
92 function get_offset($node, $field, $pos) {
93 $fld = $node->$field;
94
95 return $fld[$pos]['timezone'];
96 }
97
98 /*
99 * PRIVATE METHOD. Do not use outside. Return type is based on used connector.
100 * returns time zone name as date is stored in database according to Date API.
101 */
102 function get_offset_db($node, $field, $pos) {
103 $fld = $node->$field;
104
105 return $fld[$pos]['timezone_db'];
106 }
107
108 function is_event_enabled($contenttype) {
109
110 $rsvp_content_types = variable_get('rsvp_content_types', array());
111 if (!isset ($rsvp_content_types[$contenttype])) {
112 return false;
113 }
114 else {
115 return true;
116 }
117 }
118
119 function isTypesAreSelectable() {
120 return true;
121 }
122
123 //returns true if the connector supports multiple dates per field per content-type. (e.g. Repeatable dates in Date API).
124 function hasMultipleDatesPerField() {
125 return true;
126 }
127
128
129 }
130
131 function rsvp_dateconnector_getconnector() {
132 return new RsvpDateConnectorImpl();
133 }

  ViewVC Help
Powered by ViewVC 1.1.2