Skip to content

Commit

Permalink
Merge pull request #137 from 5pm-HDH/address-in-appointment
Browse files Browse the repository at this point in the history
Address in appointment
  • Loading branch information
DumbergerL authored Apr 20, 2023
2 parents e81e0f5 + 0c90d93 commit 2d52bf0
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ composer.phar
.phpunit.result.cache

# ignore log-files
*.log
*.log

/http-dump
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- Add Address-Property to Appointment ([PR137](https://github.com/5pm-HDH/churchtools-api/pull/137))

### Changed

Expand Down
7 changes: 6 additions & 1 deletion docs/out/CTLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CTLog

By default, there are two log types:
By default, there are three log types:

**File-Log (Info):**

Expand All @@ -17,6 +17,11 @@ By default, there are two log types:
- Logs by default the log-level: ERROR, CRITICAL, ALERT, EMERGENCY
- Log is displayed to the php-console

**HTTP-Log**

- Stores all HTTP-Response Data in the folder `http-dump`.
- Enable with `CTLog::enableHttpLog();`

## Enable / disable

Both file-log and console-log is enabled by default. To disable and (re-)enable you can use:
Expand Down
56 changes: 56 additions & 0 deletions docs/out/CalendarAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,62 @@ Load appointments for calendar:
var_dump( $lastAppointment->getEndDate());
// Output: "2022-08-07T16:00:00Z"

var_dump( $lastAppointment->getAllDay());
// Output: "false"


var_dump( $lastAppointment->getNote());
// Output: "Test Note"

var_dump( $lastAppointment->getVersion());
// Output: 1

var_dump( $lastAppointment->getInformation());
// Output: "Information Text"

var_dump( $lastAppointment->getLink());
// Output: "https://example.com"

var_dump( $lastAppointment->getIsInternal());
// Output: false


// Repeat of Appointment
var_dump( $lastAppointment->getRepeatId());
// Output: 0

var_dump( $lastAppointment->getRepeatFrequency());
// Output: 1


// Retrieve Address:
var_dump( $lastAppointment->getAddress()?->getMeetingAt());
// Output: "Evangelische Brückengemeinde"

var_dump( $lastAppointment->getAddress()?->getStreet());
// Output: "Wilhelmstraße 132"

var_dump( $lastAppointment->getAddress()?->getAddition());
// Output: "-"

var_dump( $lastAppointment->getAddress()?->getDistrict());
// Output: "-"

var_dump( $lastAppointment->getAddress()?->getZip());
// Output: "89518"

var_dump( $lastAppointment->getAddress()?->getCity());
// Output: "Heidenheim an der Brenz"

var_dump( $lastAppointment->getAddress()?->getCountry());
// Output: "DE"

var_dump( $lastAppointment->getAddress()?->getLatitude());
// Output: "48.680651"

var_dump( $lastAppointment->getAddress()?->getLongitude());
// Output: "10.130883553439624"


```

Expand Down
7 changes: 6 additions & 1 deletion docs/src/ressources/CTLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CTLog

By default, there are two log types:
By default, there are three log types:

**File-Log (Info):**

Expand All @@ -17,6 +17,11 @@ By default, there are two log types:
- Logs by default the log-level: ERROR, CRITICAL, ALERT, EMERGENCY
- Log is displayed to the php-console

**HTTP-Log**

- Stores all HTTP-Response Data in the folder `http-dump`.
- Enable with `CTLog::enableHttpLog();`

## Enable / disable

Both file-log and console-log is enabled by default. To disable and (re-)enable you can use:
Expand Down
26 changes: 26 additions & 0 deletions src/CTLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ class CTLog
{
private const LOG_FILE = __DIR__ . '/../churchtools-api.log';
private const LOG_FILE_WARNING = __DIR__ . '/../churchtools-api-warning.log';
private const LOG_HTTP_DATA_DIR = __DIR__ . '/../http-dump/';

private static ?Logger $logger = null;
private static bool $fileLogEnabled = true;
private static bool $consoleLogEnabled = true;
private static bool $httpLogEnabled = true;
private static string $httpLogName = "Log";

// Log-Level: https://github.com/Seldaek/monolog/blob/main/doc/01-usage.md#log-levels
private static int $consoleLogLevel = Logger::ERROR;
Expand Down Expand Up @@ -55,6 +58,29 @@ public static function enableConsoleLog($enabled = true): void
self::createLog();
}

public static function enableHttpLog($enabled = true): void
{
$deciple = ["Peter", "John", "James", "Andrew", "Philip", "Bartholomew", "Thomas", "Matthew", "James", "Juda", "Simon", "Judas-Iscariot"];
$index = array_rand($deciple, 1);

self::$httpLogEnabled = $enabled;
self::$httpLogName = $deciple[$index] . random_int(100,1000);
}

public static function logHttpData(array $httpData): void
{
if(!self::$httpLogEnabled){
return;
}

if(!file_exists(self::LOG_HTTP_DATA_DIR)){
mkdir(self::LOG_HTTP_DATA_DIR);
}

$fileName = date("Y-m-d-H-i-s") . "-" . self::$httpLogName . ".json";
file_put_contents(self::LOG_HTTP_DATA_DIR . $fileName, json_encode($httpData, JSON_PRETTY_PRINT));
}

public static function setConsoleLogLevelError(): void
{
self::$consoleLogLevel = Logger::ERROR;
Expand Down
184 changes: 184 additions & 0 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php


namespace CTApi\Models;


use CTApi\Models\Traits\FillWithData;

class Address
{
use FillWithData;

protected ?string $meetingAt = null;
protected ?string $street = null;
protected ?string $addition = null;
protected ?string $district = null;
protected ?string $zip = null;
protected ?string $city = null;
protected ?string $country = null;
protected ?string $latitude = null;
protected ?string $longitude = null;

/**
* @return string|null
*/
public function getMeetingAt(): ?string
{
return $this->meetingAt;
}

/**
* @param string|null $meetingAt
* @return Address
*/
public function setMeetingAt(?string $meetingAt): Address
{
$this->meetingAt = $meetingAt;
return $this;
}

/**
* @return string|null
*/
public function getStreet(): ?string
{
return $this->street;
}

/**
* @param string|null $street
* @return Address
*/
public function setStreet(?string $street): Address
{
$this->street = $street;
return $this;
}

/**
* @return string|null
*/
public function getAddition(): ?string
{
return $this->addition;
}

/**
* @param string|null $addition
* @return Address
*/
public function setAddition(?string $addition): Address
{
$this->addition = $addition;
return $this;
}

/**
* @return string|null
*/
public function getDistrict(): ?string
{
return $this->district;
}

/**
* @param string|null $district
* @return Address
*/
public function setDistrict(?string $district): Address
{
$this->district = $district;
return $this;
}

/**
* @return string|null
*/
public function getZip(): ?string
{
return $this->zip;
}

/**
* @param string|null $zip
* @return Address
*/
public function setZip(?string $zip): Address
{
$this->zip = $zip;
return $this;
}

/**
* @return string|null
*/
public function getCity(): ?string
{
return $this->city;
}

/**
* @param string|null $city
* @return Address
*/
public function setCity(?string $city): Address
{
$this->city = $city;
return $this;
}

/**
* @return string|null
*/
public function getCountry(): ?string
{
return $this->country;
}

/**
* @param string|null $country
* @return Address
*/
public function setCountry(?string $country): Address
{
$this->country = $country;
return $this;
}

/**
* @return string|null
*/
public function getLatitude(): ?string
{
return $this->latitude;
}

/**
* @param string|null $latitude
* @return Address
*/
public function setLatitude(?string $latitude): Address
{
$this->latitude = $latitude;
return $this;
}

/**
* @return string|null
*/
public function getLongitude(): ?string
{
return $this->longitude;
}

/**
* @param string|null $longitude
* @return Address
*/
public function setLongitude(?string $longitude): Address
{
$this->longitude = $longitude;
return $this;
}
}
22 changes: 22 additions & 0 deletions src/Models/Appointment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Appointment extends AbstractModel
protected ?string $note = null;
protected ?string $version = null;
protected ?Calendar $calendar = null;
protected ?Address $address = null;
protected ?string $information = null;
protected ?string $link = null;
protected ?bool $isInternal = null;
Expand Down Expand Up @@ -41,6 +42,9 @@ protected function fillArrayType(string $key, array $data): void
case "meta":
$this->meta = Meta::createModelFromData($data);
break;
case "address":
$this->address = Address::createModelFromData($data);
break;
default:
$this->fillDefault($key, $data);
}
Expand All @@ -56,6 +60,24 @@ public function setId(?string $id): Appointment
return $this;
}

/**
* @return Address|null
*/
public function getAddress(): ?Address
{
return $this->address;
}

/**
* @param Address|null $address
* @return Appointment
*/
public function setAddress(?Address $address): Appointment
{
$this->address = $address;
return $this;
}

/**
* @return string|null
*/
Expand Down
Loading

0 comments on commit 2d52bf0

Please sign in to comment.