96 lines
2.3 KiB
PHP
96 lines
2.3 KiB
PHP
<?php
|
|
class PagePrint
|
|
{
|
|
protected $controller = null;
|
|
protected $action = null;
|
|
|
|
protected $pagePRINT = array(
|
|
'identite-fiche' => 'siret,id',
|
|
'identite-etablissements' => 'siret,id,actif',
|
|
'identite-liens' => 'siret,id',
|
|
'identite-evenements' => 'siret,id',
|
|
);
|
|
|
|
protected $pagePDF = array(
|
|
'identite-fiche' => 'siret,id',
|
|
'identite-etablissements' => 'siret,id,actif',
|
|
'identite-liens' => 'siret,id',
|
|
'identite-evenements' => 'siret,id',
|
|
);
|
|
|
|
protected $pageXML = array(
|
|
'identite-fiche' => 'siret,id',
|
|
'identite-etablissements' => 'siret,id,actif',
|
|
'identite-liens' => 'siret,id',
|
|
'identite-evenements' => 'siret,id',
|
|
);
|
|
|
|
public function __construct($controller, $action)
|
|
{
|
|
$this->controller = $controller;
|
|
$this->action = $action;
|
|
}
|
|
|
|
protected function getTypeElement($type)
|
|
{
|
|
$element = array();
|
|
switch($type){
|
|
case 'print':
|
|
$element = $this->pagePRINT;
|
|
break;
|
|
case 'pdf':
|
|
$element = $this->pagePDF;
|
|
break;
|
|
case 'xml':
|
|
$element = $this->pageXML;
|
|
break;
|
|
}
|
|
return $element;
|
|
}
|
|
|
|
public function exportable($type)
|
|
{
|
|
$element = $this->getTypeElement($type);
|
|
if (array_key_exists($this->controller.'-'.$this->action, $element)){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function filename($type, $params = array())
|
|
{
|
|
$element = $this->getTypeElement($type);
|
|
$filename = $this->controller.'-'.$this->action;
|
|
$key = $this->controller.'-'.$this->action;
|
|
if (array_key_exists($key, $element)){
|
|
$part = explode(',', $element[$key]);
|
|
foreach( $part as $item ){
|
|
if (!empty($params[$item])){
|
|
$filename.= '-'.$params[$item];
|
|
}
|
|
}
|
|
}
|
|
return $filename;
|
|
}
|
|
|
|
public function objectToXML($object, $params)
|
|
{
|
|
require_once 'XML/Serializer.php';
|
|
$options = array (
|
|
'addDecl' => TRUE,
|
|
'encoding' => 'UTF-8',
|
|
'indent' => ' ',
|
|
'rootName' => 'root',
|
|
'defaultTagName' => 'element',
|
|
);
|
|
// Instantiate the serializer with the options
|
|
$Serializer = new XML_Serializer($options);
|
|
// Serialize the data structure
|
|
$result = $Serializer->serialize($object);
|
|
if($result === true) {
|
|
$content = $Serializer->getSerializedData();
|
|
$filename = $this->filename('xml', $params);
|
|
file_put_contents(APPLICATION_PATH.'/../cache/pagesxml/'.$filename.'.xml', $content);
|
|
}
|
|
}
|
|
} |