コード例 #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;
 }