action = $action; } return $this; } public function getAction() { return $this->action; } public function buildSql() { $customFieldMap = array(); $filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false); $this->params = array_merge(array(':action' => $this->action), $filter['params']); if ($this->groupby == false) { $this->sql = " SELECT tt.usrid, tt.user, tt.final AS getter, tt.record_id, tt.date, tt.mime, tt.file, tt.comment FROM ( SELECT DISTINCT(log.id), log.usrid, log.user, d.final, d.comment, d.record_id, d.date, record.mime, record.originalname as file FROM (log_docs AS d) INNER JOIN log FORCE INDEX (date_site) ON (log.id = d.log_id) INNER JOIN record ON (record.record_id = d.record_id) WHERE (" . $filter['sql'] . ") AND (d.action = :action) ) AS tt"; // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND); $customFieldMap = array( 'log.usrid' => 'tt.usrid', 'log.user' => 'tt.user', 'd.final' => 'getter', 'd.record_id' => 'tt.record_id', 'd.date' => 'tt.date', 'record.mime' => 'tt.mime', 'file' => 'tt.file', 'd.comment' => 'tt.comment' ); $stmt = $this->getConnBas()->prepare($this->sql); $stmt->execute($this->params); $this->total_row = $stmt->rowCount(); $stmt->closeCursor(); $this->sql .= $this->filter->getOrderFilter($customFieldMap) ? : ''; $this->sql .= $this->filter->getLimitFilter() ? : ''; } else { $this->sql = " SELECT " . $this->groupby . ", SUM(1) AS nombre FROM ( SELECT DISTINCT(log.id), TRIM(" . $this->getTransQuery($this->groupby) . ") AS " . $this->groupby . " , log.usrid , d.final, d.record_id, d.date FROM (log_docs as d) INNER JOIN log FORCE INDEX (date_site) ON (log.id = d.log_id) INNER JOIN record ON (record.record_id = d.record_id) WHERE (" . $filter['sql'] . ") AND (d.action = :action) ) AS tt LEFT JOIN subdef AS s ON (s.record_id=tt.record_id) WHERE s.name='document' GROUP BY " . $this->groupby . " ORDER BY nombre"; // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND); $stmt = $this->getConnBas()->prepare($this->sql); $stmt->execute($this->params); $this->total_row = $stmt->rowCount(); $stmt->closeCursor(); } return $this; } public function sqlDistinctValByField($field) { $filter = $this->filter->getReportFilter() ? : array('params' => array(), 'sql' => false); $this->params = array_merge(array(':action' => $this->action), $filter['params']); $this->sql = " SELECT DISTINCT(val) FROM ( SELECT DISTINCT(log.id), " . $this->getTransQuery($field) . " AS val FROM (log_docs as d) INNER JOIN log FORCE INDEX (date_site) ON (log.id = d.log_id) INNER JOIN record ON (record.record_id = d.record_id) LEFT JOIN subdef as s ON (s.record_id=d.record_id AND s.name='document') WHERE (" . $filter['sql'] . ") AND (d.action = :action) ) AS tt " . ($this->filter->getOrderFilter() ? $this->filter->getOrderFilter() : ''); // no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND); return array('sql' => $this->sql, 'params' => $this->params); } }