Created
September 7, 2017 10:10
-
-
Save shlaikov/3f54973ed15bb5d30cc750411a278512 to your computer and use it in GitHub Desktop.
ShopWindows Article, Catalog
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
<?php | |
class Article | |
{ | |
private $posCode; | |
private $article; | |
private $xml; | |
public function __construct($posCode, $article) | |
{ | |
$this->posCode = $posCode; | |
$this->article = $article; | |
$this->xml = $this->getArticle(); | |
} | |
public function model() | |
{ | |
return array( | |
'_id' => $this->article, | |
'xml' => $this->xml | |
); | |
} | |
private function getArticle() | |
{ | |
$request = new GetArticle($this->posCode, $this->article); | |
return $request->execute(); | |
} | |
} |
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
<?php | |
class Catalog | |
{ | |
private $id; | |
private $xml; | |
public function __construct($posCode) { | |
$this->id = $posCode; | |
$this->xml = $this->getCatalog(); | |
} | |
public function model() | |
{ | |
return array( | |
'_id' => $this->id, | |
'xml' => $this->xml | |
); | |
} | |
private function getCatalog() | |
{ | |
$request = new GetCatalog($this->id); | |
return $request->execute(); | |
} | |
} |
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
<?php | |
class GetArticle | |
{ | |
protected $posCode; | |
protected $articleAbbrev; | |
public function execute() | |
{ | |
return $this->doRequest(); | |
} | |
public function __construct($posCode, $article) | |
{ | |
$this->posCode = $posCode; | |
$this->articleAbbrev = $article; | |
} | |
private function setUrl() | |
{ | |
$url = PCInterface::BASE_URL; | |
$url .= 'pos/posservlet?artCode='; | |
$url .= $this->articleAbbrev; | |
$url .= '&posCode='. $this->posCode; | |
$url .= '&op=getArticle'; | |
return $url; | |
} | |
private function doRequest() | |
{ | |
$ch= curl_init(); | |
curl_setopt ($ch, CURLOPT_URL, $this->setUrl()); | |
curl_setopt($ch,CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$data = curl_exec($ch); | |
curl_close ($ch); | |
return($data); | |
} | |
public function getArticlesFromCatalog($posCode) | |
{ | |
$request = new GetCatalog($posCode); | |
$data = $request->execute(); | |
$catalog = new SimpleXMLElement($data); | |
foreach ($catalog->category->articles->article as $article) { | |
var_dump($article['code']); | |
} | |
} | |
} |
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
<?php | |
class GetCatalog | |
{ | |
protected $posCode; | |
public function execute() | |
{ | |
return $this->doRequest(); | |
} | |
public function __construct($posCode) | |
{ | |
$this->posCode = $posCode; | |
} | |
private function setUrl() | |
{ | |
$url = PCInterface::BASE_URL; | |
$url .= 'pos/posservlet?posCode='; | |
$url .= $this->posCode; | |
$url .= '&op=getCatalog'; | |
return $url; | |
} | |
private function doRequest() | |
{ | |
$ch= curl_init(); | |
curl_setopt ($ch, CURLOPT_URL, $this->setUrl()); | |
curl_setopt($ch,CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$data = curl_exec($ch); | |
curl_close ($ch); | |
return($data); | |
} | |
} |
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
<?php | |
class UpdateCollections | |
{ | |
private $params; | |
private $posCode; | |
private $articles; | |
private $collections = array('Article','Catalog'); | |
public function update(array $params) | |
{ | |
$this->params = $params; | |
$this->posCode = $params['POS_CODE']; | |
$this->articles = Project::getInstance()->getArticles($this->posCode); | |
$mongo = MongoConnector::connect(); | |
$db = $mongo->selectDB($params['connectUrl']); | |
foreach ($this->articles as $article) { | |
foreach ($this->setCollections() as $collection) { | |
$db->createCollection($collection); | |
$cursor = $db->selectCollection($collection); | |
$cursor->save($this->fill($collection, $article)); | |
} | |
} | |
$mongo->close(); | |
} | |
private function fill($collection, $article) | |
{ | |
switch ($collection) { | |
case 'Article': | |
$data = $this->getArticleData($this->posCode, $article); | |
return $data; | |
break; | |
case 'Catalog': | |
$data = $this->getCatalogData($this->posCode); | |
return $data; | |
break; | |
} | |
return null; | |
} | |
public function getArticleData($posCode, $id) | |
{ | |
return (new Article($posCode, $id))->model(); | |
} | |
public function getCatalogData($posCode) | |
{ | |
return (new Catalog($posCode))->model(); | |
} | |
private function setCollections() | |
{ | |
return $this->collections; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment