示例#1
0
 public function __construct(Application $app, module_report $report)
 {
     $this->conn = $app['phraseanet.appbox']->get_connection();
     $this->connbas = $app['phraseanet.appbox']->get_databox($report->getSbasId())->get_connection();
     $this->filter = new module_report_sqlfilter($app, $report);
     $this->sql = '';
     $this->params = [];
     $this->total_row = 0;
     $this->enable_limit = $report->getEnableLimit();
 }
示例#2
0
 /**
  * @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(Application $app, $rs)
 {
     $i = 0;
     $pref = parent::getPreff($app, $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)) {
             try {
                 $record = new \record_adapter($app, $this->sbas_id, $row['record_id']);
             } catch (\Exception_Record_AdapterNotFound $e) {
                 continue;
             }
             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++;
     }
 }
示例#3
0
 /**
  * @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(Application $app, $rs)
 {
     $i = 0;
     $pref = parent::getPreff($app, $this->sbas_id);
     //// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($rs, true)), FILE_APPEND);
     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)) {
             //// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, $row['record_id']), FILE_APPEND);
             try {
                 $record = new \record_adapter($app, $this->sbas_id, $row['record_id']);
                 $caption = $record->get_caption();
                 foreach ($pref as $field) {
                     //// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, $field), FILE_APPEND);
                     try {
                         $this->result[$i][$field] = $caption->get_field($field)->get_serialized_values();
                     } catch (\Exception $e) {
                         $this->result[$i][$field] = '';
                     }
                 }
             } catch (\Exception_Record_AdapterNotFound $e) {
                 foreach ($pref as $field) {
                     $this->result[$i][$field] = '';
                 }
             }
         }
         $i++;
         //// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
     }
 }
示例#4
0
 /**
  * constructor
  *
  * @param Application $app
  * @param string      $arg1    start date of the  report
  * @param string      $arg2    end date of the report
  * @param integer     $sbas_id id of the databox
  * @param string      $collist
  */
 public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
 {
     parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
     $this->title = $this->app->trans('report:: validated documents');
 }
示例#5
0
 private function getCSVResponse(Application $app, \module_report $report, $type)
 {
     // set headers
     $headers = [];
     foreach (array_keys($report->getDisplay()) as $k) {
         $headers[$k] = $k;
     }
     // set headers as first row
     $result = $report->getResult();
     array_unshift($result, $headers);
     $collection = new CallbackCollection($result, function ($row) use($report) {
         // restrict fields to the displayed ones
         return array_map('strip_tags', array_intersect_key($row, $report->getDisplay()));
     });
     $filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
     $response = new CSVFileResponse($filename, function () use($app, $collection) {
         $app['csv.exporter']->export('php://output', $collection);
     });
     return $response;
 }
示例#6
0
 /**
  * constructor
  *
  * @param Application $app
  * @param string      $arg1    start date of the  report
  * @param string      $arg2    end date of the report
  * @param integer     $sbas_id id of the databox
  * @param string      $collist
  */
 public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
 {
     parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
     $this->title = $this->app->trans('Sent documents (mail)');
 }
示例#7
0
 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;
 }
示例#8
0
 /**
  * Set Report configuration according to request parameters
  *
  * @param  Application    $app     An application instance
  * @param  Request        $request A request instance
  * @param  \module_report $report  A report instance
  * @param  Array          $conf    A report column configuration
  * @param  Boolean        $what    Whether to group on a particular field or not
  * @return Array
  */
 private function doReport(Application $app, Request $request, \module_report $report, $conf, $what = false)
 {
     if ($app['conf']->get(['registry', 'modules', 'anonymous-report'])) {
         if (isset($conf['user'])) {
             unset($conf['user']);
         }
         if (isset($conf['ip'])) {
             unset($conf['ip']);
         }
     }
     //save initial conf
     $base_conf = $conf;
     //format conf according user preferences
     if ('' !== ($columnsList = $request->request->get('list_column', ''))) {
         $new_conf = $conf;
         $columns = explode(",", $columnsList);
         foreach (array_keys($conf) as $col) {
             if (!in_array($col, $columns)) {
                 unset($new_conf[$col]);
             }
         }
         $conf = $new_conf;
     }
     //display content of a table column when user click on it
     if ($request->request->get('conf') == 'on') {
         return $app->json(['liste' => $app['twig']->render('report/listColumn.html.twig', ['conf' => $base_conf]), "title" => $app->trans("configuration")]);
     }
     //set order
     if ('' !== ($order = $request->request->get('order', '')) && '' !== ($field = $request->request->get('champ', ''))) {
         $report->setOrder($field, $order);
     }
     //work on filters
     $mapColumnTitleToSqlField = $report->getTransQueryString();
     $currentfilter = [];
     if ('' !== ($serializedFilter = $request->request->get('liste_filter', ''))) {
         $currentfilter = @unserialize(urldecode($serializedFilter));
     }
     $filter = new \module_report_filter($app, $currentfilter, $mapColumnTitleToSqlField);
     if ('' !== ($filterColumn = $request->request->get('filter_column', ''))) {
         $field = current(explode(' ', $filterColumn));
         $value = $request->request->get('filter_value', '');
         if ($request->request->get('liste') == 'on') {
             return $app->json(['diag' => $app['twig']->render('report/colFilter.html.twig', ['result' => $report->colFilter($field), 'field' => $field]), "title" => $app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
         }
         if ($field === $value) {
             $filter->removeFilter($field);
         } else {
             $filter->addFilter($field, '=', $value);
         }
     }
     //set new request filter if user asking for them
     if ($request->request->get('precise') == 1) {
         $filter->addFilter('xml', 'LIKE', $request->request->get('word', ''));
     } elseif ($request->request->get('precise') == 2) {
         $filter->addFilter('record_id', '=', $request->request->get('word', ''));
     }
     //set filters to current report
     $report->setFilter($filter->getTabFilter());
     $report->setActiveColumn($filter->getActiveColumn());
     $report->setPostingFilter($filter->getPostingFilter());
     // display a new arraywhere results are group
     if ('' !== ($groupby = $request->request->get('groupby', ''))) {
         $report->setConfig(false);
         $groupby = current(explode(' ', $groupby));
         $reportArray = $report->buildReport(false, $groupby);
         if (count($reportArray['allChamps']) > 0 && count($reportArray['display']) > 0) {
             $groupField = isset($reportArray['display'][$reportArray['allChamps'][0]]['title']) ? $reportArray['display'][$reportArray['allChamps'][0]]['title'] : '';
         } else {
             $groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
         }
         return $app->json(['rs' => $app['twig']->render('report/ajax_data_content.html.twig', ['result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray, 'is_infouser' => false, 'is_nav' => false, 'is_groupby' => true, 'is_plot' => false, 'is_doc' => false]), 'display_nav' => false, 'title' => $app->trans('Groupement des resultats sur le champ %name%', ['%name%' => $groupField])]);
     }
     //set Limit
     if ($report->getEnableLimit() && '' !== ($page = $request->request->get('page', '')) && '' !== ($limit = $request->request->get('limit', ''))) {
         $report->setLimit($page, $limit);
     } else {
         $report->setLimit(false, false);
     }
     //time to build our report
     if (false === $what) {
         $reportArray = $report->buildReport($conf);
     } else {
         $reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
     }
     return $reportArray;
 }
示例#9
0
 /**
  * constructor
  *
  * @param Application $app
  * @param string      $arg1    start date of the  report
  * @param string      $arg2    end date of the report
  * @param integer     $sbas_id id of the databox
  * @param string      $collist
  */
 public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
 {
     parent::__construct($app, $arg1, $arg2, $sbas_id, '');
     $this->title = $this->app->trans('report::Connexions');
 }
示例#10
0
 /**
  * constructor
  *
  * @param Application $app
  * @param string      $arg1    start date of the report
  * @param string      $arg2    end date of the report
  * @param integer     $sbas_id databox id
  * @param string      $collist
  */
 public function __construct(Application $app, $arg1, $arg2, $sbas_id, $collist)
 {
     parent::__construct($app, $arg1, $arg2, $sbas_id, $collist);
 }
示例#11
0
 private function getCSVResponse(\module_report $report, $type)
 {
     // set headers
     $headers = [];
     foreach (array_keys($report->getDisplay()) as $k) {
         $headers[$k] = $k;
     }
     // set headers as first row
     $result = $report->getResult();
     array_unshift($result, $headers);
     $collection = new CallbackCollection($result, function ($row) use($headers) {
         // restrict fields to the displayed ones
         //    return array_map("strip_tags", array_intersect_key($row, $report->getDisplay()));
         $ret = array();
         foreach ($headers as $f) {
             $ret[$f] = array_key_exists($f, $row) ? strip_tags($row[$f]) : '';
         }
         return $ret;
     });
     $filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
     /** @var Exporter $exporter */
     $exporter = $this->app['csv.exporter'];
     $cb = function () use($exporter, $collection) {
         $exporter->export('php://output', $collection);
     };
     $response = new CSVFileResponse($filename, $cb);
     return $response;
 }
示例#12
0
 public function testGetterSetter()
 {
     $report = new module_report(self::$DI['app'], $this->dmin, $this->dmax, 1, '');
     $bool = true;
     $report->setPrettyString($bool);
     $this->assertEquals($bool, $report->getPrettyString());
     $title = 'test';
     $report->setTitle($title);
     $this->assertEquals($title, $report->getTitle());
     $bool = false;
     $report->setCsv($bool);
     $this->assertEquals($bool, $report->getCsv());
     $filter = ['test', 'array'];
     $report->setFilter($filter);
     $this->assertEquals($filter, $report->getTabFilter());
     $periode = "2 years";
     $report->setPeriode($periode);
     $this->assertEquals($periode, $report->getPeriode());
     $postingFilter = 'my posting filter !';
     $report->setpostingFilter($postingFilter);
     $this->assertEquals($postingFilter, $report->getPostingFilter());
     $page = 223;
     $limit = 125;
     $report->setLimit($page, $limit);
     $this->assertEquals($page, $report->getNbPage());
     $this->assertEquals($limit, $report->getNbRecord());
     $report->setGroupBy($bool);
     $this->assertEquals($bool, $report->getGroupBy());
     $column = ['col1', 'col2'];
     $report->setActiveColumn($column);
     $this->assertEquals($column, $report->getActiveColumn());
     $report->setConfig($bool);
     $report->setPrint($bool);
     $report->setHasLimit($bool);
     $this->assertFalse($report->getConfig());
     $this->assertFalse($report->getPrint());
     $this->assertFalse($report->getHasLimit());
     $result = ['result', 'result'];
     $report->setResult($result);
     $this->assertEquals($result, $report->getResult());
     $total = 3200;
     $report->setTotal($total);
     $this->assertEquals($total, $report->getTotal());
     $default_display = ['a', 'b', 'c'];
     $report->setDefault_display($default_display);
     $this->assertEquals($default_display, $report->getDefault_display());
 }
示例#13
0
 public static function activiteTopTenSiteView(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
 {
     $databox = $app->findDataboxById($sbas_id);
     $conn = $databox->get_connection();
     $result = [];
     $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
     $params = [];
     $params = array_merge($params, $datefilter['params']);
     /*
             $sql = "
                 SELECT tt.referrer, SUM(1) AS nb_view
                 FROM (
                     SELECT DISTINCT(log_date.id), referrer
                     FROM (log_view)
                         INNER JOIN log AS log_date FORCE INDEX (date_site) ON (log_view.log_id = log_date.id)
                         INNER JOIN log_colls FORCE INDEX (couple) ON (log_date.id = log_colls.log_id)
                     WHERE " . $datefilter['sql'] . "" .
                 (('' !== $collfilter['sql']) ?  " AND (" . $collfilter['sql'] . ")" : '')
                 . ") AS tt
                 GROUP BY referrer
                 ORDER BY nb_view DESC ";
     */
     $sql = "SELECT tt.referrer, SUM(1) AS nb_view\n" . " FROM (\n" . "     SELECT DISTINCT(log_date.id), referrer\n" . "     FROM (log_view)\n" . "        INNER JOIN log AS log_date FORCE INDEX (date_site) ON (log_view.log_id = log_date.id)\n" . "     WHERE " . $datefilter['sql'] . ") AS tt\n" . " GROUP BY referrer\n" . " ORDER BY nb_view DESC ";
     // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
     $stmt = $conn->prepare($sql);
     $stmt->execute($params);
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     foreach ($rs as $row) {
         $row['referrer'] != 'NO REFERRER' ? $host = parent::getHost($row['referrer']) : ($host = 'NO REFERRER');
         if (!isset($result[$host]['nb'])) {
             $result[$host]['nb'] = 0;
         }
         if (!isset($result[$host]['lib'])) {
             $result[$host]['lib'] = $host;
         }
         $result[$host]['nb'] += (int) $row['nb_view'];
         $result[$host]['id'] = "false";
     }
     return $result;
 }
示例#14
0
 public static function activiteTopTenSiteView(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
 {
     $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
     $conn = $databox->get_connection();
     $result = [];
     $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
     $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);
     $params = [];
     $params = array_merge($params, $datefilter['params'], $collfilter['params']);
     $sql = "\n            SELECT tt.referrer, SUM(1) AS nb_view\n            FROM (\n                SELECT DISTINCT(log_date.id), referrer\n                FROM (log_view)\n                    INNER JOIN log AS log_date FORCE INDEX (date_site) ON (log_view.log_id = log_date.id)\n                    INNER JOIN log_colls FORCE INDEX (couple) ON (log_date.id = log_colls.log_id)\n                WHERE " . $datefilter['sql'] . "\n                AND (" . $collfilter['sql'] . ")\n            ) AS tt\n            GROUP BY referrer\n            ORDER BY nb_view DESC ";
     $stmt = $conn->prepare($sql);
     $stmt->execute($params);
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     foreach ($rs as $row) {
         $row['referrer'] != 'NO REFERRER' ? $host = parent::getHost($row['referrer']) : ($host = 'NO REFERRER');
         if (!isset($result[$host]['nb'])) {
             $result[$host]['nb'] = 0;
         }
         if (!isset($result[$host]['lib'])) {
             $result[$host]['lib'] = $host;
         }
         $result[$host]['nb'] += (int) $row['nb_view'];
         $result[$host]['id'] = "false";
     }
     return $result;
 }
示例#15
0
}
?>
					<input type="button" name="cancel" value="<?php 
echo _l('Cancel');
?>
" onclick="window.location.href='<?php 
echo module_report::link_open(false);
?>
';" class="submit_button" />
				</td>
			</tr>
			<tr>
				<td align="center" colspan="3">
					<span class="button">
					<?php 
echo create_link("Print", "print", module_report::link_generate($report['report_id'], array('arguments' => array('o' => 'print'))));
?>
				</span>
				<span class="button">
					<?php 
echo create_link("Xls", "xls", module_report::link_generate($report['report_id'], array('arguments' => array('o' => 'xls'))));
?>
				</span> 
				</td>
			</tr>
		</tbody>
	</table>


</form>