Skip to content

Commit

Permalink
Dosyalar Aktarıldı
Browse files Browse the repository at this point in the history
  • Loading branch information
ismail0234 committed Nov 22, 2019
1 parent 938fed0 commit 50be64d
Show file tree
Hide file tree
Showing 14 changed files with 1,438 additions and 1 deletion.
175 changes: 175 additions & 0 deletions IS/PazarYeri/Trendyol/Helper/Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php

namespace IS\PazarYeri\Trendyol\Helper;

Class Database
{

/**
*
* SQLite Veritabanı Bağlantısı
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
*
*/
protected $db = null;

/**
*
* SQLite Veritabanı Sınıfı Oluşturucu
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
*
*/
public function __construct($firstSetupDate)
{
$this->checkSQLiteAndPDODriver();

$SQLitePath = __DIR__ . '/../Data/';
if (!file_exists($SQLitePath)) {
mkdir($SQLitePath, 0777);
}

$this->db = new \PDO("sqlite:" . $SQLitePath . 'trendyol.sqlite');
$this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->checkAndCreateTables($firstSetupDate);
}

/**
*
* SQLite ve PDO sürücülerini kontrol etme
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
*
*/
protected function checkSQLiteAndPDODriver()
{

$response = \PDO::getAvailableDrivers();
if (count($response) <= 0 || empty($response)) {
throw new N11Exception("Sunucunuzda PDO Aktif Olmalıdır.");
}

if (!in_array('sqlite', $response)) {
throw new N11Exception("Sunucunuzda SQLite PDO Sürücüsü Aktif Olmalıdır.");
}

}

/**
*
* SQLite Veritabanı tablolarını kontrol etme ve oluşturma
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
*
*/
public function checkAndCreateTables($firstSetupDate)
{

$sqlQuerys = array(
'CREATE TABLE IF NOT EXISTS `orders` (
`orderid` INTEGER NOT NULL ,
`status` TINYINT NOT NULL DEFAULT \'0\' ,
`date` INTEGER NOT NULL ,
PRIMARY KEY (`orderid`)
);',
'CREATE TABLE IF NOT EXISTS `settings` (
`lastOrderDate` INTEGER NOT NULL DEFAULT \'0\'
);',
);

foreach ($sqlQuerys as $sql) {
$this->db->query($sql);
}

$settings = $this->selectSettings();
if (!isset($settings->lastOrderId)) {
$prepare = $this->db->prepare('INSERT INTO settings (lastOrderDate) VALUES(?)');
$prepare->execute(array($firstSetupDate));
}

}

/**
*
* Siparişleri SQLite üzerinde tamamlandı olarak işaretleme
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param int $orderId
* @return bool
*
*/
public function updateStartDate($startDate)
{
$prepare = $this->db->prepare('UPDATE `settings` SET lastOrderDate = ?');
return $prepare->execute(array($startDate));
}

/**
*
* Siparişleri SQLite üzerinde tutma
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param int $orderId
* @return int
*
*/
public function addOrder($orderId)
{

$prepare = $this->db->prepare('INSERT INTO `orders` (orderid, status, date) VALUES(?, ?, ?)');
$prepare->execute(array($orderId, 0 , time()));
return $this->db->lastInsertId();

}

/**
*
* Siparişleri SQLite üzerinde kontrol etme
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param int $orderId
* @return object
*
*/
public function selectOrder($orderId)
{

$prepare = $this->db->prepare('SELECT * FROM `orders` WHERE orderid = ?');
$prepare->execute(array($orderId));
return $prepare->fetch(\PDO::FETCH_OBJ);
}

/**
*
* Siparişleri SQLite üzerinde tamamlandı olarak işaretleme
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param int $orderId
* @return bool
*
*/
public function finishOrder($orderId)
{

$prepare = $this->db->prepare('UPDATE `orders` SET status = ? WHERE orderid = ?');
return $prepare->execute(array(1 , $orderId));
}

/**
*
* WebHookService Ayarlarını getirir.
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @return object
*
*/
public function selectSettings()
{

$prepare = $this->db->prepare('SELECT * FROM `settings`');
$prepare->execute();
return $prepare->fetch(\PDO::FETCH_OBJ);
}

}
85 changes: 85 additions & 0 deletions IS/PazarYeri/Trendyol/Helper/Format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace IS\PazarYeri\Trendyol\Helper;

Class Format
{

public static function initialize($query, $data)
{

if ($data === true) {
$data = array();
}

if ($query === true) {
$query = $data;
}

$responseList = array();
foreach ($query as $key => $value)
{
if (!isset($data[$key])) {
continue;
}

if (isset($value['required']) && !in_array($data[$key], $value['required'] )) {
continue;
}

if (isset($value['format'])) {
$formatName = $value['format'];
$data[$key] = self::$formatName($data[$key]);
}

$responseList[$key] = self::trim($data[$key]);
}

return $responseList;
}

/**
*
* Url içerisindeki özel parametleri ayıklar
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param string $apiUrl
* @return array
*
*/
public function getUrlSpecialParameters($apiUrl)
{
if(preg_match_all('@\{(.*?)\}@si', $apiUrl, $output))
{
return $output[1];
}
return array();
}

/**
*
* UnixTime değerini milisaniye cinsine çevririr.
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param int $timestamp
*
*/
public static function unixTime($timestamp)
{
return $timestamp * 1000;
}

/**
*
* Metnin başındaki ve sonundaki boşlukları siler.
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param int $timestamp
*
*/
public static function trim($text)
{
return trim($text);
}

}
84 changes: 84 additions & 0 deletions IS/PazarYeri/Trendyol/Helper/Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace IS\PazarYeri\Trendyol\Helper;

use IS\PazarYeri\Trendyol\Services;

Class GateWay
{

/**
*
* @description Trendyol Api Supplier Id
*
*/
public $apiSupplierId;

/**
*
* @description Trendyol Api Kullanıcı Adı
*
*/
public $apiUsername;

/**
*
* @description Trendyol Api Şifre
*
*/
public $apiPassword;

/**
*
* @description REST Api için kabul edilen servisler
*
*/
protected $allowedServices = array(
'brand' => 'BrandService',
'cargo' => 'CargoService',
'category' => 'CategoryService',
'product' => 'ProductService',
'order' => 'OrderService',
'webhook' => 'WebhookService',
);

/**
*
* @description REST Api servislerinin ilk çağırma için hazırlanması
* @param string
* @return service
*
*/
public function __get($name)
{
if (!isset($this->allowedServices[$name])) {
throw new TrendyolException("Geçersiz Servis!");
}

if (isset($this->$name)) {
return $this->$name;
}

$this->$name = $this->createServiceInstance($this->allowedServices[$name]);
return $this->$name;
}

/**
*
* Servis sınıfının ilk örneğini oluşturma
*
* @author Ismail Satilmis <ismaiil_0234@hotmail.com>
* @param string $serviceName
* @return string
*
*/
protected function createServiceInstance($serviceName)
{
$serviceName = "IS\PazarYeri\Trendyol\Services\\" . $serviceName;
if (!class_exists($serviceName)) {
throw new TrendyolException("Geçersiz Servis!");
}
return new $serviceName($this->apiSupplierId, $this->apiUsername, $this->apiPassword);
}

}
Loading

0 comments on commit 50be64d

Please sign in to comment.