FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
CopyrightLister.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2014-2015 Siemens AG
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License version 2.1 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this library; if not, write to the Free Software Foundation, Inc.0
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 ***********************************************************/
19 
25 namespace Fossology\Lib\Util;
26 
32 
34 {
36  private $dbManager;
38  private $uploadDao;
40  private $treeDao;
42  private $copyrightDao;
43 
44  private $includeContainer = FALSE;
45  private $excludingCopyright = -1;
46  private $includingCopyright = -1;
48  private $type = "";
49  private $agentId;
50 
51  function __construct()
52  {
53  global $container;
54  $this->dbManager = $container->get('db.manager');
55  $this->uploadDao = $container->get('dao.upload');
56  $this->treeDao = $container->get('dao.tree');
57  $this->copyrightDao = $container->get('dao.copyright');
58  }
59 
60  public function setContainerInclusion($includeContainer)
61  {
62  $this->includeContainer = $includeContainer;
63  }
64 
65  public function setExcludingCopyright($excludingCopyright)
66  {
67  $this->excludingCopyright = $excludingCopyright;
68  }
69 
70  public function setIncludingCopyright($includingCopyright)
71  {
72  $this->includingCopyright = $includingCopyright;
73  }
74 
75  public function setType($type)
76  {
77  $this->type = $type;
78  }
79 
84  public function getCopyrightList($itemId, $uploadId)
85  {
86  if (empty($itemId)) {
87  $itemId = $this->uploadDao->getUploadParent($uploadId);
88  }
89  if (!$this->selectAgentId($uploadId)) {
90  echo 'no valid copyright agent found';
91  return;
92  }
93  $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($uploadId);
94  $toprow = $this->uploadDao->getItemTreeBounds($itemId,$uploadtree_tablename);
95 
96  $extraWhere = 'agent_fk='.$this->agentId.' AND lft>'.$toprow->getLeft().' AND rgt<'.$toprow->getRight();
97  $allCopyrightEntries = $this->copyrightDao->getAllEntries('copyright', $uploadId, $uploadtree_tablename,
98  empty($this->type)||$this->type=='all' ? null : $this->type, false, null, $extraWhere);
99 
100  $modeMask = empty($this->includeContainer) ? (3<<28) : (1<<28);
101  $sql = "SELECT uploadtree_pk, ufile_name, lft, rgt FROM $uploadtree_tablename
102  WHERE upload_fk=$1 AND lft>$2 AND rgt<$3 AND (ufile_mode & $4) = 0
103  ORDER BY uploadtree_pk";
104  $this->dbManager->prepare($outerStmt=__METHOD__.'.loopThroughAllRecordsInTree',$sql);
105  $outerresult = $this->dbManager->execute($outerStmt,array($toprow->getUploadId(),$toprow->getLeft(),$toprow->getRight(),$modeMask));
106  while ($row = $this->dbManager->fetchArray($outerresult)) {
107  $this->printRow($row,$uploadtree_tablename, $allCopyrightEntries); //$this->uploadDao->getParentItemBounds($uploadId)->getItemId());
108  }
109  $this->dbManager->freeResult($outerresult);
110  }
111 
116  private function selectAgentId($uploadId)
117  {
118  global $container;
119  /* @var $agentDao AgentDao */
120  $agentDao = $container->get('dao.agent');
121  $agentRec = $agentDao->agentARSList($tableName="copyright_ars", $uploadId, 1);
122 
123  if ($agentRec === false) {
124  echo _("No data available \n");
125  return false;
126  }
127  $this->agentId = $agentRec[0]["agent_fk"];
128  return true;
129  }
130 
134  private function printRow($row,$uploadtree_tablename, &$allCopyrightEntries, $parentId=0)
135  {
136  $filepath = $this->treeDao->getFullPath($row['uploadtree_pk'], $uploadtree_tablename, $parentId);
137 
138  $copyrightArray = array();
139  foreach ($allCopyrightEntries as $entry) {
140  if ($entry['uploadtree_pk'] == $row['uploadtree_pk']) {
141  $copyrightArray[] = $entry['content'];
142  }
143  }
144  $copyright = implode(', ', $copyrightArray);
145 
147  if (-1 != $this->includingCopyright && -1 != $this->excludingCopyright && !empty($this->includingCopyright) &&
148  !empty($this->excludingCopyright)) {
149  if (empty($copyright) || stristr($copyright, $this->includingCopyright) ||
150  stristr($copyright, $this->excludingCopyright)) {
151  return;
152  }
153  } else if (
155  ! (-1 == $this->includingCopyright && -1 == $this->excludingCopyright) &&
157  ! (empty($this->includingCopyright) && empty($this->excludingCopyright)) &&
159  ! (empty($this->includingCopyright) && empty($copyright)) &&
161  ! (empty($this->excludingCopyright) && !empty($copyright)) &&
163  ! (-1 != $this->includingCopyright && !empty($this->includingCopyright) && !empty($copyright) && stristr($copyright, $this->includingCopyright)) &&
165  ! (-1 != $this->excludingCopyright && !empty($this->excludingCopyright) && !empty($copyright) && !stristr($copyright, $this->excludingCopyright))) {
166  return;
167  }
168  print ("$filepath: $copyright\n");
169  }
170 }
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
printRow($row, $uploadtree_tablename, &$allCopyrightEntries, $parentId=0)
write out text in format &#39;filepath: copyright list&#39;