-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
4,274 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
/.idea/ |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<?php | ||
|
||
namespace Mk\Feed\Generators; | ||
|
||
use Latte\Engine; | ||
use Mk\Feed\Storage; | ||
use Nette\Object; | ||
use Mk\Feed\FileEmptyException; | ||
use Mk\Feed\ItemIncompletedException; | ||
|
||
|
@@ -12,7 +12,10 @@ | |
* @author Martin Knor <[email protected]> | ||
* @package Mk\Feed\Generators | ||
*/ | ||
abstract class BaseGenerator extends Object implements IGenerator { | ||
abstract class BaseGenerator implements IGenerator { | ||
|
||
/* Použití smartobject viz php 7.2 to nette 2.4 */ | ||
use \Nette\SmartObject; | ||
|
||
/** @var bool true if some products added */ | ||
private $prepared = false; | ||
|
@@ -23,6 +26,18 @@ abstract class BaseGenerator extends Object implements IGenerator { | |
/** @var \Mk\Feed\Storage */ | ||
private $storage; | ||
|
||
/** @var array */ | ||
private $config; | ||
|
||
/** @var string */ | ||
private $link; | ||
|
||
/** @var string */ | ||
private $description; | ||
|
||
/** @var string */ | ||
private $storeName; | ||
|
||
/** | ||
* BaseGenerator constructor. | ||
* @param \Mk\Feed\Storage $storage | ||
|
@@ -32,6 +47,30 @@ public function __construct(Storage $storage) | |
$this->storage = $storage; | ||
} | ||
|
||
/** | ||
* @param string $link | ||
*/ | ||
public function setLink(string $link): void { | ||
$this->link = $link; | ||
} | ||
|
||
/** | ||
* @param string $description | ||
*/ | ||
public function setDescription(string $description): void { | ||
$this->description = $description; | ||
} | ||
|
||
/** | ||
* @param string $storeName | ||
*/ | ||
public function setStoreName(string $storeName): void { | ||
$this->storeName = $storeName; | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* @param $name | ||
* @return string path to template | ||
|
@@ -45,6 +84,7 @@ abstract protected function getTemplate($name); | |
protected function prepare() | ||
{ | ||
$this->handle = tmpfile(); | ||
|
||
$this->prepareTemplate('header'); | ||
$this->prepared = true; | ||
} | ||
|
@@ -103,11 +143,15 @@ public function save($filename) | |
*/ | ||
protected function prepareTemplate($template) | ||
{ | ||
|
||
$latte = new Engine; | ||
$content = $latte->renderToString($this->getTemplate($template), array('storeName' => $this->storeName, 'description' => $this->description, 'link' => $this->link)); | ||
$file = $this->getTemplate($template); | ||
$footerHandle = fopen('safe://' . $file, 'r'); | ||
$footer = fread($footerHandle, filesize($file)); | ||
fclose($footerHandle); | ||
fwrite($this->handle, $footer); | ||
fwrite($this->handle, $content); | ||
// fwrite($this->handle, $footer); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -10,15 +10,18 @@ | |
* @author Martin Knor <[email protected]> | ||
* @package Mk\Feed\Generators\Zbozi | ||
*/ | ||
abstract class BaseItem extends Nette\Object implements Mk\Feed\Generators\IItem | ||
abstract class BaseItem implements Mk\Feed\Generators\IItem | ||
{ | ||
|
||
/* Použití smartobject viz php 7.2 to nette 2.4 */ | ||
use \Nette\SmartObject; | ||
/** | ||
* Validate item | ||
* @return bool return true if item is valid | ||
*/ | ||
public function validate() { | ||
$reflection = $this->getReflection(); | ||
|
||
$reflection = new Nette\Reflection\ClassType(get_called_class()); | ||
|
||
foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $v) { | ||
if ($v->getAnnotation('required')) { | ||
|
@@ -30,4 +33,5 @@ public function validate() { | |
|
||
return TRUE; | ||
} | ||
|
||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace Mk\Feed\Generators\Custom; | ||
|
||
use Nette\Caching\Cache; | ||
use Nette\Caching\IStorage; | ||
|
||
class CategoriesHelper { | ||
|
||
CONST CATEGORY_URL = 'http://www.heureka.cz/direct/xml-export/shops/heureka-sekce.xml'; | ||
|
||
/** @var \Nette\Caching\Cache */ | ||
private $cache; | ||
|
||
function __construct(IStorage $storage = null) | ||
{ | ||
if ($storage) { | ||
$this->cache = new Cache($storage, __CLASS__); | ||
} | ||
} | ||
|
||
public function getCategories() | ||
{ | ||
$categories = array(); | ||
if (!$this->cache || !($categories = $this->cache->load('categories'))) { | ||
$xml = file_get_contents(self::CATEGORY_URL); | ||
$dom = new \DOMDocument(); | ||
|
||
$dom->loadXML($xml); | ||
$xpath = new \DOMXPath($dom); | ||
/** @var \DOMElement[] $_categories */ | ||
$_categories = $xpath->query(".//CATEGORY"); | ||
|
||
foreach ($_categories as $category) { | ||
$categoryIdElement = $xpath->query($category->getNodePath().'/CATEGORY_ID'); | ||
$id = isset($categoryIdElement[0]) ? (int)$categoryIdElement[0]->nodeValue : null; | ||
|
||
$categoryFullNameElement = $xpath->query($category->getNodePath().'/CATEGORY_FULLNAME'); | ||
$_cat = isset($categoryFullNameElement[0]) ? (string)$categoryFullNameElement[0]->nodeValue : null; | ||
|
||
if($id && $_cat) { | ||
$_cat = str_replace('Heureka.cz | ', '', $_cat); | ||
$categories[$id] = $_cat; | ||
} | ||
} | ||
|
||
asort($categories); | ||
|
||
if ($this->cache) { | ||
$this->cache->save('categories', $categories); | ||
} | ||
} | ||
|
||
return $categories; | ||
} | ||
} |
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,116 @@ | ||
<?php | ||
|
||
namespace Mk\Feed\Generators\Custom; | ||
|
||
use Mk, Nette; | ||
|
||
/** | ||
* Class Delivery | ||
* @author Martin Knor <[email protected]> | ||
* @package Mk\Feed\Generators\Heureka | ||
*/ | ||
class Delivery{ | ||
|
||
/* Použití smartobject viz php 7.2 to nette 2.4 */ | ||
use \Nette\SmartObject; | ||
|
||
CONST CESKA_POSTA = 'CESKA_POSTA', | ||
CESKA_POSTA_NA_POSTU = 'CESKA_POSTA_NA_POSTU', | ||
CSAD_LOGISTIK_OSTRAVA = 'CSAD_LOGISTIK_OSTRAVA', | ||
DPD = 'DPD', | ||
DHL = 'DHL', | ||
DSV = 'DSV', | ||
EMS = 'EMS', | ||
FOFR = 'FOFR', | ||
GEBRUDER_WEISS = 'GEBRUDER_WEISS', | ||
GEIS = 'GEIS', | ||
GENERAL_PARCEL = 'GENERAL_PARCEL', | ||
GLS = 'GLS', | ||
HDS = 'HDS', | ||
HEUREKAPOINT = 'HEUREKAPOINT', | ||
INTIME = 'INTIME', | ||
PPL = 'PPL', | ||
RADIALKA = 'RADIALKA', | ||
SEEGMULLER = 'SEEGMULLER', | ||
TNT = 'TNT', | ||
TOPTRANS = 'TOPTRANS', | ||
UPS = 'UPS', | ||
ULOZENKA = 'ULOZENKA', | ||
VLASTNI_PREPRAVA = 'VLASTNI_PREPRAVA', | ||
ZASILKOVNA = 'ZASILKOVNA'; | ||
|
||
static $ids = array( | ||
self::CESKA_POSTA, | ||
self::CESKA_POSTA_NA_POSTU, | ||
self::CSAD_LOGISTIK_OSTRAVA, | ||
self::DPD, | ||
self::DHL, | ||
self::DSV, | ||
self::EMS, | ||
self::FOFR, | ||
self::GEBRUDER_WEISS, | ||
self::GEIS, | ||
self::GENERAL_PARCEL, | ||
self::GLS, | ||
self::HDS, | ||
self::HEUREKAPOINT, | ||
self::INTIME, | ||
self::PPL, | ||
self::RADIALKA, | ||
self::SEEGMULLER, | ||
self::TNT, | ||
self::TOPTRANS, | ||
self::UPS, | ||
self::ULOZENKA, | ||
self::VLASTNI_PREPRAVA, | ||
self::ZASILKOVNA, | ||
); | ||
|
||
/** @var string */ | ||
private $id; | ||
/** @var float */ | ||
private $price; | ||
/** @var float|null */ | ||
private $priceCod; | ||
|
||
/** | ||
* Delivery constructor. | ||
* @param $id | ||
* @param $price | ||
* @param null $priceCod | ||
*/ | ||
public function __construct($id, $price, $priceCod = null) | ||
{ | ||
if (!in_array($id, self::$ids)) { | ||
throw new \InvalidArgumentException("Delivery with id $id doesn\t exist"); | ||
} | ||
$this->id = (string) $id; | ||
$this->price = (float) $price; | ||
$this->priceCod = isset($priceCod) ? (float) $priceCod : null; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getPrice() | ||
{ | ||
return $this->price; | ||
} | ||
|
||
/** | ||
* @return float|null | ||
*/ | ||
public function getPriceCod() | ||
{ | ||
return $this->priceCod; | ||
} | ||
|
||
} |
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,24 @@ | ||
<?php | ||
namespace Mk\Feed\Generators\Custom; | ||
|
||
use Mk\Feed\Generators\BaseGenerator; | ||
|
||
/** | ||
* Class HeurekaGenerator | ||
* @author Martin Knor <[email protected]> | ||
* @package Mk\Feed\Generators | ||
* @see http://sluzby.heureka.cz/napoveda/xml-feed/ Documentation | ||
*/ | ||
abstract class Generator extends BaseGenerator { | ||
|
||
/** | ||
* @param $name | ||
* @return string | ||
*/ | ||
protected function getTemplate($name) | ||
{ | ||
$reflection = new \ReflectionClass(__CLASS__); | ||
return dirname($reflection->getFileName()) . '/latte/' . $name . '.latte'; | ||
} | ||
|
||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Mk\Feed\Generators\Custom; | ||
|
||
use Mk, Nette; | ||
|
||
/** | ||
* Class Gift | ||
* @author Martin Knor <[email protected]> | ||
* @package Mk\Feed\Generators\Heureka | ||
*/ | ||
class Gift { | ||
|
||
/* Použití smartobject viz php 7.2 to nette 2.4 */ | ||
use \Nette\SmartObject; | ||
|
||
/** @var string */ | ||
protected $name; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Gift constructor. | ||
* @param $name | ||
*/ | ||
public function __construct($name) | ||
{ | ||
|
||
$this->name = (string)$name; | ||
} | ||
|
||
} |
Oops, something went wrong.