webservice/library/Metier/Infogreffe/DocST.php
Michael RICOIS 53e213202b CS PSR-2
2016-11-24 16:02:49 +01:00

166 lines
3.9 KiB
PHP
Executable File

<?php
require_once dirname(__FILE__) . '/Service.php';
/**
* Infogreffe : Document Statut
*/
class Metier_Infogreffe_DocST extends Metier_Infogreffe_Service
{
/**
* PDO Connection with Doctrine
* @var \Doctrine\DBAL\Connection
*/
protected $conn;
/**
* Infogreffe : Document Bilan
* @param \Doctrine\DBAL\Connection $conn
*/
public function __construct($conn = null)
{
parent::__construct();
// Set Database
if ($conn === null) {
$this->conn = Zend_Registry::get('doctrine');
} else {
$this->conn = $conn;
}
// Set type
$this->type_document = 'ST';
}
/**
* Défini le SIREN
* @param string $siren
* @return void
*/
public function setSiren($siren)
{
$this->siren = $siren;
}
public function getList()
{
}
public function getCommandeT()
{
$this->mode_diffusion = 'T';
$this->reference_client = 'T'.date('YmdHis');
$dir = $this->getFilePath($type, $dateCloture);
if (! file_exists($this->config->storage->path . '/' . $dir)) {
mkdir($this->config->storage->path . '/' . $dir, 0777, true);
}
//Set the filename
$filename = $dir . '/' . $this->getFileName($type, $dateCloture);
try {
$xml = $this->callRequest();
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode());
}
$item = $this->formatItem($xml);
$url = $item['url_acces'];
if (empty($url)) {
throw new Exception('File url not given');
}
if ($orderId !== null) {
$this->conn->update('sdv1.greffe_commandes_st', array(
'cmdUrl' => $url,
'dateCommande' => date('YmdHis')),
array('id' => $orderId));
}
//Récupérer le fichier
$getfile = $this->download($url, $filename);
//Analyser le fichier - Nombre de page et taille
$infos = $this->pdfInfos($getfile);
//Enregistrer les infos du fichier dans la base de données
if (false !== $infos) {
$this->dbSetFile(basename($filename), $infos['size'], $infos['pages'], $infos['version']);
} else {
$this->dbSetFile(basename($filename));
}
return $filename;
}
/**
* Name of file
* @param string $type
* @param string $dateCloture
* Format : AAAA-MM-JJ
* @return string
*/
public function getFileName($type, $dateCloture)
{
if ($type=='') {
$type = 'sociaux';
}
$date = substr($dateCloture, 0, 4).substr($dateCloture, 5, 2).substr($dateCloture, 8, 2);
return 'ST-' . $this->siren . '-' . $type . '-' . $date . '.pdf';
}
/**
* Path of file
* @param string $type
* @param string $dateCloture
* Format : AAAA-MM-JJ
* @return string
*/
public function getFilePath($type, $dateCloture)
{
return 'statut/' . $type . '/' . substr($dateCloture, 0, 4);
}
/**
* Format XML to Array for a list of items
* @param string $xml
* @return array
*/
protected function formatList($xml)
{
}
/**
* Format XML to Array for one item
* @param string $xml
* @return array
*/
protected function formatItem($xml)
{
}
/**
* Update informations about an item in database
* @param array $list
* @return boolean
*/
protected function dbUpdateItem($list)
{
}
/**
* Set file informations in database
* @param string $filename
* @param int $size
* @param int $numberOfPage
* @param string $version
* @return boolean
*/
public function dbSetFile($filename, $size = 0, $numberOfPage = '', $version = '')
{
}
}