-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ZMSKVR-72): create closure for specific day and office
- Loading branch information
Showing
23 changed files
with
613 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @package Zmsadmin | ||
* @copyright BerlinOnline Stadtportal GmbH & Co. KG | ||
**/ | ||
|
||
namespace BO\Zmsadmin; | ||
|
||
use BO\Slim\Render; | ||
use BO\Zmsdb\Closure; | ||
use BO\Zmsentities\Collection\AvailabilityList; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ScopeAvailabilityDayClosure extends BaseController | ||
{ | ||
/** | ||
* @SuppressWarnings(Param) | ||
* @return ResponseInterface | ||
*/ | ||
public function readResponse( | ||
\Psr\Http\Message\RequestInterface $request, | ||
\Psr\Http\Message\ResponseInterface $response, | ||
array $args | ||
): ResponseInterface { | ||
$scopeId = $args['id']; | ||
$date = $args['date']; | ||
|
||
try { | ||
$closureToggled = \App::$http->readPostResult( | ||
'/scope/' . $scopeId . '/availability/' . $date . '/closure/toggle/', | ||
new \BO\Zmsentities\Closure() | ||
)->getEntity(); | ||
} catch (\Exception $e) { | ||
var_dump($e->getMessage());exit; | ||
} | ||
|
||
return \BO\Slim\Render::withJson( | ||
$response, | ||
[ | ||
'closure' => $closureToggled | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* @package ZMS API | ||
* @copyright BerlinOnline Stadtportal GmbH & Co. KG | ||
**/ | ||
|
||
namespace BO\Zmsapi; | ||
|
||
use BO\Slim\Render; | ||
use BO\Mellon\Validator; | ||
use BO\Zmsdb\Closure; | ||
use BO\Zmsentities\Closure as ClosureEntity; | ||
use BO\Zmsentities\Availability as Entity; | ||
use BO\Zmsentities\Collection\AvailabilityList as Collection; | ||
use BO\Zmsdb\Availability as AvailabilityRepository; | ||
use BO\Zmsdb\Slot as SlotRepository; | ||
use BO\Zmsdb\Config as ConfigRepository; | ||
use BO\Zmsdb\Helper\CalculateSlots as CalculateSlotsHelper; | ||
use BO\Zmsdb\Connection\Select as DbConnection; | ||
use BO\Zmsentities\Collection\ClosureList; | ||
use DateTime; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use BO\Zmsapi\Exception\BadRequest as BadRequestException; | ||
use BO\Zmsapi\Exception\Availability\AvailabilityNotFound as NotfoundException; | ||
|
||
/** | ||
* @SuppressWarnings(Coupling) | ||
*/ | ||
class AvailabilityClosureToggle extends BaseController | ||
{ | ||
/** | ||
* @SuppressWarnings(Param) | ||
* @return ResponseInterface | ||
*/ | ||
public function readResponse( | ||
RequestInterface $request, | ||
ResponseInterface $response, | ||
array $args | ||
): ResponseInterface { | ||
(new Helper\User($request))->checkRights(); | ||
$input = Validator::input()->isJson()->assertValid()->getValue(); | ||
if (! $input || count($input) === 0) { | ||
throw new BadRequestException(); | ||
} | ||
$data = []; | ||
$scopeId = $args['id']; | ||
$date = $args['date']; | ||
$closure = null; | ||
|
||
try { | ||
$closure = (new Closure())->readByScopeIdAndDate($scopeId, new DateTime($date)); | ||
} catch (\Exception $e) { | ||
} | ||
|
||
if (empty($closure->getId())) { | ||
$closure = (new Closure())->createOne($scopeId, new DateTime($date)); | ||
$closure->existing = true; | ||
$data['message'] = 'Closure has been created'; | ||
} else { | ||
(new Closure())->deleteEntity($closure->getId()); | ||
$closure->existing = false; | ||
$data['message'] = 'Closure has been deleted'; | ||
} | ||
|
||
$message = Response\Message::create($request); | ||
$message->data = $closure; | ||
|
||
$response = Render::withLastModified($response, time(), '0'); | ||
$response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DROP TABLE IF EXISTS `closures`; | ||
CREATE TABLE `closures` ( | ||
`id` INT(5) UNSIGNED AUTO_INCREMENT, | ||
`year` SMALLINT(5), | ||
`month` TINYINT(5), | ||
`day` TINYINT(5), | ||
`StandortID` INT(5) UNSIGNED, | ||
`updateTimestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`), | ||
INDEX (StandortID), | ||
INDEX (StandortID, year, month, day) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace BO\Zmsdb; | ||
|
||
use BO\Zmsentities\Closure as Entity; | ||
use BO\Zmsentities\Collection\ClosureList as Collection; | ||
use DateTime; | ||
|
||
class Closure extends Base | ||
{ | ||
public function readByScopeId($scopeId = 0) | ||
{ | ||
$closureList = new Collection(); | ||
$query = new Query\Closure(Query\Base::SELECT); | ||
$query->addEntityMapping() | ||
->addConditionScopeId($scopeId); | ||
$result = $this->fetchList($query, new Entity()); | ||
if (count($result)) { | ||
foreach ($result as $entity) { | ||
if ($entity instanceof Entity) { | ||
$closureList->addEntity($entity); | ||
} | ||
} | ||
} | ||
return $closureList; | ||
} | ||
|
||
public function readByScopeIdAndDate($scopeId, DateTime $date) | ||
{ | ||
$query = new Query\Closure(Query\Base::SELECT); | ||
$query->addEntityMapping() | ||
->addConditionScopeId($scopeId) | ||
->addConditionDate($date); | ||
|
||
return $this->fetchOne($query, new \BO\Zmsentities\Closure()); | ||
} | ||
|
||
public function deleteEntity($itemId) | ||
{ | ||
$query = new Query\Closure(Query\Base::DELETE); | ||
$query->addConditionClosureId($itemId); | ||
return ($this->deleteItem($query)); | ||
} | ||
|
||
public function createOne($scopeId, DateTime $date) | ||
{ | ||
$query = new Query\Closure(Query\Base::INSERT); | ||
$query->addValues( | ||
array( | ||
'StandortID' => $scopeId, | ||
'year' => (int) $date->format('Y'), | ||
'month' => (int) $date->format('m'), | ||
'day' => (int) $date->format('d') | ||
) | ||
); | ||
$this->writeItem($query); | ||
$id = $this->getWriter()->lastInsertId(); | ||
|
||
return $this->readEntity($id); | ||
} | ||
|
||
public function readEntity($id) | ||
{ | ||
$query = new Query\Closure(Query\Base::SELECT); | ||
$query->addEntityMapping() | ||
->addConditionId($id); | ||
|
||
return $this->fetchOne($query, new \BO\Zmsentities\Closure()); | ||
} | ||
} |
Oops, something went wrong.