41 $this->uploadDao = $uploadDao;
42 $this->logger =
new Logger(self::class);
44 $this->clearingDao = $container->get(
'dao.clearing');
55 public function getHighlights($uploadTreeId, $tableName=
"copyright", $agentId=0,
56 $typeToHighlightTypeMap=array(
57 'statement' => Highlight::COPYRIGHT,
58 'email' => Highlight::EMAIL,
59 'url' => Highlight::URL,
60 'author' => Highlight::AUTHOR)
64 $row = $this->uploadDao->getUploadEntry($uploadTreeId);
66 if (!empty($row[
'pfile_fk'])) {
67 $pFileId = $row[
'pfile_fk'];
69 $text = _(
"Could not locate the corresponding pfile.");
73 $statementName = __METHOD__.$tableName;
74 $params = array($pFileId);
76 if (!empty($agentId)) {
77 $statementName .=
'.agentId';
78 $addAgentValue =
' AND agent_fk=$2';
81 $columnsToSelect =
"type, content, copy_startbyte, copy_endbyte";
82 $getHighlightForTableName =
"SELECT $columnsToSelect FROM $tableName WHERE copy_startbyte IS NOT NULL AND pfile_fk=$1 $addAgentValue";
83 if ($tableName !=
"copyright") {
84 $sql = $getHighlightForTableName;
86 $sql =
"$getHighlightForTableName UNION SELECT $columnsToSelect FROM author WHERE copy_startbyte IS NOT NULL AND pfile_fk=$1 $addAgentValue";
88 $this->
dbManager->prepare($statementName,$sql);
89 $result = $this->
dbManager->execute($statementName, $params);
91 $highlights = array();
92 while ($row = $this->
dbManager->fetchArray($result)) {
94 $content = $row[
'content'];
96 $highlightType = array_key_exists($type, $typeToHighlightTypeMap) ? $typeToHighlightTypeMap[$type] : Highlight::UNDEFINED;
97 $highlights[] =
new Highlight($row[
'copy_startbyte'], $row[
'copy_endbyte'], $highlightType, -1, -1, $content, $htmlElement);
115 public function saveDecision($tableName, $pfileId, $userId , $clearingType,
116 $description, $textFinding, $comment, $decision_pk=-1)
118 $primaryColumn = $tableName .
'_pk';
119 $assocParams = array(
120 'user_fk' => $userId,
121 'pfile_fk' => $pfileId,
122 'clearing_decision_type_fk' => $clearingType,
123 'description' => $description,
124 'textfinding' => $textFinding,
125 'hash' => hash(
'sha256', $textFinding),
129 if ($decision_pk <= 0) {
131 foreach ($rows as $row) {
132 if ($row[
'pfile_fk'] == $pfileId) {
133 $decision_pk = $row[$primaryColumn];
137 if ($decision_pk <= 0) {
138 return $this->
dbManager->insertTableRow($tableName, $assocParams,
139 __METHOD__.
'Insert.'.$tableName, $primaryColumn);
141 $assocParams[
'is_enabled'] =
true;
142 $this->
dbManager->updateTableRow($tableName, $assocParams, $primaryColumn,
143 $decision_pk, __METHOD__.
'Update.'.$tableName);
148 public function removeDecision($tableName,$pfileId, $decisionId)
150 $primaryColumn = $tableName .
'_pk';
154 WHERE $primaryColumn = $1 156 $this->
dbManager->execute(__METHOD__, array($decisionId, $pfileId));
159 public function undoDecision($tableName,$pfileId, $decisionId)
161 $primaryColumn = $tableName .
'_pk';
165 WHERE $primaryColumn = $1 167 $this->
dbManager->execute(__METHOD__, array($decisionId, $pfileId));
178 public function getScannerEntries($tableName, $uploadTreeTableName, $uploadId, $type, $extrawhere)
180 $statementName = __METHOD__.$tableName.$uploadTreeTableName;
182 $extendWClause = null;
184 if ($uploadTreeTableName ===
"uploadtree_a") {
185 $params[]= $uploadId;
186 $extendWClause .=
" AND UT.upload_fk = $".count($params);
187 $statementName .=
".withUI";
190 if ($type !== null && $type !=
"skipcontent") {
192 $extendWClause .=
" AND C.type = $".count($params);
193 $statementName .=
".withType";
196 if ($extrawhere !== null) {
197 $extendWClause .=
" AND ". $extrawhere;
198 $statementName .=
"._".$extrawhere.
"_";
201 $sql =
"SELECT UT.uploadtree_pk as uploadtree_pk, C.content AS content 203 INNER JOIN $uploadTreeTableName UT ON C.pfile_fk = UT.pfile_fk 204 WHERE C.content IS NOT NULL 206 AND C.is_enabled='true' 208 ORDER BY UT.uploadtree_pk, C.content DESC";
209 $this->
dbManager->prepare($statementName, $sql);
210 $sqlResult = $this->
dbManager->execute($statementName, $params);
211 $result = $this->
dbManager->fetchAll($sqlResult);
212 $this->
dbManager->freeResult($sqlResult);
226 $decisionType, $extrawhere=
"")
228 $statementName = __METHOD__.$tableName.$uploadTreeTableName;
230 $extendWClause = null;
232 if ($uploadTreeTableName ===
"uploadtree_a") {
233 $params[]= $uploadId;
234 $extendWClause .=
" AND UT.upload_fk = $".count($params);
235 $statementName .=
".withUI";
238 if (!empty($decisionType)) {
239 $params[]= $decisionType;
240 $extendWClause .=
" AND clearing_decision_type_fk = $".count($params);
241 $statementName .=
".withDecisionType";
244 if (!empty($extrawhere)) {
245 $extendWClause .=
" AND ". $extrawhere;
246 $statementName .=
"._".$extrawhere.
"_";
249 $columns =
"CD.description as description, CD.textfinding as textfinding, CD.comment as comments, UT.uploadtree_pk as uploadtree_pk";
251 $primaryColumn = $tableName .
'_pk';
252 $sql =
"SELECT $columns 254 INNER JOIN $uploadTreeTableName UT ON CD.pfile_fk = UT.pfile_fk 255 WHERE CD.is_enabled = 'true' 257 ORDER BY CD.pfile_fk, UT.uploadtree_pk, CD.textfinding, CD.$primaryColumn DESC";
258 $this->
dbManager->prepare($statementName, $sql);
259 $sqlResult = $this->
dbManager->execute($statementName, $params);
260 $result = $this->
dbManager->fetchAll($sqlResult);
261 $this->
dbManager->freeResult($sqlResult);
276 public function getAllEntriesReport($tableName, $uploadId, $uploadTreeTableName, $type=null, $onlyCleared=
false, $decisionType=null, $extrawhere=null, $groupId=null)
278 $tableNameDecision = $tableName.
"_decision";
279 if ($tableName ==
'copyright') {
280 $scannerEntries = $this->
getScannerEntries($tableName, $uploadTreeTableName, $uploadId, $type, $extrawhere);
281 if (!empty($groupId)) {
282 $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
283 $irrelevantDecisions = $this->clearingDao->getFilesForDecisionTypeFolderLevel($itemTreeBounds, $groupId);
284 $uniqueIrrelevantDecisions = array_unique(array_column($irrelevantDecisions,
'uploadtree_pk'));
285 foreach ($scannerEntries as $key => $value) {
286 if (in_array($value[
'uploadtree_pk'], $uniqueIrrelevantDecisions)) {
287 unset($scannerEntries[$key]);
291 $editedEntries = $this->
getEditedEntries($tableNameDecision, $uploadTreeTableName, $uploadId, $decisionType);
292 return array_merge($scannerEntries, $editedEntries);
294 return $this->
getEditedEntries($tableNameDecision, $uploadTreeTableName, $uploadId, $decisionType);
298 public function getAllEntries($tableName, $uploadId, $uploadTreeTableName, $type=null, $onlyCleared=
false, $decisionType=null, $extrawhere=null)
300 $statementName = __METHOD__.$tableName.$uploadTreeTableName;
304 $distinctContent =
"";
305 $tableNameDecision = $tableName.
"_decision";
307 if ($uploadTreeTableName ===
"uploadtree_a") {
308 $params []= $uploadId;
309 $whereClause .=
" AND UT.upload_fk = $".count($params);
310 $statementName .=
".withUI";
312 if ($type !== null && $type !=
"skipcontent") {
314 $whereClause .=
" AND C.type = $".count($params);
315 $statementName .=
".withType";
318 $clearingTypeClause = null;
321 if ($decisionType !== null) {
322 $params []= $decisionType;
323 $clearingTypeClause =
"WHERE clearing_decision_type_fk = $".count($params);
324 $statementName .=
".withDecisionType";
326 throw new \Exception(
"requested only cleared but no type given");
330 if ($decisionType !== null) {
331 $params []= $decisionType;
332 $clearingTypeClause =
"WHERE clearing_decision_type_fk IS NULL OR clearing_decision_type_fk = $".count($params);
333 $statementName .=
".withDecisionType";
336 $statementName .=
".".$joinType.
"Join";
338 if ($extrawhere !== null) {
339 $whereClause .=
"AND ". $extrawhere;
340 $statementName .=
"._".$extrawhere.
"_";
342 $decisionTableKey = $tableNameDecision .
"_pk";
344 $latestInfo =
"SELECT DISTINCT ON(CD.pfile_fk, UT.uploadtree_pk, C.content, CD.textfinding) 345 CD.description as description, CD.textfinding as textfinding, 346 CD.comment as comments, UT.uploadtree_pk as uploadtree_pk, 347 CD.clearing_decision_type_fk AS clearing_decision_type_fk, 350 INNER JOIN $uploadTreeTableName UT 351 ON C.pfile_fk = UT.pfile_fk 352 $joinType JOIN (SELECT * FROM $tableNameDecision WHERE is_enabled='true') AS CD 353 ON C.pfile_fk = CD.pfile_fk 354 WHERE C.content IS NOT NULL 356 AND C.is_enabled='true' 358 ORDER BY CD.pfile_fk, UT.uploadtree_pk, C.content, CD.textfinding, CD.$decisionTableKey DESC";
360 if ($clearingTypeClause !== null) {
361 $sql =
"SELECT * FROM ($latestInfo) AS latestInfo $clearingTypeClause";
366 $this->
dbManager->prepare($statementName, $sql);
367 $sqlResult = $this->
dbManager->execute($statementName, $params);
368 $result = $this->
dbManager->fetchAll($sqlResult);
369 $this->
dbManager->freeResult($sqlResult);
381 $statementName = __METHOD__.$tableName;
382 $orderTablePk = $tableName.
'_pk';
383 $sql =
"SELECT * FROM $tableName where pfile_fk = $1 and is_enabled order by $orderTablePk desc";
384 $params = array($pfileId);
386 return $this->
dbManager->getRows($sql, $params, $statementName);
404 $statementName = __METHOD__ .
".$tableName";
405 $orderTablePk = $tableName.
'_pk';
410 if ($upload != null) {
411 if (empty($uploadtreetable)) {
414 $statementName.=
".filterUpload";
416 $join =
"INNER JOIN $uploadtreetable AS ut ON cp.pfile_fk = ut.pfile_fk";
417 $joinWhere =
"AND ut.upload_fk = $" . count($params);
420 $sql =
"SELECT * FROM $tableName AS cp $join " .
421 "WHERE cp.hash = $1 $joinWhere ORDER BY $orderTablePk;";
423 return $this->
dbManager->getRows($sql, $params, $statementName);
433 public function updateTable($item, $hash, $content, $userId, $cpTable=
'copyright', $action=
'')
435 $itemTable = $item->getUploadTreeTableName();
436 $stmt = __METHOD__.
".$cpTable.$itemTable";
437 $params = array($hash,$item->getLeft(),$item->getRight());
439 if ($action ==
"delete") {
440 $setSql =
"is_enabled='false'";
442 }
else if ($action ==
"rollback") {
443 $setSql =
"is_enabled='true'";
444 $stmt .=
'.rollback';
446 $setSql =
"content = $4, hash = md5($4), is_enabled='true'";
447 $params[] = $content;
450 $cpTablePk = $cpTable.
"_pk";
451 $sql =
"UPDATE $cpTable AS cpr SET $setSql 453 INNER JOIN $itemTable AS ut ON cp.pfile_fk = ut.pfile_fk 454 WHERE cpr.$cpTablePk = cp.$cpTablePk 456 AND ( ut.lft BETWEEN $2 AND $3 )";
457 if (
'uploadtree_a' == $item->getUploadTreeTableName()) {
458 $params[] = $item->getUploadId();
459 $sql .=
" AND ut.upload_fk=$".count($params);
463 $this->
dbManager->prepare($stmt,
"$sql");
464 $resource = $this->
dbManager->execute($stmt, $params);
saveDecision($tableName, $pfileId, $userId, $clearingType, $description, $textFinding, $comment, $decision_pk=-1)
updateTable($item, $hash, $content, $userId, $cpTable='copyright', $action='')
getScannerEntries($tableName, $uploadTreeTableName, $uploadId, $type, $extrawhere)
getEditedEntries($tableName, $uploadTreeTableName, $uploadId, $decisionType, $extrawhere="")
getAllEntriesReport($tableName, $uploadId, $uploadTreeTableName, $type=null, $onlyCleared=false, $decisionType=null, $extrawhere=null, $groupId=null)
getDecisionsFromHash($tableName, $hash, $upload=null, $uploadtreetable=null)
Get all the decisions based on hash.
fo_dbManager * dbManager
fo_dbManager object
getHighlights($uploadTreeId, $tableName="copyright", $agentId=0, $typeToHighlightTypeMap=array( 'statement'=> Highlight::COPYRIGHT, 'email'=> Highlight::EMAIL, 'url'=> Highlight::URL, 'author'=> Highlight::AUTHOR))
getDecisions($tableName, $pfileId)