13 use Symfony\Component\HttpFoundation\JsonResponse;
14 use Symfony\Component\HttpFoundation\Response;
16 define(
"TITLE_SPASHTCOPYRIGHTHISTOGRAMPROCESSPOST", _(
"Private: Browse post"));
31 private $uploadtree_tablename;
44 private $dataTablesUtility;
53 $this->Name =
"ajax-spasht-copyright-hist";
54 $this->Title = TITLE_SPASHTCOPYRIGHTHISTOGRAMPROCESSPOST;
56 $this->OutputType =
'JSON';
60 parent::__construct();
62 $this->dataTablesUtility = $container->get(
'utils.data_tables_utility');
63 $this->uploadDao = $container->get(
'dao.upload');
64 $this->
dbManager = $container->get(
'db.manager');
65 $this->spashtDao = $container->get(
'dao.spasht');
76 if ($this->
State != PLUGIN_STATE_READY) {
84 if ($action==
"deletedecision" || $action==
"undodecision") {
87 }
else if ($action==
"deleteHashDecision" || $action==
"undoHashDecision") {
89 }
else if ($action==
"update" || $action==
"delete" || $action==
"undo") {
91 $getEachID = array_filter(explode(
",",
trim($id,
',')),
function($var) {
94 if (count($getEachID) == 4) {
95 list($upload, $item, $hash, $type) = $getEachID;
97 return new Response(
'bad request while '.$action,
98 Response::HTTP_BAD_REQUEST,
99 array(
'Content-type'=>
'text/plain')
105 if (!(($action ==
"getData" || $action ==
"getDeactivatedData") &&
106 ($this->uploadDao->isAccessible($upload, Auth::getGroupId())) ||
107 ($this->uploadDao->isEditable($upload, Auth::getGroupId())))) {
108 $permDeniedText = _(
"Permission Denied");
109 $returnValue =
"<h2>$permDeniedText</h2>";
114 if (in_array($type, $this->textFindingTypes) &&
115 ($action ==
"getData" || $action ==
"getDeactivatedData")) {
117 if ($action ==
"getData") {
118 $returnValue = $textFindingsHandler->doGetData($type, $upload);
119 } elseif ($action ==
"getDeactivatedData") {
120 $returnValue = $textFindingsHandler->doGetData($type, $upload,
false);
125 $returnValue = $this->
doGetData($upload);
127 case "getDeactivatedData":
128 $returnValue = $this->
doGetData($upload,
false);
131 $returnValue = $this->
doUpdate($item, $hash, $type);
134 $returnValue = $this->
doDelete($item, $hash, $type);
137 $returnValue = $this->
doUndo($item, $hash, $type);
140 $returnValue =
"<h2>" . _(
"Unknown action") .
"</h2>";
155 protected function doGetData($upload, $activated =
true)
161 $this->listPage =
"spasht-copyright-list";
163 header(
'Content-type: text/json');
164 list ($aaData, $iTotalRecords, $iTotalDisplayRecords) = $this->
getTableData(
165 $upload, $item, $agent_pk, $type, $this->listPage, $filter, $activated);
166 return new JsonResponse(array(
167 'sEcho' => intval($_GET[
'sEcho']),
169 'iTotalRecords' => $iTotalRecords,
170 'iTotalDisplayRecords' => $iTotalDisplayRecords
189 $filter, $activated =
true)
191 list ($rows, $iTotalDisplayRecords, $iTotalRecords) = $this->
getCopyrights(
196 $rw = $this->uploadDao->isEditable($upload, Auth::getGroupId());
197 foreach ($rows as $row) {
198 $aaData [] = $this->
fillTableRow($row, $item, $upload, $agent_pk, $type,
203 return array($aaData, $iTotalRecords, $iTotalDisplayRecords);
220 $agentId, $type, $filter, $activated =
true)
228 list($left, $right) = $this->uploadDao->getLeftAndRight($item,
229 $uploadTreeTableName);
236 if (
'uploadtree_a' == $uploadTreeTableName) {
237 $sql_upload =
" AND UT.upload_fk=$upload_pk ";
242 if ($type ==
'statement' && $filter ==
"nolic") {
243 $noLicStr =
"No_license_found";
244 $voidLicStr =
"Void";
245 $join =
" INNER JOIN license_file AS LF on cp.pfile_fk=LF.pfile_fk ";
246 $filterQuery =
" AND LF.rf_fk IN (SELECT rf_pk FROM license_ref WHERE rf_shortname IN ('$noLicStr','$voidLicStr')) ";
250 $params = array($left, $right, $agentId);
252 $filterParms = $params;
254 $unorderedQuery =
"FROM $tableName AS cp " .
255 "INNER JOIN $uploadTreeTableName AS UT ON cp.pfile_fk = UT.pfile_fk " .
257 "WHERE textfinding!='' " .
258 "AND ( UT.lft BETWEEN $1 AND $2 ) " .
259 "AND cp.agent_fk= $3 " .
260 "AND cp.is_enabled=" . ($activated ?
'true' :
'false') .
262 $totalFilter = $filterQuery .
" " . $searchFilter;
264 $grouping =
" GROUP BY hash, textfinding ";
266 $countQuery =
"SELECT count(*) FROM (SELECT textfinding AS content, count(*) $unorderedQuery $totalFilter $grouping) as K";
267 $iTotalDisplayRecordsRow = $this->
dbManager->getSingleRow($countQuery,
268 $filterParms, __METHOD__.$tableName .
".count" .
269 ($activated ?
'' :
'_deactivated'));
270 $iTotalDisplayRecords = $iTotalDisplayRecordsRow[
'count'];
272 $countAllQuery =
"SELECT count(*) FROM (SELECT textfinding AS content, count(*) $unorderedQuery$grouping) as K";
273 $iTotalRecordsRow = $this->
dbManager->getSingleRow($countAllQuery, $params,
274 __METHOD__,$tableName .
"count.all" . ($activated ?
'' :
'_deactivated'));
275 $iTotalRecords = $iTotalRecordsRow[
'count'];
278 $filterParms[] = $offset;
279 $range .=
' OFFSET $' . count($filterParms);
280 $filterParms[] = $limit;
281 $range .=
' LIMIT $' . count($filterParms);
283 $sql =
"SELECT textfinding AS content, hash, count(*) as copyright_count " .
284 $unorderedQuery . $totalFilter .
" GROUP BY content, hash " .
285 $orderString . $range;
286 $statement = __METHOD__ . $filter.$tableName . $uploadTreeTableName .
287 ($activated ?
'' :
'_deactivated');
288 $rows = $this->
dbManager->getRows($sql, $filterParms, $statement);
290 return array($rows, $iTotalDisplayRecords, $iTotalRecords);
304 return "copyright_spasht";
313 $columnNamesInDatabase = array(
'copyright_count',
'content');
317 return $this->dataTablesUtility->getSortingString($_GET,
318 $columnNamesInDatabase, $defaultOrder);
329 if (empty($searchPattern)) {
332 $filterParams[] =
"%$searchPattern%";
333 return ' AND textfinding like $'.count($filterParams).
' ';
346 private function getTableRowAction($hash, $uploadTreeId, $upload, $type, $activated =
true, $rw =
true)
351 $act .=
" hidden='true'";
353 $act .=
" id='delete$type$hash' onClick='delete$type($upload,$uploadTreeId,\"$hash\",\"$type\");' class=\"delete\" src=\"images/space_16.png\">";
356 $act .=
" hidden='true'";
358 $act .=
" id='update$type$hash'>deactivated [<a href=\"#\" id='undo$type$hash' onClick='undo$type($upload,$uploadTreeId,\"$hash\",\"$type\");return false;'>Undo</a>]</span>";
362 return "deactivated";
380 private function fillTableRow($row, $uploadTreeId, $upload, $agentId, $type,
381 $listPage, $filter =
"", $activated =
true, $rw =
true)
383 $hash = $row[
'hash'];
384 $output = array(
'DT_RowId' =>
"$upload,$uploadTreeId,$hash,$type" );
388 $urlArgs =
"?mod=".$listPage.
"&agent=$agentId&item=$uploadTreeId&hash=$hash&type=$type";
389 if (!empty($filter)) {
390 $urlArgs .=
"&filter=$filter";
392 $link .= $urlArgs .
"'>" . $row[
'copyright_count'] .
"</a>";
394 $output[
'0'] = $row[
'copyright_count'];
397 $type, $activated, $rw);
398 if ($rw && $activated) {
399 $output[
'3'] =
"<input type='checkbox' class='deleteBySelect$type' id='deleteBySelect$type$hash' value='".$upload.
",".$uploadTreeId.
",".$hash.
",".$type.
"'>";
401 $output[
'3'] =
"<input type='checkbox' class='undoBySelect$type' id='undoBySelect$type$hash' value='".$upload.
",".$uploadTreeId.
",".$hash.
",".$type.
"'>";
417 return new Response(
'empty content not allowed',
418 Response::HTTP_BAD_REQUEST, array(
'Content-type'=>
'text/plain'));
421 $item = $this->uploadDao->getItemTreeBounds($itemId,
423 $this->spashtDao->updateCopyright($item, $hash, $content);
425 return new Response(
'success', Response::HTTP_OK,
426 array(
'Content-type'=>
'text/plain'));
438 $item = $this->uploadDao->getItemTreeBounds($itemId,
440 $this->spashtDao->updateCopyright($item, $hash,
'',
'delete');
441 return new Response(
'Successfully deleted', Response::HTTP_OK,
442 array(
'Content-type'=>
'text/plain'));
452 protected function doUndo($itemId, $hash, $type)
454 $item = $this->uploadDao->getItemTreeBounds($itemId,
456 $this->spashtDao->updateCopyright($item, $hash,
'',
'rollback');
457 return new Response(
'Successfully restored', Response::HTTP_OK,
458 array(
'Content-type'=>
'text/plain'));
463 $NewPlugin->Initialize();
char * uploadtree_tablename
upload.uploadtree_tablename
This is the Plugin class. All plugins should:
Handles Ajax requests for text findings.
Contains the constants and helpers for authentication of user.
static returnSortOrder()
Get sorting orders.
Handles Ajax requests for copyright.
addSearchFilter(&$filterParams)
Add filter on content.
doUpdate($itemId, $hash, $type)
Update result.
getCopyrights($upload_pk, $item, $uploadTreeTableName, $agentId, $type, $filter, $activated=true)
Get results from database and format for JSON.
doDelete($itemId, $hash, $type)
Disable a result.
getOrderString()
Create sorting string for database query.
Output()
Display the loaded menu and plugins.
doGetData($upload, $activated=true)
Handles GET request and create a JSON response.
getTableName($type)
Get table name based on statement type.
doUndo($itemId, $hash, $type)
Rollback a result.
__construct()
base constructor. Most plugins will just use this
getTableData($upload, $item, $agent_pk, $type, $listPage, $filter, $activated=true)
Get the copyright data and fill in expected format.
getTableRowAction($hash, $uploadTreeId, $upload, $type, $activated=true, $rw=true)
Helper to create action column for results.
fillTableRow($row, $uploadTreeId, $upload, $agentId, $type, $listPage, $filter="", $activated=true, $rw=true)
Fill table content for JSON response.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
if(! defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
fo_dbManager * dbManager
fo_dbManager object