FOSSology  4.4.0
Open Source License Compliance by Open Source Software
UploadTreeViewProxy.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Proxy;
9 
11 
13 {
14  const CONDITION_UPLOAD = 1;
15  const CONDITION_RANGE = 2;
16  const CONDITION_PLAIN_FILES = 3;
17 
23  public function __construct(ItemTreeBounds $itemTreeBounds, $constraints = array(), $viewSuffix=null)
24  {
25  $dbViewQuery = self::getUploadTreeView($itemTreeBounds, $constraints);
26  parent::__construct($dbViewQuery, 'UploadTreeView' . ($viewSuffix ? '.' . $viewSuffix : ''));
27  }
28 
34  private static function getUploadTreeView(ItemTreeBounds $itemTreeBounds, $constraints)
35  {
36  $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
37  $isDefaultTable = $uploadTreeTableName == 'uploadtree_a' || $uploadTreeTableName == 'uploadtree';
38  if ($isDefaultTable) {
39  $constraints[] = self::CONDITION_UPLOAD;
40  }
41  $baseQuery = "SELECT * FROM $uploadTreeTableName";
42  $condition = self::getConstraintsCondition($itemTreeBounds, $constraints);
43  return $baseQuery . $condition;
44  }
45 
46  private static function getConstraintsCondition(ItemTreeBounds $itemTreeBounds, $constraints)
47  {
48  $conditions = array();
49  foreach (array_unique($constraints) as $constraint) {
50  $conditions[] = self::getConstraintCondition($itemTreeBounds, $constraint);
51  }
52  $condition = implode(' AND ', $conditions);
53  return $condition ? ' WHERE ' . $condition : '';
54  }
55 
56  private static function getConstraintCondition(ItemTreeBounds $itemTreeBounds, $constraint)
57  {
58  switch ($constraint) {
59  case self::CONDITION_UPLOAD:
60  $uploadId = $itemTreeBounds->getUploadId();
61  return "upload_fk = $uploadId";
62  case self::CONDITION_RANGE:
63  $left = $itemTreeBounds->getLeft();
64  $right = $itemTreeBounds->getRight();
65  return "lft BETWEEN $left AND $right";
66  case self::CONDITION_PLAIN_FILES:
67  return '((ufile_mode & (3<<28))=0) AND pfile_fk != 0';
68  default:
69  throw new \InvalidArgumentException("constraint $constraint is not defined");
70  }
71  }
72 }
__construct(ItemTreeBounds $itemTreeBounds, $constraints=array(), $viewSuffix=null)
static getUploadTreeView(ItemTreeBounds $itemTreeBounds, $constraints)