14 namespace Fossology\Lib\Util;
31 private $copyrightDao;
33 private $includeContainer = FALSE;
34 private $excludingCopyright = -1;
35 private $includingCopyright = -1;
40 function __construct()
43 $this->
dbManager = $container->get(
'db.manager');
44 $this->uploadDao = $container->get(
'dao.upload');
45 $this->treeDao = $container->get(
'dao.tree');
46 $this->copyrightDao = $container->get(
'dao.copyright');
49 public function setContainerInclusion($includeContainer)
51 $this->includeContainer = $includeContainer;
54 public function setExcludingCopyright($excludingCopyright)
56 $this->excludingCopyright = $excludingCopyright;
59 public function setIncludingCopyright($includingCopyright)
61 $this->includingCopyright = $includingCopyright;
64 public function setType($type)
76 $itemId = $this->uploadDao->getUploadParent($uploadId);
79 echo
'no valid copyright agent found';
82 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($uploadId);
83 $toprow = $this->uploadDao->getItemTreeBounds($itemId,$uploadtree_tablename);
85 $extraWhere =
'agent_fk='.$this->agentId.
' AND lft>'.$toprow->getLeft().
' AND rgt<'.$toprow->getRight();
86 $allCopyrightEntries = $this->copyrightDao->getAllEntries(
'copyright', $uploadId, $uploadtree_tablename,
87 empty($this->type)||$this->type==
'all' ?
null : $this->type,
false,
null, $extraWhere);
89 $modeMask = empty($this->includeContainer) ? (3<<28) : (1<<28);
90 $sql =
"SELECT uploadtree_pk, ufile_name, lft, rgt FROM $uploadtree_tablename
91 WHERE upload_fk=$1 AND lft>$2 AND rgt<$3 AND (ufile_mode & $4) = 0
92 ORDER BY uploadtree_pk";
93 $this->
dbManager->prepare($outerStmt=__METHOD__.
'.loopThroughAllRecordsInTree',$sql);
94 $outerresult = $this->
dbManager->execute($outerStmt,array($toprow->getUploadId(),$toprow->getLeft(),$toprow->getRight(),$modeMask));
95 while ($row = $this->
dbManager->fetchArray($outerresult)) {
96 $this->
printRow($row,$uploadtree_tablename, $allCopyrightEntries);
98 $this->
dbManager->freeResult($outerresult);
109 $agentDao = $container->get(
'dao.agent');
110 $agentRec = $agentDao->agentARSList($tableName=
"copyright_ars", $uploadId, 1);
112 if ($agentRec ===
false) {
113 echo _(
"No data available \n");
116 $this->agentId = $agentRec[0][
"agent_fk"];
123 private function printRow($row,$uploadtree_tablename, &$allCopyrightEntries, $parentId=0)
125 $filepath = $this->treeDao->getFullPath($row[
'uploadtree_pk'], $uploadtree_tablename, $parentId);
127 $copyrightArray = array();
128 foreach ($allCopyrightEntries as $entry) {
129 if ($entry[
'uploadtree_pk'] == $row[
'uploadtree_pk']) {
130 $copyrightArray[] = $entry[
'content'];
133 $copyright = implode(
', ', $copyrightArray);
136 if (-1 != $this->includingCopyright && -1 != $this->excludingCopyright && !empty($this->includingCopyright) &&
137 !empty($this->excludingCopyright)) {
138 if (empty($copyright) || stristr($copyright, $this->includingCopyright) ||
139 stristr($copyright, $this->excludingCopyright)) {
144 ! (-1 == $this->includingCopyright && -1 == $this->excludingCopyright) &&
146 ! (empty($this->includingCopyright) && empty($this->excludingCopyright)) &&
148 ! (empty($this->includingCopyright) && empty($copyright)) &&
150 ! (empty($this->excludingCopyright) && !empty($copyright)) &&
152 ! (-1 != $this->includingCopyright && !empty($this->includingCopyright) && !empty($copyright) && stristr($copyright, $this->includingCopyright)) &&
154 ! (-1 != $this->excludingCopyright && !empty($this->excludingCopyright) && !empty($copyright) && !stristr($copyright, $this->excludingCopyright))) {
157 print (
"$filepath: $copyright\n");
getCopyrightList($itemId, $uploadId)
printRow($row, $uploadtree_tablename, &$allCopyrightEntries, $parentId=0)
write out text in format 'filepath: copyright list'
fo_dbManager * dbManager
fo_dbManager object