| 1 |
<?php |
| 2 |
include_once( dirname(__FILE__) . '/iCalcreator.class.php' ); |
| 3 |
|
| 4 |
// class Ical_HC_Model extends MY_Model_Virtual |
| 5 |
class Ical_HC_Model |
| 6 |
{ |
| 7 |
protected $shifts = array(); |
| 8 |
protected $timezone = ''; |
| 9 |
|
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
$tz = HC_Lib::timezone(); |
| 13 |
$this->set_timezone( $tz ); |
| 14 |
} |
| 15 |
|
| 16 |
public function set_timezone( $tz ) |
| 17 |
{ |
| 18 |
$this->timezone = $tz; |
| 19 |
} |
| 20 |
public function timezone() |
| 21 |
{ |
| 22 |
return $this->timezone; |
| 23 |
} |
| 24 |
|
| 25 |
public function add( $sh ) |
| 26 |
{ |
| 27 |
$this->shifts[] = $sh; |
| 28 |
} |
| 29 |
|
| 30 |
public function print_out() |
| 31 |
{ |
| 32 |
$t = HC_Lib::time(); |
| 33 |
|
| 34 |
$t2 = HC_Lib::time(); |
| 35 |
$t2->setTimezone('UTC'); |
| 36 |
|
| 37 |
$timezone = $this->timezone(); |
| 38 |
|
| 39 |
$web_dir = HC_Lib::web_dir_name( HC_Lib::link()->url() ); |
| 40 |
$my_unique = md5($web_dir); |
| 41 |
$my_unique = 'hc-ical-' . $my_unique; |
| 42 |
|
| 43 |
$cal = new hc_vcalendar(); // initiate new CALENDAR |
| 44 |
|
| 45 |
// $cal->setConfig( 'unique_id', $web_dir ); |
| 46 |
$cal->setConfig( 'unique_id', $my_unique ); |
| 47 |
// $cal->setProperty( 'method', 'publish' ); |
| 48 |
$cal->setProperty( 'method', 'request' ); |
| 49 |
|
| 50 |
$cal->setProperty( 'x-wr-timezone', $timezone ); |
| 51 |
|
| 52 |
$vtz = new hc_vtimezone(); |
| 53 |
$vtz->setProperty( 'tzid', $timezone ); |
| 54 |
$cal->addComponent( $vtz ); |
| 55 |
|
| 56 |
reset( $this->shifts ); |
| 57 |
foreach( $this->shifts as $sh ){ |
| 58 |
$views = array( |
| 59 |
'location' => $sh->present_location(HC_PRESENTER::VIEW_RAW), |
| 60 |
'user' => $sh->present_user(HC_PRESENTER::VIEW_RAW), |
| 61 |
); |
| 62 |
|
| 63 |
$event = new hc_vevent(); // initiate a new EVENT |
| 64 |
$event->setProperty( 'uid', 'obj-' . $sh->id . '-' . $my_unique ); |
| 65 |
|
| 66 |
// $event->setProperty( 'summary', $views['user'] . ' @ ' . $views['location'] ); |
| 67 |
// $event->setProperty( 'description', $views['user'] . ' @ ' . $views['location'] ); |
| 68 |
|
| 69 |
$summary = $views['location']; |
| 70 |
$summary = $views['user'] . ' @ ' . $views['location']; |
| 71 |
// $description = $views['location']; |
| 72 |
$description = $views['user'] . ' @ ' . $views['location']; |
| 73 |
|
| 74 |
// $event->setAttendee( 'test@test.com' ); |
| 75 |
// $event->setOrganizer( 'test@test.com' ); |
| 76 |
|
| 77 |
$t->setDateDb( $sh->date ); |
| 78 |
$t->modify( '+' . $sh->start . ' seconds' ); |
| 79 |
|
| 80 |
list( $year, $month, $day, $hour, $min ) = $t->getParts(); |
| 81 |
// $event->setProperty( 'dtstart', $year, $month, $day, $hour, $min, 00, 'Z' ); // 24 dec 2006 19.30 |
| 82 |
$event->setProperty( 'dtstart', $year, $month, $day, $hour, $min, 00, $timezone ); |
| 83 |
|
| 84 |
$t2->setTimestamp( $t->getTimestamp() ); |
| 85 |
list( $year, $month, $day, $hour, $min ) = $t2->getParts(); |
| 86 |
$event->setProperty( 'dtstart', $year, $month, $day, $hour, $min, 00, 'Z' ); // 24 dec 2006 19.30 |
| 87 |
|
| 88 |
// $t->modify( '+' . $sh->get_duration() . ' seconds' ); |
| 89 |
// list( $year, $month, $day, $hour, $min ) = $t->getParts(); |
| 90 |
// $event->setProperty( 'duration', 0, 0, 0, 0, $a->getProp('duration') ); |
| 91 |
$event->setProperty( 'duration', 0, 0, 0, 0, $sh->get_duration(FALSE) ); |
| 92 |
|
| 93 |
$t2->setTimestamp( $t->getTimestamp() ); |
| 94 |
$t2->modify( '+' . $sh->get_duration() . ' seconds' ); |
| 95 |
list( $year, $month, $day, $hour, $min ) = $t2->getParts(); |
| 96 |
// $event->setProperty( 'dtend', $year, $month, $day, $hour, $min, 00, 'Z' ); // 24 dec 2006 19.30 |
| 97 |
|
| 98 |
$add_notes = TRUE; |
| 99 |
|
| 100 |
if( ! $sh->note ){ |
| 101 |
$add_notes = FALSE; |
| 102 |
} |
| 103 |
else { |
| 104 |
$acl = HC_App::acl(); |
| 105 |
|
| 106 |
if( ! $acl->set_object($sh)->can('notes_view') ){ |
| 107 |
$add_notes = FALSE; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
if( $add_notes ){ |
| 112 |
$sh->note |
| 113 |
->include_related( 'author', array('id', 'first_name', 'last_name', 'active'), TRUE, TRUE ) |
| 114 |
; |
| 115 |
$notes = $sh->note->get(); |
| 116 |
|
| 117 |
$current_user = HC_App::model('user'); |
| 118 |
$current_user->get_by_id(0); |
| 119 |
$acl->set_user( $current_user ); |
| 120 |
|
| 121 |
$notes = $acl->set_user( $current_user )->filter( $notes, 'view' ); |
| 122 |
|
| 123 |
if( $notes ){ |
| 124 |
$comments = array(); |
| 125 |
foreach( $notes as $note ){ |
| 126 |
$noteText = $note->content; |
| 127 |
$noteUserView = $note->author->present_title( HC_PRESENTER::VIEW_RAW ); |
| 128 |
$comments[] = $noteUserView . ': ' . $noteText; |
| 129 |
} |
| 130 |
$commentsView = join( ", ", $comments ); |
| 131 |
$event->setProperty( 'comment', $commentsView ); |
| 132 |
$description .= " (" . $commentsView . ')'; |
| 133 |
|
| 134 |
// only comments |
| 135 |
// $comments = array(); |
| 136 |
// reset( $notes ); |
| 137 |
// foreach( $notes as $note ){ |
| 138 |
// $noteText = $note->content; |
| 139 |
// $comments[] = $noteText; |
| 140 |
// } |
| 141 |
// $commentsView = join( ", ", $comments ); |
| 142 |
// $description = $commentsView; |
| 143 |
// $summary = $commentsView; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
$event->setProperty( 'location', $views['location'] ); |
| 148 |
$event->setProperty( 'description', $description ); |
| 149 |
$event->setProperty( 'summary', $summary ); |
| 150 |
|
| 151 |
$cal->addComponent( $event ); |
| 152 |
|
| 153 |
continue; |
| 154 |
} |
| 155 |
|
| 156 |
$return = $cal->createCalendar(); // generate and get output in string |
| 157 |
return $return; |
| 158 |
} |
| 159 |
} |