-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing the data export for EDK as a part of issue #10
- Loading branch information
Showing
11 changed files
with
212 additions
and
9 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
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,61 @@ | ||
<?php | ||
/* | ||
* This file is part of Cantiga Project. Copyright 2015 Tomasz Jedrzejewski. | ||
* | ||
* Cantiga Project is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Cantiga Project is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Foobar; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
namespace WIO\EdkBundle\EventListener; | ||
|
||
use Cantiga\ExportBundle\Event\ExportEvent; | ||
use WIO\EdkBundle\Repository\EdkExportRepository; | ||
|
||
/** | ||
* Handles the external data export. | ||
* | ||
* @author Tomasz Jędrzejewski | ||
*/ | ||
class ExportListener | ||
{ | ||
/** | ||
* @var EdkExportRepository | ||
*/ | ||
private $repo; | ||
|
||
public function __construct(EdkExportRepository $repository) | ||
{ | ||
$this->repo = $repository; | ||
} | ||
|
||
|
||
/** | ||
* Handles the data export of additional area descriptions, routes and territories to the external systems. | ||
* | ||
* @param \WIO\EdkBundle\EventListener\ExportEvent $event | ||
*/ | ||
public function onProjectExported(ExportEvent $event) | ||
{ | ||
$areaBlock = $event->getBlock('area'); | ||
|
||
$territoryBlock = $this->repo->exportTerritories($event->getProjectId()); | ||
$routeBlock = $this->repo->exportRoutes($event->getLastExportAt(), $areaBlock->getIds()); | ||
$areaDescBlock = $this->repo->exportAreaDescriptions($event->getLastExportAt(), $areaBlock->getIds()); | ||
$routeDescBlock = $this->repo->exportRouteDescriptions($event->getLastExportAt(), $routeBlock->getIds()); | ||
|
||
$event->addBlock('territory', $territoryBlock); | ||
$event->addBlock('route', $routeBlock); | ||
$event->addBlock('areaDesc', $areaDescBlock); | ||
$event->addBlock('routeDesc', $routeDescBlock); | ||
} | ||
} |
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,107 @@ | ||
<?php | ||
/* | ||
* This file is part of Cantiga Project. Copyright 2015 Tomasz Jedrzejewski. | ||
* | ||
* Cantiga Project is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Cantiga Project is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Foobar; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
namespace WIO\EdkBundle\Repository; | ||
|
||
use Cantiga\CoreBundle\CoreTables; | ||
use Cantiga\ExportBundle\Entity\ExportBlock; | ||
use Doctrine\DBAL\Connection; | ||
use PDO; | ||
use WIO\EdkBundle\EdkTables; | ||
|
||
/** | ||
* @author Tomasz Jędrzejewski | ||
*/ | ||
class EdkExportRepository | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $conn; | ||
|
||
public function __construct(Connection $conn) | ||
{ | ||
$this->conn = $conn; | ||
} | ||
|
||
public function exportTerritories($projectId) | ||
{ | ||
$stmt = $this->conn->prepare('SELECT `id`, `name` FROM `'.CoreTables::TERRITORY_TBL.'` WHERE `projectId` = :id'); | ||
$stmt->bindValue(':id', $projectId); | ||
$stmt->execute(); | ||
|
||
$block = new ExportBlock(); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$block->addId($row['id']); | ||
$block->addUpdate($row); | ||
} | ||
$stmt->closeCursor(); | ||
return $block; | ||
} | ||
|
||
public function exportAreaDescriptions($lastExport, $areaIds) | ||
{ | ||
$block = new ExportBlock(); | ||
if (sizeof($areaIds) > 0) { | ||
$stmt = $this->conn->query('SELECT `areaId`, `noteType`, `content`, `lastUpdatedAt` FROM `'.EdkTables::AREA_NOTE_TBL.'` WHERE `areaId` IN ('.implode(',', $areaIds).') '); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$block->addId(['areaId' => $row['areaId'], 'noteType' => $row['noteType']]); | ||
if ($row['lastUpdatedAt'] > $lastExport) { | ||
$block->addUpdate($row); | ||
} | ||
} | ||
$stmt->closeCursor(); | ||
} | ||
return $block; | ||
} | ||
|
||
public function exportRoutes($lastExport, $areaIds) | ||
{ | ||
$block = new ExportBlock(); | ||
if (sizeof ($areaIds) > 0) { | ||
$stmt = $this->conn->query('SELECT r.*, a.territoryId, x.registrationType, x.startTime, x.endTime, x.externalRegistrationUrl FROM `'.EdkTables::ROUTE_TBL.'` r ' | ||
. 'INNER JOIN `'.CoreTables::AREA_TBL.'` a ON a.`id` = r.`areaId` ' | ||
. 'LEFT JOIN `'.EdkTables::REGISTRATION_SETTINGS_TBL.'` x ON x.`routeId` = r.`id` ' | ||
. 'WHERE r.`areaId` IN ('.implode(',', $areaIds).') AND r.`approved` = 1'); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$block->addId($row['id']); | ||
if ($row['updatedAt'] > $lastExport) { | ||
$block->addUpdate($row); | ||
} | ||
} | ||
$stmt->closeCursor(); | ||
} | ||
return $block; | ||
} | ||
|
||
public function exportRouteDescriptions($lastExport, $routeIds) | ||
{ | ||
$block = new ExportBlock(); | ||
if (sizeof ($routeIds) > 0) { | ||
$stmt = $this->conn->query('SELECT `routeId`, `noteType`, `content`, `lastUpdatedAt` FROM `'.EdkTables::ROUTE_NOTE_TBL.'` WHERE `routeId` IN ('.implode(',', $routeIds).') '); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$block->addId(['routeId' => $row['routeId'], 'noteType' => $row['noteType']]); | ||
if ($row['lastUpdatedAt'] > $lastExport) { | ||
$block->addUpdate($row); | ||
} | ||
} | ||
$stmt->closeCursor(); | ||
} | ||
return $block; | ||
} | ||
} |
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