本文整理汇总了PHP中DateTimeValue::add方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeValue::add方法的具体用法?PHP DateTimeValue::add怎么用?PHP DateTimeValue::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeValue
的用法示例。
在下文中一共展示了DateTimeValue::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEventLimits
function getEventLimits($event, $date, &$event_start, &$event_duration, &$end_modified)
{
$end_modified = false;
if ($event instanceof ProjectEvent) {
$event_start = new DateTimeValue($event->getStart()->getTimestamp() + 3600 * logged_user()->getTimezone());
$event_duration = new DateTimeValue($event->getDuration()->getTimestamp() + 3600 * logged_user()->getTimezone());
} else {
if ($event instanceof ProjectTask) {
/* @var $event ProjectTask */
$work_day_start = new DateTimeValue($date->getTimestamp());
$wsd = user_config_option('work_day_start_time');
$work_day_start->setHour(substr($wsd, 0, strpos($wsd, ':')));
$work_day_start->setMinute(substr($wsd, strpos($wsd, ':') + 1));
if ($event->getStartDate() instanceof DateTimeValue) {
$event_start = new DateTimeValue($event->getStartDate()->getTimestamp() + 3600 * logged_user()->getTimezone());
} else {
if ($event->getTimeEstimate() > 0 && $event->getDueDate() instanceof DateTimeValue) {
$event_start = new DateTimeValue($event->getDueDate()->getTimestamp() + 3600 * logged_user()->getTimezone());
$event_start->advance($event->getTimeEstimate() * -60);
} else {
$event_start = $work_day_start;
}
}
$work_day_end = new DateTimeValue($date->getTimestamp());
$wed = user_config_option('work_day_end_time');
$work_day_end->setHour(substr($wed, 0, strpos($wed, ':')));
$work_day_end->setMinute(substr($wed, strpos($wed, ':') + 1));
if ($event->getDueDate() instanceof DateTimeValue) {
$event_duration = new DateTimeValue($event->getDueDate()->getTimestamp() + 3600 * logged_user()->getTimezone());
} else {
if ($event->getTimeEstimate() > 0 && $event->getStartDate() instanceof DateTimeValue) {
$event_duration = new DateTimeValue($event_start->getTimestamp());
$event_duration->advance($event->getTimeEstimate() * 60);
} else {
$event_duration = $work_day_end;
}
}
}
}
$tomorrow = new DateTimeValue($date->getTimestamp());
$tomorrow->add('d', 1);
if ($event_duration->getTimestamp() > $tomorrow->getTimestamp()) {
$event_duration = new DateTimeValue($tomorrow->getTimestamp());
$end_modified = true;
}
if ($event_start->getTimestamp() < $date->getTimestamp()) {
if (!$event->isRepetitive()) {
$event_start = new DateTimeValue($date->getTimestamp());
} else {
$event_start->setDay($date->getDay());
$event_start->setMonth($date->getMonth());
$event_start->setYear($date->getYear());
}
}
}
示例2: getEventLimits
function getEventLimits($event, $date, &$event_start, &$event_duration, &$end_modified)
{
$end_modified = false;
$event_start = new DateTimeValue($event->getStart()->getTimestamp() + 3600 * logged_user()->getTimezone());
$event_duration = new DateTimeValue($event->getDuration()->getTimestamp() + 3600 * logged_user()->getTimezone());
$tomorrow = new DateTimeValue($date->getTimestamp());
$tomorrow->add('d', 1);
if ($event_duration->getTimestamp() > $tomorrow->getTimestamp()) {
$event_duration = new DateTimeValue($tomorrow->getTimestamp());
$end_modified = true;
}
if ($event_start->getTimestamp() < $date->getTimestamp()) {
if (!$event->isRepetitive()) {
$event_start = new DateTimeValue($date->getTimestamp());
} else {
$event_start->setDay($date->getDay());
$event_start->setMonth($date->getMonth());
$event_start->setYear($date->getYear());
}
}
}
示例3: instantiate
function instantiate()
{
$selected_members = array();
$id = get_id();
$template = COTemplates::findById($id);
if (!$template instanceof COTemplate) {
flash_error(lang("template dnx"));
ajx_current("empty");
return;
}
$parameters = TemplateParameters::getParametersByTemplate($id);
$parameterValues = array_var($_POST, 'parameterValues');
if (count($parameters) > 0 && !isset($parameterValues)) {
ajx_current("back");
return;
}
if (array_var($_POST, 'members')) {
$selected_members = json_decode(array_var($_POST, 'members'));
} else {
$context = active_context();
foreach ($context as $selection) {
if ($selection instanceof Member) {
$selected_members[] = $selection->getId();
}
}
}
$objects = $template->getObjects();
$controller = new ObjectController();
if (count($selected_members > 0)) {
$selected_members_instances = Members::findAll(array('conditions' => 'id IN (' . implode($selected_members) . ')'));
} else {
$selected_members_instances = array();
}
DB::beginWork();
$active_context = active_context();
foreach ($objects as $object) {
if (!$object instanceof ContentDataObject) {
continue;
}
// copy object
$copy = $object->copy();
if ($copy->columnExists('is_template')) {
$copy->setColumnValue('is_template', false);
}
if ($copy instanceof ProjectTask) {
// don't copy parent task and milestone
$copy->setMilestoneId(0);
$copy->setParentId(0);
}
$copy->save();
/* if (!can_write(logged_user(), $selected_members_instances, $copy->getObjectTypeId()) ) {
flash_error(lang('no context permissions to add', $copy instanceof ProjectTask ? lang("tasks") : ($copy instanceof ProjectMilestone ? lang('milestones') : '')));
DB::rollback();
ajx_current("empty");
return;
}*/
// Copy members from origial object, if it doesn't have then use active context members
/* $template_object_members = $object->getMemberIds();
if (count($template_object_members) == 0) {
$object_member_ids = active_context_members(false);
if (count($object_member_ids) > 0) {
$template_object_members = Members::findAll(array("id" => true, "conditions" => "id IN (".implode(",", $object_member_ids).")"));
}
}*/
/* Set instantiated object members:
* foreach dimension:
* if no member is active then the instantiated object is put in the same members as the original for current dimension
* if a member is selected in current dimension then the instantiated object will be put in that member
*/
$template_object_members = $object->getMembers();
$object_members = array();
foreach ($active_context as $selection) {
if ($selection instanceof Member) {
// member selected
$object_members[] = $selection->getId();
} else {
if ($selection instanceof Dimension) {
// no member selected
foreach ($template_object_members as $tom) {
if ($tom->getDimensionId() == $selection->getId()) {
$object_members[] = $tom->getId();
}
}
}
}
}
$controller->add_to_members($copy, $object_members);
// copy linked objects
$copy->copyLinkedObjectsFrom($object);
// copy subtasks if applicable
if ($copy instanceof ProjectTask) {
ProjectTasks::copySubTasks($object, $copy, false);
foreach ($copy->getOpenSubTasks(false) as $m_task) {
$controller->add_to_members($m_task, $object_members);
}
$manager = $copy->manager();
} else {
if ($copy instanceof ProjectMilestone) {
ProjectMilestones::copyTasks($object, $copy, false);
foreach ($copy->getTasks(false) as $m_task) {
//.........这里部分代码省略.........
示例4: getMondayOfWeek
/**
* Returns the date for the datetimevalue's week's monday
*
* @return DateTimeValue
*/
function getMondayOfWeek(){
$dow = (integer)$this->format('N');
$dt = new DateTimeValue($this->getTimestamp());
$dt->add('d', -($dow - 1));
return $dt;
}
示例5: edit
/**
* Edit timeslot
*
* @param void
* @return null
*/
function edit()
{
$this->setTemplate('add_timeslot');
$timeslot = Timeslots::findById(get_id());
if (!$timeslot instanceof Timeslot) {
flash_error(lang('timeslot dnx'));
ajx_current("empty");
return;
}
$object = $timeslot->getRelObject();
if (!$object instanceof ContentDataObject) {
flash_error(lang('object dnx'));
ajx_current("empty");
return;
}
if (!$object->canAddTimeslot(logged_user())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
if (!$timeslot->canEdit(logged_user())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$timeslot_data = array_var($_POST, 'timeslot');
if (!is_array($timeslot_data)) {
$timeslot_data = array('contact_id' => $timeslot->getContactId(), 'description' => $timeslot->getDescription(), 'start_time' => $timeslot->getStartTime(), 'end_time' => $timeslot->getEndTime(), 'is_fixed_billing' => $timeslot->getIsFixedBilling(), 'hourly_billing' => $timeslot->getHourlyBilling(), 'fixed_billing' => $timeslot->getFixedBilling());
}
tpl_assign('timeslot_form_object', $object);
tpl_assign('timeslot', $timeslot);
tpl_assign('timeslot_data', $timeslot_data);
tpl_assign('show_billing', BillingCategories::count() > 0);
if (is_array(array_var($_POST, 'timeslot'))) {
try {
$this->percent_complete_delete($timeslot);
$timeslot->setContactId(array_var($timeslot_data, 'contact_id', logged_user()->getId()));
$timeslot->setDescription(array_var($timeslot_data, 'description'));
$st = getDateValue(array_var($timeslot_data, 'start_value'), DateTimeValueLib::now());
$st->setHour(array_var($timeslot_data, 'start_hour'));
$st->setMinute(array_var($timeslot_data, 'start_minute'));
$et = getDateValue(array_var($timeslot_data, 'end_value'), DateTimeValueLib::now());
$et->setHour(array_var($timeslot_data, 'end_hour'));
$et->setMinute(array_var($timeslot_data, 'end_minute'));
$st = new DateTimeValue($st->getTimestamp() - logged_user()->getTimezone() * 3600);
$et = new DateTimeValue($et->getTimestamp() - logged_user()->getTimezone() * 3600);
$timeslot->setStartTime($st);
$timeslot->setEndTime($et);
if ($timeslot->getStartTime() > $timeslot->getEndTime()) {
flash_error(lang('error start time after end time'));
ajx_current("empty");
return;
}
$seconds = array_var($timeslot_data, 'subtract_seconds', 0);
$minutes = array_var($timeslot_data, 'subtract_minutes', 0);
$hours = array_var($timeslot_data, 'subtract_hours', 0);
$subtract = $seconds + 60 * $minutes + 3600 * $hours;
if ($subtract < 0) {
flash_error(lang('pause time cannot be negative'));
ajx_current("empty");
return;
}
$testEndTime = new DateTimeValue($timeslot->getEndTime()->getTimestamp());
$testEndTime->add('s', -$subtract);
if ($timeslot->getStartTime() > $testEndTime) {
flash_error(lang('pause time cannot exceed timeslot time'));
ajx_current("empty");
return;
}
$timeslot->setSubtract($subtract);
if ($timeslot->getUser()->getDefaultBillingId()) {
$timeslot->setIsFixedBilling(array_var($timeslot_data, 'is_fixed_billing', false));
$timeslot->setHourlyBilling(array_var($timeslot_data, 'hourly_billing', 0));
if ($timeslot->getIsFixedBilling()) {
$timeslot->setFixedBilling(array_var($timeslot_data, 'fixed_billing', 0));
} else {
$timeslot->setFixedBilling($timeslot->getHourlyBilling() * $timeslot->getMinutes() / 60);
}
if ($timeslot->getBillingId() == 0 && ($timeslot->getHourlyBilling() > 0 || $timeslot->getFixedBilling() > 0)) {
$timeslot->setBillingId($timeslot->getUser()->getDefaultBillingId());
}
}
DB::beginWork();
$timeslot->save();
$timeslot_time = ($timeslot->getEndTime()->getTimestamp() - ($timeslot->getStartTime()->getTimestamp() + $timeslot->getSubtract())) / 3600;
$task = ProjectTasks::findById($timeslot->getRelObjectId());
if ($task->getTimeEstimate() > 0) {
$timeslot_percent = round($timeslot_time * 100 / ($task->getTimeEstimate() / 60));
$total_percentComplete = $timeslot_percent + $task->getPercentCompleted();
if ($total_percentComplete < 0) {
$total_percentComplete = 0;
}
$task->setPercentCompleted($total_percentComplete);
$task->save();
//.........这里部分代码省略.........
示例6: mktime
function move_event() {
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$event = ProjectEvents::findById(get_id());
if(!$event->canEdit(logged_user())){
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$is_read = $event->getIsRead(logged_user()->getId());
$year = array_var($_GET, 'year', $event->getStart()->getYear());
$month = array_var($_GET, 'month', $event->getStart()->getMonth());
$day = array_var($_GET, 'day', $event->getStart()->getDay());
$hour = array_var($_GET, 'hour', 0);
$min = array_var($_GET, 'min', 0);
if ($hour == -1) $hour = format_date($event->getStart(), 'H', logged_user()->getTimezone() );
if ($min == -1) $min = format_date($event->getStart(), 'i', logged_user()->getTimezone() );
if ($event->isRepetitive()) {
$orig_date = DateTimeValueLib::dateFromFormatAndString('Y-m-d H:i:s', array_var($_GET, 'orig_date'));
$diff = DateTimeValueLib::get_time_difference($orig_date->getTimestamp(), mktime($hour, $min, 0, $month, $day, $year));
$new_start = new DateTimeValue($event->getStart()->getTimestamp());
$new_start->add('d', $diff['days']);
$new_start->add('h', $diff['hours']);
$new_start->add('m', $diff['minutes']);
if ($event->getRepeatH()) {
$event->setRepeatDow(date("w", mktime($hour, $min, 0, $month, $day, $year))+1);
$wnum = 0;
$tmp_day = $new_start->getDay();
while ($tmp_day > 0) {
$tmp_day -= 7;
$wnum++;
}
$event->setRepeatWnum($wnum);
}
} else {
$new_start = new DateTimeValue(mktime($hour, $min, 0, $month, $day, $year) - logged_user()->getTimezone() * 3600);
}
$diff = DateTimeValueLib::get_time_difference($event->getStart()->getTimestamp(), $event->getDuration()->getTimestamp());
$new_duration = new DateTimeValue($new_start->getTimestamp());
$new_duration->add('d', $diff['days']);
$new_duration->add('h', $diff['hours']);
$new_duration->add('m', $diff['minutes']);
// see if we have to reload
$os = format_date($event->getStart(), 'd', logged_user()->getTimezone() );
$od = format_date($event->getDuration(), 'd', logged_user()->getTimezone() );
$ohm = format_date($event->getDuration(), 'H:i', logged_user()->getTimezone() );
$nd = format_date($new_duration, 'd', logged_user()->getTimezone() );
$nhm = format_date($new_duration, 'H:i', logged_user()->getTimezone() );
$different_days = ($os != $od && $ohm != '00:00') || ($day != $nd && $nhm != '00:00');
DB::beginWork();
$event->setStart($new_start->format("Y-m-d H:i:s"));
$event->setDuration($new_duration->format("Y-m-d H:i:s"));
$event->save();
$old_reminders = ObjectReminders::getByObject($event);
if($old_reminders != null){
$object_controller = new ObjectController();
$object_controller->update_reminders($event, $old_reminders); //updating the old ones
}else if(user_config_option("add_event_autoreminder")){
$reminder = new ObjectReminder();
$def = explode(",",user_config_option("reminders_events"));
$minutes = array_var($def, 2) * array_var($def, 1);
$reminder->setMinutesBefore($minutes);
$reminder->setType(array_var($def, 0));
$reminder->setContext("start");
$reminder->setObject($event);
$reminder->setUserId(0);
$date = $event->getStart();
if ($date instanceof DateTimeValue) {
$rdate = new DateTimeValue($date->getTimestamp() - $minutes * 60);
$reminder->setDate($rdate);
}
$reminder->save();
}
if (!$is_read) {
$event->setIsRead(logged_user()->getId(), false);
}
if($event->getSpecialID() != ""){
$this->sync_calendar_extern($event);
}
DB::commit();
ajx_extra_data($this->get_updated_event_data($event));
if ($different_days || $event->isRepetitive()) ajx_current("reload");
else ajx_current("empty");
}
示例7: instantiate
function instantiate()
{
$id = get_id();
$template = COTemplates::findById($id);
if (!$template instanceof COTemplate) {
flash_error(lang("template dnx"));
ajx_current("empty");
return;
}
$parameters = TemplateParameters::getParametersByTemplate($id);
$parameterValues = array_var($_POST, 'parameterValues');
if (count($parameters) > 0 && !isset($parameterValues)) {
ajx_current("back");
return;
}
$objects = $template->getObjects();
foreach ($objects as $object) {
if (!$object instanceof ProjectDataObject) {
continue;
}
// copy object
$copy = $object->copy();
if ($copy->columnExists('is_template')) {
$copy->setColumnValue('is_template', false);
}
if ($copy instanceof ProjectTask) {
// don't copy parent task and milestone
$copy->setMilestoneId(0);
$copy->setParentId(0);
}
$copy->save();
$wsId = array_var($_POST, 'project_id', active_or_personal_project()->getId());
// if specified, set workspace
$workspace = Projects::findById($wsId);
if (!$workspace instanceof Project) {
$workspace = active_or_personal_project();
}
$copy->addToWorkspace($workspace);
// add object tags and specified tags
$tags = implode(',', $object->getTagNames());
$copy->setTagsFromCSV($tags . "," . array_var($_POST, 'tags'));
// copy linked objects
$copy->copyLinkedObjectsFrom($object);
// copy subtasks if applicable
if ($copy instanceof ProjectTask) {
ProjectTasks::copySubTasks($object, $copy, false);
$manager = new ProjectTask();
} else {
if ($copy instanceof ProjectMilestone) {
ProjectMilestones::copyTasks($object, $copy, false);
$manager = new ProjectMilestone();
}
}
// copy custom properties
$copy->copyCustomPropertiesFrom($object);
// set property values as defined in template
$objProp = TemplateObjectProperties::getPropertiesByTemplateObject($id, $object->getId());
foreach ($objProp as $property) {
$propName = $property->getProperty();
$value = $property->getValue();
if ($manager->getColumnType($propName) == DATA_TYPE_STRING) {
if (is_array($parameterValues)) {
foreach ($parameterValues as $param => $val) {
$value = str_replace('{' . $param . '}', $val, $value);
}
}
} else {
if ($manager->getColumnType($propName) == DATA_TYPE_DATE || $manager->getColumnType($propName) == DATA_TYPE_DATETIME) {
$operator = '+';
if (strpos($value, '+') === false) {
$operator = '-';
}
$opPos = strpos($value, $operator);
if ($opPos !== false) {
$dateParam = substr($value, 1, strpos($value, '}') - 1);
$dateUnit = substr($value, strlen($value) - 1);
// d, w or m (for days, weeks or months)
if ($dateUnit == 'm') {
$dateUnit = 'M';
// make month unit uppercase to call DateTimeValue::add with correct parameter
}
$dateNum = (int) substr($value, strpos($value, $operator), strlen($value) - 2);
$date = $parameterValues[$dateParam];
$date = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $date);
$value = $date->add($dateUnit, $dateNum);
}
} else {
if ($manager->getColumnType($propName) == DATA_TYPE_INTEGER) {
if (is_array($parameterValues)) {
foreach ($parameterValues as $param => $val) {
$value = str_replace('{' . $param . '}', $val, $value);
}
}
}
}
}
if ($value != '') {
$copy->setColumnValue($propName, $value);
$copy->save();
}
//.........这里部分代码省略.........
示例8: cloneTask
function cloneTask($new_st_date = '', $new_due_date = '', $copy_status = false, $copy_repeat_options = true, $parent_subtask = 0)
{
$new_task = new TemplateTask();
if ($parent_subtask != 0) {
$new_task->setParentId($parent_subtask);
} else {
$new_task->setParentId($this->getParentId());
}
$new_task->setObjectName($this->getObjectName());
$new_task->setText($this->getText());
$new_task->setAssignedToContactId($this->getAssignedToContactId());
$new_task->setAssignedOn($this->getAssignedOn());
$new_task->setAssignedById($this->getAssignedById());
$new_task->setTimeEstimate($this->getTimeEstimate());
$new_task->setStartedOn($this->getStartedOn());
$new_task->setStartedById($this->getStartedById());
$new_task->setPriority($this->getPriority());
$new_task->setState($this->getState());
$new_task->setOrder($this->getOrder());
$new_task->setMilestoneId($this->getMilestoneId());
$new_task->setFromTemplateId($this->getFromTemplateId());
$new_task->setUseStartTime($this->getUseStartTime());
$new_task->setUseDueTime($this->getUseDueTime());
$new_task->setTypeContent($this->getTypeContent());
if ($this->getParentId() == 0) {
//if not subtask
if ($this->getOriginalTaskId() == 0) {
$new_task->setOriginalTaskId($this->getObjectId());
} else {
$new_task->setOriginalTaskId($this->getOriginalTaskId());
}
}
if ($this->getDueDate() instanceof DateTimeValue) {
$new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
}
if ($this->getStartDate() instanceof DateTimeValue) {
$new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
}
if ($copy_status) {
$new_task->setCompletedById($this->getCompletedById());
$new_task->setCompletedOn($this->getCompletedOn());
}
if ($copy_repeat_options) {
$new_task->setRepeatEnd($this->getRepeatEnd());
$new_task->setRepeatForever($this->getRepeatForever());
$new_task->setRepeatNum($this->getRepeatNum());
$new_task->setRepeatBy($this->getRepeatBy());
$new_task->setRepeatD($this->getRepeatD());
$new_task->setRepeatM($this->getRepeatM());
$new_task->setRepeatY($this->getRepeatY());
}
if ($new_st_date != "") {
if ($new_task->getStartDate() instanceof DateTimeValue) {
$new_task->setStartDate($new_st_date);
}
}
if ($new_due_date != "") {
if ($new_task->getDueDate() instanceof DateTimeValue) {
$new_task->setDueDate($new_due_date);
}
}
$new_task->save();
if (is_array($this->getAllLinkedObjects())) {
foreach ($this->getAllLinkedObjects() as $lo) {
$new_task->linkObject($lo);
}
}
$sub_tasks = $this->getAllSubTasks();
foreach ($sub_tasks as $st) {
$new_dates = $this->getNextRepetitionDatesSubtask($st, $new_task, $new_st_date, $new_due_date);
if ($st->getParentId() == $this->getId()) {
$new_st = $st->cloneTask(array_var($new_dates, 'st'), array_var($new_dates, 'due'), $copy_status, $copy_repeat_options, $new_task->getId());
if ($copy_status) {
$new_st->setCompletedById($st->getCompletedById());
$new_st->setCompletedOn($st->getCompletedOn());
$new_st->save();
}
$new_task->attachTask($new_st);
}
}
foreach ($this->getAllComments() as $com) {
$new_com = new Comment();
$new_com->setAuthorEmail($com->getAuthorEmail());
$new_com->setAuthorName($com->getAuthorName());
$new_com->setAuthorHomepage($com->getAuthorHomepage());
$new_com->setCreatedById($com->getCreatedById());
$new_com->setCreatedOn($com->getCreatedOn());
$new_com->setUpdatedById($com->getUpdatedById());
$new_com->setUpdatedOn($com->getUpdatedOn());
$new_com->setText($com->getText());
$new_com->setRelObjectId($new_task->getId());
$new_com->save();
}
$_POST['subscribers'] = array();
foreach ($this->getSubscribers() as $sub) {
$_POST['subscribers']["user_" . $sub->getId()] = "checked";
}
$obj_controller = new ObjectController();
$obj_controller->add_to_members($new_task, $this->getMemberIds());
$obj_controller->add_subscribers($new_task);
//.........这里部分代码省略.........
示例9: edit
/**
* Edit timeslot
*
* @param void
* @return null
*/
function edit()
{
if (!can_manage_time(logged_user(), true)) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$this->setTemplate('add_timeslot');
$timeslot = Timeslots::findById(get_id());
if (!$timeslot instanceof Timeslot) {
flash_error(lang('timeslot dnx'));
ajx_current("empty");
return;
}
// if
$object = $timeslot->getObject();
if (!$object instanceof ProjectDataObject) {
flash_error(lang('object dnx'));
ajx_current("empty");
return;
}
// if
if (!$object->canAddTimeslot(logged_user())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
// if
if (!$timeslot->canEdit(logged_user())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
// if
$timeslot_data = array_var($_POST, 'timeslot');
if (!is_array($timeslot_data)) {
$timeslot_data = array('description' => $timeslot->getDescription(), 'start_time' => $timeslot->getStartTime(), 'end_time' => $timeslot->getEndTime(), 'is_fixed_billing' => $timeslot->getIsFixedBilling(), 'hourly_billing' => $timeslot->getHourlyBilling(), 'fixed_billing' => $timeslot->getFixedBilling());
// array
}
// if
tpl_assign('timeslot_form_object', $object);
tpl_assign('timeslot', $timeslot);
tpl_assign('timeslot_data', $timeslot_data);
tpl_assign('show_billing', BillingCategories::count() > 0);
if (is_array(array_var($_POST, 'timeslot'))) {
try {
$timeslot->setDescription(array_var($timeslot_data, 'description'));
$st = getDateValue(array_var($timeslot_data, 'start_value'), DateTimeValueLib::now());
$st->setHour(array_var($timeslot_data, 'start_hour'));
$st->setMinute(array_var($timeslot_data, 'start_minute'));
$et = getDateValue(array_var($timeslot_data, 'end_value'), DateTimeValueLib::now());
$et->setHour(array_var($timeslot_data, 'end_hour'));
$et->setMinute(array_var($timeslot_data, 'end_minute'));
$st = new DateTimeValue($st->getTimestamp() - logged_user()->getTimezone() * 3600);
$et = new DateTimeValue($et->getTimestamp() - logged_user()->getTimezone() * 3600);
$timeslot->setStartTime($st);
$timeslot->setEndTime($et);
if ($timeslot->getStartTime() > $timeslot->getEndTime()) {
flash_error(lang('error start time after end time'));
ajx_current("empty");
return;
}
$seconds = array_var($timeslot_data, 'subtract_seconds', 0);
$minutes = array_var($timeslot_data, 'subtract_minutes', 0);
$hours = array_var($timeslot_data, 'subtract_hours', 0);
$subtract = $seconds + 60 * $minutes + 3600 * $hours;
if ($subtract < 0) {
flash_error(lang('pause time cannot be negative'));
ajx_current("empty");
return;
}
$testEndTime = new DateTimeValue($timeslot->getEndTime()->getTimestamp());
$testEndTime->add('s', -$subtract);
if ($timeslot->getStartTime() > $testEndTime) {
flash_error(lang('pause time cannot exceed timeslot time'));
ajx_current("empty");
return;
}
$timeslot->setSubtract($subtract);
/* Billing */
$timeslot->setIsFixedBilling(array_var($timeslot_data, 'is_fixed_billing', false));
$timeslot->setHourlyBilling(array_var($timeslot_data, 'hourly_billing', 0));
if ($timeslot->getIsFixedBilling()) {
$timeslot->setFixedBilling(array_var($timeslot_data, 'fixed_billing', 0));
} else {
$timeslot->setFixedBilling($timeslot->getHourlyBilling() * $timeslot->getMinutes() / 60);
}
if ($timeslot->getBillingId() == 0 && ($timeslot->getHourlyBilling() > 0 || $timeslot->getFixedBilling() > 0)) {
$timeslot->setBillingId($timeslot->getUser()->getDefaultBillingId());
}
DB::beginWork();
$timeslot->save();
DB::commit();
flash_success(lang('success edit timeslot'));
//.........这里部分代码省略.........
示例10: mktime
function move_event()
{
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$event = ProjectEvents::findById(get_id());
if (!$event->canEdit(logged_user())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$is_read = $event->getIsRead(logged_user()->getId());
$year = array_var($_GET, 'year', $event->getStart()->getYear());
$month = array_var($_GET, 'month', $event->getStart()->getMonth());
$day = array_var($_GET, 'day', $event->getStart()->getDay());
$hour = array_var($_GET, 'hour', 0);
$min = array_var($_GET, 'min', 0);
if ($hour == -1) {
$hour = format_date($event->getStart(), 'H', logged_user()->getTimezone());
}
if ($min == -1) {
$min = format_date($event->getStart(), 'i', logged_user()->getTimezone());
}
if ($event->isRepetitive()) {
$orig_date = DateTimeValueLib::dateFromFormatAndString('Y-m-d H:i:s', array_var($_GET, 'orig_date'));
$diff = DateTimeValueLib::get_time_difference($orig_date->getTimestamp(), mktime($hour, $min, 0, $month, $day, $year));
$new_start = new DateTimeValue($event->getStart()->getTimestamp());
$new_start->add('d', $diff['days']);
$new_start->add('h', $diff['hours']);
$new_start->add('m', $diff['minutes']);
if ($event->getRepeatH()) {
$event->setRepeatDow(date("w", mktime($hour, $min, 0, $month, $day, $year)) + 1);
$wnum = 0;
$tmp_day = $new_start->getDay();
while ($tmp_day > 0) {
$tmp_day -= 7;
$wnum++;
}
$event->setRepeatWnum($wnum);
}
} else {
$new_start = new DateTimeValue(mktime($hour, $min, 0, $month, $day, $year) - logged_user()->getTimezone() * 3600);
}
$diff = DateTimeValueLib::get_time_difference($event->getStart()->getTimestamp(), $event->getDuration()->getTimestamp());
$new_duration = new DateTimeValue($new_start->getTimestamp());
$new_duration->add('d', $diff['days']);
$new_duration->add('h', $diff['hours']);
$new_duration->add('m', $diff['minutes']);
// see if we have to reload
$os = format_date($event->getStart(), 'd', logged_user()->getTimezone());
$od = format_date($event->getDuration(), 'd', logged_user()->getTimezone());
$ohm = format_date($event->getDuration(), 'H:i', logged_user()->getTimezone());
$nd = format_date($new_duration, 'd', logged_user()->getTimezone());
$nhm = format_date($new_duration, 'H:i', logged_user()->getTimezone());
$different_days = $os != $od && $ohm != '00:00' || $day != $nd && $nhm != '00:00';
DB::beginWork();
$event->setStart($new_start->format("Y-m-d H:i:s"));
$event->setDuration($new_duration->format("Y-m-d H:i:s"));
$event->save();
if (!$is_read) {
$event->setIsRead(logged_user()->getId(), false);
}
if ($event->getSpecialID() != "") {
$this->sync_calendar_extern($event);
}
DB::commit();
ajx_extra_data($this->get_updated_event_data($event));
if ($different_days || $event->isRepetitive()) {
ajx_current("reload");
} else {
ajx_current("empty");
}
}
示例11: getRangeProjectEvents
/**
* Returns all events for the given range, tag and considers the active project
*
* @param DateTimeValue $date
* @param String $tags
* @return unknown
*/
static function getRangeProjectEvents(DateTimeValue $start_date, DateTimeValue $end_date, $tags = '', $project = null, $archived = false)
{
$start_year = date("Y", mktime(0, 0, 1, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear()));
$start_month = date("m", mktime(0, 0, 1, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear()));
$start_day = date("d", mktime(0, 0, 1, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear()));
$end_year = date("Y", mktime(0, 0, 1, $end_date->getMonth(), $end_date->getDay(), $end_date->getYear()));
$end_month = date("m", mktime(0, 0, 1, $end_date->getMonth(), $end_date->getDay(), $end_date->getYear()));
$end_day = date("d", mktime(0, 0, 1, $end_date->getMonth(), $end_date->getDay(), $end_date->getYear()));
if (!is_numeric($start_day) or !is_numeric($start_month) or !is_numeric($start_year) or !is_numeric($end_day) or !is_numeric($end_month) or !is_numeric($end_year)) {
return NULL;
}
$invited = " AND `id` IN (SELECT `event_id` FROM `" . TABLE_PREFIX . "event_invitations` WHERE `contact_id` = " . logged_user()->getId() . ")";
$tz_hm = "'" . floor(logged_user()->getTimezone()) . ":" . abs(logged_user()->getTimezone()) % 1 * 60 . "'";
$s_date = new DateTimeValue($start_date->getTimestamp() - logged_user()->getTimezone() * 3600);
$e_date = new DateTimeValue($end_date->getTimestamp() - logged_user()->getTimezone() * 3600);
$e_date->add("d", 1);
$start_date_str = $s_date->format("Y-m-d H:i:s");
$end_date_str = $e_date->format("Y-m-d H:i:s");
$first_d = $start_day;
while ($first_d > 7) {
$first_d -= 7;
}
$week_of_first_day = date("W", mktime(0, 0, 0, $start_month, $first_d, $start_year));
$conditions = "\tAND ((\n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND `duration` >= '{$start_date_str}' \n\t\t\t\t\tAND `start` < '{$end_date_str}' \n\t\t\t\t) \n\t\t\t\tOR \n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND\n\t\t\t\t\tDATE(`start`) < '{$end_date_str}'\n\t\t\t\t\tAND\n\t\t\t\t\t(\t\t\t\t\t\t\t\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_d` DAY) >= '{$start_date_str}' \n\t\t\t\t\t\t\tOR\n repeat_forever = 1\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_end >= '{$start_year}-{$start_month}-{$start_day}'\n\t\t\t\t)\n\t\t\t\tOR\n\t\t\t\t(\n\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_m` MONTH) >= '{$start_date_str}' \n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_end >= '{$start_year}-{$start_month}-{$start_day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_y` YEAR) >= '{$start_date_str}' \n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_end >= '{$start_year}-{$start_month}-{$start_day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t)\t\t\n\t\t\t\t)\n\t\t\t\tOR\n\t\t\t\t(\n\t\t\t\t\tDATE(`start`) <= '{$start_date_str}'\n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_h` = 1 \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_dow` = DAYOFWEEK('{$start_date_str}') \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_wnum` + {$week_of_first_day} - 1 = WEEK('{$start_date_str}', 3) \n\t\t\t\t\tAND\n\t\t\t\t\tMOD( ABS(PERIOD_DIFF(DATE_FORMAT(`start`, '%Y%m'), DATE_FORMAT('{$start_date_str}', '%Y%m'))), `repeat_mjump`) = 0\t\t\t\t\t\n\t\t\t\t)\t\t\t\t\n\t\t\t)\n\t\t\t{$invited}\n\t\t)";
//$result_events = self::getContentObjects(active_context(), ObjectTypes::findById(self::instance()->getObjectTypeId()), '`start`', 'ASC', $conditions, null, false, false, $start, $limit);
$result_events = self::instance()->listing(array("order" => 'start', "order_dir" => 'ASC', "extra_conditions" => $conditions, "start" => $start, "limit" => $limit))->objects;
// Find invitations for events and logged user
ProjectEvents::addInvitations($result_events);
return $result_events;
}
示例12: date
$startday = $day - date("N", mktime(0, 0, 0, $month, $day, $year)) + 1;
// beginning of the week, monday
$endday = $startday + 7;
// end of week
$today = DateTimeValueLib::now();
$today->add('h', logged_user()->getTimezone());
$currentday = $today->format("j");
$currentmonth = $today->format("n");
$currentyear = $today->format("Y");
$drawHourLine = false;
$lastday = date("t", mktime(0, 0, 0, $month, 1, $year));
// # of days in the month
$date_start = new DateTimeValue(mktime(0, 0, 0, $month, $startday, $year));
$date_end = new DateTimeValue(mktime(0, 0, 0, $month, $endday, $year));
$date_start->add('h', logged_user()->getTimezone());
$date_end->add('h', logged_user()->getTimezone());
$milestones = ProjectMilestones::getRangeMilestonesByUser($date_start, $date_end, $user_filter != -1 ? $user : null, $tags, active_project());
$tasks = ProjectTasks::getRangeTasksByUser($date_start, $date_end, $user_filter != -1 ? $user : null, $tags, active_project());
$birthdays = Contacts::instance()->getRangeContactsByBirthday($date_start, $date_end);
$tmp_tasks = array();
foreach ($tasks as $task) {
$tmp_tasks = array_merge($tmp_tasks, replicateRepetitiveTaskForCalendar($task, $date_start, $date_end));
}
$dates = array();
//datetimevalue for each day of week
$results = array();
$allday_events_count = array();
$alldayevents = array();
$today_style = array();
$month_aux = $month;
$year_aux = $year;
示例13: copy_additional_object_data
/**
* Copies related data from an object to another (members, linked_objects, custom_properties, subscribers, reminders and comments)
* @param $object: Original object to copy data
* @param $copy: Object to be modified with the data of the $orignal object
* @param $options: set which type of data will not be copied
*/
function copy_additional_object_data($object, &$copy, $options = array())
{
if (!$object instanceof ContentDataObject || !$copy instanceof ContentDataObject) {
// if not valid objects return
return;
}
$copy_members = !array_var($options, 'dont_copy_members');
$copy_linked_objects = !array_var($options, 'dont_copy_linked_objects');
$copy_custom_properties = !array_var($options, 'dont_copy_custom_properties');
$copy_subscribers = !array_var($options, 'dont_copy_subscribers');
$copy_reminders = !array_var($options, 'dont_copy_reminders');
$copy_comments = !array_var($options, 'dont_copy_comments');
$controller = new ObjectController();
// copy members
if ($copy_members) {
$object_members = $object->getMembers();
$copy->addToMembers($object_members);
Hook::fire('after_add_to_members', $copy, $object_members);
$copy->addToSharingTable();
}
// copy linked objects
if ($copy_linked_objects) {
$copy->copyLinkedObjectsFrom($object);
}
// copy custom properties
if ($copy_custom_properties) {
// custom properties defined in "settings"
$cp_object_type_id = $object->getObjectTypeId();
if ($object instanceof TemplateTask || $object instanceof TemplateMilestone) {
$cp_object_type_id = $copy->getObjectTypeId();
}
$custom_props = CustomProperties::getAllCustomPropertiesByObjectType($cp_object_type_id);
foreach ($custom_props as $c_prop) {
$values = CustomPropertyValues::getCustomPropertyValues($object->getId(), $c_prop->getId());
if (is_array($values)) {
foreach ($values as $val) {
$cp = new CustomPropertyValue();
$cp->setObjectId($copy->getId());
$cp->setCustomPropertyId($val->getCustomPropertyId());
$cp->setValue($val->getValue());
$cp->save();
}
}
}
// object properties (key-value)
$copy->copyCustomPropertiesFrom($object);
}
// copy subscribers
if ($copy_subscribers) {
$subscribers_array = array();
foreach ($object->getSubscriberIds() as $user_id) {
$subscribers_array["user_" . $user_id] = "1";
}
$controller->add_subscribers($copy, $subscribers_array);
}
// copy reminders
if ($copy_reminders) {
$reminders = ObjectReminders::getByObject($object);
foreach ($reminders as $reminder) {
$copy_reminder = new ObjectReminder();
$copy_reminder->setContext($reminder->getContext());
$reminder_date = $copy->getColumnValue($reminder->getContext());
if ($reminder_date instanceof DateTimeValue) {
$reminder_date = new DateTimeValue($reminder_date->getTimestamp());
$reminder_date->add('m', -$reminder->getMinutesBefore());
}
$copy_reminder->setDate($reminder_date);
$copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
$copy_reminder->setObject($copy);
$copy_reminder->setType($reminder->getType());
$copy_reminder->setUserId($reminder->getUserId());
$copy_reminder->save();
}
}
// copy comments
if ($copy_comments) {
foreach ($object->getAllComments() as $com) {
$new_com = new Comment();
$new_com->setAuthorEmail($com->getAuthorEmail());
$new_com->setAuthorName($com->getAuthorName());
$new_com->setAuthorHomepage($com->getAuthorHomepage());
$new_com->setCreatedById($com->getCreatedById());
$new_com->setCreatedOn($com->getCreatedOn());
$new_com->setUpdatedById($com->getUpdatedById());
$new_com->setUpdatedOn($com->getUpdatedOn());
$new_com->setText($com->getText());
$new_com->setRelObjectId($copy->getId());
$new_com->save();
}
}
}
示例14: cloneTask
function cloneTask($copy_status = false)
{
$new_task = new ProjectTask();
$new_task->setParentId($this->getParentId());
$new_task->setTitle($this->getTitle());
$new_task->setText($this->getText());
$new_task->setAssignedToCompanyId($this->getAssignedToCompanyId());
$new_task->setAssignedToUserId($this->getAssignedToUserId());
$new_task->setAssignedOn($this->getAssignedOn());
$new_task->setAssignedById($this->getAssignedById());
$new_task->setTimeEstimate($this->getTimeEstimate());
$new_task->setStartedOn($this->getStartedOn());
$new_task->setStartedById($this->getStartedById());
$new_task->setPriority($this->getPriority());
$new_task->setState($this->getState());
$new_task->setOrder($this->getOrder());
$new_task->setMilestoneId($this->getMilestoneId());
$new_task->setIsPrivate($this->getIsPrivate());
$new_task->setIsTemplate($this->getIsTemplate());
$new_task->setFromTemplateId($this->getFromTemplateId());
if ($this->getDueDate() instanceof DateTimeValue) {
$new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
}
if ($this->getStartDate() instanceof DateTimeValue) {
$new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
}
if ($copy_status) {
$new_task->setCompletedById($this->getCompletedById());
$new_task->setCompletedOn($this->getCompletedOn());
}
$new_task->save();
$new_task->setTagsFromCSV(implode(",", $this->getTagNames()));
foreach ($this->getWorkspaces() as $ws) {
$new_task->addToWorkspace($ws);
}
if (is_array($this->getAllLinkedObjects())) {
foreach ($this->getAllLinkedObjects() as $lo) {
$new_task->linkObject($lo);
}
}
$sub_tasks = $this->getAllSubTasks();
foreach ($sub_tasks as $st) {
if ($st->getParentId() == $this->getId()) {
$new_st = $st->cloneTask($copy_status);
if ($copy_status) {
$new_st->setCompletedById($st->getCompletedById());
$new_st->setCompletedOn($st->getCompletedOn());
$new_st->save();
}
$new_task->attachTask($new_st);
}
}
foreach ($this->getAllComments() as $com) {
$new_com = new Comment();
$new_com->setAuthorEmail($com->getAuthorEmail());
$new_com->setAuthorName($com->getAuthorName());
$new_com->setAuthorHomepage($com->getAuthorHomepage());
$new_com->setCreatedById($com->getCreatedById());
$new_com->setCreatedOn($com->getCreatedOn());
$new_com->setUpdatedById($com->getUpdatedById());
$new_com->setUpdatedOn($com->getUpdatedOn());
$new_com->setIsAnonymous($com->getIsAnonymous());
$new_com->setIsPrivate($com->getIsPrivate());
$new_com->setText($com->getText());
$new_com->setRelObjectId($new_task->getId());
$new_com->setRelObjectManager("ProjectTasks");
$new_com->save();
}
$_POST['subscribers'] = array();
foreach ($this->getSubscribers() as $sub) {
$_POST['subscribers']["user_" . $sub->getId()] = "checked";
}
$obj_controller = new ObjectController();
$obj_controller->add_subscribers($new_task);
foreach ($this->getCustomProperties() as $prop) {
$new_prop = new ObjectProperty();
$new_prop->setRelObjectId($new_task->getId());
$new_prop->setRelObjectManager($prop->getRelObjectManager());
$new_prop->setPropertyName($prop->getPropertyName());
$new_prop->setPropertyValue($prop->getPropertyValue());
$new_prop->save();
}
$custom_props = CustomProperties::getAllCustomPropertiesByObjectType("ProjectTasks");
foreach ($custom_props as $c_prop) {
$values = CustomPropertyValues::getCustomPropertyValues($this->getId(), $c_prop->getId());
if (is_array($values)) {
foreach ($values as $val) {
$cp = new CustomPropertyValue();
$cp->setObjectId($new_task->getId());
$cp->setCustomPropertyId($val->getCustomPropertyId());
$cp->setValue($val->getValue());
$cp->save();
}
}
}
$reminders = ObjectReminders::getByObject($this);
foreach ($reminders as $reminder) {
$copy_reminder = new ObjectReminder();
$copy_reminder->setContext($reminder->getContext());
$reminder_date = $new_task->getColumnValue($reminder->getContext());
//.........这里部分代码省略.........
示例15: generateICalInfo
function generateICalInfo($events, $calendar_name, $user = null) {
if ($user == null) $user = logged_user();
$ical_info = '';
$ical_info .= "BEGIN:VCALENDAR\r\n";
$ical_info .= "VERSION:2.0\r\n";
$ical_info .= "PRODID:PHP\r\n";
$ical_info .= "METHOD:REQUEST\r\n";
$ical_info .= "X-WR-CALNAME:$calendar_name\r\n";
// timezone info
$tz = ($user->getTimezone() < 0 ? "-":"+").str_pad(abs($user->getTimezone())*100, 4, '0', STR_PAD_LEFT);
$tz_desc = $user->getTimezone() > 0 ? lang("timezone gmt +".$user->getTimezone()) : lang("timezone gmt ".$user->getTimezone());
$ical_info .= "BEGIN:VTIMEZONE\r\n";
$ical_info .= "TZID:$tz_desc\r\n";
$ical_info .= "BEGIN:STANDARD\r\n";
$ical_info .= "TZOFFSETFROM:$tz\r\n";
$ical_info .= "TZOFFSETTO:$tz\r\n";
$ical_info .= "END:STANDARD\r\n";
$ical_info .= "END:VTIMEZONE\r\n";
foreach ($events as $event) {
$ical_info .= "BEGIN:VEVENT\r\n";
$event_start = new DateTimeValue($event->getStart()->getTimestamp() + 3600 * $user->getTimezone());
$event_duration = new DateTimeValue($event->getDuration()->getTimestamp() + 3600 * $user->getTimezone());
$startNext = new DateTimeValue($event_start->getTimestamp());
$startNext->add('d', 1);
if ($event->getTypeId() == 2) $ical_info .= "DTSTART;VALUE=DATE:" . $event_start->format('Ymd') ."\r\n";
else $ical_info .= "DTSTART:" . $event_start->format('Ymd') ."T". $event_start->format('His') ."\r\n";
if ($event->getTypeId() == 2) $ical_info .= "DTEND;VALUE=DATE:" . $startNext->format('Ymd') ."\r\n";
else $ical_info .= "DTEND:" . $event_duration->format('Ymd') ."T". $event_duration->format('His') ."\r\n";
$uid = $event->getId() . "@";
$url = str_replace('http://', '', ROOT_URL);
$uid .= str_replace('www.', '', $url);
$description = str_replace(array(chr(13).chr(10), chr(13), chr(10)),'\n', $event->getDescription());
$ical_info .= "DESCRIPTION:$description\r\n";
$ical_info .= "SUMMARY:" . $event->getSubject() . "\r\n";
$ical_info .= "UID:$uid\r\n";
$ical_info .= "SEQUENCE:0\r\n";
$ical_info .= "DTSTAMP:".$event->getUpdatedOn()->format('Ymd').'T'.$event->getUpdatedOn()->format('His')."\r\n";
$invitations = $event->getInvitations();
if (is_array($invitations) && array_var($invitations, $user->getId())) {
$inv = array_var($invitations, $user->getId());
$inv->getInvitationState();
if ($inv->getInvitationState() == 1) $ical_info .= "STATUS:CONFIRMED\r\n";
else if ($inv->getInvitationState() == 2) $ical_info .= "STATUS:CANCELLED\r\n";
else $ical_info .= "STATUS:TENTATIVE\r\n";
}
$rrule = '';
if ($event->getRepeatD() > 0 || $event->getRepeatM() > 0 || $event->getRepeatY() > 0 || $event->getRepeatForever() > 0) {
$rrule_ok = true;
if ($event->getRepeatD() > 0) {
if ($event->getRepeatD() % 7 == 0) {
$freq = "FREQ=WEEKLY;";
$interval = "INTERVAL=".($event->getRepeatD() / 7);
} else {
$freq = "FREQ=DAILY;";
$interval = "INTERVAL=".$event->getRepeatD();
}
} else if ($event->getRepeatM() > 0) {
$freq = "FREQ=MONTHLY;";
$interval = "INTERVAL=".$event->getRepeatM();
} else if ($event->getRepeatY() > 0) {
$freq = "FREQ=YEARLY;";
$interval = "INTERVAL=".$event->getRepeatY();
} else {
$rrule_ok = false;
}
$until = '';
$count = '';
if (!$event->getRepeatForever() && $event->getRepeatNum() > 0) $count = ";COUNT=".$event->getRepeatNum();
else if (!$event->getRepeatForever() && $event->getRepeatEnd()) $until = ";UNTIL=".$event->getRepeatEnd()->format('Ymd').'T'.$event->getRepeatEnd()->format('His');
if ($rrule_ok) $rrule = "RRULE:$freq$interval$count$until\r\n";
}
if ($event->getRepeatH() > 0) {
"RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=1TU";
$interval = "INTERVAL=".$event->getRepeatMjump();
switch ($event->getRepeatDow()) {
case 1: $day = "SU"; break;
case 2: $day = "MO"; break;
case 3: $day = "TU"; break;
case 4: $day = "WE"; break;
case 5: $day = "TH"; break;
case 6: $day = "FR"; break;
case 7: $day = "SA"; break;
default: $day = "MO"; break;
}
$byday = "BYDAY=" . $event->getRepeatWnum() . $day;
$rrule = "RRULE:FREQ=MONTHLY;$interval;$byday\r\n";
}
$ical_info .= $rrule;
$ical_info .= "END:VEVENT\r\n";
}
//.........这里部分代码省略.........