mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 13:33:14 +00:00
Fix CS
This commit is contained in:
@@ -18,71 +18,63 @@
|
||||
class module_admin
|
||||
{
|
||||
|
||||
function getTree($position=false)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$usr_id = $session->get_usr_id();
|
||||
|
||||
$user = User_Adapter::getInstance($usr_id, $appbox);
|
||||
|
||||
$available = array(
|
||||
'connected'
|
||||
, 'registrations'
|
||||
, 'taskmanager'
|
||||
, 'base'
|
||||
, 'bases'
|
||||
, 'collection'
|
||||
, 'user'
|
||||
, 'users'
|
||||
);
|
||||
|
||||
$feature = 'connected';
|
||||
$featured = false;
|
||||
$position = explode(':', $position);
|
||||
if (count($position) > 0)
|
||||
function getTree($position = false)
|
||||
{
|
||||
if (in_array($position[0], $available))
|
||||
{
|
||||
$feature = $position[0];
|
||||
if (isset($position[1]))
|
||||
$featured = $position[1];
|
||||
}
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$usr_id = $session->get_usr_id();
|
||||
|
||||
$user = User_Adapter::getInstance($usr_id, $appbox);
|
||||
|
||||
$available = array(
|
||||
'connected'
|
||||
, 'registrations'
|
||||
, 'taskmanager'
|
||||
, 'base'
|
||||
, 'bases'
|
||||
, 'collection'
|
||||
, 'user'
|
||||
, 'users'
|
||||
);
|
||||
|
||||
$feature = 'connected';
|
||||
$featured = false;
|
||||
$position = explode(':', $position);
|
||||
if (count($position) > 0) {
|
||||
if (in_array($position[0], $available)) {
|
||||
$feature = $position[0];
|
||||
if (isset($position[1]))
|
||||
$featured = $position[1];
|
||||
}
|
||||
}
|
||||
|
||||
$databoxes = $off_databoxes = array();
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
try {
|
||||
if ( ! $user->ACL()->has_access_to_sbas($databox->get_sbas_id()))
|
||||
continue;
|
||||
|
||||
$connbas = $databox->get_connection();
|
||||
} catch (Exception $e) {
|
||||
$off_databoxes[] = $databox;
|
||||
continue;
|
||||
}
|
||||
$databoxes[] = $databox;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'feature' => $feature
|
||||
, 'featured' => $featured
|
||||
, 'databoxes' => $databoxes
|
||||
, 'off_databoxes' => $off_databoxes
|
||||
);
|
||||
|
||||
|
||||
$core = \bootstrap::getCore();
|
||||
$twig = $core->getTwig();
|
||||
|
||||
return $twig->render('admin/tree.html.twig', $params);
|
||||
}
|
||||
|
||||
$databoxes = $off_databoxes = array();
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!$user->ACL()->has_access_to_sbas($databox->get_sbas_id()))
|
||||
continue;
|
||||
|
||||
$connbas = $databox->get_connection();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$off_databoxes[] = $databox;
|
||||
continue;
|
||||
}
|
||||
$databoxes[] = $databox;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'feature' => $feature
|
||||
, 'featured' => $featured
|
||||
, 'databoxes' => $databoxes
|
||||
, 'off_databoxes' => $off_databoxes
|
||||
);
|
||||
|
||||
|
||||
$core = \bootstrap::getCore();
|
||||
$twig = $core->getTwig();
|
||||
|
||||
return $twig->render('admin/tree.html.twig', $params);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -18,25 +18,24 @@
|
||||
class module_client
|
||||
{
|
||||
|
||||
public function getLanguage($lng)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$out = array();
|
||||
$out['createWinInvite'] = _('paniers:: Quel nom souhaitez vous donner a votre panier ?');
|
||||
$out['chuNameEmpty'] = _('paniers:: Quel nom souhaitez vous donner a votre panier ?');
|
||||
$out['noDLok'] = _('export:: aucun document n\'est disponible au telechargement');
|
||||
$out['confirmRedirectAuth'] = _('invite:: Redirection vers la zone d\'authentification, cliquez sur OK pour continuer ou annulez');
|
||||
$out['serverName'] = $registry->get('GV_ServerName');
|
||||
$out['serverError'] = _('phraseanet::erreur: Une erreur est survenue, si ce probleme persiste, contactez le support technique');
|
||||
$out['serverTimeout'] = _('phraseanet::erreur: La connection au serveur Phraseanet semble etre indisponible');
|
||||
$out['serverDisconnected'] = _('phraseanet::erreur: Votre session est fermee, veuillez vous re-authentifier');
|
||||
$out['confirmDelBasket'] = _('paniers::Vous etes sur le point de supprimer ce panier. Cette action est irreversible. Souhaitez-vous continuer ?');
|
||||
$out['annuler'] = _('boutton::annuler');
|
||||
$out['fermer'] = _('boutton::fermer');
|
||||
$out['renewRss'] = _('boutton::renouveller');
|
||||
|
||||
return p4string::jsonencode($out);
|
||||
}
|
||||
public function getLanguage($lng)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$out = array();
|
||||
$out['createWinInvite'] = _('paniers:: Quel nom souhaitez vous donner a votre panier ?');
|
||||
$out['chuNameEmpty'] = _('paniers:: Quel nom souhaitez vous donner a votre panier ?');
|
||||
$out['noDLok'] = _('export:: aucun document n\'est disponible au telechargement');
|
||||
$out['confirmRedirectAuth'] = _('invite:: Redirection vers la zone d\'authentification, cliquez sur OK pour continuer ou annulez');
|
||||
$out['serverName'] = $registry->get('GV_ServerName');
|
||||
$out['serverError'] = _('phraseanet::erreur: Une erreur est survenue, si ce probleme persiste, contactez le support technique');
|
||||
$out['serverTimeout'] = _('phraseanet::erreur: La connection au serveur Phraseanet semble etre indisponible');
|
||||
$out['serverDisconnected'] = _('phraseanet::erreur: Votre session est fermee, veuillez vous re-authentifier');
|
||||
$out['confirmDelBasket'] = _('paniers::Vous etes sur le point de supprimer ce panier. Cette action est irreversible. Souhaitez-vous continuer ?');
|
||||
$out['annuler'] = _('boutton::annuler');
|
||||
$out['fermer'] = _('boutton::fermer');
|
||||
$out['renewRss'] = _('boutton::renouveller');
|
||||
|
||||
return p4string::jsonencode($out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,20 +26,19 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_aboutAuthors extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('List authors and contributors');
|
||||
$this->setDescription('List authors and contributors');
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -26,20 +26,19 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_aboutLicense extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('This program license');
|
||||
$this->setDescription('This program license');
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -25,233 +25,202 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_checkExtension extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Delete a documentation field from a Databox');
|
||||
|
||||
$this->addOption('usr_id', 'u', InputOption::VALUE_OPTIONAL, 'Usr_id to use. If no user, get the first available');
|
||||
|
||||
$this->addOption('query', '', InputOption::VALUE_OPTIONAL, 'The query', 'last');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!extension_loaded('phrasea2'))
|
||||
printf("Missing Extension php-phrasea");
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$usr_id = $input->getOption('usr_id');
|
||||
|
||||
try
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$TestUser = \User_Adapter::getInstance($usr_id, $appbox);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Wrong user !</error>");
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('Delete a documentation field from a Databox');
|
||||
|
||||
$this->addOption('usr_id', 'u', InputOption::VALUE_OPTIONAL, 'Usr_id to use. If no user, get the first available');
|
||||
|
||||
$this->addOption('query', '', InputOption::VALUE_OPTIONAL, 'The query', 'last');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\nWill do the check with user <info>%s</info> (%s)\n"
|
||||
, $TestUser->get_display_name()
|
||||
, $TestUser->get_email()
|
||||
)
|
||||
);
|
||||
|
||||
$output->writeln("PHRASEA FUNCTIONS");
|
||||
|
||||
foreach (get_extension_funcs("phrasea2") as $function)
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln("<info>$function</info>");
|
||||
|
||||
if ( ! extension_loaded('phrasea2'))
|
||||
printf("Missing Extension php-phrasea");
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$usr_id = $input->getOption('usr_id');
|
||||
|
||||
try {
|
||||
$TestUser = \User_Adapter::getInstance($usr_id, $appbox);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Wrong user !</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\nWill do the check with user <info>%s</info> (%s)\n"
|
||||
, $TestUser->get_display_name()
|
||||
, $TestUser->get_email()
|
||||
)
|
||||
);
|
||||
|
||||
$output->writeln("PHRASEA FUNCTIONS");
|
||||
|
||||
foreach (get_extension_funcs("phrasea2") as $function) {
|
||||
$output->writeln("<info>$function</info>");
|
||||
}
|
||||
|
||||
$Core = \bootstrap::getCore();
|
||||
$configuration = $Core->getConfiguration();
|
||||
$choosenConnection = $configuration->getPhraseanet()->get('database');
|
||||
$connexion = $configuration->getConnexion($choosenConnection);
|
||||
$hostname = $connexion->get('host');
|
||||
$port = $connexion->get('port');
|
||||
$user = $connexion->get('user');
|
||||
$password = $connexion->get('password');
|
||||
$dbname = $connexion->get('dbname');
|
||||
|
||||
$output->writeln("\n-- phrasea_conn --");
|
||||
|
||||
if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true) {
|
||||
$output->writeln("<error>Failed ! </error> got no connection");
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
$output->writeln("<info>Succes ! </info> got connection");
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
$output->writeln("\n-- phrasea_info --");
|
||||
|
||||
foreach (phrasea_info() as $key => $value) {
|
||||
$output->writeln("\t$key => $value");
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
$output->writeln("\n-- phrasea_create_session --");
|
||||
|
||||
$sessid = phrasea_create_session((string) $TestUser->get_id());
|
||||
|
||||
if (ctype_digit((string) $sessid)) {
|
||||
$output->writeln("<info>Succes ! </info> got session id $sessid");
|
||||
} else {
|
||||
$output->writeln("<error>Failed ! </error> got no session id");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_open_session --");
|
||||
|
||||
$ph_session = phrasea_open_session($sessid, $usr_id);
|
||||
|
||||
if ($ph_session) {
|
||||
$output->writeln("<info>Succes ! </info> got session ");
|
||||
} else {
|
||||
$output->writeln("<error>Failed ! </error> got no session ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_clear_cache --");
|
||||
|
||||
$ret = phrasea_clear_cache($sessid);
|
||||
|
||||
if ($sessid) {
|
||||
$output->writeln("<info>Succes ! </info> got session ");
|
||||
} else {
|
||||
$output->writeln("<error>Failed ! </error> got no session ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$tbases = array();
|
||||
|
||||
foreach ($ph_session["bases"] as $phbase) {
|
||||
$tcoll = array();
|
||||
foreach ($phbase["collections"] as $coll) {
|
||||
$tcoll[] = 0 + $coll["base_id"];
|
||||
}
|
||||
if (sizeof($tcoll) > 0) {
|
||||
$kbase = "S" . $phbase["sbas_id"];
|
||||
$tbases[$kbase] = array();
|
||||
$tbases[$kbase]["sbas_id"] = $phbase["sbas_id"];
|
||||
$tbases[$kbase]["searchcoll"] = $tcoll;
|
||||
$tbases[$kbase]["mask_xor"] = $tbases[$kbase]["mask_and"] = 0;
|
||||
|
||||
$qp = new searchEngine_adapter_phrasea_queryParser();
|
||||
$treeq = $qp->parsequery($input->getOption('query'));
|
||||
$arrayq = $qp->makequery($treeq);
|
||||
|
||||
$tbases[$kbase]["arrayq"] = $arrayq;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("\n-- phrasea_query --");
|
||||
|
||||
$nbanswers = 0;
|
||||
foreach ($tbases as $kb => $base) {
|
||||
$tbases[$kb]["results"] = NULL;
|
||||
|
||||
$ret = phrasea_query2(
|
||||
$ph_session["session_id"]
|
||||
, $base["sbas_id"]
|
||||
, $base["searchcoll"]
|
||||
, $base["arrayq"]
|
||||
, $registry->get('GV_sit')
|
||||
, $usr_id
|
||||
, FALSE
|
||||
, PHRASEA_MULTIDOC_DOCONLY
|
||||
, ''
|
||||
, array()
|
||||
);
|
||||
|
||||
|
||||
if ($ret) {
|
||||
$output->writeln("<info>Succes ! </info> got result on sbas_id " . $base["sbas_id"]);
|
||||
} else {
|
||||
$output->writeln("<error>Failed ! </error> No results on sbas_id " . $base["sbas_id"]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$tbases[$kb]["results"] = $ret;
|
||||
|
||||
$nbanswers += $tbases[$kb]["results"]["nbanswers"];
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("Got a total of <info>$nbanswers</info> answers");
|
||||
|
||||
$output->writeln("\n-- phrasea_fetch_results --");
|
||||
|
||||
$rs = phrasea_fetch_results($sessid, $usr_id, 1, true, '[[em]]', '[[/em]]');
|
||||
|
||||
if ($rs) {
|
||||
$output->writeln("<info>Succes ! </info> got result ");
|
||||
} else {
|
||||
$output->writeln("<error>Failed ! </error> got no result ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_close_session --");
|
||||
|
||||
$rs = phrasea_close_session($sessid);
|
||||
|
||||
if ($rs) {
|
||||
$output->writeln("<info>Succes ! </info> closed ! ");
|
||||
} else {
|
||||
$output->writeln("<error>Failed ! </error> not closed ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$Core = \bootstrap::getCore();
|
||||
$configuration = $Core->getConfiguration();
|
||||
$choosenConnection = $configuration->getPhraseanet()->get('database');
|
||||
$connexion = $configuration->getConnexion($choosenConnection);
|
||||
$hostname = $connexion->get('host');
|
||||
$port = $connexion->get('port');
|
||||
$user = $connexion->get('user');
|
||||
$password = $connexion->get('password');
|
||||
$dbname = $connexion->get('dbname');
|
||||
|
||||
$output->writeln("\n-- phrasea_conn --");
|
||||
|
||||
if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true)
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no connection");
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got connection");
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
$output->writeln("\n-- phrasea_info --");
|
||||
|
||||
foreach (phrasea_info() as $key => $value)
|
||||
{
|
||||
$output->writeln("\t$key => $value");
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
$output->writeln("\n-- phrasea_create_session --");
|
||||
|
||||
$sessid = phrasea_create_session((string) $TestUser->get_id());
|
||||
|
||||
if (ctype_digit((string) $sessid))
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got session id $sessid");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no session id");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_open_session --");
|
||||
|
||||
$ph_session = phrasea_open_session($sessid, $usr_id);
|
||||
|
||||
if ($ph_session)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got session ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no session ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_clear_cache --");
|
||||
|
||||
$ret = phrasea_clear_cache($sessid);
|
||||
|
||||
if ($sessid)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got session ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no session ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$tbases = array();
|
||||
|
||||
foreach ($ph_session["bases"] as $phbase)
|
||||
{
|
||||
$tcoll = array();
|
||||
foreach ($phbase["collections"] as $coll)
|
||||
{
|
||||
$tcoll[] = 0 + $coll["base_id"];
|
||||
}
|
||||
if (sizeof($tcoll) > 0)
|
||||
{
|
||||
$kbase = "S" . $phbase["sbas_id"];
|
||||
$tbases[$kbase] = array();
|
||||
$tbases[$kbase]["sbas_id"] = $phbase["sbas_id"];
|
||||
$tbases[$kbase]["searchcoll"] = $tcoll;
|
||||
$tbases[$kbase]["mask_xor"] = $tbases[$kbase]["mask_and"] = 0;
|
||||
|
||||
$qp = new searchEngine_adapter_phrasea_queryParser();
|
||||
$treeq = $qp->parsequery($input->getOption('query'));
|
||||
$arrayq = $qp->makequery($treeq);
|
||||
|
||||
$tbases[$kbase]["arrayq"] = $arrayq;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("\n-- phrasea_query --");
|
||||
|
||||
$nbanswers = 0;
|
||||
foreach ($tbases as $kb => $base)
|
||||
{
|
||||
$tbases[$kb]["results"] = NULL;
|
||||
|
||||
$ret = phrasea_query2(
|
||||
$ph_session["session_id"]
|
||||
, $base["sbas_id"]
|
||||
, $base["searchcoll"]
|
||||
, $base["arrayq"]
|
||||
, $registry->get('GV_sit')
|
||||
, $usr_id
|
||||
, FALSE
|
||||
, PHRASEA_MULTIDOC_DOCONLY
|
||||
, ''
|
||||
, array()
|
||||
);
|
||||
|
||||
|
||||
if ($ret)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got result on sbas_id " . $base["sbas_id"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> No results on sbas_id " . $base["sbas_id"]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$tbases[$kb]["results"] = $ret;
|
||||
|
||||
$nbanswers += $tbases[$kb]["results"]["nbanswers"];
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("Got a total of <info>$nbanswers</info> answers");
|
||||
|
||||
$output->writeln("\n-- phrasea_fetch_results --");
|
||||
|
||||
$rs = phrasea_fetch_results($sessid, $usr_id, 1, true, '[[em]]', '[[/em]]');
|
||||
|
||||
if ($rs)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got result ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no result ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_close_session --");
|
||||
|
||||
$rs = phrasea_close_session($sessid);
|
||||
|
||||
if ($rs)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> closed ! ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> not closed ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,74 +25,66 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_fieldsDelete extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Delete a documentation field from a Databox');
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
|
||||
|
||||
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!$input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
if (!$input->getOption('meta_struct_id'))
|
||||
throw new \Exception('Missing argument meta_struct_id');
|
||||
|
||||
try
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('Delete a documentation field from a Databox');
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
|
||||
|
||||
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
try
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$field = $databox->get_meta_structure()->get_element((int) $input->getOption('meta_struct_id'));
|
||||
|
||||
if ( ! $input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
if ( ! $input->getOption('meta_struct_id'))
|
||||
throw new \Exception('Missing argument meta_struct_id');
|
||||
|
||||
try {
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$field = $databox->get_meta_structure()->get_element((int) $input->getOption('meta_struct_id'));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Invalid meta struct id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$continue = mb_strtolower(
|
||||
$dialog->ask(
|
||||
$output
|
||||
, "<question>About to delete " . $field->get_name() . " (y/N)</question>"
|
||||
, 'n'
|
||||
)
|
||||
);
|
||||
|
||||
if ($continue != 'y') {
|
||||
$output->writeln("Request canceled by user");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("Deleting ... ");
|
||||
|
||||
$field->delete();
|
||||
|
||||
$output->writeln("Done with success !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid meta struct id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$continue = mb_strtolower(
|
||||
$dialog->ask(
|
||||
$output
|
||||
, "<question>About to delete " . $field->get_name() . " (y/N)</question>"
|
||||
, 'n'
|
||||
)
|
||||
);
|
||||
|
||||
if($continue != 'y')
|
||||
{
|
||||
$output->writeln("Request canceled by user");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("Deleting ... ");
|
||||
|
||||
$field->delete();
|
||||
|
||||
$output->writeln("Done with success !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,46 +25,43 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_fieldsList extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('List all databox fields');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
public function __construct($name = null)
|
||||
{
|
||||
/* @var $databox \databox */
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\n ---------------- \nOn databox %s (sbas_id %d) :\n"
|
||||
, $databox->get_viewname()
|
||||
, $databox->get_sbas_id()
|
||||
)
|
||||
);
|
||||
parent::__construct($name);
|
||||
|
||||
foreach ($databox->get_meta_structure()->get_elements() as $field)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
" %2d - <info>%s</info> (%s) %s"
|
||||
, $field->get_id()
|
||||
, $field->get_name()
|
||||
, $field->get_type()
|
||||
, ($field->is_multi() ? '<comment>multi</comment>' : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->setDescription('List all databox fields');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
/* @var $databox \databox */
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\n ---------------- \nOn databox %s (sbas_id %d) :\n"
|
||||
, $databox->get_viewname()
|
||||
, $databox->get_sbas_id()
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($databox->get_meta_structure()->get_elements() as $field) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
" %2d - <info>%s</info> (%s) %s"
|
||||
, $field->get_id()
|
||||
, $field->get_name()
|
||||
, $field->get_type()
|
||||
, ($field->is_multi() ? '<comment>multi</comment>' : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -25,260 +25,227 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_fieldsMerge extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Merge databox structure fields');
|
||||
|
||||
$this->addOption(
|
||||
'source'
|
||||
, 'f'
|
||||
, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Metadata structure ids for source'
|
||||
, array()
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
'destination'
|
||||
, 'd'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'Metadata structure id destination'
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
'sbas_id'
|
||||
, 's'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'Databox sbas_id'
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
'separator'
|
||||
, ''
|
||||
, InputOption::VALUE_OPTIONAL
|
||||
, 'Separator for concatenation (if destination is monovalued)'
|
||||
, ';'
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln("");
|
||||
|
||||
if (!$input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
try
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
$this->setDescription('Merge databox structure fields');
|
||||
|
||||
$sources = array();
|
||||
|
||||
foreach ($input->getOption('source') as $source_id)
|
||||
{
|
||||
$sources[] = $databox->get_meta_structure()->get_element($source_id);
|
||||
}
|
||||
|
||||
if (count($sources) === 0)
|
||||
throw new \Exception('No sources to proceed');
|
||||
|
||||
if (!$input->getOption('destination'))
|
||||
throw new \Exception('Missing argument destination');
|
||||
|
||||
$separator = ' ' . $input->getOption('separator') . ' ';
|
||||
|
||||
$destination = $databox->get_meta_structure()->get_element($input->getOption('destination'));
|
||||
|
||||
$types = $multis = array();
|
||||
|
||||
foreach ($sources as $source)
|
||||
{
|
||||
array_push($types, $source->get_type());
|
||||
array_push($multis, $source->is_multi());
|
||||
}
|
||||
|
||||
$types = array_unique($types);
|
||||
$multis = array_unique($multis);
|
||||
|
||||
if (count(array_unique($types)) > 1)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf("Warning, trying to merge inconsistent types : <comment>%s</comment>\n"
|
||||
, implode(', ', $types)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (count(array_unique($multis)) > 1)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"Warning, trying to merge <comment>mono and multi</comment> values fields\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$field_names = array();
|
||||
foreach ($sources as $source)
|
||||
{
|
||||
$field_names[] = $source->get_name();
|
||||
}
|
||||
|
||||
if (count($multis) == 1)
|
||||
{
|
||||
if ($multis[0] === false && !$destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mono valued fields</info> in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode($separator, $field_names)
|
||||
)
|
||||
$this->addOption(
|
||||
'source'
|
||||
, 'f'
|
||||
, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Metadata structure ids for source'
|
||||
, array()
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
}
|
||||
elseif ($multis[0] === true && !$destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>multi valued</info> fields in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode(' ', $field_names)
|
||||
)
|
||||
|
||||
$this->addOption(
|
||||
'destination'
|
||||
, 'd'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'Metadata structure id destination'
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
}
|
||||
elseif ($multis[0] === false && $destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mono valued fields</info> in a "
|
||||
. "<info>multivalued field</info>"
|
||||
)
|
||||
|
||||
$this->addOption(
|
||||
'sbas_id'
|
||||
, 's'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'Databox sbas_id'
|
||||
);
|
||||
}
|
||||
elseif ($multis[0] === true && $destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>multi valued fields</info> in a "
|
||||
. "<info>multivalued field</info>"
|
||||
)
|
||||
|
||||
$this->addOption(
|
||||
'separator'
|
||||
, ''
|
||||
, InputOption::VALUE_OPTIONAL
|
||||
, 'Separator for concatenation (if destination is monovalued)'
|
||||
, ';'
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif ($destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mixed valued</info> fields in a "
|
||||
. "<info>multivalued</info> field"
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mixed valued</info> fields in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode($separator, $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$start = 0;
|
||||
$quantity = 100;
|
||||
|
||||
do
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$sql = 'SELECT record_id FROM record
|
||||
$output->writeln("");
|
||||
|
||||
if ( ! $input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
try {
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$sources = array();
|
||||
|
||||
foreach ($input->getOption('source') as $source_id) {
|
||||
$sources[] = $databox->get_meta_structure()->get_element($source_id);
|
||||
}
|
||||
|
||||
if (count($sources) === 0)
|
||||
throw new \Exception('No sources to proceed');
|
||||
|
||||
if ( ! $input->getOption('destination'))
|
||||
throw new \Exception('Missing argument destination');
|
||||
|
||||
$separator = ' ' . $input->getOption('separator') . ' ';
|
||||
|
||||
$destination = $databox->get_meta_structure()->get_element($input->getOption('destination'));
|
||||
|
||||
$types = $multis = array();
|
||||
|
||||
foreach ($sources as $source) {
|
||||
array_push($types, $source->get_type());
|
||||
array_push($multis, $source->is_multi());
|
||||
}
|
||||
|
||||
$types = array_unique($types);
|
||||
$multis = array_unique($multis);
|
||||
|
||||
if (count(array_unique($types)) > 1) {
|
||||
$output->writeln(
|
||||
sprintf("Warning, trying to merge inconsistent types : <comment>%s</comment>\n"
|
||||
, implode(', ', $types)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (count(array_unique($multis)) > 1) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"Warning, trying to merge <comment>mono and multi</comment> values fields\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$field_names = array();
|
||||
foreach ($sources as $source) {
|
||||
$field_names[] = $source->get_name();
|
||||
}
|
||||
|
||||
if (count($multis) == 1) {
|
||||
if ($multis[0] === false && ! $destination->is_multi()) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mono valued fields</info> in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode($separator, $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
} elseif ($multis[0] === true && ! $destination->is_multi()) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>multi valued</info> fields in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode(' ', $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
} elseif ($multis[0] === false && $destination->is_multi()) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mono valued fields</info> in a "
|
||||
. "<info>multivalued field</info>"
|
||||
)
|
||||
);
|
||||
} elseif ($multis[0] === true && $destination->is_multi()) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>multi valued fields</info> in a "
|
||||
. "<info>multivalued field</info>"
|
||||
)
|
||||
);
|
||||
}
|
||||
} elseif ($destination->is_multi()) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mixed valued</info> fields in a "
|
||||
. "<info>multivalued</info> field"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mixed valued</info> fields in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode($separator, $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
}
|
||||
|
||||
$start = 0;
|
||||
$quantity = 100;
|
||||
|
||||
do {
|
||||
$sql = 'SELECT record_id FROM record
|
||||
ORDER BY record_id LIMIT ' . $start . ', ' . $quantity;
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($results as $row)
|
||||
{
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
foreach ($results as $row) {
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
|
||||
$datas = array();
|
||||
$datas = array();
|
||||
|
||||
foreach ($sources as $source)
|
||||
{
|
||||
try
|
||||
{
|
||||
$value = $record->get_caption()->get_field($source->get_name())->get_value();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$value = array();
|
||||
}
|
||||
if (!is_array($value))
|
||||
{
|
||||
$value = array($value);
|
||||
}
|
||||
foreach ($sources as $source) {
|
||||
try {
|
||||
$value = $record->get_caption()->get_field($source->get_name())->get_value();
|
||||
} catch (\Exception $e) {
|
||||
$value = array();
|
||||
}
|
||||
if ( ! is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
$datas = array_merge($datas, $value);
|
||||
}
|
||||
$datas = array_merge($datas, $value);
|
||||
}
|
||||
|
||||
$datas = array_unique($datas);
|
||||
$datas = array_unique($datas);
|
||||
|
||||
if (!$destination->is_multi())
|
||||
{
|
||||
$datas = array(implode($separator, $datas));
|
||||
}
|
||||
if ( ! $destination->is_multi()) {
|
||||
$datas = array(implode($separator, $datas));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$record->get_caption()->get_field($destination->get_name())->set_value($datas);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$record->set_metadatas(
|
||||
array(
|
||||
array(
|
||||
'meta_struct_id' => $destination->get_id()
|
||||
, 'meta_id' => null
|
||||
, 'value' => $datas
|
||||
)
|
||||
)
|
||||
, true
|
||||
);
|
||||
}
|
||||
unset($record);
|
||||
}
|
||||
try {
|
||||
$record->get_caption()->get_field($destination->get_name())->set_value($datas);
|
||||
} catch (\Exception $e) {
|
||||
$record->set_metadatas(
|
||||
array(
|
||||
array(
|
||||
'meta_struct_id' => $destination->get_id()
|
||||
, 'meta_id' => null
|
||||
, 'value' => $datas
|
||||
)
|
||||
)
|
||||
, true
|
||||
);
|
||||
}
|
||||
unset($record);
|
||||
}
|
||||
|
||||
$start += $quantity;
|
||||
$start += $quantity;
|
||||
} while (count($results) > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
while (count($results) > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
protected function displayHelpConcatenation(OutputInterface $output)
|
||||
{
|
||||
|
||||
protected function displayHelpConcatenation(OutputInterface $output)
|
||||
{
|
||||
|
||||
$output->writeln("\nYou can choose the concatenation order in the "
|
||||
. "commandline (first option is first value) and set a separator "
|
||||
. "with the --separator option)");
|
||||
|
||||
return $this;
|
||||
}
|
||||
$output->writeln("\nYou can choose the concatenation order in the "
|
||||
. "commandline (first option is first value) and set a separator "
|
||||
. "with the --separator option)");
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -25,82 +25,74 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_fieldsRename extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Rename a documentation field from a Databox');
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
|
||||
|
||||
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
|
||||
|
||||
$this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'The new name');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!$input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
if (!$input->getOption('meta_struct_id'))
|
||||
throw new \Exception('Missing argument meta_struct_id');
|
||||
|
||||
if (!$input->getOption('name'))
|
||||
throw new \Exception('Missing argument name');
|
||||
|
||||
$new_name = $input->getOption('name');
|
||||
|
||||
try
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('Rename a documentation field from a Databox');
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
|
||||
|
||||
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
|
||||
|
||||
$this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'The new name');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
try
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$field = $databox->get_meta_structure()->get_element((int) $input->getArgument('meta_struct_id'));
|
||||
|
||||
if ( ! $input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
if ( ! $input->getOption('meta_struct_id'))
|
||||
throw new \Exception('Missing argument meta_struct_id');
|
||||
|
||||
if ( ! $input->getOption('name'))
|
||||
throw new \Exception('Missing argument name');
|
||||
|
||||
$new_name = $input->getOption('name');
|
||||
|
||||
try {
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$field = $databox->get_meta_structure()->get_element((int) $input->getArgument('meta_struct_id'));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Invalid meta struct id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$continue = mb_strtolower(
|
||||
$dialog->ask(
|
||||
$output
|
||||
, "<question>About to rename " . $field->get_name() . " into " . $new_name . " (y/N)</question>"
|
||||
, 'n'
|
||||
)
|
||||
);
|
||||
|
||||
if ($continue != 'y') {
|
||||
$output->writeln("Request canceled by user");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("Renaming ... ");
|
||||
|
||||
$field->set_name($new_name);
|
||||
$field->save();
|
||||
|
||||
$output->writeln("Done with success !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid meta struct id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$continue = mb_strtolower(
|
||||
$dialog->ask(
|
||||
$output
|
||||
, "<question>About to rename " . $field->get_name() . " into ".$new_name." (y/N)</question>"
|
||||
, 'n'
|
||||
)
|
||||
);
|
||||
|
||||
if($continue != 'y')
|
||||
{
|
||||
$output->writeln("Request canceled by user");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("Renaming ... ");
|
||||
|
||||
$field->set_name($new_name);
|
||||
$field->save();
|
||||
|
||||
$output->writeln("Done with success !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,57 +25,52 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_schedulerStart extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Start the scheduler');
|
||||
$this->addOption(
|
||||
$this->setDescription('Start the scheduler');
|
||||
$this->addOption(
|
||||
'nolog'
|
||||
, NULL
|
||||
, 1 | InputOption::VALUE_NONE
|
||||
, 'do not log (scheduler) to logfile'
|
||||
, NULL
|
||||
);
|
||||
$this->addOption(
|
||||
);
|
||||
$this->addOption(
|
||||
'notasklog'
|
||||
, NULL
|
||||
, 1 | InputOption::VALUE_NONE
|
||||
, 'do not log (tasks) to logfiles'
|
||||
, NULL
|
||||
);
|
||||
$this->setHelp(
|
||||
);
|
||||
$this->setHelp(
|
||||
"You should use launch the command and finish it with `&`"
|
||||
. " to return to the console\n\n"
|
||||
. "\tie : <info>bin/console scheduler:start &</info>"
|
||||
);
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $zinput, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($zinput, $output); //, !$input->getOption('nolog'), !$input->getOption('notasklog'));
|
||||
|
||||
try
|
||||
public function execute(InputInterface $zinput, OutputInterface $output)
|
||||
{
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($output, true);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if ( ! setup::is_installed()) {
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($zinput, $output); //, !$input->getOption('nolog'), !$input->getOption('notasklog'));
|
||||
|
||||
try {
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($output, true);
|
||||
} catch (\Exception $e) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,54 +25,46 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_schedulerState extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Get scheduler state');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('Get scheduler state');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
if ( ! setup::is_installed()) {
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
$state = $task_manager->get_scheduler_state();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($state['status'] == 'started')
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try {
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
|
||||
$state = $task_manager->get_scheduler_state();
|
||||
|
||||
if ($state['status'] == 'started') {
|
||||
$output->writeln(sprintf(
|
||||
'Scheduler is %s on pid %d'
|
||||
, $state['schedstatus']
|
||||
, $state['schedpid']
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln(sprintf('Scheduler is %s', $state['status']));
|
||||
}
|
||||
));
|
||||
} else {
|
||||
$output->writeln(sprintf('Scheduler is %s', $state['status']));
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,40 +25,35 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_schedulerStop extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Stop the scheduler');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('Stop the scheduler');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
|
||||
if ( ! setup::is_installed()) {
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try {
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
|
||||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,138 +25,126 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_sphinxGenerateSuggestion extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Generate suggestions for Sphinx Search Engine');
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
define('FREQ_THRESHOLD', 10);
|
||||
define('SUGGEST_DEBUG', 0);
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$params = phrasea::sbas_params();
|
||||
|
||||
foreach ($params as $sbas_id => $p)
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$index = crc32(
|
||||
str_replace(
|
||||
array('.', '%')
|
||||
, '_'
|
||||
, sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname'])
|
||||
)
|
||||
);
|
||||
parent::__construct($name);
|
||||
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/dict' . $index . '.txt';
|
||||
$this->setDescription('Generate suggestions for Sphinx Search Engine');
|
||||
|
||||
$databox = databox::get_instance($sbas_id);
|
||||
|
||||
$output->writeln("process Databox " . $databox->get_viewname() . " / $index\n");
|
||||
|
||||
if(!is_executable("/usr/local/bin/indexer"))
|
||||
{
|
||||
$output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!file_exists($tmp_file))
|
||||
{
|
||||
$output->writeln("<error> file '".$tmp_file."' does not exist</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$cmd = '/usr/local/bin/indexer metadatas' . $index . ' --buildstops ' . $tmp_file . ' 1000000 --buildfreqs';
|
||||
exec($cmd);
|
||||
|
||||
try
|
||||
{
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = 'TRUNCATE suggest';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = $this->BuildDictionarySQL($output, file_get_contents($tmp_file));
|
||||
|
||||
if (trim($sql) !== '')
|
||||
{
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
unlink($tmp_file);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function BuildTrigrams($keyword)
|
||||
{
|
||||
$t = "__" . $keyword . "__";
|
||||
|
||||
$trigrams = "";
|
||||
for ($i = 0; $i < strlen($t) - 2; $i++)
|
||||
$trigrams .= substr($t, $i, 3) . " ";
|
||||
|
||||
return $trigrams;
|
||||
}
|
||||
|
||||
protected function BuildDictionarySQL(OutputInterface $output, $in)
|
||||
{
|
||||
$out = '';
|
||||
|
||||
$n = 0;
|
||||
$lines = explode("\n", $in);
|
||||
foreach ($lines as $line)
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (trim($line) === '')
|
||||
continue;
|
||||
list ( $keyword, $freq ) = explode(" ", trim($line));
|
||||
define('FREQ_THRESHOLD', 10);
|
||||
define('SUGGEST_DEBUG', 0);
|
||||
|
||||
if ($freq < FREQ_THRESHOLD || strstr($keyword, "_") !== false || strstr($keyword, "'") !== false)
|
||||
continue;
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
if (ctype_digit($keyword))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (mb_strlen($keyword) < 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$params = phrasea::sbas_params();
|
||||
|
||||
$trigrams = $this->BuildTrigrams($keyword);
|
||||
foreach ($params as $sbas_id => $p) {
|
||||
$index = crc32(
|
||||
str_replace(
|
||||
array('.', '%')
|
||||
, '_'
|
||||
, sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname'])
|
||||
)
|
||||
);
|
||||
|
||||
if ($n++)
|
||||
$out .= ",\n";
|
||||
$out .= "( $n, '$keyword', '$trigrams', $freq )";
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/dict' . $index . '.txt';
|
||||
|
||||
$databox = databox::get_instance($sbas_id);
|
||||
|
||||
$output->writeln("process Databox " . $databox->get_viewname() . " / $index\n");
|
||||
|
||||
if ( ! is_executable("/usr/local/bin/indexer")) {
|
||||
$output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( ! file_exists($tmp_file)) {
|
||||
$output->writeln("<error> file '" . $tmp_file . "' does not exist</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$cmd = '/usr/local/bin/indexer metadatas' . $index . ' --buildstops ' . $tmp_file . ' 1000000 --buildfreqs';
|
||||
exec($cmd);
|
||||
|
||||
try {
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = 'TRUNCATE suggest';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = $this->BuildDictionarySQL($output, file_get_contents($tmp_file));
|
||||
|
||||
if (trim($sql) !== '') {
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
unlink($tmp_file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (trim($out) !== '')
|
||||
protected function BuildTrigrams($keyword)
|
||||
{
|
||||
$out = "INSERT INTO suggest VALUES " . $out . ";";
|
||||
$t = "__" . $keyword . "__";
|
||||
|
||||
$trigrams = "";
|
||||
for ($i = 0; $i < strlen($t) - 2; $i ++ )
|
||||
$trigrams .= substr($t, $i, 3) . " ";
|
||||
|
||||
return $trigrams;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Generated <info>%d</info> suggestions", $n));
|
||||
protected function BuildDictionarySQL(OutputInterface $output, $in)
|
||||
{
|
||||
$out = '';
|
||||
|
||||
return $out;
|
||||
}
|
||||
$n = 0;
|
||||
$lines = explode("\n", $in);
|
||||
foreach ($lines as $line) {
|
||||
if (trim($line) === '')
|
||||
continue;
|
||||
list ( $keyword, $freq ) = explode(" ", trim($line));
|
||||
|
||||
if ($freq < FREQ_THRESHOLD || strstr($keyword, "_") !== false || strstr($keyword, "'") !== false)
|
||||
continue;
|
||||
|
||||
if (ctype_digit($keyword)) {
|
||||
continue;
|
||||
}
|
||||
if (mb_strlen($keyword) < 3) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$trigrams = $this->BuildTrigrams($keyword);
|
||||
|
||||
if ($n ++)
|
||||
$out .= ",\n";
|
||||
$out .= "( $n, '$keyword', '$trigrams', $freq )";
|
||||
}
|
||||
|
||||
if (trim($out) !== '') {
|
||||
$out = "INSERT INTO suggest VALUES " . $out . ";";
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Generated <info>%d</info> suggestions", $n));
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
@@ -25,63 +25,61 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_systemBackupDB extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$dir = sprintf(
|
||||
$dir = sprintf(
|
||||
'%s/config/'
|
||||
, dirname(dirname(dirname(dirname(__DIR__))))
|
||||
);
|
||||
);
|
||||
|
||||
$this->setDescription('Backup Phraseanet Databases');
|
||||
$this->setDescription('Backup Phraseanet Databases');
|
||||
|
||||
$this->addArgument('directory', null, 'The directory where to backup', $dir);
|
||||
$this->addArgument('directory', null, 'The directory where to backup', $dir);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
$output->writeln('Argument must be an Id.');
|
||||
|
||||
return 1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be backup...', true);
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$ok = true;
|
||||
|
||||
$ok = $this->dump_base($appbox, $input, $output) && $ok;
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ok = $this->dump_base($databox, $input, $output) && $ok;
|
||||
if ( ! setup::is_installed()) {
|
||||
$output->writeln('Argument must be an Id.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be backup...', true);
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$ok = true;
|
||||
|
||||
$ok = $this->dump_base($appbox, $input, $output) && $ok;
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
$ok = $this->dump_base($databox, $input, $output) && $ok;
|
||||
}
|
||||
|
||||
return (int) ! $ok;
|
||||
}
|
||||
|
||||
return (int) !$ok;
|
||||
}
|
||||
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$date_obj = new DateTime();
|
||||
|
||||
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$date_obj = new DateTime();
|
||||
|
||||
$filename = sprintf(
|
||||
$filename = sprintf(
|
||||
'%s%s_%s.sql'
|
||||
, p4string::addEndSlash($input->getArgument('directory'))
|
||||
, $base->get_dbname()
|
||||
, $date_obj->format('Y_m_d_H_i_s')
|
||||
);
|
||||
);
|
||||
|
||||
$output->write(sprintf('Generating %s ... ', $filename));
|
||||
$output->write(sprintf('Generating %s ... ', $filename));
|
||||
|
||||
$command = sprintf(
|
||||
$command = sprintf(
|
||||
'mysqldump --host %s --port %s --user %s --password=%s'
|
||||
. ' --database %s --default-character-set=utf8 > %s'
|
||||
, $base->get_host()
|
||||
@@ -90,24 +88,18 @@ class module_console_systemBackupDB extends Command
|
||||
, $base->get_passwd()
|
||||
, $base->get_dbname()
|
||||
, escapeshellarg($filename)
|
||||
);
|
||||
);
|
||||
|
||||
system($command);
|
||||
system($command);
|
||||
|
||||
if (file_exists($filename) && filesize($filename) > 0)
|
||||
{
|
||||
$output->writeln('OK');
|
||||
if (file_exists($filename) && filesize($filename) > 0) {
|
||||
$output->writeln('OK');
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} else {
|
||||
$output->writeln('<error>Failed</error>');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln('<error>Failed</error>');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,20 +26,20 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_systemClearCache extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Empty cache directories, clear Memcached, Redis if avalaible');
|
||||
$this->setDescription('Empty cache directories, clear Memcached, Redis if avalaible');
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$files = $dirs = array();
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$files = $dirs = array();
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->files()
|
||||
->exclude('.git')
|
||||
->exclude('.svn')
|
||||
@@ -48,15 +48,14 @@ class module_console_systemClearCache extends Command
|
||||
, __DIR__ . '/../../../../tmp/cache_twig/'
|
||||
));
|
||||
|
||||
$count = 1;
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$files[$file->getPathname()] = $file->getPathname();
|
||||
$count++;
|
||||
}
|
||||
$count = 1;
|
||||
foreach ($finder as $file) {
|
||||
$files[$file->getPathname()] = $file->getPathname();
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->directories()
|
||||
->in(array(
|
||||
__DIR__ . '/../../../../tmp/cache_minify'
|
||||
@@ -65,31 +64,26 @@ class module_console_systemClearCache extends Command
|
||||
->exclude('.git')
|
||||
->exclude('.svn');
|
||||
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$dirs[$file->getPathname()] = $file->getPathname();
|
||||
printf('%4d) %s' . PHP_EOL, $count, $file->getPathname());
|
||||
$count++;
|
||||
foreach ($finder as $file) {
|
||||
$dirs[$file->getPathname()] = $file->getPathname();
|
||||
printf('%4d) %s' . PHP_EOL, $count, $file->getPathname());
|
||||
$count ++;
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
foreach ($dirs as $dir) {
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
if (setup::is_installed()) {
|
||||
$Core = \bootstrap::getCore();
|
||||
$Core['CacheService']->flushAll();
|
||||
}
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
foreach ($dirs as $dir)
|
||||
{
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
if(setup::is_installed())
|
||||
{
|
||||
$Core = \bootstrap::getCore();
|
||||
$Core['CacheService']->flushAll();
|
||||
}
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,101 +26,89 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_systemConfigCheck extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Check the configuration');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!function_exists('_'))
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
|
||||
$output->writeln('Canceled');
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('Check the configuration');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
|
||||
if (setup::is_installed())
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
if ( ! function_exists('_')) {
|
||||
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
|
||||
$output->writeln('Canceled');
|
||||
|
||||
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
|
||||
$ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
}
|
||||
else
|
||||
{
|
||||
$registry = new Setup_Registry();
|
||||
return 1;
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
|
||||
if (setup::is_installed()) {
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
|
||||
$ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
} else {
|
||||
$registry = new Setup_Registry();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
|
||||
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
|
||||
$ok = $this->processConstraints(setup::check_cache_opcode(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE SERVER ***'));
|
||||
$ok = $this->processConstraints(setup::check_cache_server(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
|
||||
$ok = $this->processConstraints(setup::check_php_configuration(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
|
||||
$ok = $this->processConstraints(setup::check_php_extension(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHRASEA ***'));
|
||||
$ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
|
||||
$ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return (int) ! $ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
|
||||
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
|
||||
$ok = $this->processConstraints(setup::check_cache_opcode(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE SERVER ***'));
|
||||
$ok = $this->processConstraints(setup::check_cache_server(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
|
||||
$ok = $this->processConstraints(setup::check_php_configuration(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
|
||||
$ok = $this->processConstraints(setup::check_php_extension(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHRASEA ***'));
|
||||
$ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
|
||||
$ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return (int)!$ok;
|
||||
}
|
||||
|
||||
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
|
||||
{
|
||||
$hasError = false;
|
||||
foreach ($constraints as $constraint)
|
||||
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
|
||||
{
|
||||
if (!$hasError && !$this->processConstraint($constraint, $output))
|
||||
{
|
||||
$hasError = true;
|
||||
}
|
||||
$hasError = false;
|
||||
foreach ($constraints as $constraint) {
|
||||
if ( ! $hasError && ! $this->processConstraint($constraint, $output)) {
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ! $hasError;
|
||||
}
|
||||
|
||||
return !$hasError;
|
||||
}
|
||||
|
||||
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
|
||||
{
|
||||
$ok = true;
|
||||
if ($constraint->is_ok())
|
||||
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
|
||||
{
|
||||
$output->writeln("\t\t<info>" . $constraint->get_message() . '</info>');
|
||||
}
|
||||
elseif ($constraint->is_blocker())
|
||||
{
|
||||
$output->writeln("\t!!!\t<error>" . $constraint->get_message() . '</error>');
|
||||
$ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\t/!\\\t<comment>" . $constraint->get_message() . '</comment>');
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
$ok = true;
|
||||
if ($constraint->is_ok()) {
|
||||
$output->writeln("\t\t<info>" . $constraint->get_message() . '</info>');
|
||||
} elseif ($constraint->is_blocker()) {
|
||||
$output->writeln("\t!!!\t<error>" . $constraint->get_message() . '</error>');
|
||||
$ok = false;
|
||||
} else {
|
||||
$output->writeln("\t/!\\\t<comment>" . $constraint->get_message() . '</comment>');
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
}
|
||||
|
@@ -25,288 +25,259 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_systemExport extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Export all phraseanet records to a directory');
|
||||
$this->setDescription('Export all phraseanet records to a directory');
|
||||
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
// $this->addOption('useoriginalname', 'o', InputOption::VALUE_OPTIONAL
|
||||
// , 'Use original name for dest files', false);
|
||||
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
// $this->addOption('excludefield', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
// , 'Exclude field from XML', array());
|
||||
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
// $this->addOption('excludestatus', '', InputOption::VALUE_OPTIONAL
|
||||
// , 'Exclude Status', false);
|
||||
|
||||
$this->addOption('docperdir', 'd', InputOption::VALUE_OPTIONAL
|
||||
, 'Maximum number of files per dir', 100);
|
||||
$this->addOption('docperdir', 'd', InputOption::VALUE_OPTIONAL
|
||||
, 'Maximum number of files per dir', 100);
|
||||
|
||||
$this->addOption('caption', 'c', InputOption::VALUE_OPTIONAL
|
||||
, 'Export Caption (XML)', false);
|
||||
$this->addOption('caption', 'c', InputOption::VALUE_OPTIONAL
|
||||
, 'Export Caption (XML)', false);
|
||||
|
||||
$this->addOption('limit', 'l', InputOption::VALUE_OPTIONAL
|
||||
, 'Limit files quantity (for test purposes)', false);
|
||||
$this->addOption('limit', 'l', InputOption::VALUE_OPTIONAL
|
||||
, 'Limit files quantity (for test purposes)', false);
|
||||
|
||||
$this->addOption('base_id', 'b', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Restrict on base_ids', array());
|
||||
$this->addOption('base_id', 'b', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Restrict on base_ids', array());
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Restrict on sbas_ids', array());
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Restrict on sbas_ids', array());
|
||||
|
||||
$this->addArgument('directory', InputOption::VALUE_REQUIRED
|
||||
, 'The directory where to export');
|
||||
$this->addArgument('directory', InputOption::VALUE_REQUIRED
|
||||
, 'The directory where to export');
|
||||
|
||||
$this->addOption('sanitize', '', InputOption::VALUE_REQUIRED
|
||||
, 'Sanitize filenames. Set to 0 to disable', true);
|
||||
$this->addOption('sanitize', '', InputOption::VALUE_REQUIRED
|
||||
, 'Sanitize filenames. Set to 0 to disable', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$docPerDir = max(1, (int) $input->getOption('docperdir'));
|
||||
|
||||
/**
|
||||
*
|
||||
* To implement
|
||||
*
|
||||
$useOriginalName = !!$input->getOption('useoriginalname');
|
||||
$excludeFields = $input->getOption('excludefield');
|
||||
$exportStatus = !$input->getOption('excludestatus');
|
||||
*
|
||||
*/
|
||||
|
||||
$Caption = $input->getOption('caption');
|
||||
|
||||
$limit = ctype_digit($input->getOption('limit')) ? max(0, (int) $input->getOption('limit')) : false;
|
||||
|
||||
$restrictBaseIds = $input->getOption('base_id');
|
||||
|
||||
$restrictSbasIds = $input->getOption('sbas_id');
|
||||
|
||||
$sanitize = $input->getOption('sanitize');
|
||||
|
||||
|
||||
$export_directory = $input->getArgument('directory');
|
||||
|
||||
if (!$export_directory)
|
||||
{
|
||||
throw new Exception('Missing directory argument');
|
||||
return $this;
|
||||
}
|
||||
|
||||
$export_directory = realpath(substr($export_directory, 0, 1) === '/' ? $export_directory : getcwd() . '/' . $export_directory . '/');
|
||||
|
||||
if (!$export_directory)
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
throw new Exception('Export directory does not exists or is not accessible');
|
||||
}
|
||||
$docPerDir = max(1, (int) $input->getOption('docperdir'));
|
||||
|
||||
if (!is_writable($export_directory))
|
||||
{
|
||||
throw new Exception('Export directory is not writable');
|
||||
}
|
||||
/**
|
||||
*
|
||||
* To implement
|
||||
*
|
||||
$useOriginalName = !!$input->getOption('useoriginalname');
|
||||
$excludeFields = $input->getOption('excludefield');
|
||||
$exportStatus = !$input->getOption('excludestatus');
|
||||
*
|
||||
*/
|
||||
$Caption = $input->getOption('caption');
|
||||
|
||||
/**
|
||||
* Sanitize
|
||||
*/
|
||||
foreach ($restrictBaseIds as $key => $base_id)
|
||||
{
|
||||
$restrictBaseIds[$key] = (int) $base_id;
|
||||
}
|
||||
foreach ($restrictSbasIds as $key => $sbas_id)
|
||||
{
|
||||
$restrictSbasIds[$key] = (int) $sbas_id;
|
||||
}
|
||||
$limit = ctype_digit($input->getOption('limit')) ? max(0, (int) $input->getOption('limit')) : false;
|
||||
|
||||
$restrictBaseIds = $input->getOption('base_id');
|
||||
|
||||
$restrictSbasIds = $input->getOption('sbas_id');
|
||||
|
||||
$sanitize = $input->getOption('sanitize');
|
||||
|
||||
|
||||
if (count($restrictSbasIds) > 0)
|
||||
{
|
||||
$output->writeln("Export datas from selected sbas_ids");
|
||||
}
|
||||
elseif (count($restrictBaseIds) > 0)
|
||||
{
|
||||
$output->writeln("Export datas from selected base_ids");
|
||||
}
|
||||
$export_directory = $input->getArgument('directory');
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$total = $errors = 0;
|
||||
|
||||
$unicode = new \unicode();
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
$output->writeln(sprintf("Processing <info>%s</info>", $databox->get_viewname()));
|
||||
|
||||
if (count($restrictSbasIds) > 0 && !in_array($databox->get_sbas_id(), $restrictSbasIds))
|
||||
{
|
||||
$output->writeln(sprintf("Databox not selected, bypassing ..."));
|
||||
continue;
|
||||
}
|
||||
|
||||
$go = true;
|
||||
$coll_ids = array();
|
||||
|
||||
if (count($restrictBaseIds) > 0)
|
||||
{
|
||||
$go = false;
|
||||
foreach ($databox->get_collections() as $collection)
|
||||
{
|
||||
if (in_array($collection->get_base_id(), $restrictBaseIds))
|
||||
{
|
||||
|
||||
$go = true;
|
||||
$coll_ids[] = $collection->get_coll_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$go)
|
||||
{
|
||||
$output->writeln(sprintf("Collections not selected, bypassing ..."));
|
||||
continue;
|
||||
}
|
||||
|
||||
$local_export = $export_directory
|
||||
. '/' . $unicode->remove_nonazAZ09($databox->get_viewname(), true, true)
|
||||
. '/';
|
||||
|
||||
system_file::mkdir($local_export);
|
||||
|
||||
$sql = 'SELECT record_id FROM record WHERE parent_record_id = 0 ';
|
||||
|
||||
if (count($coll_ids) > 0)
|
||||
{
|
||||
$sql .= ' AND coll_id IN (' . implode(', ', $coll_ids) . ') ';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY record_id ASC ';
|
||||
|
||||
if ($limit)
|
||||
{
|
||||
$sql .= ' LIMIT 0, ' . $limit;
|
||||
}
|
||||
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
|
||||
$done = 0;
|
||||
$current_total = count($rs);
|
||||
$total += $current_total;
|
||||
$l = strlen((string) $current_total) + 1;
|
||||
|
||||
$dir_format = 'datas%' . strlen((string) ceil($current_total / $docPerDir)) . 'd';
|
||||
|
||||
$dir_increment = 0;
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
if (($done % $docPerDir) === 0)
|
||||
{
|
||||
$dir_increment++;
|
||||
$in_dir_files = array();
|
||||
$current_dir = $local_export . sprintf($dir_format, $dir_increment) . '/';
|
||||
system_file::mkdir($current_dir);
|
||||
if ( ! $export_directory) {
|
||||
throw new Exception('Missing directory argument');
|
||||
}
|
||||
|
||||
if ($sanitize)
|
||||
{
|
||||
$filename = $unicode->remove_nonazAZ09($record->get_original_name(), true, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = $record->get_original_name();
|
||||
$export_directory = realpath(substr($export_directory, 0, 1) === '/' ? $export_directory : getcwd() . '/' . $export_directory . '/');
|
||||
|
||||
if ( ! $export_directory) {
|
||||
throw new Exception('Export directory does not exists or is not accessible');
|
||||
}
|
||||
|
||||
$this->generateDefinitiveFilename($in_dir_files, $filename);
|
||||
|
||||
$output_file = $current_dir . $filename;
|
||||
|
||||
if (!$this->processRecords($record, $output_file, $Caption))
|
||||
{
|
||||
$errors++;
|
||||
if ( ! is_writable($export_directory)) {
|
||||
throw new Exception('Export directory is not writable');
|
||||
}
|
||||
|
||||
$done++;
|
||||
/**
|
||||
* Sanitize
|
||||
*/
|
||||
foreach ($restrictBaseIds as $key => $base_id) {
|
||||
$restrictBaseIds[$key] = (int) $base_id;
|
||||
}
|
||||
foreach ($restrictSbasIds as $key => $sbas_id) {
|
||||
$restrictSbasIds[$key] = (int) $sbas_id;
|
||||
}
|
||||
|
||||
$output->write(sprintf("\r#%" . $l . "d record remaining", $current_total - $done));
|
||||
}
|
||||
$output->writeln(" | " . $current_total . " records done\n");
|
||||
|
||||
if (count($restrictSbasIds) > 0) {
|
||||
$output->writeln("Export datas from selected sbas_ids");
|
||||
} elseif (count($restrictBaseIds) > 0) {
|
||||
$output->writeln("Export datas from selected base_ids");
|
||||
}
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$total = $errors = 0;
|
||||
|
||||
$unicode = new \unicode();
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
$output->writeln(sprintf("Processing <info>%s</info>", $databox->get_viewname()));
|
||||
|
||||
if (count($restrictSbasIds) > 0 && ! in_array($databox->get_sbas_id(), $restrictSbasIds)) {
|
||||
$output->writeln(sprintf("Databox not selected, bypassing ..."));
|
||||
continue;
|
||||
}
|
||||
|
||||
$go = true;
|
||||
$coll_ids = array();
|
||||
|
||||
if (count($restrictBaseIds) > 0) {
|
||||
$go = false;
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
if (in_array($collection->get_base_id(), $restrictBaseIds)) {
|
||||
|
||||
$go = true;
|
||||
$coll_ids[] = $collection->get_coll_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $go) {
|
||||
$output->writeln(sprintf("Collections not selected, bypassing ..."));
|
||||
continue;
|
||||
}
|
||||
|
||||
$local_export = $export_directory
|
||||
. '/' . $unicode->remove_nonazAZ09($databox->get_viewname(), true, true)
|
||||
. '/';
|
||||
|
||||
system_file::mkdir($local_export);
|
||||
|
||||
$sql = 'SELECT record_id FROM record WHERE parent_record_id = 0 ';
|
||||
|
||||
if (count($coll_ids) > 0) {
|
||||
$sql .= ' AND coll_id IN (' . implode(', ', $coll_ids) . ') ';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY record_id ASC ';
|
||||
|
||||
if ($limit) {
|
||||
$sql .= ' LIMIT 0, ' . $limit;
|
||||
}
|
||||
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
|
||||
$done = 0;
|
||||
$current_total = count($rs);
|
||||
$total += $current_total;
|
||||
$l = strlen((string) $current_total) + 1;
|
||||
|
||||
$dir_format = 'datas%' . strlen((string) ceil($current_total / $docPerDir)) . 'd';
|
||||
|
||||
$dir_increment = 0;
|
||||
foreach ($rs as $row) {
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
if (($done % $docPerDir) === 0) {
|
||||
$dir_increment ++;
|
||||
$in_dir_files = array();
|
||||
$current_dir = $local_export . sprintf($dir_format, $dir_increment) . '/';
|
||||
system_file::mkdir($current_dir);
|
||||
}
|
||||
|
||||
if ($sanitize) {
|
||||
$filename = $unicode->remove_nonazAZ09($record->get_original_name(), true, true, true);
|
||||
} else {
|
||||
$filename = $record->get_original_name();
|
||||
}
|
||||
|
||||
$this->generateDefinitiveFilename($in_dir_files, $filename);
|
||||
|
||||
$output_file = $current_dir . $filename;
|
||||
|
||||
if ( ! $this->processRecords($record, $output_file, $Caption)) {
|
||||
$errors ++;
|
||||
}
|
||||
|
||||
$done ++;
|
||||
|
||||
$output->write(sprintf("\r#%" . $l . "d record remaining", $current_total - $done));
|
||||
}
|
||||
$output->writeln(" | " . $current_total . " records done\n");
|
||||
}
|
||||
|
||||
$output->writeln("$total records done, $errors errors occured");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$output->writeln("$total records done, $errors errors occured");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function generateDefinitiveFilename(array &$existing, &$filename)
|
||||
{
|
||||
$definitive_filename = $filename;
|
||||
$suffix = 2;
|
||||
while (array_key_exists($definitive_filename, $existing))
|
||||
protected function generateDefinitiveFilename(array &$existing, &$filename)
|
||||
{
|
||||
$pathinfo = pathinfo($filename);
|
||||
$definitive_filename = $filename;
|
||||
$suffix = 2;
|
||||
while (array_key_exists($definitive_filename, $existing)) {
|
||||
$pathinfo = pathinfo($filename);
|
||||
|
||||
$definitive_filename = $pathinfo['filename'] . '_' . $suffix .
|
||||
(isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '');
|
||||
$suffix++;
|
||||
$definitive_filename = $pathinfo['filename'] . '_' . $suffix .
|
||||
(isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '');
|
||||
$suffix ++;
|
||||
}
|
||||
|
||||
$existing[$filename] = $filename;
|
||||
$filename = $definitive_filename;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$existing[$filename] = $filename;
|
||||
$filename = $definitive_filename;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function processRecords(\record_adapter $record, $outfile, $caption)
|
||||
{
|
||||
|
||||
try
|
||||
protected function processRecords(\record_adapter $record, $outfile, $caption)
|
||||
{
|
||||
$file = new system_file($record->get_subdef('document')->get_pathfile());
|
||||
|
||||
try {
|
||||
$file = new system_file($record->get_subdef('document')->get_pathfile());
|
||||
} catch (\Exception_Media_SubdefNotFound $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
copy($file->getPathname(), $outfile);
|
||||
|
||||
$dest_file = new system_file($outfile);
|
||||
|
||||
touch(
|
||||
$dest_file->getPathname()
|
||||
, $record->get_creation_date()->format('U')
|
||||
, $record->get_modification_date()->format('U')
|
||||
);
|
||||
|
||||
switch (strtolower($caption)) {
|
||||
case 'xml':
|
||||
$pathinfo = pathinfo($dest_file->getPathname());
|
||||
$xml = $record->get_caption()->serialize(caption_record::SERIALIZE_XML);
|
||||
$xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
|
||||
file_put_contents($xml_file, $xml);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (\Exception_Media_SubdefNotFound $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
copy($file->getPathname(), $outfile);
|
||||
|
||||
$dest_file = new system_file($outfile);
|
||||
|
||||
touch(
|
||||
$dest_file->getPathname()
|
||||
, $record->get_creation_date()->format('U')
|
||||
, $record->get_modification_date()->format('U')
|
||||
);
|
||||
|
||||
switch (strtolower($caption))
|
||||
{
|
||||
case 'xml':
|
||||
$pathinfo = pathinfo($dest_file->getPathname());
|
||||
$xml = $record->get_caption()->serialize(caption_record::SERIALIZE_XML);
|
||||
$xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
|
||||
file_put_contents($xml_file, $xml);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,126 +26,107 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_systemMailCheck extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Check if email addresses are unique (mandatory since 3.5)');
|
||||
$this->addOption('list'
|
||||
$this->setDescription('Check if email addresses are unique (mandatory since 3.5)');
|
||||
$this->addOption('list'
|
||||
, 'l'
|
||||
, null
|
||||
, 'List all bad accounts instead of the interactive mode'
|
||||
);
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$output->writeln("Processing...");
|
||||
|
||||
$bad_users = User_Adapter::get_wrong_email_users($appbox);
|
||||
|
||||
foreach ($bad_users as $email => $users)
|
||||
{
|
||||
if ($input->getOption('list'))
|
||||
{
|
||||
$this->write_infos($email, $users, $output, $appbox);
|
||||
}
|
||||
elseif ($this->manage_group($email, $users, $output, $appbox) === false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
return $this;
|
||||
}
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function manage_group($email, $users, $output, $appbox)
|
||||
{
|
||||
$is_stopped = false;
|
||||
|
||||
while (!$is_stopped)
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->write_infos($email, $users, $output, $appbox);
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
do
|
||||
{
|
||||
$question = '<question>What should I do ? '
|
||||
. 'continue (C), detach from mail (d), or stop (s)</question>';
|
||||
$output->writeln("Processing...");
|
||||
|
||||
$continue = mb_strtolower($dialog->ask($output, $question, 'C'));
|
||||
}
|
||||
while (!in_array($continue, array('c', 'd', 's')));
|
||||
$bad_users = User_Adapter::get_wrong_email_users($appbox);
|
||||
|
||||
foreach ($bad_users as $email => $users) {
|
||||
if ($input->getOption('list')) {
|
||||
$this->write_infos($email, $users, $output, $appbox);
|
||||
} elseif ($this->manage_group($email, $users, $output, $appbox) === false) {
|
||||
break;
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
}
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function manage_group($email, $users, $output, $appbox)
|
||||
{
|
||||
$is_stopped = false;
|
||||
|
||||
while ( ! $is_stopped) {
|
||||
$this->write_infos($email, $users, $output, $appbox);
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
do {
|
||||
$question = '<question>What should I do ? '
|
||||
. 'continue (C), detach from mail (d), or stop (s)</question>';
|
||||
|
||||
$continue = mb_strtolower($dialog->ask($output, $question, 'C'));
|
||||
} while ( ! in_array($continue, array('c', 'd', 's')));
|
||||
|
||||
|
||||
if ($continue == 's')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
elseif ($continue == 'c')
|
||||
{
|
||||
if ($continue == 's') {
|
||||
return false;
|
||||
} elseif ($continue == 'c') {
|
||||
return true;
|
||||
} elseif ($continue == 'd') {
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
$id = $dialog->ask($output, '<question>Which id ?</question>', '');
|
||||
|
||||
try {
|
||||
$tmp_user = User_Adapter::getInstance($id, $appbox);
|
||||
|
||||
if ($tmp_user->get_email() != $email) {
|
||||
throw new Exception('Invalid user');
|
||||
}
|
||||
|
||||
$tmp_user->set_email(null);
|
||||
|
||||
unset($users[$id]);
|
||||
} catch (Exception $e) {
|
||||
$output->writeln('<error>Wrong id</error>');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($users) <= 1) {
|
||||
$output->writeln(sprintf("<info>\n%s fixed !</info>", $email));
|
||||
$is_stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
elseif ($continue == 'd')
|
||||
{
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
$id = $dialog->ask($output, '<question>Which id ?</question>', '');
|
||||
|
||||
try
|
||||
{
|
||||
$tmp_user = User_Adapter::getInstance($id, $appbox);
|
||||
|
||||
if ($tmp_user->get_email() != $email)
|
||||
{
|
||||
throw new Exception('Invalid user');
|
||||
}
|
||||
|
||||
$tmp_user->set_email(null);
|
||||
|
||||
unset($users[$id]);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$output->writeln('<error>Wrong id</error>');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($users) <= 1)
|
||||
{
|
||||
$output->writeln(sprintf("<info>\n%s fixed !</info>", $email));
|
||||
$is_stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function write_infos($email, $users, $output, $appbox)
|
||||
{
|
||||
$output->writeln($email);
|
||||
|
||||
foreach ($users as $user)
|
||||
protected function write_infos($email, $users, $output, $appbox)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\t %5d %40s %s"
|
||||
, $user->get_id()
|
||||
, $user->get_display_name()
|
||||
, $user->get_last_connection()->format('Y m d')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$output->writeln($email);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\t %5d %40s %s"
|
||||
, $user->get_id()
|
||||
, $user->get_display_name()
|
||||
, $user->get_last_connection()->format('Y m d')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,22 +37,21 @@ class module_console_systemTemplateGenerator extends Command
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$tplDirs = array(
|
||||
realpath(__DIR__ . '/../../../../templates/web/'),
|
||||
realpath(__DIR__ . '/../../../../templates/mobile/')
|
||||
realpath(__DIR__ . '/../../../../templates/web/'),
|
||||
realpath(__DIR__ . '/../../../../templates/mobile/')
|
||||
);
|
||||
|
||||
$n_ok = $n_error = 0;
|
||||
$n_ok = $n_error = 0;
|
||||
|
||||
foreach ($tplDirs as $tplDir)
|
||||
{
|
||||
foreach ($tplDirs as $tplDir) {
|
||||
$tmpDir = __DIR__ . '/../../../../tmp/cache_twig/';
|
||||
|
||||
$loader = new Twig_Loader_Filesystem($tplDir);
|
||||
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => $tmpDir,
|
||||
'auto_reload' => true
|
||||
));
|
||||
'cache' => $tmpDir,
|
||||
'auto_reload' => true
|
||||
));
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
|
||||
@@ -93,16 +92,12 @@ class module_console_systemTemplateGenerator extends Command
|
||||
|
||||
|
||||
$finder = new Symfony\Component\Finder\Finder();
|
||||
foreach ($finder->files()->in(array($tplDir)) as $file)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach ($finder->files()->in(array($tplDir)) as $file) {
|
||||
try {
|
||||
$twig->loadTemplate(str_replace($tplDir, '', $file->getPathname()));
|
||||
$output->writeln('' . $file . '');
|
||||
$n_ok ++;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
$output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||
$n_error ++;
|
||||
}
|
||||
@@ -112,8 +107,7 @@ class module_console_systemTemplateGenerator extends Command
|
||||
$output->writeln("");
|
||||
$output->write(sprintf('%d templates generated. ', $n_ok));
|
||||
|
||||
if ($n_error > 0)
|
||||
{
|
||||
if ($n_error > 0) {
|
||||
$output->write(sprintf('<error>%d templates failed.</error>', $n_error));
|
||||
}
|
||||
|
||||
@@ -121,5 +115,4 @@ class module_console_systemTemplateGenerator extends Command
|
||||
|
||||
return $n_error;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,92 +26,73 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_systemUpgrade extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Upgrade Phraseanet to the lastest version');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$Core = \bootstrap::getCore();
|
||||
if (!setup::is_installed())
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
|
||||
$output->writeln('Would you like it to be created based on your settings ?');
|
||||
$this->setDescription('Upgrade Phraseanet to the lastest version');
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
do
|
||||
{
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
|
||||
}
|
||||
while (!in_array($continue, array('y', 'n')));
|
||||
|
||||
if ($continue == 'y')
|
||||
{
|
||||
try
|
||||
{
|
||||
$connexionInc = new \SplFileObject(__DIR__ . '/../../../../config/connexion.inc');
|
||||
$configInc = new \SplFileObject(__DIR__ . '/../../../../config/config.inc');
|
||||
|
||||
$Core->getConfiguration()->upgradeFromOldConf($configInc, $connexionInc);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be upgraded', true);
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
do
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
|
||||
}
|
||||
while (!in_array($continue, array('y', 'n')));
|
||||
$Core = \bootstrap::getCore();
|
||||
if ( ! setup::is_installed()) {
|
||||
|
||||
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
|
||||
$output->writeln('Would you like it to be created based on your settings ?');
|
||||
|
||||
if ($continue == 'y')
|
||||
{
|
||||
try
|
||||
{
|
||||
$Core = \bootstrap::getCore();
|
||||
$output->write('<info>Upgrading...</info>', true);
|
||||
$appbox = appbox::get_instance($Core);
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
do {
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
|
||||
} while ( ! in_array($continue, array('y', 'n')));
|
||||
|
||||
if (count(User_Adapter::get_wrong_email_users($appbox)) > 0)
|
||||
{
|
||||
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
|
||||
if ($continue == 'y') {
|
||||
try {
|
||||
$connexionInc = new \SplFileObject(__DIR__ . '/../../../../config/connexion.inc');
|
||||
$configInc = new \SplFileObject(__DIR__ . '/../../../../config/config.inc');
|
||||
|
||||
$Core->getConfiguration()->upgradeFromOldConf($configInc, $connexionInc);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
}
|
||||
|
||||
$upgrader = new Setup_Upgrade($appbox);
|
||||
$advices = $appbox->forceUpgrade($upgrader);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
|
||||
}
|
||||
$output->write('Phraseanet is going to be upgraded', true);
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
do {
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
|
||||
} while ( ! in_array($continue, array('y', 'n')));
|
||||
|
||||
|
||||
if ($continue == 'y') {
|
||||
try {
|
||||
$Core = \bootstrap::getCore();
|
||||
$output->write('<info>Upgrading...</info>', true);
|
||||
$appbox = appbox::get_instance($Core);
|
||||
|
||||
if (count(User_Adapter::get_wrong_email_users($appbox)) > 0) {
|
||||
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
|
||||
}
|
||||
|
||||
$upgrader = new Setup_Upgrade($appbox);
|
||||
$advices = $appbox->forceUpgrade($upgrader);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
|
||||
}
|
||||
} else {
|
||||
$output->write('<info>Canceled</info>', true);
|
||||
}
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->write('<info>Canceled</info>', true);
|
||||
}
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,56 +26,49 @@ use Symfony\Component\Console\Command\Command;
|
||||
class module_console_tasklist extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('List tasks');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
parent::__construct($name);
|
||||
|
||||
return 1;
|
||||
$this->setDescription('List tasks');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if ( ! setup::is_installed()) {
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
if (count($tasks) === 0)
|
||||
{
|
||||
$output->writeln('No tasks on your install !');
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
foreach ($tasks as $task)
|
||||
{
|
||||
$this->print_task($task, $output);
|
||||
}
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
return 0;
|
||||
try {
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
|
||||
if (count($tasks) === 0) {
|
||||
$output->writeln('No tasks on your install !');
|
||||
}
|
||||
|
||||
foreach ($tasks as $task) {
|
||||
$this->print_task($task, $output);
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
|
||||
protected function print_task(task_abstract $task, OutputInterface &$output)
|
||||
{
|
||||
return 1;
|
||||
$message = $task->get_task_id() . "\t" . ($task->get_status() ) . "\t" . $task->get_title();
|
||||
$output->writeln($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
protected function print_task(task_abstract $task, OutputInterface &$output)
|
||||
{
|
||||
$message = $task->get_task_id() . "\t" . ($task->get_status() ) . "\t" . $task->get_title();
|
||||
$output->writeln($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,117 +25,105 @@ use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_taskrun extends Command
|
||||
{
|
||||
private $task;
|
||||
private $shedulerPID;
|
||||
|
||||
private $task;
|
||||
private $shedulerPID;
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->task = NULL;
|
||||
$this->shedulerPID = NULL;
|
||||
|
||||
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
|
||||
$this->addOption(
|
||||
'runner'
|
||||
, 'r'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'The name of the runner (manual, scheduler...)'
|
||||
, task_abstract::RUNNER_MANUAL
|
||||
);
|
||||
$this->addOption(
|
||||
'nolog'
|
||||
, NULL
|
||||
, 1 | InputOption::VALUE_NONE
|
||||
, 'do not log to logfile'
|
||||
, NULL
|
||||
);
|
||||
$this->setDescription('Run task');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
function sig_handler($signo)
|
||||
{
|
||||
if ($this->task)
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$this->task->log(sprintf("signal %s received", $signo));
|
||||
if ($signo == SIGTERM)
|
||||
$this->task->set_running(false);
|
||||
}
|
||||
}
|
||||
parent::__construct($name);
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
$this->task = NULL;
|
||||
$this->shedulerPID = NULL;
|
||||
|
||||
return 1;
|
||||
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
|
||||
$this->addOption(
|
||||
'runner'
|
||||
, 'r'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'The name of the runner (manual, scheduler...)'
|
||||
, task_abstract::RUNNER_MANUAL
|
||||
);
|
||||
$this->addOption(
|
||||
'nolog'
|
||||
, NULL
|
||||
, 1 | InputOption::VALUE_NONE
|
||||
, 'do not log to logfile'
|
||||
, NULL
|
||||
);
|
||||
$this->setDescription('Run task');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$task_id = (int) $input->getArgument('task_id');
|
||||
|
||||
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
|
||||
throw new \RuntimeException('Argument must be an Id.');
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$this->task = $task_manager->get_task($task_id);
|
||||
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
|
||||
function sig_handler($signo)
|
||||
{
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$runner = task_abstract::RUNNER_SCHEDULER;
|
||||
$registry = $appbox->get_registry();
|
||||
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
|
||||
if (file_exists($schedFile))
|
||||
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
|
||||
}
|
||||
|
||||
register_tick_function(array($this, 'tick_handler'), true);
|
||||
declare(ticks = 1);
|
||||
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
|
||||
|
||||
$this->task->run($runner, $input, $output);
|
||||
|
||||
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
|
||||
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
|
||||
{
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
}
|
||||
}
|
||||
|
||||
public function tick_handler()
|
||||
{
|
||||
static $start = FALSE;
|
||||
|
||||
if ($start === FALSE)
|
||||
{
|
||||
$start = time();
|
||||
}
|
||||
|
||||
if (time() - $start > 0)
|
||||
{
|
||||
if ($this->shedulerPID)
|
||||
{
|
||||
if (!posix_kill($this->shedulerPID, 0))
|
||||
{
|
||||
if (method_exists($this->task, 'signal'))
|
||||
$this->task->signal('SIGNAL_SCHEDULER_DIED');
|
||||
else
|
||||
$this->task->set_status(task_abstract::STATUS_TOSTOP);
|
||||
if ($this->task) {
|
||||
$this->task->log(sprintf("signal %s received", $signo));
|
||||
if ($signo == SIGTERM)
|
||||
$this->task->set_running(false);
|
||||
}
|
||||
}
|
||||
|
||||
$start = time();
|
||||
}
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if ( ! setup::is_installed()) {
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$task_id = (int) $input->getArgument('task_id');
|
||||
|
||||
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
|
||||
throw new \RuntimeException('Argument must be an Id.');
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$this->task = $task_manager->get_task($task_id);
|
||||
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
} else {
|
||||
$runner = task_abstract::RUNNER_SCHEDULER;
|
||||
$registry = $appbox->get_registry();
|
||||
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
|
||||
if (file_exists($schedFile))
|
||||
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
|
||||
}
|
||||
|
||||
register_tick_function(array($this, 'tick_handler'), true);
|
||||
declare(ticks = 1);
|
||||
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
|
||||
|
||||
$this->task->run($runner, $input, $output);
|
||||
|
||||
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
|
||||
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
}
|
||||
}
|
||||
|
||||
public function tick_handler()
|
||||
{
|
||||
static $start = FALSE;
|
||||
|
||||
if ($start === FALSE) {
|
||||
$start = time();
|
||||
}
|
||||
|
||||
if (time() - $start > 0) {
|
||||
if ($this->shedulerPID) {
|
||||
if ( ! posix_kill($this->shedulerPID, 0)) {
|
||||
if (method_exists($this->task, 'signal'))
|
||||
$this->task->signal('SIGNAL_SCHEDULER_DIED');
|
||||
else
|
||||
$this->task->set_status(task_abstract::STATUS_TOSTOP);
|
||||
}
|
||||
}
|
||||
|
||||
$start = time();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -17,131 +17,113 @@
|
||||
*/
|
||||
class module_report_add extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: document ajoute');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('add')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('add');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
elseif ($field == 'size')
|
||||
$caption = p4string::format_octets($value);
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: document ajoute');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('add')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('add');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter") {
|
||||
try {
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
} elseif ($field == 'date')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
elseif ($field == 'size')
|
||||
$caption = p4string::format_octets($value);
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($rs as $row) {
|
||||
foreach ($this->champ as $key => $value) {
|
||||
if ($row[$value]) {
|
||||
if ($value == 'date') {
|
||||
$this->result[$i][$value] = $this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
} elseif ($value == 'size') {
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else {
|
||||
if ($value == 'comment') {
|
||||
$this->result[$i][$value] = ' ';
|
||||
} else {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i ++;
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,183 +17,160 @@
|
||||
*/
|
||||
class module_report_connexion extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user'
|
||||
, 'usrid' => 'log.usrid'
|
||||
, 'ddate' => 'log.date'
|
||||
, 'societe' => 'log.societe'
|
||||
, 'pays' => 'log.pays'
|
||||
, 'activite' => 'log.activite'
|
||||
, 'fonction' => 'log.fonction'
|
||||
, 'site' => 'log.site'
|
||||
, 'sit_session' => 'log.sit_session'
|
||||
, 'coll_list' => 'log.coll_list'
|
||||
, 'appli' => 'log.appli'
|
||||
, 'ip' => 'log.ip'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user'
|
||||
, 'usrid' => 'log.usrid'
|
||||
, 'ddate' => 'log.date'
|
||||
, 'societe' => 'log.societe'
|
||||
, 'pays' => 'log.pays'
|
||||
, 'activite' => 'log.activite'
|
||||
, 'fonction' => 'log.fonction'
|
||||
, 'site' => 'log.site'
|
||||
, 'sit_session' => 'log.sit_session'
|
||||
, 'coll_list' => 'log.coll_list'
|
||||
, 'appli' => 'log.appli'
|
||||
, 'ip' => 'log.ip'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name connexion::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report::Connexions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false)
|
||||
{
|
||||
$sql = $this->sqlBuilder('connexion');
|
||||
$sql = $sql->setGroupBy($groupby);
|
||||
$sql = $sql->buildSql();
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the list with all distinct result
|
||||
* @param string $field the field from the request displayed in a array
|
||||
* @return string $liste
|
||||
*/
|
||||
public function colFilter($field)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('connexion');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name connexion::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
if ($field == "appli")
|
||||
$caption = implode(' ', phrasea::modulesName(@unserialize($value)));
|
||||
elseif ($field == 'ddate')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
else
|
||||
$caption = $row['val'];
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report::Connexions');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false)
|
||||
{
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if (!isset($row[$value]))
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
continue;
|
||||
}
|
||||
$sql = $this->sqlBuilder('connexion');
|
||||
$sql = $sql->setGroupBy($groupby);
|
||||
$sql = $sql->buildSql();
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
if ($value == 'coll_list')
|
||||
{
|
||||
$coll = explode(",", $row[$value]);
|
||||
$this->result[$i][$value] = "";
|
||||
foreach ($coll as $id)
|
||||
{
|
||||
if ($this->result[$i][$value] != "")
|
||||
{
|
||||
$this->result[$i][$value].= " / ";
|
||||
$this->result[$i][$value] .= phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $id));
|
||||
}
|
||||
elseif ($this->result[$i][$value] == "")
|
||||
{
|
||||
$this->result[$i][$value] = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $id));
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($value == 'appli')
|
||||
{
|
||||
$applis = false;
|
||||
if (($applis = @unserialize($row[$value])) !== false)
|
||||
{
|
||||
if (empty($applis))
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
/**
|
||||
* @desc build the list with all distinct result
|
||||
* @param string $field the field from the request displayed in a array
|
||||
* @return string $liste
|
||||
*/
|
||||
public function colFilter($field)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('connexion');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
if ($field == "appli")
|
||||
$caption = implode(' ', phrasea::modulesName(@unserialize($value)));
|
||||
elseif ($field == 'ddate')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = implode(' ', phrasea::modulesName($applis));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
$caption = $row['val'];
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
elseif ($value == 'ddate')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNbConn($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
foreach ($rs as $row) {
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $key => $value) {
|
||||
if ( ! isset($row[$value])) {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
continue;
|
||||
}
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
if ($value == 'coll_list') {
|
||||
$coll = explode(",", $row[$value]);
|
||||
$this->result[$i][$value] = "";
|
||||
foreach ($coll as $id) {
|
||||
if ($this->result[$i][$value] != "") {
|
||||
$this->result[$i][$value].= " / ";
|
||||
$this->result[$i][$value] .= phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $id));
|
||||
} elseif ($this->result[$i][$value] == "") {
|
||||
$this->result[$i][$value] = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $id));
|
||||
}
|
||||
}
|
||||
} elseif ($value == 'appli') {
|
||||
$applis = false;
|
||||
if (($applis = @unserialize($row[$value])) !== false) {
|
||||
if (empty($applis)) {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
} else {
|
||||
$this->result[$i][$value] = implode(' ', phrasea::modulesName($applis));
|
||||
}
|
||||
} else {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
} elseif ($value == 'ddate') {
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
} else {
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
|
||||
$finalfilter = $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= '(' . $collfilter['sql'] . ') AND ';
|
||||
$finalfilter .= 'log_date.site = :site_id';
|
||||
public static function getNbConn($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$sql = "SELECT COUNT(usrid) as nb
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
|
||||
$finalfilter = $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= '(' . $collfilter['sql'] . ') AND ';
|
||||
$finalfilter .= 'log_date.site = :site_id';
|
||||
|
||||
$sql = "SELECT COUNT(usrid) as nb
|
||||
FROM log as log_date
|
||||
WHERE " . $finalfilter;
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return (int) $row['nb'];
|
||||
}
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return (int) $row['nb'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,353 +17,327 @@
|
||||
*/
|
||||
class module_report_dashboard implements module_report_dashboard_componentInterface
|
||||
{
|
||||
/**
|
||||
* objet user
|
||||
* @var user
|
||||
*/
|
||||
public $usr;
|
||||
|
||||
/**
|
||||
* objet user
|
||||
* @var user
|
||||
*/
|
||||
public $usr;
|
||||
/**
|
||||
* @la date mini du report
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmin;
|
||||
|
||||
/**
|
||||
* @la date mini du report
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmin;
|
||||
/**
|
||||
* @desc la date maxi du report
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmax;
|
||||
|
||||
/**
|
||||
* @desc la date maxi du report
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmax;
|
||||
/**
|
||||
* @desc le tableau qui contient toutes les collections ou l'utilisateur
|
||||
* a le droit de report
|
||||
* @var <array>
|
||||
*/
|
||||
public $authorizedCollection = array();
|
||||
|
||||
/**
|
||||
* @desc le tableau qui contient toutes les collections ou l'utilisateur
|
||||
* a le droit de report
|
||||
* @var <array>
|
||||
*/
|
||||
public $authorizedCollection = array();
|
||||
/**
|
||||
* @desc le tableau qui contient le dashboard
|
||||
* @var <array>
|
||||
*/
|
||||
public $dashboard = array();
|
||||
|
||||
/**
|
||||
* @desc le tableau qui contient le dashboard
|
||||
* @var <array>
|
||||
*/
|
||||
public $dashboard = array();
|
||||
/**
|
||||
* @des le nombre par defaut de resultats afficher par categorie
|
||||
* @var <int>
|
||||
*/
|
||||
public $nbtop = 10;
|
||||
|
||||
/**
|
||||
* @des le nombre par defaut de resultats afficher par categorie
|
||||
* @var <int>
|
||||
*/
|
||||
public $nbtop = 10;
|
||||
/**
|
||||
* @desc la periode par defaut d'affichage du dashboard
|
||||
* @var <string>
|
||||
*/
|
||||
public $periode = '-1 month';
|
||||
|
||||
/**
|
||||
* @desc la periode par defaut d'affichage du dashboard
|
||||
* @var <string>
|
||||
*/
|
||||
public $periode = '-1 month';
|
||||
/**
|
||||
* @desc le sbasid de la base ou on effectue le report
|
||||
* @var <int>
|
||||
*/
|
||||
public $sbasid;
|
||||
|
||||
/**
|
||||
* @desc le sbasid de la base ou on effectue le report
|
||||
* @var <int>
|
||||
*/
|
||||
public $sbasid;
|
||||
|
||||
/**
|
||||
* @desc Construit un dashboard selon les droits du usrid, si sbas vaut null
|
||||
* c'est un report sur toutes les bases, sinon sur le sbasid
|
||||
* @param <int> $usrid
|
||||
* @param <int> $sbasid
|
||||
*/
|
||||
public function __construct($usr, $sbasid = null)
|
||||
{
|
||||
$this->usr = $usr;
|
||||
if (is_null($sbasid))
|
||||
$this->sbasid = 'all';
|
||||
else
|
||||
$this->sbasid = $sbasid;
|
||||
$this->initDate();
|
||||
$this->setAuthCollection();
|
||||
$this->getPlotLegendDay($this->dmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc genere le report
|
||||
* @return dashboard_main
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->setReport();
|
||||
$this->process();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc modifier les date du report
|
||||
* @param Datetime $dmin
|
||||
* @param Datetime $dmax
|
||||
* @return <void>
|
||||
*/
|
||||
public function setDate($dmin, $dmax)
|
||||
{
|
||||
$dmin = new Datetime($dmin);
|
||||
$dmax = new Datetime($dmax);
|
||||
|
||||
$dmax->modify('+23 hours +59 minutes +59 seconds');
|
||||
|
||||
$this->dmax = $dmax->format('d-m-Y');
|
||||
$this->dmin = $dmin->format('d-m-Y');
|
||||
|
||||
$this->getPlotLegendDay($this->dmin, $this->dmax);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return la liste des collection authoriséee
|
||||
* @return <array>
|
||||
*/
|
||||
public function authorizedCollection()
|
||||
{
|
||||
return $this->authorizedCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return le titre de la date
|
||||
* @param <string> $d vaut 'dmin' ou 'dmax'
|
||||
* @return <string>
|
||||
*/
|
||||
public function getTitleDate($d)
|
||||
{
|
||||
if ($d == 'dmax')
|
||||
/**
|
||||
* @desc Construit un dashboard selon les droits du usrid, si sbas vaut null
|
||||
* c'est un report sur toutes les bases, sinon sur le sbasid
|
||||
* @param <int> $usrid
|
||||
* @param <int> $sbasid
|
||||
*/
|
||||
public function __construct($usr, $sbasid = null)
|
||||
{
|
||||
$datetime = new Datetime($this->dmax);
|
||||
|
||||
return phraseadate::getPrettyString($datetime);
|
||||
}
|
||||
elseif ($d == 'dmin')
|
||||
{
|
||||
$datetime = new Datetime($this->dmin);
|
||||
|
||||
return phraseadate::getPrettyString($datetime);
|
||||
}
|
||||
else
|
||||
throw new Exception('argument must be string dmin or dmax');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if a dashboard is valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->dashboard) && sizeof($this->dashboard) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return le dashboard
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->dashboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc construct the legend for charts
|
||||
* if dmax === false dmax = now();
|
||||
* @param <Datetime> $dmin
|
||||
* @param <Datetime> $dmax
|
||||
* @return <void>
|
||||
*/
|
||||
protected function getPlotLegendDay($dmin, $dmax = false)
|
||||
{
|
||||
if (!$dmax)
|
||||
{
|
||||
$date = new Datetime();
|
||||
$dmax = $date->format('d-m-Y');
|
||||
}
|
||||
else
|
||||
{
|
||||
$date = new Datetime($dmax);
|
||||
$dmax = $date->format('d-m-Y');
|
||||
}
|
||||
$this->legendDay[] = phraseadate::getPrettyString($date);
|
||||
|
||||
while ($dmin != $dmax)
|
||||
{
|
||||
$date->modify('-1 day');
|
||||
$dmax = $date->format('d-m-Y');
|
||||
$this->legendDay[] = phraseadate::getPrettyString($date);
|
||||
$this->nb_days++;
|
||||
}
|
||||
$this->legendDay = array_reverse($this->legendDay);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc merge tous les resultats dans dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$tri = $this->group()->tri();
|
||||
$x = $tri->getDash();
|
||||
$a = $tri->top()->getTop($this->nbtop);
|
||||
$this->dashboard = array();
|
||||
foreach ($a as $k => $v)
|
||||
{
|
||||
if (array_key_exists($k, $x))
|
||||
{
|
||||
$x[$k] = $v;
|
||||
}
|
||||
}
|
||||
$this->dashboard = $x;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc init dmin and dmax
|
||||
* @return <void>
|
||||
*/
|
||||
protected function initDate()
|
||||
{
|
||||
$datetime = new Datetime();
|
||||
$this->dmax = $datetime->format('d-m-Y');
|
||||
$datetime->modify($this->periode);
|
||||
$this->dmin = $datetime->format('d-m-Y');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc construit un array avec tous les collections ou l'utilisateur
|
||||
* a le droit de reporting
|
||||
* @return <array>
|
||||
*/
|
||||
public function getAllColl()
|
||||
{
|
||||
$all_coll = array();
|
||||
|
||||
$base_ids = $this->usr->ACL()->get_granted_base(array('canreport'));
|
||||
|
||||
foreach ($base_ids as $base_id => $collection)
|
||||
{
|
||||
$databox = $collection->get_databox();
|
||||
$sbas_id = $databox->get_sbas_id();
|
||||
if (!isset($all_coll[$sbas_id]))
|
||||
{
|
||||
$all_coll[$sbas_id] = array();
|
||||
$all_coll[$sbas_id]['name_sbas'] = $databox->get_viewname();
|
||||
}
|
||||
$all_coll[$sbas_id]['sbas_collections'][] = array(
|
||||
'base_id' => $base_id,
|
||||
'sbas_id' => $sbas_id,
|
||||
'coll_id' => $collection->get_base_id(),
|
||||
'name' => $collection->get_name()
|
||||
);
|
||||
$this->usr = $usr;
|
||||
if (is_null($sbasid))
|
||||
$this->sbasid = 'all';
|
||||
else
|
||||
$this->sbasid = $sbasid;
|
||||
$this->initDate();
|
||||
$this->setAuthCollection();
|
||||
$this->getPlotLegendDay($this->dmin);
|
||||
}
|
||||
|
||||
return $all_coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @des set authorizedCollection
|
||||
* @return <void>
|
||||
*/
|
||||
protected function setAuthCollection()
|
||||
{
|
||||
$all_coll = $this->getAllColl();
|
||||
|
||||
foreach ($all_coll as $sbas => $info)
|
||||
/**
|
||||
* @desc genere le report
|
||||
* @return dashboard_main
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$listeColl = array();
|
||||
$this->setReport();
|
||||
$this->process();
|
||||
|
||||
foreach ($info['sbas_collections'] as $key => $value)
|
||||
{
|
||||
$listeColl[] = (int) $value['coll_id'];
|
||||
}
|
||||
|
||||
$this->authorizedCollection[] = array(
|
||||
'sbas_id' => (int) $sbas,
|
||||
'coll' => implode(',', $listeColl),
|
||||
'name' => phrasea::sbas_names($sbas)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc la liste des base authorisee sous forme de string
|
||||
* @param <string> $separotor
|
||||
* @return string
|
||||
*/
|
||||
public function getListeBase($separator)
|
||||
{
|
||||
$all_coll = $this->getAllColl();
|
||||
$liste = '';
|
||||
foreach ($all_coll as $sbas => $info)
|
||||
/**
|
||||
* @desc modifier les date du report
|
||||
* @param Datetime $dmin
|
||||
* @param Datetime $dmax
|
||||
* @return <void>
|
||||
*/
|
||||
public function setDate($dmin, $dmax)
|
||||
{
|
||||
$liste .= phrasea::sbas_names($sbas) . ' ' . $separator . ' ';
|
||||
$dmin = new Datetime($dmin);
|
||||
$dmax = new Datetime($dmax);
|
||||
|
||||
$dmax->modify('+23 hours +59 minutes +59 seconds');
|
||||
|
||||
$this->dmax = $dmax->format('d-m-Y');
|
||||
$this->dmin = $dmin->format('d-m-Y');
|
||||
|
||||
$this->getPlotLegendDay($this->dmin, $this->dmax);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return $liste;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Foreach authorized collection, fill the dashboard
|
||||
* with an object dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
protected function setReport()
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($this->authorizedCollection as $key => $value)
|
||||
/**
|
||||
* @desc return la liste des collection authoriséee
|
||||
* @return <array>
|
||||
*/
|
||||
public function authorizedCollection()
|
||||
{
|
||||
$sbasid = $value['sbas_id'];
|
||||
$coll = $value['coll'];
|
||||
try
|
||||
{
|
||||
if ($this->sbasid != "all")
|
||||
{
|
||||
if ($this->sbasid == $sbasid)
|
||||
{
|
||||
$this->dashboard[$sbasid] = module_report_dashboard_feed::getInstance(
|
||||
$sbasid, $coll, $this->dmin, $this->dmax
|
||||
);
|
||||
break;
|
||||
}
|
||||
return $this->authorizedCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return le titre de la date
|
||||
* @param <string> $d vaut 'dmin' ou 'dmax'
|
||||
* @return <string>
|
||||
*/
|
||||
public function getTitleDate($d)
|
||||
{
|
||||
if ($d == 'dmax') {
|
||||
$datetime = new Datetime($this->dmax);
|
||||
|
||||
return phraseadate::getPrettyString($datetime);
|
||||
} elseif ($d == 'dmin') {
|
||||
$datetime = new Datetime($this->dmin);
|
||||
|
||||
return phraseadate::getPrettyString($datetime);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dashboard[$sbasid] = module_report_dashboard_feed::getInstance(
|
||||
$sbasid, $coll, $this->dmin, $this->dmax
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
$i++;
|
||||
throw new Exception('argument must be string dmin or dmax');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* @desc check if a dashboard is valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->dashboard) && sizeof($this->dashboard) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return dashboard_group
|
||||
*/
|
||||
public function group()
|
||||
{
|
||||
return new module_report_dashboard_group($this);
|
||||
}
|
||||
/**
|
||||
* @desc return le dashboard
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->dashboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc construct the legend for charts
|
||||
* if dmax === false dmax = now();
|
||||
* @param <Datetime> $dmin
|
||||
* @param <Datetime> $dmax
|
||||
* @return <void>
|
||||
*/
|
||||
protected function getPlotLegendDay($dmin, $dmax = false)
|
||||
{
|
||||
if ( ! $dmax) {
|
||||
$date = new Datetime();
|
||||
$dmax = $date->format('d-m-Y');
|
||||
} else {
|
||||
$date = new Datetime($dmax);
|
||||
$dmax = $date->format('d-m-Y');
|
||||
}
|
||||
$this->legendDay[] = phraseadate::getPrettyString($date);
|
||||
|
||||
while ($dmin != $dmax) {
|
||||
$date->modify('-1 day');
|
||||
$dmax = $date->format('d-m-Y');
|
||||
$this->legendDay[] = phraseadate::getPrettyString($date);
|
||||
$this->nb_days ++;
|
||||
}
|
||||
$this->legendDay = array_reverse($this->legendDay);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc merge tous les resultats dans dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$tri = $this->group()->tri();
|
||||
$x = $tri->getDash();
|
||||
$a = $tri->top()->getTop($this->nbtop);
|
||||
$this->dashboard = array();
|
||||
foreach ($a as $k => $v) {
|
||||
if (array_key_exists($k, $x)) {
|
||||
$x[$k] = $v;
|
||||
}
|
||||
}
|
||||
$this->dashboard = $x;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc init dmin and dmax
|
||||
* @return <void>
|
||||
*/
|
||||
protected function initDate()
|
||||
{
|
||||
$datetime = new Datetime();
|
||||
$this->dmax = $datetime->format('d-m-Y');
|
||||
$datetime->modify($this->periode);
|
||||
$this->dmin = $datetime->format('d-m-Y');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc construit un array avec tous les collections ou l'utilisateur
|
||||
* a le droit de reporting
|
||||
* @return <array>
|
||||
*/
|
||||
public function getAllColl()
|
||||
{
|
||||
$all_coll = array();
|
||||
|
||||
$base_ids = $this->usr->ACL()->get_granted_base(array('canreport'));
|
||||
|
||||
foreach ($base_ids as $base_id => $collection) {
|
||||
$databox = $collection->get_databox();
|
||||
$sbas_id = $databox->get_sbas_id();
|
||||
if ( ! isset($all_coll[$sbas_id])) {
|
||||
$all_coll[$sbas_id] = array();
|
||||
$all_coll[$sbas_id]['name_sbas'] = $databox->get_viewname();
|
||||
}
|
||||
$all_coll[$sbas_id]['sbas_collections'][] = array(
|
||||
'base_id' => $base_id,
|
||||
'sbas_id' => $sbas_id,
|
||||
'coll_id' => $collection->get_base_id(),
|
||||
'name' => $collection->get_name()
|
||||
);
|
||||
}
|
||||
|
||||
return $all_coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @des set authorizedCollection
|
||||
* @return <void>
|
||||
*/
|
||||
protected function setAuthCollection()
|
||||
{
|
||||
$all_coll = $this->getAllColl();
|
||||
|
||||
foreach ($all_coll as $sbas => $info) {
|
||||
$listeColl = array();
|
||||
|
||||
foreach ($info['sbas_collections'] as $key => $value) {
|
||||
$listeColl[] = (int) $value['coll_id'];
|
||||
}
|
||||
|
||||
$this->authorizedCollection[] = array(
|
||||
'sbas_id' => (int) $sbas,
|
||||
'coll' => implode(',', $listeColl),
|
||||
'name' => phrasea::sbas_names($sbas)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc la liste des base authorisee sous forme de string
|
||||
* @param <string> $separotor
|
||||
* @return string
|
||||
*/
|
||||
public function getListeBase($separator)
|
||||
{
|
||||
$all_coll = $this->getAllColl();
|
||||
$liste = '';
|
||||
foreach ($all_coll as $sbas => $info) {
|
||||
$liste .= phrasea::sbas_names($sbas) . ' ' . $separator . ' ';
|
||||
}
|
||||
|
||||
return $liste;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Foreach authorized collection, fill the dashboard
|
||||
* with an object dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
protected function setReport()
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($this->authorizedCollection as $key => $value) {
|
||||
$sbasid = $value['sbas_id'];
|
||||
$coll = $value['coll'];
|
||||
try {
|
||||
if ($this->sbasid != "all") {
|
||||
if ($this->sbasid == $sbasid) {
|
||||
$this->dashboard[$sbasid] = module_report_dashboard_feed::getInstance(
|
||||
$sbasid, $coll, $this->dmin, $this->dmax
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->dashboard[$sbasid] = module_report_dashboard_feed::getInstance(
|
||||
$sbasid, $coll, $this->dmin, $this->dmax
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return dashboard_group
|
||||
*/
|
||||
public function group()
|
||||
{
|
||||
return new module_report_dashboard_group($this);
|
||||
}
|
||||
}
|
||||
|
@@ -17,9 +17,10 @@
|
||||
*/
|
||||
interface module_report_dashboard_componentInterface
|
||||
{
|
||||
public function process();
|
||||
|
||||
public function getDash();
|
||||
public function process();
|
||||
|
||||
public function isValid();
|
||||
public function getDash();
|
||||
|
||||
public function isValid();
|
||||
}
|
||||
|
@@ -17,268 +17,222 @@
|
||||
*/
|
||||
class module_report_dashboard_feed implements module_report_dashboard_componentInterface
|
||||
{
|
||||
/**
|
||||
* @desc la date mini des resultats
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmin;
|
||||
|
||||
/**
|
||||
* @desc la date mini des resultats
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmin;
|
||||
/**
|
||||
* @desc la date maxi des resultats
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmax;
|
||||
/**
|
||||
* @desc version sql de la date mini
|
||||
* @var <string>
|
||||
*/
|
||||
public $dminsql;
|
||||
/**
|
||||
* @desc version sql de la date maxi
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmaxsql;
|
||||
/**
|
||||
* @desc le sbasid de la base sur lequel on effectue les requetes
|
||||
* @var <int>
|
||||
*/
|
||||
public $sbasid;
|
||||
/**
|
||||
* @la liste des collections séparés par une virgule
|
||||
* sur laquelle on effectue les requetes
|
||||
* @var <string>
|
||||
*/
|
||||
public $collection;
|
||||
/**
|
||||
* @desc le tableau qui contien les resultats
|
||||
* @var <array>
|
||||
*/
|
||||
public $report = array();
|
||||
/**
|
||||
* @desc la date maxi des resultats
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmax;
|
||||
|
||||
/**
|
||||
* @desc return l'objet stockee dans le cache si i l existe sinon instancie
|
||||
* un nouveau objet dashboard_feed
|
||||
* @param <int> $sbasid
|
||||
* @param <string> $sbas_coll
|
||||
* @param <string> $dmin
|
||||
* @param <string> $dmax
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance($sbasid, $sbas_coll, $dmin, $dmax)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$cache_id = 'feed_' . md5($sbasid . '_' . $sbas_coll . '_' . $dmin . '_' . $dmax);
|
||||
/**
|
||||
* @desc version sql de la date mini
|
||||
* @var <string>
|
||||
*/
|
||||
public $dminsql;
|
||||
|
||||
try
|
||||
{
|
||||
return $appbox->get_data_from_cache($cache_id);
|
||||
}
|
||||
catch (Exception $e)
|
||||
/**
|
||||
* @desc version sql de la date maxi
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmaxsql;
|
||||
|
||||
/**
|
||||
* @desc le sbasid de la base sur lequel on effectue les requetes
|
||||
* @var <int>
|
||||
*/
|
||||
public $sbasid;
|
||||
|
||||
/**
|
||||
* @la liste des collections séparés par une virgule
|
||||
* sur laquelle on effectue les requetes
|
||||
* @var <string>
|
||||
*/
|
||||
public $collection;
|
||||
|
||||
/**
|
||||
* @desc le tableau qui contien les resultats
|
||||
* @var <array>
|
||||
*/
|
||||
public $report = array();
|
||||
|
||||
/**
|
||||
* @desc return l'objet stockee dans le cache si i l existe sinon instancie
|
||||
* un nouveau objet dashboard_feed
|
||||
* @param <int> $sbasid
|
||||
* @param <string> $sbas_coll
|
||||
* @param <string> $dmin
|
||||
* @param <string> $dmax
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance($sbasid, $sbas_coll, $dmin, $dmax)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$cache_id = 'feed_' . md5($sbasid . '_' . $sbas_coll . '_' . $dmin . '_' . $dmax);
|
||||
|
||||
}
|
||||
try {
|
||||
return $appbox->get_data_from_cache($cache_id);
|
||||
} catch (Exception $e) {
|
||||
|
||||
$tmp = new self($sbasid, $sbas_coll, $dmin, $dmax);
|
||||
}
|
||||
|
||||
$appbox->set_data_to_cache($tmp, $cache_id);
|
||||
$tmp = new self($sbasid, $sbas_coll, $dmin, $dmax);
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
$appbox->set_data_to_cache($tmp, $cache_id);
|
||||
|
||||
/**
|
||||
* @desc Remplis les resultats bruts pour valeures passees en param
|
||||
* @param <int> $sbasid
|
||||
* @param <string> $sbas_collection, les collection sous forme de string
|
||||
* séparés par une virgule
|
||||
* @param <string> $dmin, Y-m-d
|
||||
* @param <string> $dmax, Y-m-d
|
||||
*/
|
||||
public function __construct($sbasid, $sbas_collection, $dmin, $dmax)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbasid);
|
||||
$this->dmin = $dmin;
|
||||
$this->dmax = $dmax;
|
||||
$this->dminsql = $this->dateToSqlDate('dmin');
|
||||
$this->dmaxsql = $this->dateToSqlDate('dmax');
|
||||
$this->sbasid = $sbasid;
|
||||
$this->collection = $sbas_collection;
|
||||
$this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return les date dormate pour les requetes sql;
|
||||
* @param <string> $d, vaut 'dmin' ou 'dmax'
|
||||
* @return Datetime
|
||||
*/
|
||||
private function dateToSqlDate($d)
|
||||
{
|
||||
if ($d == 'dmax')
|
||||
{
|
||||
$datetime = new Datetime($this->dmax);
|
||||
|
||||
return phraseadate::format_mysql($datetime);
|
||||
}
|
||||
elseif ($d == 'dmin')
|
||||
{
|
||||
$datetime = new Datetime($this->dmin);
|
||||
|
||||
return phraseadate::format_mysql($datetime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc fill the dash results for the current sbas
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Get number of DLs
|
||||
$this->report['nb_dl'] = module_report_download::getNbDl(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
//Get Number of connexions
|
||||
$this->report['nb_conn'] = module_report_connexion::getNbConn(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
$registry = registry::get_instance();
|
||||
if ($registry->get('GV_anonymousReport') == false)
|
||||
{
|
||||
/**
|
||||
* get Top ten user of
|
||||
* number of dl doc, prev
|
||||
* number of weight dl by doc, prev
|
||||
*/
|
||||
$top = module_report_activity::topTenUser(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
$this->report['top_ten_user_doc'] = $top['top_ten_doc'];
|
||||
$this->report['top_ten_user_prev'] = $top['top_ten_prev'];
|
||||
$this->report['top_ten_user_poiddoc'] = $top['top_ten_poiddoc'];
|
||||
$this->report['top_ten_user_poidprev'] = $top['top_ten_poidprev'];
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* get avtivity by hour
|
||||
* @desc Remplis les resultats bruts pour valeures passees en param
|
||||
* @param <int> $sbasid
|
||||
* @param <string> $sbas_collection, les collection sous forme de string
|
||||
* séparés par une virgule
|
||||
* @param <string> $dmin, Y-m-d
|
||||
* @param <string> $dmax, Y-m-d
|
||||
*/
|
||||
$this->report['activity'] = module_report_activity::activity(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
// get activty by day
|
||||
$this->report['activity_day'] = module_report_activity::activityDay(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
// get Most document and preview DL
|
||||
$topdl = module_report_download::getTopDl(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
$this->report['top_dl_preview'] = $topdl['preview'];
|
||||
$this->report['top_dl_document'] = $topdl['document'];
|
||||
|
||||
if ($registry->get('GV_anonymousReport') == false)
|
||||
public function __construct($sbasid, $sbas_collection, $dmin, $dmax)
|
||||
{
|
||||
// get users that ask the most questions
|
||||
$this->report['ask'] = module_report_activity::activityQuestion(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
$conn = connection::getPDOConnection($sbasid);
|
||||
$this->dmin = $dmin;
|
||||
$this->dmax = $dmax;
|
||||
$this->dminsql = $this->dateToSqlDate('dmin');
|
||||
$this->dmaxsql = $this->dateToSqlDate('dmax');
|
||||
$this->sbasid = $sbasid;
|
||||
$this->collection = $sbas_collection;
|
||||
$this->process();
|
||||
}
|
||||
//get the refferer
|
||||
$this->report['top_ten_site'] = module_report_activity::activiteTopTenSiteView(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
//Get the most asked questions
|
||||
$this->report['top_ten_question'] = module_report_activity::activiteTopQuestion(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
//get the number of added docuùments
|
||||
$this->report['activity_added'] = module_report_activity::activiteAddedDocument(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
//get number of edited document
|
||||
$this->report['activity_edited'] = module_report_activity::activiteEditedDocument(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
if ($registry->get('GV_anonymousReport') == false)
|
||||
/**
|
||||
* @desc return les date dormate pour les requetes sql;
|
||||
* @param <string> $d, vaut 'dmin' ou 'dmax'
|
||||
* @return Datetime
|
||||
*/
|
||||
private function dateToSqlDate($d)
|
||||
{
|
||||
//get users that add the most documents
|
||||
$this->report['top_ten_added'] = module_report_activity::activiteAddedTopTenUser(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
if ($d == 'dmax') {
|
||||
$datetime = new Datetime($this->dmax);
|
||||
|
||||
return phraseadate::format_mysql($datetime);
|
||||
} elseif ($d == 'dmin') {
|
||||
$datetime = new Datetime($this->dmin);
|
||||
|
||||
return phraseadate::format_mysql($datetime);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
|
||||
/**
|
||||
* @desc fill the dash results for the current sbas
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
try {
|
||||
//Get number of DLs
|
||||
$this->report['nb_dl'] = module_report_download::getNbDl(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
//Get Number of connexions
|
||||
$this->report['nb_conn'] = module_report_connexion::getNbConn(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
$registry = registry::get_instance();
|
||||
if ($registry->get('GV_anonymousReport') == false) {
|
||||
/**
|
||||
* get Top ten user of
|
||||
* number of dl doc, prev
|
||||
* number of weight dl by doc, prev
|
||||
*/
|
||||
$top = module_report_activity::topTenUser(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
|
||||
$this->report['top_ten_user_doc'] = $top['top_ten_doc'];
|
||||
$this->report['top_ten_user_prev'] = $top['top_ten_prev'];
|
||||
$this->report['top_ten_user_poiddoc'] = $top['top_ten_poiddoc'];
|
||||
$this->report['top_ten_user_poidprev'] = $top['top_ten_poidprev'];
|
||||
}
|
||||
|
||||
/**
|
||||
* get avtivity by hour
|
||||
*/
|
||||
$this->report['activity'] = module_report_activity::activity(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
|
||||
// get activty by day
|
||||
$this->report['activity_day'] = module_report_activity::activityDay(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
// get Most document and preview DL
|
||||
$topdl = module_report_download::getTopDl(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
|
||||
$this->report['top_dl_preview'] = $topdl['preview'];
|
||||
$this->report['top_dl_document'] = $topdl['document'];
|
||||
|
||||
if ($registry->get('GV_anonymousReport') == false) {
|
||||
// get users that ask the most questions
|
||||
$this->report['ask'] = module_report_activity::activityQuestion(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
}
|
||||
//get the refferer
|
||||
$this->report['top_ten_site'] = module_report_activity::activiteTopTenSiteView(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
//Get the most asked questions
|
||||
$this->report['top_ten_question'] = module_report_activity::activiteTopQuestion(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
|
||||
//get the number of added docuùments
|
||||
$this->report['activity_added'] = module_report_activity::activiteAddedDocument(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
|
||||
//get number of edited document
|
||||
$this->report['activity_edited'] = module_report_activity::activiteEditedDocument(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
if ($registry->get('GV_anonymousReport') == false) {
|
||||
//get users that add the most documents
|
||||
$this->report['top_ten_added'] = module_report_activity::activiteAddedTopTenUser(
|
||||
$this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
|
||||
);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return variable that contains the results
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if the results are valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->report) && sizeof($this->report) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @desc return variable that contains the results
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if the results are valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->report) && sizeof($this->report) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -17,93 +17,81 @@
|
||||
*/
|
||||
class module_report_dashboard_group implements module_report_dashboard_componentInterface
|
||||
{
|
||||
public $group_dash;
|
||||
public $dashboard = array();
|
||||
private $valid = false;
|
||||
|
||||
public $group_dash;
|
||||
public $dashboard = array();
|
||||
private $valid = false;
|
||||
|
||||
/**
|
||||
* @desc group the dashboard
|
||||
*/
|
||||
public function __construct(module_report_dashboard $report)
|
||||
{
|
||||
if ($report->isValid())
|
||||
/**
|
||||
* @desc group the dashboard
|
||||
*/
|
||||
public function __construct(module_report_dashboard $report)
|
||||
{
|
||||
$this->valid = true;
|
||||
$this->dashboard = $report->getDash();
|
||||
if ($report->isValid()) {
|
||||
$this->valid = true;
|
||||
$this->dashboard = $report->getDash();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc GROUP the dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if ($this->valid)
|
||||
/**
|
||||
* @desc GROUP the dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if (is_null($this->group_dash))
|
||||
$this->group_dash = array();
|
||||
foreach ($this->dashboard as $key => $dash)
|
||||
{
|
||||
if (is_object($dash) &&
|
||||
$dash instanceof module_report_dashboard_feed &&
|
||||
$dash->isValid())
|
||||
{
|
||||
$onedash = $dash->getDash();
|
||||
foreach ($onedash as $typeofreport => $value)
|
||||
{
|
||||
if (is_array($value) && sizeof($value) == 0)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
$this->group_dash[$typeofreport][] = $value;
|
||||
if ($this->valid) {
|
||||
if (is_null($this->group_dash))
|
||||
$this->group_dash = array();
|
||||
foreach ($this->dashboard as $key => $dash) {
|
||||
if (is_object($dash) &&
|
||||
$dash instanceof module_report_dashboard_feed &&
|
||||
$dash->isValid()) {
|
||||
$onedash = $dash->getDash();
|
||||
foreach ($onedash as $typeofreport => $value) {
|
||||
if (is_array($value) && sizeof($value) == 0)
|
||||
continue;
|
||||
else {
|
||||
$this->group_dash[$typeofreport][] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Exception("cannot group on a none dashboard object");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("cannot group on a none dashboard object");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* @desc check if the grouped dash is valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->group_dash) && sizeof($this->group_dash) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if the grouped dash is valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->group_dash) && sizeof($this->group_dash) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return the results
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->group_dash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Tri de grouped dash
|
||||
* @return dashboard_merge
|
||||
*/
|
||||
public function tri()
|
||||
{
|
||||
return new module_report_dashboard_merge($this);
|
||||
}
|
||||
/**
|
||||
* @desc return the results
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->group_dash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Tri de grouped dash
|
||||
* @return dashboard_merge
|
||||
*/
|
||||
public function tri()
|
||||
{
|
||||
return new module_report_dashboard_merge($this);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -17,205 +17,192 @@
|
||||
*/
|
||||
class module_report_dashboard_merge implements module_report_dashboard_componentInterface
|
||||
{
|
||||
public $sort = array();
|
||||
public $sorted = array();
|
||||
private $currentkey;
|
||||
private $valid = false;
|
||||
|
||||
public $sort = array();
|
||||
public $sorted = array();
|
||||
private $currentkey;
|
||||
private $valid = false;
|
||||
|
||||
/**
|
||||
* @desc tri le dashboard
|
||||
* @param dashboard_group $dash_organize
|
||||
*/
|
||||
public function __construct(module_report_dashboard_group $dash_organize)
|
||||
{
|
||||
if ($dash_organize->isValid())
|
||||
/**
|
||||
* @desc tri le dashboard
|
||||
* @param dashboard_group $dash_organize
|
||||
*/
|
||||
public function __construct(module_report_dashboard_group $dash_organize)
|
||||
{
|
||||
$this->valid = true;
|
||||
$this->sort = $dash_organize->getDash();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @des main function execute the process of triage
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if ($this->valid)
|
||||
{
|
||||
foreach ($this->sort as $key => $value)
|
||||
{
|
||||
$this->currentkey = $key;
|
||||
switch ($this->currentkey)
|
||||
{
|
||||
case "nb_conn":
|
||||
$this->sum();
|
||||
break;
|
||||
case "nb_dl":
|
||||
$this->sum();
|
||||
break;
|
||||
case "activity":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_day":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_edited":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_added":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "top_ten_user_doc":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_prev":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_poiddoc":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_poidprev":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_dl_preview":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_dl_document":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_question":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "ask":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_site":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_added":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if ($dash_organize->isValid()) {
|
||||
$this->valid = true;
|
||||
$this->sort = $dash_organize->getDash();
|
||||
}
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le dashboard trie
|
||||
* @return <type>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check si les resultats sont valides
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->sorted) && sizeof($this->sorted) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <void>
|
||||
*/
|
||||
private function sum()
|
||||
{
|
||||
$this->sorted[$this->currentkey] = 0;
|
||||
foreach ($this->sort[$this->currentkey] as $k => $v)
|
||||
$this->sorted[$this->currentkey] += $v;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Tri all result of activity type
|
||||
* @return <void>
|
||||
*/
|
||||
private function triActivity()
|
||||
{
|
||||
foreach ($this->sort[$this->currentkey] as $sbas => $val)
|
||||
/**
|
||||
* @des main function execute the process of triage
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
foreach ($val as $key => $value)
|
||||
{
|
||||
if ($this->valid) {
|
||||
foreach ($this->sort as $key => $value) {
|
||||
$this->currentkey = $key;
|
||||
switch ($this->currentkey) {
|
||||
case "nb_conn":
|
||||
$this->sum();
|
||||
break;
|
||||
case "nb_dl":
|
||||
$this->sum();
|
||||
break;
|
||||
case "activity":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_day":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_edited":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_added":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "top_ten_user_doc":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_prev":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_poiddoc":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_poidprev":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_dl_preview":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_dl_document":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_question":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "ask":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_site":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_added":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isset($this->sorted[$this->currentkey][$key]) ?
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le dashboard trie
|
||||
* @return <type>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check si les resultats sont valides
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->sorted) && sizeof($this->sorted) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <void>
|
||||
*/
|
||||
private function sum()
|
||||
{
|
||||
$this->sorted[$this->currentkey] = 0;
|
||||
foreach ($this->sort[$this->currentkey] as $k => $v)
|
||||
$this->sorted[$this->currentkey] += $v;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Tri all result of activity type
|
||||
* @return <void>
|
||||
*/
|
||||
private function triActivity()
|
||||
{
|
||||
foreach ($this->sort[$this->currentkey] as $sbas => $val) {
|
||||
foreach ($val as $key => $value) {
|
||||
|
||||
isset($this->sorted[$this->currentkey][$key]) ?
|
||||
$this->sorted[$this->currentkey][$key] += $value :
|
||||
$this->sorted[$this->currentkey][$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc force value to string values
|
||||
* this is the format to respect for displaying float results in
|
||||
* SVG google charts
|
||||
*
|
||||
* @return void;
|
||||
*/
|
||||
private function toString()
|
||||
{
|
||||
foreach ($this->sorted[$this->currentkey] as $k => $v)
|
||||
$this->sorted[$this->currentkey][$k] =
|
||||
(string) number_format($v, 2, '.', '');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc tri all result of top ten type
|
||||
* @return void
|
||||
*/
|
||||
private function triTopTen()
|
||||
{
|
||||
foreach ($this->sort[$this->currentkey] as $sbas => $val)
|
||||
{
|
||||
foreach ($val as $id => $info)
|
||||
{
|
||||
foreach ($info as $k => $v)
|
||||
{
|
||||
if (is_int($v) || is_float($v))
|
||||
isset($this->sorted[$this->currentkey][$id][$k]) ?
|
||||
$this->sorted[$this->currentkey][$id][$k] += $v :
|
||||
$this->sorted[$this->currentkey][$id][$k] = $v;
|
||||
elseif (is_string($v))
|
||||
$this->sorted[$this->currentkey][$id][$k] = $v;
|
||||
else
|
||||
$this->sorted[$this->currentkey][$id][$k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* @desc force value to string values
|
||||
* this is the format to respect for displaying float results in
|
||||
* SVG google charts
|
||||
*
|
||||
* @return void;
|
||||
*/
|
||||
private function toString()
|
||||
{
|
||||
foreach ($this->sorted[$this->currentkey] as $k => $v)
|
||||
$this->sorted[$this->currentkey][$k] =
|
||||
(string) number_format($v, 2, '.', '');
|
||||
|
||||
/**
|
||||
* @desc get only the number of result we wants
|
||||
* @return dashboard_order
|
||||
*/
|
||||
public function top()
|
||||
{
|
||||
return new module_report_dashboard_sort($this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc tri all result of top ten type
|
||||
* @return void
|
||||
*/
|
||||
private function triTopTen()
|
||||
{
|
||||
foreach ($this->sort[$this->currentkey] as $sbas => $val) {
|
||||
foreach ($val as $id => $info) {
|
||||
foreach ($info as $k => $v) {
|
||||
if (is_int($v) || is_float($v))
|
||||
isset($this->sorted[$this->currentkey][$id][$k]) ?
|
||||
$this->sorted[$this->currentkey][$id][$k] += $v :
|
||||
$this->sorted[$this->currentkey][$id][$k] = $v;
|
||||
elseif (is_string($v))
|
||||
$this->sorted[$this->currentkey][$id][$k] = $v;
|
||||
else
|
||||
$this->sorted[$this->currentkey][$id][$k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc get only the number of result we wants
|
||||
* @return dashboard_order
|
||||
*/
|
||||
public function top()
|
||||
{
|
||||
return new module_report_dashboard_sort($this);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -17,178 +17,145 @@
|
||||
*/
|
||||
class module_report_dashboard_sort implements module_report_dashboard_componentInterface
|
||||
{
|
||||
public $arrayToSort = array();
|
||||
public $arraySorted = array();
|
||||
|
||||
public $arrayToSort = array();
|
||||
public $arraySorted = array();
|
||||
|
||||
public function __construct(module_report_dashboard_merge $tridash)
|
||||
{
|
||||
if ($tridash->isValid())
|
||||
public function __construct(module_report_dashboard_merge $tridash)
|
||||
{
|
||||
$this->arrayToSort = $tridash->getDash();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
foreach ($this->arrayToSort as $key => $value)
|
||||
{
|
||||
switch ($key)
|
||||
{
|
||||
case "top_ten_user_doc":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_prev":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_poiddoc":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_poidprev":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_dl_preview":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_dl_document":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_question":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "ask":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_site":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_added":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
default;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc tri les tableaux en fonction des parametres qu'on lui passe c'est la
|
||||
* fonction array_multisort qui est appelée
|
||||
* p1 : le tableau a trier, p2: la clef du tableau sur lequel on effectue le
|
||||
* tri, p3 SORT_DESC ou SORT_ASC,
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function array_orderby()
|
||||
{
|
||||
//arguments
|
||||
$args = func_get_args();
|
||||
//data = first argument
|
||||
$data = array_shift($args);
|
||||
|
||||
foreach ($args as $n => $field)
|
||||
{
|
||||
if (is_string($field)) // = clef
|
||||
{
|
||||
$tmp = array();
|
||||
foreach ($data as $key => $row)
|
||||
$tmp[$key] = $row[$field];
|
||||
$args[$n] = &$tmp;
|
||||
}
|
||||
else
|
||||
$args[$n] = &$field;
|
||||
}
|
||||
$args[] = &$data;
|
||||
|
||||
call_user_func_array("array_multisort", $args);
|
||||
|
||||
return array_pop($args);
|
||||
}
|
||||
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->arraySorted) && sizeof($this->arraySorted) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDash()
|
||||
{
|
||||
return $this->arraySorted;
|
||||
}
|
||||
|
||||
public function getTop($nbtop)
|
||||
{
|
||||
if (!is_int($nbtop))
|
||||
|
||||
return array();
|
||||
|
||||
$tmp = array();
|
||||
|
||||
if ($this->isValid())
|
||||
{
|
||||
foreach ($this->arraySorted as $k => $v)
|
||||
{
|
||||
$i = 0;
|
||||
$tmp[$k] = array();
|
||||
foreach ($v as $a)
|
||||
{
|
||||
if ($i < $nbtop)
|
||||
array_push($tmp[$k], $a);
|
||||
else
|
||||
break;
|
||||
$i++;
|
||||
if ($tridash->isValid()) {
|
||||
$this->arrayToSort = $tridash->getDash();
|
||||
}
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
public function process()
|
||||
{
|
||||
foreach ($this->arrayToSort as $key => $value) {
|
||||
switch ($key) {
|
||||
case "top_ten_user_doc":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_prev":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_poiddoc":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_poidprev":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_dl_preview":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_dl_document":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_question":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "ask":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_site":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_added":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key], 'nb', SORT_DESC
|
||||
);
|
||||
break;
|
||||
default;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc tri les tableaux en fonction des parametres qu'on lui passe c'est la
|
||||
* fonction array_multisort qui est appelée
|
||||
* p1 : le tableau a trier, p2: la clef du tableau sur lequel on effectue le
|
||||
* tri, p3 SORT_DESC ou SORT_ASC,
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function array_orderby()
|
||||
{
|
||||
//arguments
|
||||
$args = func_get_args();
|
||||
//data = first argument
|
||||
$data = array_shift($args);
|
||||
|
||||
foreach ($args as $n => $field) {
|
||||
if (is_string($field)) { // = clef
|
||||
$tmp = array();
|
||||
foreach ($data as $key => $row)
|
||||
$tmp[$key] = $row[$field];
|
||||
$args[$n] = &$tmp;
|
||||
}
|
||||
else
|
||||
$args[$n] = &$field;
|
||||
}
|
||||
$args[] = &$data;
|
||||
|
||||
call_user_func_array("array_multisort", $args);
|
||||
|
||||
return array_pop($args);
|
||||
}
|
||||
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->arraySorted) && sizeof($this->arraySorted) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDash()
|
||||
{
|
||||
return $this->arraySorted;
|
||||
}
|
||||
|
||||
public function getTop($nbtop)
|
||||
{
|
||||
if ( ! is_int($nbtop))
|
||||
return array();
|
||||
|
||||
$tmp = array();
|
||||
|
||||
if ($this->isValid()) {
|
||||
foreach ($this->arraySorted as $k => $v) {
|
||||
$i = 0;
|
||||
$tmp[$k] = array();
|
||||
foreach ($v as $a) {
|
||||
if ($i < $nbtop)
|
||||
array_push($tmp[$k], $a);
|
||||
else
|
||||
break;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -17,189 +17,176 @@
|
||||
*/
|
||||
class module_report_download extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'coll_id' => 'record.coll_id',
|
||||
'ddate' => "log_docs.date",
|
||||
'id' => 'log_docs.id',
|
||||
'log_id' => 'log_docs.log_id',
|
||||
'record_id' => 'log_docs.record_id',
|
||||
'final' => 'log_docs.final',
|
||||
'comment' => 'log_docs.comment',
|
||||
'size' => 'subdef.size',
|
||||
'mime' => 'subdef.mime',
|
||||
'file' => 'subdef.file'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'coll_id' => 'record.coll_id',
|
||||
'ddate' => "log_docs.date",
|
||||
'id' => 'log_docs.id',
|
||||
'log_id' => 'log_docs.log_id',
|
||||
'record_id' => 'log_docs.record_id',
|
||||
'final' => 'log_docs.final',
|
||||
'comment' => 'log_docs.comment',
|
||||
'size' => 'subdef.size',
|
||||
'mime' => 'subdef.mime',
|
||||
'file' => 'subdef.file'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: telechargements');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$sql = $this->sqlBuilder('download')
|
||||
->setOn($on)->setGroupBy($groupby)->buildSql();
|
||||
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('download');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
if ($field == 'coll_id')
|
||||
{
|
||||
$caption = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value));
|
||||
}
|
||||
elseif ($field == 'ddate')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
elseif ($field == 'size')
|
||||
$caption = p4string::format_octets($value);
|
||||
else
|
||||
$caption = $value;
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: telechargements');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
$sql = $this->sqlBuilder('download')
|
||||
->setOn($on)->setGroupBy($groupby)->buildSql();
|
||||
|
||||
foreach ($this->champ as $column)
|
||||
{
|
||||
$this->formatResult($column, $row[$column], $i);
|
||||
}
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
if (array_key_exists('record_id', $row))
|
||||
{
|
||||
$record = new \record_adapter($this->sbas_id, $row['record_id']);
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('download');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
foreach ($pref as $field)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->result[$i][$field] = $record->get_caption()
|
||||
->get_field($field)
|
||||
->get_serialized_values();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->result[$i][$field] = '';
|
||||
}
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
if ($field == 'coll_id') {
|
||||
$caption = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value));
|
||||
} elseif ($field == 'ddate')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
elseif ($field == 'size')
|
||||
$caption = p4string::format_octets($value);
|
||||
else
|
||||
$caption = $value;
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
private function formatResult($column, $value, $i)
|
||||
{
|
||||
if ($value)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
if ($column == 'coll_id')
|
||||
$this->result[$i][$column] = $this->formatCollId($value);
|
||||
elseif ($column == 'ddate')
|
||||
$this->result[$i][$column] = $this->formatDateValue($value);
|
||||
elseif ($column == 'size')
|
||||
$this->result[$i][$column] = p4string::format_octets($value);
|
||||
else
|
||||
$this->result[$i][$column] = $value;
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
|
||||
foreach ($this->champ as $column) {
|
||||
$this->formatResult($column, $row[$column], $i);
|
||||
}
|
||||
|
||||
if (array_key_exists('record_id', $row)) {
|
||||
$record = new \record_adapter($this->sbas_id, $row['record_id']);
|
||||
|
||||
foreach ($pref as $field) {
|
||||
try {
|
||||
$this->result[$i][$field] = $record->get_caption()
|
||||
->get_field($field)
|
||||
->get_serialized_values();
|
||||
} catch (\Exception $e) {
|
||||
$this->result[$i][$field] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
private function formatResult($column, $value, $i)
|
||||
{
|
||||
if ($column == 'comment')
|
||||
$this->result[$i][$column] = '';
|
||||
else
|
||||
$this->result[$i][$column] = $this->formatEmptyValue();
|
||||
if ($value) {
|
||||
if ($column == 'coll_id')
|
||||
$this->result[$i][$column] = $this->formatCollId($value);
|
||||
elseif ($column == 'ddate')
|
||||
$this->result[$i][$column] = $this->formatDateValue($value);
|
||||
elseif ($column == 'size')
|
||||
$this->result[$i][$column] = p4string::format_octets($value);
|
||||
else
|
||||
$this->result[$i][$column] = $value;
|
||||
}
|
||||
else {
|
||||
if ($column == 'comment')
|
||||
$this->result[$i][$column] = '';
|
||||
else
|
||||
$this->result[$i][$column] = $this->formatEmptyValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function formatEmptyValue()
|
||||
{
|
||||
return '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
private function formatEmptyValue()
|
||||
{
|
||||
return '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
|
||||
private function formatDateValue($value)
|
||||
{
|
||||
$datetime = new DateTime($value);
|
||||
$dateString = $datetime->format(DATE_ATOM);
|
||||
private function formatDateValue($value)
|
||||
{
|
||||
$datetime = new DateTime($value);
|
||||
$dateString = $datetime->format(DATE_ATOM);
|
||||
|
||||
return $this->pretty_string ?
|
||||
phraseadate::getPrettyString($datetime) : $dateString;
|
||||
}
|
||||
return $this->pretty_string ?
|
||||
phraseadate::getPrettyString($datetime) : $dateString;
|
||||
}
|
||||
|
||||
private function formatCollId($value)
|
||||
{
|
||||
return phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value));
|
||||
}
|
||||
private function formatCollId($value)
|
||||
{
|
||||
return phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value));
|
||||
}
|
||||
|
||||
public static function getNbDl($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
public static function getNbDl($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
|
||||
$finalfilter = $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= $collfilter['sql'] . ' AND ';
|
||||
$finalfilter .= 'log.site = :site_id';
|
||||
$finalfilter = $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= $collfilter['sql'] . ' AND ';
|
||||
$finalfilter .= 'log.site = :site_id';
|
||||
|
||||
$sql = '
|
||||
$sql = '
|
||||
SELECT SUM(1) AS nb
|
||||
FROM ( log
|
||||
INNER JOIN log_docs as log_date ON log.id = log_date.log_id
|
||||
@@ -214,38 +201,38 @@ class module_report_download extends module_report
|
||||
)
|
||||
ORDER BY log_date.date DESC
|
||||
';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $row ? $row['nb'] : 0;
|
||||
}
|
||||
return $row ? $row['nb'] : 0;
|
||||
}
|
||||
|
||||
public static function getTopDl($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$databox = \databox::get_instance((int) $sbas_id);
|
||||
$conn = $databox->get_connection();
|
||||
public static function getTopDl($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$databox = \databox::get_instance((int) $sbas_id);
|
||||
$conn = $databox->get_connection();
|
||||
|
||||
$registry = $databox->get_registry();
|
||||
$registry = $databox->get_registry();
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
|
||||
$finalfilter = "";
|
||||
$array = array(
|
||||
'preview' => array(),
|
||||
'document' => array()
|
||||
);
|
||||
$finalfilter = "";
|
||||
$array = array(
|
||||
'preview' => array(),
|
||||
'document' => array()
|
||||
);
|
||||
|
||||
$finalfilter .= $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= $collfilter['sql'] . ' AND ';
|
||||
$finalfilter .= 'log.site = :site_id';
|
||||
$finalfilter .= $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= $collfilter['sql'] . ' AND ';
|
||||
$finalfilter .= 'log.site = :site_id';
|
||||
|
||||
|
||||
$sql = '
|
||||
$sql = '
|
||||
SELECT record.record_id as id, SUM(1) AS nb, subdef.name
|
||||
FROM ( log
|
||||
INNER JOIN log_docs as log_date ON log.id = log_date.log_id
|
||||
@@ -263,36 +250,31 @@ class module_report_download extends module_report
|
||||
ORDER BY nb DESC
|
||||
';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$record = $databox->get_record($row['id']);
|
||||
foreach ($rs as $row) {
|
||||
$record = $databox->get_record($row['id']);
|
||||
|
||||
$k = $row['id'] . '_' . $sbas_id;
|
||||
$orig_name = $record->get_original_name();
|
||||
$k = $row['id'] . '_' . $sbas_id;
|
||||
$orig_name = $record->get_original_name();
|
||||
|
||||
if ($row['name'] == 'document')
|
||||
{
|
||||
$array[$row['name']][$k]['nb'] = (int) $row['nb'];
|
||||
$array[$row['name']][$k]['lib'] = $orig_name;
|
||||
$array[$row['name']][$k]['sbasid'] = $sbas_id;
|
||||
$array[$row['name']][$k]['id'] = $row['id'];
|
||||
}
|
||||
elseif ($row['name'] == "preview")
|
||||
{
|
||||
$array[$row['name']][$k]['nb'] = (int) $row['nb'];
|
||||
$array[$row['name']][$k]['lib'] = $orig_name;
|
||||
$array[$row['name']][$k]['sbasid'] = $sbas_id;
|
||||
$array[$row['name']][$k]['id'] = $row['id'];
|
||||
}
|
||||
if ($row['name'] == 'document') {
|
||||
$array[$row['name']][$k]['nb'] = (int) $row['nb'];
|
||||
$array[$row['name']][$k]['lib'] = $orig_name;
|
||||
$array[$row['name']][$k]['sbasid'] = $sbas_id;
|
||||
$array[$row['name']][$k]['id'] = $row['id'];
|
||||
} elseif ($row['name'] == "preview") {
|
||||
$array[$row['name']][$k]['nb'] = (int) $row['nb'];
|
||||
$array[$row['name']][$k]['lib'] = $orig_name;
|
||||
$array[$row['name']][$k]['sbasid'] = $sbas_id;
|
||||
$array[$row['name']][$k]['id'] = $row['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -17,137 +17,116 @@
|
||||
*/
|
||||
class module_report_edit extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: edited documents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('edit')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('edit');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$ret = array();
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
{
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
elseif ($field == 'size')
|
||||
{
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: edited documents');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('edit')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('edit');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$ret = array();
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter") {
|
||||
try {
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
} elseif ($field == 'date') {
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
} elseif ($field == 'size') {
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value) {
|
||||
if ($row[$value]) {
|
||||
if ($value == 'date') {
|
||||
$this->result[$i][$value] = $this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
} elseif ($value == 'size') {
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else {
|
||||
if ($value == 'comment') {
|
||||
$this->result[$i][$value] = ' ';
|
||||
} else {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,118 +17,104 @@
|
||||
*/
|
||||
class module_report_filter
|
||||
{
|
||||
private $posting_filter = array();
|
||||
private $cor_query = array();
|
||||
private $active_column = array();
|
||||
private $trans = array(
|
||||
'user' => 'phraseanet::utilisateurs',
|
||||
'ddate' => 'report:: date',
|
||||
'ip' => 'report:: IP',
|
||||
'appli' => 'report:: modules',
|
||||
'fonction' => 'report::fonction',
|
||||
'activite' => 'report::activite',
|
||||
'pays' => 'report::pays',
|
||||
'societe' => 'report::societe',
|
||||
'record_id' => 'report:: record id',
|
||||
'final' => 'phraseanet:: sous definition',
|
||||
'coll_id' => 'report:: collections',
|
||||
'comment' => 'report:: commentaire',
|
||||
'search' => 'report:: question',
|
||||
);
|
||||
|
||||
private $posting_filter = array();
|
||||
private $cor_query = array();
|
||||
private $active_column = array();
|
||||
private $trans = array(
|
||||
'user' => 'phraseanet::utilisateurs',
|
||||
'ddate' => 'report:: date',
|
||||
'ip' => 'report:: IP',
|
||||
'appli' => 'report:: modules',
|
||||
'fonction' => 'report::fonction',
|
||||
'activite' => 'report::activite',
|
||||
'pays' => 'report::pays',
|
||||
'societe' => 'report::societe',
|
||||
'record_id' => 'report:: record id',
|
||||
'final' => 'phraseanet:: sous definition',
|
||||
'coll_id' => 'report:: collections',
|
||||
'comment' => 'report:: commentaire',
|
||||
'search' => 'report:: question',
|
||||
);
|
||||
|
||||
public function __construct($current_filter, $correspondance)
|
||||
{
|
||||
$this->tab_filter = $current_filter;
|
||||
$this->cor_query = $correspondance;
|
||||
}
|
||||
|
||||
private function checkSameFilter($field, $operator, $value)
|
||||
{
|
||||
$test = true;
|
||||
if (sizeof($this->tab_filter) > 0)
|
||||
public function __construct($current_filter, $correspondance)
|
||||
{
|
||||
foreach ($this->tab_filter as $filters => $a_filter)
|
||||
{
|
||||
if (in_array($field, $a_filter) &&
|
||||
in_array($operator, $a_filter) && in_array($value, $a_filter))
|
||||
{
|
||||
$test = false;
|
||||
break;
|
||||
}
|
||||
elseif (in_array($field, $a_filter) &&
|
||||
in_array($operator, $a_filter) && !in_array($value, $a_filter))
|
||||
{
|
||||
$a_filter['v'] = $value;
|
||||
$test = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->tab_filter = $current_filter;
|
||||
$this->cor_query = $correspondance;
|
||||
}
|
||||
|
||||
return $test;
|
||||
}
|
||||
|
||||
public function addFilter($field, $operator, $value)
|
||||
{
|
||||
if ($this->checkSameFilter($field, $operator, $value))
|
||||
$this->tab_filter[] = array('f' => $field, 'o' => $operator, 'v' => $value);
|
||||
}
|
||||
|
||||
public function getPostingFilter()
|
||||
{
|
||||
if (sizeof($this->tab_filter) > 0)
|
||||
private function checkSameFilter($field, $operator, $value)
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $filter)
|
||||
{
|
||||
if (empty($filter['v']))
|
||||
$value = _('report:: non-renseigne');
|
||||
else
|
||||
$value = $filter['v'];
|
||||
|
||||
if (array_key_exists($filter['f'], $this->trans))
|
||||
$field = _($this->trans[$filter['f']]);
|
||||
else
|
||||
$field = $filter['f'];
|
||||
|
||||
if ($filter['f'] == 'appli')
|
||||
{
|
||||
$value = implode(' ', phrasea::modulesName(@unserialize($value)));
|
||||
}
|
||||
elseif ($filter['f'] == "ddate")
|
||||
{
|
||||
$value = phraseadate::getPrettyString(new DateTime($value));
|
||||
$test = true;
|
||||
if (sizeof($this->tab_filter) > 0) {
|
||||
foreach ($this->tab_filter as $filters => $a_filter) {
|
||||
if (in_array($field, $a_filter) &&
|
||||
in_array($operator, $a_filter) && in_array($value, $a_filter)) {
|
||||
$test = false;
|
||||
break;
|
||||
} elseif (in_array($field, $a_filter) &&
|
||||
in_array($operator, $a_filter) && ! in_array($value, $a_filter)) {
|
||||
$a_filter['v'] = $value;
|
||||
$test = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->posting_filter[] = array('f' => $field, 'v' => $value);
|
||||
}
|
||||
return $test;
|
||||
}
|
||||
|
||||
return $this->posting_filter;
|
||||
}
|
||||
|
||||
public function removeFilter($field)
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $value)
|
||||
public function addFilter($field, $operator, $value)
|
||||
{
|
||||
if ($value['f'] == $field)
|
||||
unset($this->tab_filter[$key]);
|
||||
if ($this->checkSameFilter($field, $operator, $value))
|
||||
$this->tab_filter[] = array('f' => $field, 'o' => $operator, 'v' => $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveColumn()
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $value)
|
||||
public function getPostingFilter()
|
||||
{
|
||||
$this->active_column[] = $value['f'];
|
||||
if (sizeof($this->tab_filter) > 0) {
|
||||
foreach ($this->tab_filter as $key => $filter) {
|
||||
if (empty($filter['v']))
|
||||
$value = _('report:: non-renseigne');
|
||||
else
|
||||
$value = $filter['v'];
|
||||
|
||||
if (array_key_exists($filter['f'], $this->trans))
|
||||
$field = _($this->trans[$filter['f']]);
|
||||
else
|
||||
$field = $filter['f'];
|
||||
|
||||
if ($filter['f'] == 'appli') {
|
||||
$value = implode(' ', phrasea::modulesName(@unserialize($value)));
|
||||
} elseif ($filter['f'] == "ddate") {
|
||||
$value = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
|
||||
$this->posting_filter[] = array('f' => $field, 'v' => $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->posting_filter;
|
||||
}
|
||||
|
||||
return $this->active_column;
|
||||
}
|
||||
public function removeFilter($field)
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $value) {
|
||||
if ($value['f'] == $field)
|
||||
unset($this->tab_filter[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTabFilter()
|
||||
{
|
||||
return $this->tab_filter;
|
||||
}
|
||||
public function getActiveColumn()
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $value) {
|
||||
$this->active_column[] = $value['f'];
|
||||
}
|
||||
|
||||
return $this->active_column;
|
||||
}
|
||||
|
||||
public function getTabFilter()
|
||||
{
|
||||
return $this->tab_filter;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -17,138 +17,117 @@
|
||||
*/
|
||||
class module_report_push extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: pushed documents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('push')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('push');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
{
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
elseif ($field == 'size')
|
||||
{
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: pushed documents');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('push')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('push');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter") {
|
||||
try {
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
} elseif ($field == 'date') {
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
} elseif ($field == 'size') {
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value) {
|
||||
if ($row[$value]) {
|
||||
if ($value == 'date') {
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
} elseif ($value == 'size') {
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else {
|
||||
if ($value == 'comment') {
|
||||
$this->result[$i][$value] = ' ';
|
||||
} else {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,101 +17,95 @@
|
||||
*/
|
||||
class module_report_question extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user'
|
||||
, 'usrid' => 'log.usrid'
|
||||
, 'ddate' => 'log_search.date'
|
||||
, 'date' => 'log_search.date'
|
||||
, 'societe' => 'log.societe'
|
||||
, 'pays' => 'log.pays'
|
||||
, 'activite' => 'log.activite'
|
||||
, 'fonction' => 'log.fonction'
|
||||
, 'site' => 'log.site'
|
||||
, 'sit_session' => 'log.sit_session'
|
||||
, 'coll_list' => 'log.coll_list'
|
||||
, 'appli' => 'log.appli'
|
||||
, 'ip' => 'log.ip'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user'
|
||||
, 'usrid' => 'log.usrid'
|
||||
, 'ddate' => 'log_search.date'
|
||||
, 'date' => 'log_search.date'
|
||||
, 'societe' => 'log.societe'
|
||||
, 'pays' => 'log.pays'
|
||||
, 'activite' => 'log.activite'
|
||||
, 'fonction' => 'log.fonction'
|
||||
, 'site' => 'log.site'
|
||||
, 'sit_session' => 'log.sit_session'
|
||||
, 'coll_list' => 'log.coll_list'
|
||||
, 'appli' => 'log.appli'
|
||||
, 'ip' => 'log.ip'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: question');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false)
|
||||
{
|
||||
$sql = $this->sqlBuilder('question')->setGroupBy($groupby)->buildSql();
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('question');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
if ($field == 'appli')
|
||||
$caption = implode(' ', phrasea::modulesName(@unserialize($row['val'])));
|
||||
elseif ($field == "ddate")
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
else
|
||||
$caption = $row['val'];
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: question');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$tab = array();
|
||||
$i = 0;
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false)
|
||||
{
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'ddate')
|
||||
$this->result[$i][$value] =
|
||||
$this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
$sql = $this->sqlBuilder('question')->setGroupBy($groupby)->buildSql();
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('question');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
if ($field == 'appli')
|
||||
$caption = implode(' ', phrasea::modulesName(@unserialize($row['val'])));
|
||||
elseif ($field == "ddate")
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
else
|
||||
$caption = $row['val'];
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = "<i>" . _('report:: non-renseigne') . "</i>";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$tab = array();
|
||||
$i = 0;
|
||||
foreach ($rs as $row) {
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $key => $value) {
|
||||
if ($row[$value]) {
|
||||
if ($value == 'ddate')
|
||||
$this->result[$i][$value] =
|
||||
$this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = "<i>" . _('report:: non-renseigne') . "</i>";
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,115 +17,114 @@
|
||||
*/
|
||||
class module_report_sql
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var connection_PDO
|
||||
*/
|
||||
public $conn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var connection_PDO
|
||||
*/
|
||||
public $conn;
|
||||
/**
|
||||
*
|
||||
* @var connection_PDO
|
||||
*/
|
||||
public $connbas;
|
||||
/**
|
||||
*
|
||||
* @var module_report_sqlfilter
|
||||
*/
|
||||
public $filter;
|
||||
public $sql;
|
||||
public $params;
|
||||
public $total_row;
|
||||
public $enable_limit;
|
||||
public $groupby = false;
|
||||
public $on = false;
|
||||
/**
|
||||
*
|
||||
* @var connection_PDO
|
||||
*/
|
||||
public $connbas;
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->conn = connection::getPDOConnection();
|
||||
$this->connbas = connection::getPDOConnection($report->getSbasId());
|
||||
$this->filter = new module_report_sqlfilter($report);
|
||||
$this->sql = '';
|
||||
$this->params = array();
|
||||
$this->total_row = 0;
|
||||
$this->enable_limit = $report->getEnableLimit();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var module_report_sqlfilter
|
||||
*/
|
||||
public $filter;
|
||||
public $sql;
|
||||
public $params;
|
||||
public $total_row;
|
||||
public $enable_limit;
|
||||
public $groupby = false;
|
||||
public $on = false;
|
||||
|
||||
public function setGroupBy($groupby)
|
||||
{
|
||||
$this->groupby = $groupby;
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->conn = connection::getPDOConnection();
|
||||
$this->connbas = connection::getPDOConnection($report->getSbasId());
|
||||
$this->filter = new module_report_sqlfilter($report);
|
||||
$this->sql = '';
|
||||
$this->params = array();
|
||||
$this->total_row = 0;
|
||||
$this->enable_limit = $report->getEnableLimit();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function setGroupBy($groupby)
|
||||
{
|
||||
$this->groupby = $groupby;
|
||||
|
||||
public function getGroupby()
|
||||
{
|
||||
return $this->groupby;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOn($on)
|
||||
{
|
||||
$this->on = $on;
|
||||
public function getGroupby()
|
||||
{
|
||||
return $this->groupby;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function setOn($on)
|
||||
{
|
||||
$this->on = $on;
|
||||
|
||||
public function getOn()
|
||||
{
|
||||
return $this->on;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFilter(module_report_sqlfilter $filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return module_report_sqlfilter
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filter;
|
||||
}
|
||||
public function getOn()
|
||||
{
|
||||
return $this->on;
|
||||
}
|
||||
|
||||
public function getSql()
|
||||
{
|
||||
return $this->sql;
|
||||
}
|
||||
public function setFilter(module_report_sqlfilter $filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return module_report_sqlfilter
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getTotalRows()
|
||||
{
|
||||
return $this->total_row;
|
||||
}
|
||||
public function getSql()
|
||||
{
|
||||
return $this->sql;
|
||||
}
|
||||
|
||||
public function setTotalrows($total)
|
||||
{
|
||||
$this->total_row = $total;
|
||||
}
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getTransQuery($champ)
|
||||
{
|
||||
$tanslation = $this->filter->getCorFilter();
|
||||
if (array_key_exists($champ, $tanslation))
|
||||
public function getTotalRows()
|
||||
{
|
||||
return $this->total_row;
|
||||
}
|
||||
|
||||
return $tanslation[$champ];
|
||||
else
|
||||
public function setTotalrows($total)
|
||||
{
|
||||
$this->total_row = $total;
|
||||
}
|
||||
|
||||
return $champ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return connection_PDO
|
||||
*/
|
||||
public function getConnBas()
|
||||
{
|
||||
return $this->connbas;
|
||||
}
|
||||
public function getTransQuery($champ)
|
||||
{
|
||||
$tanslation = $this->filter->getCorFilter();
|
||||
if (array_key_exists($champ, $tanslation))
|
||||
return $tanslation[$champ];
|
||||
else
|
||||
return $champ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return connection_PDO
|
||||
*/
|
||||
public function getConnBas()
|
||||
{
|
||||
return $this->connbas;
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,8 @@
|
||||
*/
|
||||
interface module_report_sqlReportinterface
|
||||
{
|
||||
public function buildSql();
|
||||
|
||||
public function sqlDistinctValByField($field);
|
||||
public function buildSql();
|
||||
|
||||
public function sqlDistinctValByField($field);
|
||||
}
|
||||
|
@@ -17,41 +17,39 @@
|
||||
*/
|
||||
class module_report_sqlaction extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
private $action = 'add';
|
||||
|
||||
private $action = 'add';
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function setAction($action)
|
||||
{
|
||||
//possible action
|
||||
$a = array('edit', 'add', 'push', 'validate');
|
||||
if (in_array($action, $a))
|
||||
$this->action = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
if ($this->groupby == false)
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$params = array(':action' => $this->action);
|
||||
$site_filter = $this->filter->getGvSitFilter()?: array('params' => array(), 'sql' => false);
|
||||
$report_filter = $this->filter->getReportFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$record_filter = $this->filter->getRecordFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$params = array_merge($params, $site_filter['params'], $report_filter['params'], $record_filter['params']);
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
$this->sql =
|
||||
"
|
||||
public function setAction($action)
|
||||
{
|
||||
//possible action
|
||||
$a = array('edit', 'add', 'push', 'validate');
|
||||
if (in_array($action, $a))
|
||||
$this->action = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
if ($this->groupby == false) {
|
||||
$params = array(':action' => $this->action);
|
||||
$site_filter = $this->filter->getGvSitFilter()? : array('params' => array(), 'sql' => false);
|
||||
$report_filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false);
|
||||
$record_filter = $this->filter->getRecordFilter() ? : array('params' => array(), 'sql' => false);
|
||||
$params = array_merge($params, $site_filter['params'], $report_filter['params'], $record_filter['params']);
|
||||
|
||||
$this->sql =
|
||||
"
|
||||
SELECT log.usrid, log.user , d.final as getter, d.record_id, d.date, s.*
|
||||
FROM (log_docs as d
|
||||
INNER JOIN log ON " . $site_filter['sql'] . "
|
||||
@@ -60,31 +58,29 @@ class module_report_sqlaction extends module_report_sql implements module_report
|
||||
LEFT JOIN subdef as s ON s.record_id=d.record_id and s.name='document')
|
||||
WHERE";
|
||||
|
||||
$this->sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
$this->sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
|
||||
$this->sql .= $record_filter['sql'] ? " AND (" . $record_filter['sql'] . ")" : "";
|
||||
$this->sql .= $record_filter['sql'] ? " AND (" . $record_filter['sql'] . ")" : "";
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
|
||||
$this->params = $params;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->params = $params;
|
||||
} else {
|
||||
|
||||
$params = array(':action' => $this->action);
|
||||
$site_filter = $this->filter->getGvSitFilter()?: array('params' => array(), 'sql' => false);
|
||||
$report_filter = $this->filter->getReportFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$record_filter = $this->filter->getRecordFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$params = array_merge($params, $site_filter['params'], $report_filter['params'], $record_filter['params']);
|
||||
$params = array(':action' => $this->action);
|
||||
$site_filter = $this->filter->getGvSitFilter()? : array('params' => array(), 'sql' => false);
|
||||
$report_filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false);
|
||||
$record_filter = $this->filter->getRecordFilter() ? : array('params' => array(), 'sql' => false);
|
||||
$params = array_merge($params, $site_filter['params'], $report_filter['params'], $record_filter['params']);
|
||||
|
||||
$this->sql = "
|
||||
$this->sql = "
|
||||
SELECT TRIM(" . $this->getTransQuery($this->groupby) . ")
|
||||
as " . $this->groupby . ",
|
||||
SUM(1) as nombre
|
||||
@@ -95,34 +91,34 @@ class module_report_sqlaction extends module_report_sql implements module_report
|
||||
LEFT JOIN subdef as s ON s.record_id=d.record_id and s.name='document')
|
||||
WHERE ";
|
||||
|
||||
$this->sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
$this->sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
|
||||
$this->sql .= $record_filter['sql'] ? "AND (" . $record_filter['sql'] . ")" : "";
|
||||
$this->sql .= $record_filter['sql'] ? "AND (" . $record_filter['sql'] . ")" : "";
|
||||
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
|
||||
$this->params = $params;
|
||||
$this->params = $params;
|
||||
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$params = array();
|
||||
$site_filter = $this->filter->getGvSitFilter();
|
||||
$date_filter = $this->filter->getDateFilter();
|
||||
|
||||
$params = array();
|
||||
$site_filter = $this->filter->getGvSitFilter();
|
||||
$date_filter = $this->filter->getDateFilter();
|
||||
$params = array_merge($params, $site_filter['params'], $date_filter['params']); //, $record_filter ? $record_filter['params'] : array()
|
||||
|
||||
$params = array_merge($params, $site_filter['params'], $date_filter['params']);//, $record_filter ? $record_filter['params'] : array()
|
||||
|
||||
$sql = "
|
||||
$sql = "
|
||||
SELECT DISTINCT(" . $this->getTransQuery($field) . ") as val
|
||||
FROM (log_docs as d
|
||||
INNER JOIN log ON (" . $site_filter['sql'] . "
|
||||
@@ -132,16 +128,14 @@ class module_report_sqlaction extends module_report_sql implements module_report
|
||||
LEFT JOIN subdef as s ON (s.record_id=d.record_id AND s.name='document'))
|
||||
WHERE ";
|
||||
|
||||
if ($this->filter->getReportFilter())
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
$params = array_merge($params, $report_filter['params'], array(':action' => $this->action));
|
||||
if ($this->filter->getReportFilter()) {
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
$params = array_merge($params, $report_filter['params'], array(':action' => $this->action));
|
||||
}
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
$this->params = $params;
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
$this->params = $params;
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,24 +15,22 @@
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sqlconnexion extends module_report_sql
|
||||
implements module_report_sqlReportInterface
|
||||
class module_report_sqlconnexion extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = $report_filter['params'];
|
||||
|
||||
$this->params = $params;
|
||||
if ($this->groupby == false)
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->sql = "
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = $report_filter['params'];
|
||||
|
||||
$this->params = $params;
|
||||
if ($this->groupby == false) {
|
||||
$this->sql = "
|
||||
SELECT
|
||||
user,
|
||||
usrid,
|
||||
@@ -48,56 +46,53 @@ implements module_report_sqlReportInterface
|
||||
ip
|
||||
FROM log";
|
||||
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
if($this->enable_limit)
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sql = "
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
if ($this->enable_limit)
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
}
|
||||
else {
|
||||
$this->sql = "
|
||||
SELECT TRIM(" . $this->getTransQuery($this->groupby) . ")
|
||||
as " . $this->groupby . ", SUM(1) as nb
|
||||
FROM log ";
|
||||
|
||||
if ($report_filter['sql'])
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
if ($report_filter['sql'])
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
|
||||
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = $report_filter['params'];
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = $report_filter['params'];
|
||||
|
||||
$sql = 'SELECT DISTINCT(' . $this->getTransQuery($field) . ') as val
|
||||
$sql = 'SELECT DISTINCT(' . $this->getTransQuery($field) . ') as val
|
||||
FROM log ';
|
||||
|
||||
if ($report_filter['sql'])
|
||||
$sql .= ' WHERE ' . $report_filter['sql'];
|
||||
if ($report_filter['sql'])
|
||||
$sql .= ' WHERE ' . $report_filter['sql'];
|
||||
|
||||
$sql .= ' ORDER BY val ASC';
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
$sql .= ' ORDER BY val ASC';
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
}
|
||||
|
@@ -17,28 +17,25 @@
|
||||
*/
|
||||
class module_report_sqldownload extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
protected $restrict = false;
|
||||
|
||||
protected $restrict = false;
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
if($report->isInformative())
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->restrict = true;
|
||||
parent::__construct($report);
|
||||
if ($report->isInformative()) {
|
||||
$this->restrict = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$report_filters = $this->filter->getReportFilter();
|
||||
$record_filters = $this->filter->getRecordFilter() ? : array('sql' => '', 'params' => array());
|
||||
$this->params = array_merge($report_filters['params'], $record_filters['params']);
|
||||
|
||||
if ($this->groupby == false)
|
||||
public function buildSql()
|
||||
{
|
||||
$this->sql = "
|
||||
$registry = registry::get_instance();
|
||||
$report_filters = $this->filter->getReportFilter();
|
||||
$record_filters = $this->filter->getRecordFilter() ? : array('sql' => '', 'params' => array());
|
||||
$this->params = array_merge($report_filters['params'], $record_filters['params']);
|
||||
|
||||
if ($this->groupby == false) {
|
||||
$this->sql = "
|
||||
SELECT
|
||||
log.user,
|
||||
log.site,
|
||||
@@ -60,30 +57,28 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
)
|
||||
WHERE ";
|
||||
|
||||
$this->sql .= $report_filters['sql'] ? : '';
|
||||
$this->sql .= $report_filters['sql'] ? : '';
|
||||
|
||||
$this->sql .= ' AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\')';
|
||||
if($this->restrict)
|
||||
$this->sql .= ' AND ( log_docs.final = "document" OR log_docs.final = "preview")';
|
||||
$this->sql .= empty($record_filters['sql']) ? '' : ' AND ( ' . $record_filters['sql'] . ' )';
|
||||
$this->sql .= ' AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\')';
|
||||
if ($this->restrict)
|
||||
$this->sql .= ' AND ( log_docs.final = "document" OR log_docs.final = "preview")';
|
||||
$this->sql .= empty($record_filters['sql']) ? '' : ' AND ( ' . $record_filters['sql'] . ' )';
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = $this->groupby;
|
||||
$field = $this->getTransQuery($this->groupby);
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
}
|
||||
else {
|
||||
$name = $this->groupby;
|
||||
$field = $this->getTransQuery($this->groupby);
|
||||
|
||||
if ($name == 'record_id' && $this->on == 'DOC')
|
||||
{
|
||||
$this->sql = '
|
||||
if ($name == 'record_id' && $this->on == 'DOC') {
|
||||
$this->sql = '
|
||||
SELECT
|
||||
TRIM( ' . $field . ' ) AS ' . $name . ',
|
||||
SUM(1) AS telechargement,
|
||||
@@ -102,10 +97,8 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
)
|
||||
WHERE
|
||||
';
|
||||
}
|
||||
elseif ($this->on == 'DOC')
|
||||
{
|
||||
$this->sql = '
|
||||
} elseif ($this->on == 'DOC') {
|
||||
$this->sql = '
|
||||
SELECT
|
||||
TRIM(' . $field . ') AS ' . $name . ',
|
||||
SUM(1) AS telechargement
|
||||
@@ -118,11 +111,9 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
)
|
||||
WHERE
|
||||
';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
|
||||
$this->sql = '
|
||||
$this->sql = '
|
||||
SELECT
|
||||
TRIM( ' . $this->getTransQuery($this->groupby) . ') AS ' . $name . ',
|
||||
SUM(1) AS nombre
|
||||
@@ -132,41 +123,41 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
INNER JOIN subdef ON (record.record_id = subdef.record_id AND subdef.name = "document")
|
||||
)
|
||||
WHERE ';
|
||||
}
|
||||
}
|
||||
|
||||
$this->sql .= $report_filters['sql'];
|
||||
$this->sql .= $report_filters['sql'];
|
||||
|
||||
$this->sql .= ' AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\')';
|
||||
$this->sql .= ' AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\')';
|
||||
|
||||
$this->sql .= empty($record_filters['sql']) ? '' : ' AND ( ' . $record_filters['sql'] . ' )';
|
||||
$this->sql .= empty($record_filters['sql']) ? '' : ' AND ( ' . $record_filters['sql'] . ' )';
|
||||
|
||||
$this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : '';
|
||||
$this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : '';
|
||||
|
||||
$this->sql .= ' GROUP BY ' . $this->groupby;
|
||||
$this->sql .= ' GROUP BY ' . $this->groupby;
|
||||
|
||||
$this->sql .= ( $name == 'record_id' && $this->on == 'DOC') ? ' , final' : '';
|
||||
$this->sql .= ( $name == 'record_id' && $this->on == 'DOC') ? ' , final' : '';
|
||||
|
||||
if ($this->filter->getOrderFilter())
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
if ($this->filter->getOrderFilter())
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$report_filters = $this->filter->getReportFilter();
|
||||
$params = array_merge($report_filters['params']);
|
||||
$this->params = $params;
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$report_filters = $this->filter->getReportFilter();
|
||||
$params = array_merge($report_filters['params']);
|
||||
$this->params = $params;
|
||||
|
||||
$sql = '
|
||||
$sql = '
|
||||
SELECT DISTINCT( ' . $this->getTransQuery($field) . ' ) AS val
|
||||
FROM (log
|
||||
INNER JOIN log_docs ON log.id = log_docs.log_id
|
||||
@@ -174,15 +165,14 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
INNER JOIN subdef ON log_docs.record_id = subdef.record_id)
|
||||
WHERE ';
|
||||
|
||||
$sql .= $report_filters['sql'];
|
||||
$sql .= ' AND (log_docs.action = ' .
|
||||
$sql .= $report_filters['sql'];
|
||||
$sql .= ' AND (log_docs.action = ' .
|
||||
'\'download\'OR log_docs.action = \'mail\')';
|
||||
|
||||
$sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\'' : '';
|
||||
$sql .= $this->filter->getOrderFilter() ? : '';
|
||||
$sql .= $this->filter->getLimitFilter() ? : '';
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
$sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\'' : '';
|
||||
$sql .= $this->filter->getOrderFilter() ? : '';
|
||||
$sql .= $this->filter->getLimitFilter() ? : '';
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
}
|
||||
|
@@ -17,265 +17,243 @@
|
||||
*/
|
||||
class module_report_sqlfilter
|
||||
{
|
||||
public $conn;
|
||||
private $filter;
|
||||
private $cor_query = array();
|
||||
|
||||
public $conn;
|
||||
private $filter;
|
||||
private $cor_query = array();
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->conn = connection::getPDOConnection($report->getSbasid());
|
||||
|
||||
if (is_array($report->getTransQueryString()))
|
||||
$this->cor_query = $report->getTransQueryString();
|
||||
|
||||
$this->buildFilter($report);
|
||||
}
|
||||
|
||||
public static function constructDateFilter($dmin, $dmax)
|
||||
{
|
||||
return array(
|
||||
'sql' => ($dmin && $dmax ? ' log_date.date > :date_min AND log_date.date < :date_max ' : false)
|
||||
, 'params' => ($dmin && $dmax ? array(':date_min' => $dmin, ':date_max' => $dmax) : array())
|
||||
);
|
||||
}
|
||||
|
||||
public static function constructCollectionFilter($list_coll_id)
|
||||
{
|
||||
$ret = array('sql' => '', 'params' => array());
|
||||
$coll_filter = array();
|
||||
foreach (explode(',', $list_coll_id) as $val)
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$coll_filter [] = " position('," . phrasea::collFromBas($val) . ",' in concat(',' ,coll_list, ',')) > 0 ";
|
||||
}
|
||||
$ret['sql'] = implode(' OR ', $coll_filter);
|
||||
$this->conn = connection::getPDOConnection($report->getSbasid());
|
||||
|
||||
return $ret;
|
||||
}
|
||||
if (is_array($report->getTransQueryString()))
|
||||
$this->cor_query = $report->getTransQueryString();
|
||||
|
||||
public function getCorFilter()
|
||||
{
|
||||
return $this->cor_query;
|
||||
}
|
||||
|
||||
public function getReportFilter()
|
||||
{
|
||||
$finalfilter = '';
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$params = array(':log_site' => $registry->get('GV_sit'));
|
||||
|
||||
if ($this->filter['date'])
|
||||
{
|
||||
$finalfilter .= $this->filter['date']['sql'] . ' AND ';
|
||||
$params = array_merge($params, $this->filter['date']['params']);
|
||||
}
|
||||
if ($this->filter['user'])
|
||||
{
|
||||
$finalfilter .= $this->filter['user']['sql'] . ' AND ';
|
||||
$params = array_merge($params, $this->filter['user']['params']);
|
||||
}
|
||||
if ($this->filter['collection'])
|
||||
{
|
||||
$finalfilter .= '(' . $this->filter['collection']['sql'] . ') AND ';
|
||||
$params = array_merge($params, $this->filter['collection']['params']);
|
||||
}
|
||||
$finalfilter .= ' log.site = :log_site';
|
||||
|
||||
return array('sql' => $finalfilter, 'params' => $params);
|
||||
}
|
||||
|
||||
public function getGvSitFilter()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$params = array();
|
||||
$sql = '';
|
||||
|
||||
if ($registry->is_set('GV_sit'))
|
||||
{
|
||||
$sql = 'log.site = :log_site_gv_filter';
|
||||
$params[':log_site_gv_filter'] = $registry->get('GV_sit');
|
||||
$this->buildFilter($report);
|
||||
}
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
public function getUserIdFilter($id)
|
||||
{
|
||||
return array('sql' => "log.usrid = :usr_id_filter", 'params' => array(':usr_id_filter' => $id));
|
||||
}
|
||||
|
||||
public function getDateFilter()
|
||||
{
|
||||
return $this->filter['date'];
|
||||
}
|
||||
|
||||
public function getUserFilter()
|
||||
{
|
||||
return $this->filter['user'];
|
||||
}
|
||||
|
||||
public function getCollectionFilter()
|
||||
{
|
||||
return $this->filter['collection'];
|
||||
}
|
||||
|
||||
public function getRecordFilter()
|
||||
{
|
||||
return $this->filter['record'];
|
||||
}
|
||||
|
||||
public function getLimitFilter()
|
||||
{
|
||||
return $this->filter['limit'];
|
||||
}
|
||||
|
||||
public function getOrderFilter()
|
||||
{
|
||||
return $this->filter['order'];
|
||||
}
|
||||
|
||||
private function dateFilter(module_report $report)
|
||||
{
|
||||
$this->filter['date'] = false;
|
||||
if ($report->getDmin() && $report->getDmax())
|
||||
public static function constructDateFilter($dmin, $dmax)
|
||||
{
|
||||
$this->filter['date'] = array(
|
||||
'sql' => ' (log.date > :date_min_f AND log.date < :date_max_f) '
|
||||
, 'params' => array(
|
||||
':date_min_f' => $report->getDmin()
|
||||
, ':date_max_f' => $report->getDmax()
|
||||
)
|
||||
);
|
||||
return array(
|
||||
'sql' => ($dmin && $dmax ? ' log_date.date > :date_min AND log_date.date < :date_max ' : false)
|
||||
, 'params' => ($dmin && $dmax ? array(':date_min' => $dmin, ':date_max' => $dmax) : array())
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function userFilter(module_report $report)
|
||||
{
|
||||
$this->filter['user'] = false;
|
||||
$f = $report->getTabFilter();
|
||||
|
||||
if (sizeof($f) > 0)
|
||||
public static function constructCollectionFilter($list_coll_id)
|
||||
{
|
||||
$filter = array();
|
||||
$params = array();
|
||||
$n = 0;
|
||||
foreach ($f as $field => $value)
|
||||
{
|
||||
if (array_key_exists($value['f'], $this->cor_query))
|
||||
$value['f'] = $this->cor_query[$value['f']];
|
||||
|
||||
if ($value['o'] == 'LIKE')
|
||||
{
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' \'%' . str_replace(array("'", '%'), array("\'", '\%'), ' :user_filter' . $n) . '%\'';
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
$ret = array('sql' => '', 'params' => array());
|
||||
$coll_filter = array();
|
||||
foreach (explode(',', $list_coll_id) as $val) {
|
||||
$coll_filter [] = " position('," . phrasea::collFromBas($val) . ",' in concat(',' ,coll_list, ',')) > 0 ";
|
||||
}
|
||||
elseif ($value['o'] == 'OR')
|
||||
{
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' :user_filter' . $n;
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
$ret['sql'] = implode(' OR ', $coll_filter);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getCorFilter()
|
||||
{
|
||||
return $this->cor_query;
|
||||
}
|
||||
|
||||
public function getReportFilter()
|
||||
{
|
||||
$finalfilter = '';
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$params = array(':log_site' => $registry->get('GV_sit'));
|
||||
|
||||
if ($this->filter['date']) {
|
||||
$finalfilter .= $this->filter['date']['sql'] . ' AND ';
|
||||
$params = array_merge($params, $this->filter['date']['params']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' :user_filter' . $n;
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
if ($this->filter['user']) {
|
||||
$finalfilter .= $this->filter['user']['sql'] . ' AND ';
|
||||
$params = array_merge($params, $this->filter['user']['params']);
|
||||
}
|
||||
if ($this->filter['collection']) {
|
||||
$finalfilter .= '(' . $this->filter['collection']['sql'] . ') AND ';
|
||||
$params = array_merge($params, $this->filter['collection']['params']);
|
||||
}
|
||||
$finalfilter .= ' log.site = :log_site';
|
||||
|
||||
return array('sql' => $finalfilter, 'params' => $params);
|
||||
}
|
||||
|
||||
public function getGvSitFilter()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$params = array();
|
||||
$sql = '';
|
||||
|
||||
if ($registry->is_set('GV_sit')) {
|
||||
$sql = 'log.site = :log_site_gv_filter';
|
||||
$params[':log_site_gv_filter'] = $registry->get('GV_sit');
|
||||
}
|
||||
|
||||
$n++;
|
||||
}
|
||||
$filter_user = array('sql' => implode(' AND ', $filter), 'params' => $params);
|
||||
|
||||
$this->filter['user'] = $filter_user;
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function collectionFilter(module_report $report)
|
||||
{
|
||||
$this->filter['collection'] = false;
|
||||
$coll_filter = array();
|
||||
|
||||
if ($report->getUserId() == '')
|
||||
|
||||
return;
|
||||
|
||||
$tab = explode(",", $report->getListCollId());
|
||||
if(count($tab) > 0)
|
||||
public function getUserIdFilter($id)
|
||||
{
|
||||
foreach ($tab as $val)
|
||||
{
|
||||
$coll_filter[] = " position('," . phrasea::collFromBas($val) . ",' in concat(',' ,coll_list, ',')) > 0 ";
|
||||
}
|
||||
$this->filter['collection'] = array('sql' => implode(' OR ', $coll_filter), 'params' => array());
|
||||
return array('sql' => "log.usrid = :usr_id_filter", 'params' => array(':usr_id_filter' => $id));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function recordFilter(module_report $report)
|
||||
{
|
||||
$this->filter['record'] = false;
|
||||
$dl_coll_filter = $params = array();
|
||||
$n = 0;
|
||||
if (($report->getUserId() != ''))
|
||||
public function getDateFilter()
|
||||
{
|
||||
$tab = explode(",", $report->getListCollId());
|
||||
foreach ($tab as $val)
|
||||
{
|
||||
$dl_coll_filter[] = "record.coll_id = :record_fil" . $n;
|
||||
$params[":record_fil" . $n] = phrasea::collFromBas($val);
|
||||
$n++;
|
||||
}
|
||||
$this->filter['record'] = array('sql' => implode(' OR ', $dl_coll_filter), 'params' => $params);
|
||||
return $this->filter['date'];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function orderFilter(module_report $report)
|
||||
{
|
||||
$this->filter['order'] = false;
|
||||
if (sizeof($report->getOrder()) > 0)
|
||||
public function getUserFilter()
|
||||
{
|
||||
$this->filter['order'] = " ORDER BY "
|
||||
. $this->cor_query[$report->getOrder('champ')]
|
||||
. ' ' . $report->getOrder('order');
|
||||
return $this->filter['user'];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function limitFilter(module_report $report)
|
||||
{
|
||||
$p = $report->getNbPage();
|
||||
$r = $report->getNbRecord();
|
||||
|
||||
$this->filter['limit'] = false;
|
||||
if ($p && $r)
|
||||
public function getCollectionFilter()
|
||||
{
|
||||
$limit_inf = (int)($p - 1) * $r;
|
||||
$limit_sup = (int) $r;
|
||||
$this->filter['limit'] = " LIMIT " . $limit_inf . ', ' . $limit_sup;
|
||||
return $this->filter['collection'];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
public function getRecordFilter()
|
||||
{
|
||||
return $this->filter['record'];
|
||||
}
|
||||
|
||||
private function buildFilter(module_report $report)
|
||||
{
|
||||
$this->dateFilter($report);
|
||||
$this->limitFilter($report);
|
||||
$this->orderFilter($report);
|
||||
$this->recordFilter($report);
|
||||
$this->userFilter($report);
|
||||
$this->collectionFilter($report);
|
||||
public function getLimitFilter()
|
||||
{
|
||||
return $this->filter['limit'];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
public function getOrderFilter()
|
||||
{
|
||||
return $this->filter['order'];
|
||||
}
|
||||
|
||||
private function dateFilter(module_report $report)
|
||||
{
|
||||
$this->filter['date'] = false;
|
||||
if ($report->getDmin() && $report->getDmax()) {
|
||||
$this->filter['date'] = array(
|
||||
'sql' => ' (log.date > :date_min_f AND log.date < :date_max_f) '
|
||||
, 'params' => array(
|
||||
':date_min_f' => $report->getDmin()
|
||||
, ':date_max_f' => $report->getDmax()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function userFilter(module_report $report)
|
||||
{
|
||||
$this->filter['user'] = false;
|
||||
$f = $report->getTabFilter();
|
||||
|
||||
if (sizeof($f) > 0) {
|
||||
$filter = array();
|
||||
$params = array();
|
||||
$n = 0;
|
||||
foreach ($f as $field => $value) {
|
||||
if (array_key_exists($value['f'], $this->cor_query))
|
||||
$value['f'] = $this->cor_query[$value['f']];
|
||||
|
||||
if ($value['o'] == 'LIKE') {
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' \'%' . str_replace(array("'", '%'), array("\'", '\%'), ' :user_filter' . $n) . '%\'';
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
} elseif ($value['o'] == 'OR') {
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' :user_filter' . $n;
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
} else {
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' :user_filter' . $n;
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
}
|
||||
|
||||
$n ++;
|
||||
}
|
||||
$filter_user = array('sql' => implode(' AND ', $filter), 'params' => $params);
|
||||
|
||||
$this->filter['user'] = $filter_user;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function collectionFilter(module_report $report)
|
||||
{
|
||||
$this->filter['collection'] = false;
|
||||
$coll_filter = array();
|
||||
|
||||
if ($report->getUserId() == '')
|
||||
return;
|
||||
|
||||
$tab = explode(",", $report->getListCollId());
|
||||
if (count($tab) > 0) {
|
||||
foreach ($tab as $val) {
|
||||
$coll_filter[] = " position('," . phrasea::collFromBas($val) . ",' in concat(',' ,coll_list, ',')) > 0 ";
|
||||
}
|
||||
$this->filter['collection'] = array('sql' => implode(' OR ', $coll_filter), 'params' => array());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function recordFilter(module_report $report)
|
||||
{
|
||||
$this->filter['record'] = false;
|
||||
$dl_coll_filter = $params = array();
|
||||
$n = 0;
|
||||
if (($report->getUserId() != '')) {
|
||||
$tab = explode(",", $report->getListCollId());
|
||||
foreach ($tab as $val) {
|
||||
$dl_coll_filter[] = "record.coll_id = :record_fil" . $n;
|
||||
$params[":record_fil" . $n] = phrasea::collFromBas($val);
|
||||
$n ++;
|
||||
}
|
||||
$this->filter['record'] = array('sql' => implode(' OR ', $dl_coll_filter), 'params' => $params);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function orderFilter(module_report $report)
|
||||
{
|
||||
$this->filter['order'] = false;
|
||||
if (sizeof($report->getOrder()) > 0) {
|
||||
$this->filter['order'] = " ORDER BY "
|
||||
. $this->cor_query[$report->getOrder('champ')]
|
||||
. ' ' . $report->getOrder('order');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function limitFilter(module_report $report)
|
||||
{
|
||||
$p = $report->getNbPage();
|
||||
$r = $report->getNbRecord();
|
||||
|
||||
$this->filter['limit'] = false;
|
||||
if ($p && $r) {
|
||||
$limit_inf = (int) ($p - 1) * $r;
|
||||
$limit_sup = (int) $r;
|
||||
$this->filter['limit'] = " LIMIT " . $limit_inf . ', ' . $limit_sup;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function buildFilter(module_report $report)
|
||||
{
|
||||
$this->dateFilter($report);
|
||||
$this->limitFilter($report);
|
||||
$this->orderFilter($report);
|
||||
$this->recordFilter($report);
|
||||
$this->userFilter($report);
|
||||
$this->collectionFilter($report);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -18,22 +18,21 @@
|
||||
class module_report_sqlquestion extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$params = array();
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
$this->params = $params;
|
||||
|
||||
if ($this->groupby == false)
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->sql =
|
||||
"
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$params = array();
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
$this->params = $params;
|
||||
|
||||
if ($this->groupby == false) {
|
||||
$this->sql =
|
||||
"
|
||||
SELECT
|
||||
log_search.date ddate,
|
||||
search,
|
||||
@@ -49,20 +48,18 @@ class module_report_sqlquestion extends module_report_sql implements module_repo
|
||||
";
|
||||
|
||||
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sql = "
|
||||
$this->sql .= $this->filter->getLimitFilter() ? : '';
|
||||
} else {
|
||||
$this->sql = "
|
||||
SELECT
|
||||
TRIM(" . $this->getTransQuery($this->groupby) . ") as " . $this->groupby . ",
|
||||
SUM(1) as nb
|
||||
@@ -71,40 +68,39 @@ class module_report_sqlquestion extends module_report_sql implements module_repo
|
||||
ON log.id = log_search.log_id
|
||||
";
|
||||
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= " ORDER BY nb DESC";
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= " ORDER BY nb DESC";
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$params = array();
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$params = array();
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = "
|
||||
$sql = "
|
||||
SELECT DISTINCT(" . $this->getTransQuery($field) . ") as val
|
||||
FROM `log_search`
|
||||
INNER JOIN log
|
||||
ON log.id = log_search.log_id
|
||||
";
|
||||
|
||||
if ($report_filter['sql'])
|
||||
$sql .= ' WHERE ' . $report_filter['sql'];
|
||||
if ($report_filter['sql'])
|
||||
$sql .= ' WHERE ' . $report_filter['sql'];
|
||||
|
||||
$sql .= " ORDER BY " . $this->getTransQuery($field) . " ASC";
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
$sql .= " ORDER BY " . $this->getTransQuery($field) . " ASC";
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -17,138 +17,117 @@
|
||||
*/
|
||||
class module_report_validate extends module_report
|
||||
{
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: validated documents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('validate')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('validate');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
{
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
elseif ($field == 'size')
|
||||
{
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: validated documents');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row)
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('validate')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('validate');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter") {
|
||||
try {
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
} elseif ($field == 'date') {
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
} elseif ($field == 'size') {
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value) {
|
||||
if ($row[$value]) {
|
||||
if ($value == 'date') {
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
} elseif ($value == 'size') {
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else {
|
||||
if ($value == 'comment') {
|
||||
$this->result[$i][$value] = ' ';
|
||||
} else {
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user