FOSSology  4.4.0
Open Source License Compliance by Open Source Software
CopyrightView.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
4  Author: Johannes Najjar
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
10 
12 
13 class CopyrightView extends Xpview
14 {
15  const NAME = 'copyright-view';
16 
17  function __construct()
18  {
19  $this->decisionTableName = "copyright_decision";
20  $this->tableName = "copyright";
21  $this->modBack = 'copyright-hist';
22  $this->optionName = "skipFileCopyRight";
23  $this->ajaxAction = "setNextPrevCopyRight";
24  $this->skipOption = "noCopyright";
25  $this->highlightTypeToStringMap = array(Highlight::COPYRIGHT => 'copyright remark',
26  Highlight::URL => 'URL', Highlight::EMAIL => 'e-mail address',
27  Highlight::AUTHOR => 'author or maintainer');
28  $this->xptext = 'copyright/e-mail/URL';
29  $this->typeToHighlightTypeMap = array(
30  'statement' => Highlight::COPYRIGHT,
31  'email' => Highlight::EMAIL,
32  'url' => Highlight::URL,
33  'author' => Highlight::AUTHOR);
34  parent::__construct(self::NAME, array(
35  self::TITLE => _("View Copyright/Email/Url Analysis")
36  ));
37  }
38 
43  protected function additionalVars($uploadId, $uploadTreeId, $agentId)
44  {
45  if (empty($agentId)) {
46  $agentMap = $this->agentDao->getLatestAgentResultForUpload($uploadId,array('copyright', 'reso'));
47  $agentId = array_key_exists('copyright',$agentMap) ? $agentMap['copyright'] : 0;
48  if (array_key_exists('reso',$agentMap)) {
49  $ResoagentId = $agentMap['reso'];
50  $agentId .= "," . $ResoagentId;
51  }
52  }
53  $typeDescriptionPairs = array(
54  'statement' => _("FOSSology"),
55  'scancode_statement' => _("ScanCode")
56  );
57  $tableVars = array();
58  $output = array();
59  $modCopyrightHist = plugin_find('copyright-hist');
60  $filter = '';
61  foreach ($typeDescriptionPairs as $type=>$description) {
62  if ($type==="scancode_statement") {
63  $agentId = LatestAgentpk($uploadId, 'scancode_ars');
64  $this->agentName = "scancode";
65  }
66  list($out, $vars) = $modCopyrightHist->getTableForSingleType($type, $description, $uploadId, $uploadTreeId, $filter, $agentId);
67  $tableVars[$type] = $vars;
68  $output[] = $out;
69  }
70 
71  list ($vCopyright, $vScancode)=$output;
72  $vars = array('tables'=>$tableVars,
73  'foss_content' => "$vCopyright\n",
74  'scan_content' => "$vScancode\n",
75  'script' => $this->createScriptBlock());
76  return $vars;
77  }
78 
79  protected function createScriptBlock()
80  {
81  return "
82 
83  var copyrightTabViewCookie = 'stickyCopyrightViewTab';
84 
85  $(document).ready(function() {
86  tableCopyright = createTablestatement();
87  tableScancode = createTablescancode_statement();
88  $('#CopyrightViewTabs').tabs({
89  active: ($.cookie(copyrightTabViewCookie) || 0),
90  activate: function(e, ui){
91  // Get active tab index and update cookie
92  var idString = $(e.currentTarget).attr('id');
93  idString = parseInt(idString.slice(-1)) - 1;
94  $.cookie(copyrightTabViewCookie, idString);
95  }
96  });
97  });
98  ";
99  }
100 }
101 
102 register_plugin(new CopyrightView());
additionalVars($uploadId, $uploadTreeId, $agentId)
Get additional variables for a give item.
LatestAgentpk($upload_pk, $arsTableName, $arsSuccess=false)
Given an upload_pk, find the latest enabled agent_pk with results.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
Namespace for Copyright agent's UI components.