FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
UploadTreeViewProxy.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Proxy;
20 
22 
24 {
25  const CONDITION_UPLOAD = 1;
26  const CONDITION_RANGE = 2;
27  const CONDITION_PLAIN_FILES = 3;
28 
34  public function __construct(ItemTreeBounds $itemTreeBounds, $constraints = array(), $viewSuffix=null)
35  {
36  $dbViewQuery = self::getUploadTreeView($itemTreeBounds, $constraints);
37  parent::__construct($dbViewQuery, 'UploadTreeView' . ($viewSuffix ? '.' . $viewSuffix : ''));
38  }
39 
45  private static function getUploadTreeView(ItemTreeBounds $itemTreeBounds, $constraints)
46  {
47  $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
48  $isDefaultTable = $uploadTreeTableName == 'uploadtree_a' || $uploadTreeTableName == 'uploadtree';
49  if ($isDefaultTable) {
50  $constraints[] = self::CONDITION_UPLOAD;
51  }
52  $baseQuery = "SELECT * FROM $uploadTreeTableName";
53  $condition = self::getConstraintsCondition($itemTreeBounds, $constraints);
54  return $baseQuery . $condition;
55  }
56 
57  private static function getConstraintsCondition(ItemTreeBounds $itemTreeBounds, $constraints)
58  {
59  $conditions = array();
60  foreach (array_unique($constraints) as $constraint) {
61  $conditions[] = self::getConstraintCondition($itemTreeBounds, $constraint);
62  }
63  $condition = implode(' AND ', $conditions);
64  return $condition ? ' WHERE ' . $condition : '';
65  }
66 
67  private static function getConstraintCondition(ItemTreeBounds $itemTreeBounds, $constraint)
68  {
69  switch ($constraint) {
70  case self::CONDITION_UPLOAD:
71  $uploadId = $itemTreeBounds->getUploadId();
72  return "upload_fk = $uploadId";
73  case self::CONDITION_RANGE:
74  $left = $itemTreeBounds->getLeft();
75  $right = $itemTreeBounds->getRight();
76  return "lft BETWEEN $left AND $right";
77  case self::CONDITION_PLAIN_FILES:
78  return '((ufile_mode & (3<<28))=0) AND pfile_fk != 0';
79  default:
80  throw new \InvalidArgumentException("constraint $constraint is not defined");
81  }
82  }
83 }
static getUploadTreeView(ItemTreeBounds $itemTreeBounds, $constraints)
__construct(ItemTreeBounds $itemTreeBounds, $constraints=array(), $viewSuffix=null)