167 lines
3.8 KiB
PHP
167 lines
3.8 KiB
PHP
<?php
|
|
require_once dirname(__FILE__) . '/Service.php';
|
|
|
|
/**
|
|
* Infogreffe : Document Statut
|
|
*/
|
|
class SdMetier_Infogreffe_DocST extends SdMetier_Infogreffe_Service
|
|
{
|
|
|
|
/**
|
|
* Db Adapter
|
|
* @var Zend_Db_Adapter_Abstract
|
|
*/
|
|
public $db;
|
|
|
|
/**
|
|
*
|
|
* @param string $siren
|
|
*/
|
|
public function __construct($siren, $db = null)
|
|
{
|
|
parent::__construct();
|
|
|
|
//Set type
|
|
$this->type_document = 'ST';
|
|
|
|
//Set Siren
|
|
$this->siren = $siren;
|
|
|
|
//Get defaut database adapter
|
|
if ($db === null) {
|
|
$this->db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
|
} else {
|
|
$this->db = $db;
|
|
}
|
|
}
|
|
|
|
public function getList()
|
|
{
|
|
|
|
}
|
|
|
|
public function getCommandeT()
|
|
{
|
|
|
|
$this->mode_diffusion = 'T';
|
|
$this->reference_client = 'T'.date('YmdHis');
|
|
|
|
//Set the filename
|
|
$filename = $this->getFilePath($type, $dateCloture) . '/' . $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 ) {
|
|
$commandeM = new Application_Model_Sdv1GreffeCommandesBi();
|
|
$commandeM->update(array(
|
|
'cmdUrl'=> $url,
|
|
'dateCommande' => date('YmdHis'),
|
|
), '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)
|
|
{
|
|
if ($type=='') {
|
|
$type = 'sociaux';
|
|
}
|
|
$dir = 'bilans' . '/' . $type . '/' . substr($dateCloture,0,4);
|
|
if ( !file_exists( $this->config->storage->path . '/' . $dir ) ) {
|
|
mkdir($this->config->storage->path . '/' . $dir, 0777, true);
|
|
}
|
|
return $dir;
|
|
}
|
|
|
|
/**
|
|
* 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 = '')
|
|
{
|
|
|
|
}
|
|
} |