Skip to content

Commit

Permalink
Added logic for Events and Tasks support
Browse files Browse the repository at this point in the history
  • Loading branch information
ksainc committed Oct 11, 2023
1 parent 90c488e commit c185ed6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/Service/CoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ public function listFormats(string $type): array {
$response['Formats'][] = ['id' => 'XML', 'label' => 'XML'];
// retrieve all formats
if ($type == 'CC') {
$files = scandir(__DIR__ . '/../Resources/Contacts/');
$files = scandir(dirname(__DIR__) . '/Resources/Contacts/');
foreach ($files as $file) {
if (strstr($file, '.tpl')) {
$response['Formats'][] = ['id' => $file, 'label' => str_replace(".tpl", "", $file)];
}
}
}
if ($type == 'EC') {
$files = scandir(__DIR__ . '/../Resources/Events/');
$files = scandir(dirname(__DIR__) . '/Resources/Events/');
foreach ($files as $file) {
if (strstr($file, '.tpl')) {
$response['Formats'][] = ['id' => $file, 'label' => str_replace(".tpl", "", $file)];
}
}
}
if ($type == 'TC') {
$files = scandir(__DIR__ . '/../Resources/Tasks/');
$files = scandir(dirname(__DIR__) . '/Resources/Tasks/');
foreach ($files as $file) {
if (strstr($file, '.tpl')) {
$response['Formats'][] = ['id' => $file, 'label' => str_replace(".tpl", "", $file)];
Expand Down
70 changes: 61 additions & 9 deletions lib/Service/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ public function listCollections(string $uid, string $type): array {

public function generateCSV(array $service) {

// modify service entry accessed in the data store
$this->Services->modifyAccessed((string) $service['id'], time(), '');
// generate data based on data type
switch ($service['data_type']) {
case 'CC':
$this->generateContactsCSV($service);
break;
case 'EC':
// TOOD: Enable after adding events support
//$this->generateEventsCSV($service);
break;
case 'TC':
// TOOD: Enable after adding tasks support
//$this->generateTasksCSV($service);
break;
default:
return;
}

}

public function generateContactsCSV(array $service) {

// modify service entry accessed in the data store
$this->Services->modifyAccessed((string) $service['id'], time(), '');
// load entities
Expand Down Expand Up @@ -165,6 +188,27 @@ public function generateJSON(array $service) {

// modify service entry accessed in the data store
$this->Services->modifyAccessed((string) $service['id'], time(), '');
// generate data based on data type
switch ($service['data_type']) {
case 'CC':
$this->generateContactsJSON($service);
break;
case 'EC':
// TOOD: Enable after adding events support
//$this->generateEventsJSON($service);
break;
case 'TC':
// TOOD: Enable after adding tasks support
//$this->generateTasksJSON($service);
break;
default:
return;
}

}

public function generateContactsJSON(array $service) {

// load entities
$entities = $this->ContactsService->listEntities($service['data_collection']);
// document start
Expand Down Expand Up @@ -192,28 +236,36 @@ public function generateJSON(array $service) {
yield ']';

}

public function generateTemplate(array $service) {

// modify service entry accessed in the data store
$this->Services->modifyAccessed((string) $service['id'], time(), '');
// instance template service
$TemplateService = new TemplateService();
// load template
// generate data based on data type
switch ($service['data_type']) {
case 'CC':
$TemplateService->fromFile(dirname(__DIR__) . '/Resources/Contacts/' . $service['format']);
$this->generateContactsTemplate($service);
break;
case 'EC':
$TemplateService->fromFile(dirname(__DIR__) . '/Resources/Events/' . $service['format']);
// TOOD: Enable after adding events support
//$this->generateEventsTemplate($service);
break;
case 'TC':
$TemplateService->fromFile(dirname(__DIR__) . '/Resources/Tasks/' . $service['format']);
// TOOD: Enable after adding tasks support
//$this->generateTasksTemplate($service);
break;
default:
# code...
break;
return;
}

}

public function generateContactsTemplate(array $service) {

// instance template service
$TemplateService = new TemplateService();
// load template
$TemplateService->fromFile(dirname(__DIR__) . '/Resources/Contacts/' . $service['format']);
// load entities
$entities = $this->ContactsService->listEntities($service['data_collection']);
// document start
Expand Down

0 comments on commit c185ed6

Please sign in to comment.