コード例 #1
0
ファイル: TasklistController.php プロジェクト: ajaboa/crmpuan
 public function actionImportIcs($params)
 {
     $response = array('success' => true);
     $count = 0;
     $failed = array();
     if (!file_exists($_FILES['ical_file']['tmp_name'][0])) {
         throw new \Exception($lang['common']['noFileUploaded']);
     } else {
         $file = new \GO\Base\Fs\File($_FILES['ical_file']['tmp_name'][0]);
         $file->convertToUtf8();
         $contents = $file->getContents();
         $vcal = \GO\Base\VObject\Reader::read($contents);
         \GO\Base\VObject\Reader::convertVCalendarToICalendar($vcal);
         foreach ($vcal->vtodo as $vtask) {
             $event = new \GO\Tasks\Model\Task();
             try {
                 $event->importVObject($vtask, array('tasklist_id' => $params['tasklist_id']));
                 $count++;
             } catch (\Exception $e) {
                 $failed[] = $e->getMessage();
             }
         }
     }
     $response['feedback'] = sprintf(\GO::t('import_success', 'tasks'), $count);
     if (count($failed)) {
         $response['feedback'] .= "\n\n" . count($failed) . " tasks failed: " . implode('\\n', $failed);
     }
     return $response;
 }
コード例 #2
0
ファイル: Iterator.php プロジェクト: ajaboa/crmpuan
 public function next()
 {
     //		\GO::debug("next");
     $data = $this->getNextData();
     //		\GO::debug($data);
     $this->current = false;
     if (empty($data)) {
         return false;
     }
     $vcal = \GO\Base\VObject\Reader::read($data);
     $vevents = $vcal->select($this->type);
     //		\GO::debug("Found: ".count($vevents));
     $vevent = array_shift($vevents);
     if ($vevent) {
         //			\GO::debug("Found event");
         $this->current = $vevent;
         $this->key++;
         return $this->current;
     } else {
         return false;
     }
 }
コード例 #3
0
ファイル: Task.php プロジェクト: ajaboa/crmpuan
 /**
  * Import a task from a VObject 
  * 
  * @param Sabre\VObject\Component $vobject
  * @param array $attributes Extra attributes to apply to the task. Raw values should be past. No input formatting is applied.
  * @return Task 
  */
 public function importVObject(Sabre\VObject\Component $vobject, $attributes = array())
 {
     //$event = new \GO\Calendar\Model\Event();
     $this->uuid = (string) $vobject->uid;
     $this->name = (string) $vobject->summary;
     $this->description = (string) $vobject->description;
     if (!empty($vobject->dtstart)) {
         $this->start_time = $vobject->dtstart->getDateTime()->format('U');
     }
     if (!empty($vobject->dtend)) {
         $this->due_time = $vobject->dtend->getDateTime()->format('U');
         if (empty($vobject->dtstart)) {
             $this->start_time = $this->due_time;
         }
     }
     if (!empty($vobject->due)) {
         $this->due_time = $vobject->due->getDateTime()->format('U');
     }
     if (empty($vobject->dtstart)) {
         $this->start_time = 0;
     }
     if ($vobject->dtstamp) {
         $this->mtime = $vobject->dtstamp->getDateTime()->format('U');
     }
     if (empty($this->due_time)) {
         $this->due_time = time();
     }
     if ($vobject->rrule) {
         $rrule = new \GO\Base\Util\Icalendar\Rrule();
         $rrule->readIcalendarRruleString($this->start_time, (string) $vobject->rrule);
         $rrule->shiftDays(false);
         $this->rrule = $rrule->createRrule();
         if (isset($rrule->until)) {
             $this->repeat_end_time = $rrule->until;
         }
     }
     //var_dump($vobject->status);
     if ($vobject->status) {
         $this->status = (string) $vobject->status;
     }
     if ($vobject->duration) {
         $duration = \GO\Base\VObject\Reader::parseDuration($vobject->duration);
         $this->end_time = $this->start_time + $duration;
     }
     if (!empty($vobject->priority)) {
         if ((string) $vobject->priority > 5) {
             $this->priority = self::PRIORITY_LOW;
         } elseif ((string) $vobject->priority < 3) {
             $this->priority = self::PRIORITY_HIGH;
         } else {
             $this->priority = self::PRIORITY_NORMAL;
         }
     }
     if ((string) $vobject->completed != '') {
         $this->completion_time = $vobject->completed->getDateTime()->format('U');
         $this->status = 'COMPLETED';
     } else {
         $this->completion_time = 0;
     }
     if (!empty($vobject->{"percent-complete"})) {
         $this->percentage_complete = (string) $vobject->{"percent-complete"};
     }
     if ($this->status == 'COMPLETED' && empty($this->completion_time)) {
         $this->completion_time = time();
     }
     $this->reminder = 0;
     if ($vobject->valarm && $vobject->valarm->trigger) {
         $date = $vobject->valarm->getEffectiveTriggerTime();
         if ($date) {
             $this->reminder = $date->format('U');
         }
     }
     $this->setAttributes($attributes, false);
     $this->cutAttributeLengths();
     if ($this->due_time < $this->start_time) {
         $this->due_time = $this->start_time;
     }
     $this->save();
     return $this;
 }
コード例 #4
0
    public function actionIcs()
    {
        $data = 'BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Apple Inc.//iOS 7.0//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Amsterdam
BEGIN:DAYLIGHT
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20140120T131840Z
DTEND;TZID=Europe/Amsterdam:20140120T160000
DTSTAMP:20140120T131925Z
DTSTART;TZID=Europe/Amsterdam:20140120T141500
LAST-MODIFIED:20140120T131840Z
RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=20140120T131500Z;BYDAY=MO,WE
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Weekly1
TRANSP:OPAQUE
UID:26ae3ffb-546c-5a32-b87e-49306b68de91
X-GO-REMINDER-TIME:20140120T140500
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Alarm
TRIGGER:-PT10M
UID:A1AA22FB-D65D-438F-A03E-D93DC744B7EF
X-WR-ALARMUID:A1AA22FB-D65D-438F-A03E-D93DC744B7EF
END:VALARM
END:VEVENT
END:VCALENDAR';
        $vcalendar = \GO\Base\VObject\Reader::read($data);
        echo (string) $vcalendar->vevent[0]->rrule;
    }
コード例 #5
0
ファイル: ImapMessage.php プロジェクト: ajaboa/crmpuan
 /**
  * Get the VCALENDAR object as SabreDav vobject component
  * 
  * @return Sabre\VObject\Component 
  */
 public function getInvitationVcalendar()
 {
     $attachments = $this->getAttachments();
     foreach ($attachments as $attachment) {
         if ($attachment->isVcalendar()) {
             $data = $this->getImapConnection()->get_message_part_decoded($this->uid, $attachment->number, $attachment->encoding);
             $vcalendar = \GO\Base\VObject\Reader::read($data);
             if ($vcalendar && isset($vcalendar->vevent[0])) {
                 return $vcalendar;
             }
         }
     }
     return false;
 }
コード例 #6
0
ファイル: Event.php プロジェクト: ajaboa/crmpuan
 /**
  * Import an event from a VObject 
  * 
  * @param Sabre\VObject\Component $vobject
  * @param array $attributes Extra attributes to apply to the event. Raw values should be past. No input formatting is applied.
  * @param boolean $dontSave. Don't save the event. WARNING. Event can't be fully imported this way because participants and exceptions need an ID. This option is useful if you want to display info about an ICS file.
  * @param boolean $importExternal This should be switched on if importing happens from external ICS calendar.
  * @return Event 
  */
 public function importVObject(Sabre\VObject\Component $vobject, $attributes = array(), $dontSave = false, $makeSureUserParticipantExists = false, $importExternal = false)
 {
     $uid = (string) $vobject->uid;
     if (!empty($uid)) {
         $this->uuid = $uid;
     }
     $this->name = (string) $vobject->summary;
     if (empty($this->name)) {
         $this->name = \GO::t('unnamed');
     }
     $dtstart = $vobject->dtstart ? $vobject->dtstart->getDateTime() : new \DateTime();
     $dtend = $vobject->dtend ? $vobject->dtend->getDateTime() : new \DateTime();
     $substractOnEnd = 0;
     //funambol sends this special parameter
     //		if((string) $vobject->{"X-FUNAMBOL-ALLDAY"}=="1"){
     //			$this->all_day_event=1;
     //		}else
     //		{
     $this->all_day_event = isset($vobject->dtstart['VALUE']) && $vobject->dtstart['VALUE'] == 'DATE' ? 1 : 0;
     //ios sends start and end date at 00:00 hour
     //DTEND;TZID=Europe/Amsterdam:20140121T000000
     //DTSTART;TZID=Europe/Amsterdam:20140120T000000
     if ($dtstart->format('Hi') == "0000" && $dtend->format('Hi') == "0000") {
         $this->all_day_event = true;
         $substractOnEnd = 60;
     }
     //		}
     if ($this->all_day_event) {
         if ($dtstart->getTimezone()->getName() == 'UTC') {
             $this->_utcToLocal($dtstart);
         }
         if ($dtend->getTimezone()->getName() == 'UTC') {
             $this->_utcToLocal($dtend);
         }
     }
     $this->start_time = intval($dtstart->format('U'));
     $this->end_time = intval($dtend->format('U')) - $substractOnEnd;
     if ($vobject->duration) {
         $duration = \GO\Base\VObject\Reader::parseDuration($vobject->duration);
         $this->end_time = $this->start_time + $duration;
     }
     if ($this->end_time <= $this->start_time) {
         $this->end_time = $this->start_time + 3600;
     }
     if ($vobject->description) {
         $this->description = (string) $vobject->description;
     }
     if ((string) $vobject->rrule != "") {
         $rrule = new \GO\Base\Util\Icalendar\Rrule();
         $rrule->readIcalendarRruleString($this->start_time, (string) $vobject->rrule);
         $rrule->shiftDays(true);
         $this->rrule = $rrule->createRrule();
         $this->repeat_end_time = $rrule->until;
     } else {
         $this->rrule = "";
         $this->repeat_end_time = 0;
     }
     if ($vobject->{"last-modified"}) {
         $this->mtime = intval($vobject->{"last-modified"}->getDateTime()->format('U'));
     }
     if ($vobject->location) {
         $this->location = (string) $vobject->location;
     }
     //var_dump($vobject->status);
     if ($vobject->status) {
         $status = (string) $vobject->status;
         if ($this->isValidStatus($status)) {
             $this->status = $status;
         }
     }
     if (isset($vobject->class)) {
         $this->private = strtoupper($vobject->class) != 'PUBLIC';
     }
     $this->reminder = 0;
     //		if($vobject->valarm && $vobject->valarm->trigger){
     //
     //			$type = (string) $vobject->valarm->trigger["value"];
     //
     //
     //			if($type == "DURATION") {
     //				$duration = \GO\Base\VObject\Reader::parseDuration($vobject->valarm->trigger);
     //				if($duration>0){
     //					$this->reminder = $duration*-1;
     //				}
     //			}else
     //			{
     //				\GO::debug("WARNING: Ignoring unsupported reminder value of type: ".$type);
     //			}
     //
     if ($vobject->valarm && $vobject->valarm->trigger) {
         $date = $vobject->valarm->getEffectiveTriggerTime();
         if ($date) {
             if ($this->all_day_event) {
                 $this->_utcToLocal($date);
             }
             $this->reminder = $this->start_time - $date->format('U');
         }
     } elseif ($vobject->aalarm) {
         //funambol sends old vcalendar 1.0 format
         $aalarm = explode(';', (string) $vobject->aalarm);
         if (!empty($aalarm[0])) {
             $p = Sabre\VObject\DateTimeParser::parse($aalarm[0]);
             $this->reminder = $this->start_time - $p->format('U');
         }
     }
     $this->setAttributes($attributes, false);
     $recurrenceIds = $vobject->select('recurrence-id');
     if (count($recurrenceIds)) {
         //this is a single instance of a recurring series.
         //attempt to find the exception of the recurring series event by uuid
         //and recurrence time so we can set the relation cal_exceptions.exception_event_id=cal_events.id
         $firstMatch = array_shift($recurrenceIds);
         $recurrenceTime = $firstMatch->getDateTime()->format('U');
         $whereCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', $this->calendar_id, '=', 'ev')->addCondition('uuid', $this->uuid, '=', 'ev')->addCondition('time', $recurrenceTime, '=', 't');
         $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('event_id', 'ev.id', '=', 't', true, true);
         $findParams = \GO\Base\Db\FindParams::newInstance()->single()->criteria($whereCriteria)->join(Event::model()->tableName(), $joinCriteria, 'ev');
         $exception = Exception::model()->find($findParams);
         if ($exception) {
             $this->exception_for_event_id = $exception->event_id;
             if (empty($this->name) || $this->name == \GO::t('unnamed')) {
                 $this->name = $exception->mainevent->name;
             }
         } else {
             //exception was not found for this recurrence. Find the recurring series and add the exception.
             $recurringEvent = Event::model()->findByUuid($this->uuid, 0, $this->calendar_id);
             if ($recurringEvent) {
                 \GO::debug("Creating MISSING exception for " . date('c', $recurrenceTime));
                 //aftersave will create Exception
                 $this->exception_for_event_id = $recurringEvent->id;
                 //will be saved later
                 $exception = new Exception();
                 $exception->time = $recurrenceTime;
                 $exception->event_id = $recurringEvent->id;
                 if (empty($this->name) || $this->name == \GO::t('unnamed')) {
                     $this->name = $exception->mainevent->name;
                 }
             } else {
                 //ignore this because the invited participant might not be invited to the series
                 //throw new \Exception("Could not find master event!");
                 //hack to make it be seen as an exception
                 $this->exception_for_event_id = -1;
             }
         }
     }
     if ($vobject->valarm && $vobject->valarm->trigger) {
         $reminderTime = $vobject->valarm->getEffectiveTriggerTime();
         //echo $reminderTime->format('c');
         if ($this->all_day_event) {
             $this->_utcToLocal($reminderTime);
         }
         $seconds = $reminderTime->format('U');
         $this->reminder = $this->start_time - $seconds;
         if ($this->reminder < 0) {
             $this->reminder = 0;
         }
     }
     $cats = (string) $vobject->categories;
     if (!empty($cats)) {
         //Group-Office only supports a single category.
         $cats = explode(',', $cats);
         $categoryName = array_shift($cats);
         $category = Category::model()->findByName($this->calendar_id, $categoryName);
         if (!$category && !$dontSave && $this->calendar_id) {
             $category = new Category();
             $category->name = $categoryName;
             $category->calendar_id = $this->calendar_id;
             $category->save(true);
         }
         if ($category) {
             $this->category_id = $category->id;
             $this->background = $category->color;
         }
     }
     //set is_organizer flag
     if ($vobject->organizer && $this->calendar) {
         $organizerEmail = str_replace('mailto:', '', strtolower((string) $vobject->organizer));
         $this->is_organizer = $organizerEmail == $this->calendar->user->email;
     }
     if (!$dontSave) {
         $this->cutAttributeLengths();
         //			try {
         $this->_isImport = true;
         if (!$importExternal) {
             $this->setValidationRule('uuid', 'unique', array('calendar_id', 'start_time', 'exception_for_event_id'));
         }
         //				//make sure no duplicates are imported
         //				if(!is_array($previouslyImportedEventsArray)){
         //					// We do not take events from previous import iterations into account, and we will do a validation check.
         //					$this->setValidationRule('uuid', 'unique', array('calendar_id','start_time'));
         //				}else
         //				{
         //
         //					// We take into account the history if imported items to better handle recurring events, exceptions and rescheduled events.
         //
         //					if (!empty($this->rrule)) {
         //
         //						\GO::debug('=== ['.\GO\Base\Util\Date::get_timestamp($this->start_time).'] '.$this->name.' (with rrule)');
         //
         //						// Handle imported recurring event.
         //
         //						$existingEventModel = Event::model()->find(
         //							\GO\Base\Db\FindParams::newInstance()
         //								->single()
         //								->criteria(\GO\Base\Db\FindCriteria::newInstance()
         //									->addCondition('calendar_id',$this->calendar_id)
         //									->addCondition('uuid',$this->uuid)
         //									->addCondition('rrule','','!=')
         //								)
         //						);
         //
         //						if (!empty($existingEventModel)) {
         //							// Update the existing recurring event in the calendar.
         //							$this->id = $existingEventModel->id;
         //							$this->setIsNew(false);
         //						}
         //
         //					} else {
         //
         //						\GO::debug('=== ['.\GO\Base\Util\Date::get_timestamp($this->start_time).'] '.$this->name);
         //
         //						// Handle imported non-recurring event or exception event.
         //
         //						$existingEventsStmt = Event::model()->find(
         //							\GO\Base\Db\FindParams::newInstance()
         //								->criteria(\GO\Base\Db\FindCriteria::newInstance()
         //									->addCondition('calendar_id',$this->calendar_id)
         //									->addCondition('uuid',$this->uuid)
         //									->addCondition('rrule','','=')
         //								)
         //						);
         //
         //						foreach ($existingEventsStmt as $existingEventModel) {
         //							if ($existingEventModel && !self::eventIsFromCurrentImport($existingEventModel,$previouslyImportedEventsArray)) {
         //								// The existing event model in the database was previously imported during the current import process.
         //
         //								// We rightfully assume here that the latest version of this event will be saved in Group-Office as a new event later in this function.
         //								$existingEventModel->delete();
         //							}
         //						}
         //
         //					}
         //				}
         if (!$this->save()) {
             if ($importExternal) {
                 $installationName = !empty(\GO::config()->title) ? \GO::config()->title : 'Group-Office';
                 $validationErrStr = implode("\n", $this->getValidationErrors()) . "\n";
                 $mailSubject = str_replace(array('%cal', '%event'), array($this->calendar->name, $this->name), \GO::t('eventNotSavedSubject', 'calendar'));
                 $body = \GO::t('eventNotSavedBody', 'calendar');
                 $body = str_replace(array('%goname', '%event', '%starttime', '%cal', '%errormessage'), array($installationName, $this->name, \GO\Base\Util\Date::get_timestamp($this->start_time), $this->calendar->name, $validationErrStr), $body);
                 $message = \GO\Base\Mail\Message::newInstance($mailSubject)->setFrom(\GO::config()->webmaster_email, \GO::config()->title)->addTo($this->calendar->user->email);
                 $message->setHtmlAlternateBody(nl2br($body));
                 if (\GO\Base\Mail\Mailer::newGoInstance()->send($message)) {
                     throw new \GO\Base\Exception\Validation('DUE TO ERROR, CRON SENT MAIL TO: ' . $this->calendar->user->email . '. THIS IS THE EMAIL MESSAGE:' . "\r\n" . $body);
                 } else {
                     throw new \GO\Base\Exception\Validation('CRON COULD NOT SEND EMAIL WITH ERROR MESSAGE TO: ' . $this->calendar->user->email . '. THIS IS THE EMAIL MESSAGE:' . "\r\n" . $body);
                 }
             } else {
                 throw new \GO\Base\Exception\Validation(implode("\n", $this->getValidationErrors()) . "\n");
             }
         }
         $this->_isImport = false;
         //			} catch (\Exception $e) {
         //				throw new \Exception($this->name.' ['.\GO\Base\Util\Date::get_timestamp($this->start_time).' - '.\GO\Base\Util\Date::get_timestamp($this->end_time).'] '.$e->getMessage());
         //			}
         if (!empty($exception)) {
             //save the exception we found by recurrence-id
             $exception->exception_event_id = $this->id;
             $exception->save();
             \GO::debug("saved exception");
         }
         //			$test = (bool) $vobject->organizer;
         //			var_dump($test);
         //			exit();
         //
         if ($vobject->organizer) {
             $p = $this->importVObjectAttendee($this, $vobject->organizer, true);
         } else {
             $p = false;
         }
         $calendarParticipantFound = !empty($p) && $p->user_id == $this->calendar->user_id;
         $attendees = $vobject->select('attendee');
         foreach ($attendees as $attendee) {
             $p = $this->importVObjectAttendee($this, $attendee, false);
             if ($p->user_id == $this->calendar->user_id) {
                 $calendarParticipantFound = true;
             }
         }
         //if the calendar owner is not in the participants then we should chnage the is_organizer flag because otherwise the event can't be opened or accepted.
         if (!$calendarParticipantFound) {
             if ($makeSureUserParticipantExists) {
                 $participant = \GO\Calendar\Model\Participant::model()->findSingleByAttributes(array('event_id' => $this->id, 'email' => $this->calendar->user->email));
                 if (!$participant) {
                     //this is a bad situation. The import thould have detected a user for one of the participants.
                     //It uses the E-mail account aliases to determine a user. See GO_Calendar_Model_Event::importVObject
                     $participant = new \GO\Calendar\Model\Participant();
                     $participant->event_id = $this->id;
                     $participant->user_id = $this->calendar->user_id;
                     $participant->email = $this->calendar->user->email;
                 } else {
                     $participant->user_id = $this->calendar->user_id;
                 }
                 $participant->save();
             } else {
                 $this->is_organizer = true;
                 $this->save();
             }
         }
         //Add exception dates to Event
         foreach ($vobject->select('EXDATE') as $i => $exdate) {
             try {
                 $dts = $exdate->getDateTimes();
                 if ($dts === null) {
                     continue;
                 }
                 foreach ($dts as $dt) {
                     $this->addException($dt->format('U'));
                 }
             } catch (Exception $e) {
                 trigger_error($e->getMessage(), E_USER_NOTICE);
             }
         }
         if ($importExternal && $this->isRecurring()) {
             $exceptionEventsStmt = Event::model()->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', $this->calendar_id)->addCondition('uuid', $this->uuid)->addCondition('rrule', '', '=')));
             foreach ($exceptionEventsStmt as $exceptionEventModel) {
                 $exceptionEventModel->exception_for_event_id = $this->id;
                 $exceptionEventModel->save();
                 //TODO: This method only works when an exception takes place on the same day as the original occurence.
                 //We should store the RECURRENCE-ID value so we can find it later.
                 $this->addException($exceptionEventModel->start_time, $exceptionEventModel->id);
                 //					\GO::debug('=== EXCEPTION EVENT === ['.\GO\Base\Util\Date::get_timestamp($exceptionEventModel->start_time).'] '.$exceptionEventModel->name.' (\Exception for event: '.$exceptionEventModel->exception_for_event_id.')');
             }
         }
     }
     return $this;
 }
コード例 #7
0
ファイル: ContactController.php プロジェクト: ajaboa/crmpuan
 protected function actionImportVCard($params)
 {
     $summaryLog = new \GO\Base\Component\SummaryLog();
     $readOnly = !empty($params['readOnly']);
     if (isset($_FILES['files']['tmp_name'][0])) {
         $params['file'] = $_FILES['files']['tmp_name'][0];
     }
     if (!empty($params['importBaseParams'])) {
         $importBaseParams = json_decode($params['importBaseParams'], true);
         $params['addressbook_id'] = $importBaseParams['addressbook_id'];
     }
     $file = new \GO\Base\Fs\File($params['file']);
     $file->convertToUtf8();
     $options = \Sabre\VObject\Reader::OPTION_FORGIVING + \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES;
     $vcards = new \Sabre\VObject\Splitter\VCard(fopen($file->path(), 'r+'), $options);
     unset($params['file']);
     $nr = 0;
     if ($readOnly) {
         $contactsAttr = array();
     }
     while ($vObject = $vcards->getNext()) {
         $nr++;
         \GO\Base\VObject\Reader::convertVCard21ToVCard30($vObject);
         $contact = new \GO\Addressbook\Model\Contact();
         try {
             if ($contact->importVObject($vObject, $params, !$readOnly)) {
                 $summaryLog->addSuccessful();
             }
             if ($readOnly) {
                 $contactsAttr[] = $contact->getAttributes('formatted');
             }
         } catch (\Exception $e) {
             $summaryLog->addError($nr, $e->getMessage());
         }
     }
     $response = $summaryLog->getErrorsJson();
     if ($readOnly) {
         $response['contacts'] = $contactsAttr;
     }
     $response['successCount'] = $summaryLog->getTotalSuccessful();
     $response['totalCount'] = $summaryLog->getTotal();
     $response['success'] = true;
     return $response;
 }
コード例 #8
0
ファイル: TaskController.php プロジェクト: ajaboa/crmpuan
 protected function actionImportIcs($params)
 {
     $file = new \GO\Base\Fs\File($params['file']);
     $data = $file->getContents();
     $vcalendar = \GO\Base\VObject\Reader::read($data);
     \GO\Base\VObject\Reader::convertVCalendarToICalendar($vcalendar);
     foreach ($vcalendar->vtodo as $vtodo) {
         $task = new \GO\Tasks\Model\Task();
         $task->importVObject($vtodo);
     }
 }
コード例 #9
0
ファイル: CalendarController.php プロジェクト: ajaboa/crmpuan
 private function _importSmarterMailXml($params, File $file)
 {
     $sXml = new SimpleXMLElement($file->getContents());
     $count = 0;
     $failed = array();
     foreach ($sXml->children() as $obj) {
         if ($obj->getName() == 'Event') {
             $event = new Event();
             try {
                 $data = (string) $obj->Data;
                 //					\GO::debug($data);
                 $vObject = \GO\Base\VObject\Reader::read($data);
                 $event->importVObject($vObject->vevent[0], array('calendar_id' => $params['calendar_id']));
                 $count++;
                 //					break;
             } catch (\Exception $e) {
                 $failed[] = $e->getMessage();
             }
         }
     }
     $response['feedback'] = sprintf(\GO::t('import_success', 'calendar'), $count);
     if (count($failed)) {
         $response['feedback'] .= "\n\n" . count($failed) . " events failed: " . implode("\n", $failed);
     }
     return $response;
 }