FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
PackageDao.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\Dao;
20 
21 
25 use Monolog\Logger;
26 
28 {
29 
31  private $dbManager;
32 
36  public function __construct(DbManager $dbManager, Logger $logger)
37  {
38  $this->dbManager = $dbManager;
39  $this->logger = $logger;
40  }
41 
46  public function findPackageForUpload($uploadId)
47  {
48  $statementName = __METHOD__;
49 
50  $this->dbManager->prepare($statementName, "
51 SELECT p.*, u.*
52 FROM package p
53  INNER JOIN upload_packages up ON p.package_pk = up.package_fk
54  INNER JOIN upload_packages up2 ON p.package_pk = up2.package_fk
55  INNER JOIN upload u ON up2.upload_fk = u.upload_pk
56 WHERE up.upload_fk = $1
57 ORDER BY up2.upload_fk ASC");
58  $res = $this->dbManager->execute($statementName, array($uploadId));
59  $packageId = 0;
60  $packageName = "";
61  $uploads = array();
62  while ($row = $this->dbManager->fetchArray($res)) {
63  $packageId = intval($row['package_pk']);
64  $packageName = $row['package_name'];
65  $uploads[] = Upload::createFromTable($row);
66  }
67  $this->dbManager->freeResult($res);
68  return $packageId > 0 ? new Package($packageId, $packageName, $uploads) : null;
69  }
70 
74  public function createPackage($packageName)
75  {
76  $statementName = __METHOD__;
77 
78  $row = $this->dbManager->getSingleRow(
79  "INSERT INTO package (package_name) VALUES($1) RETURNING package_pk",
80  array($packageName), $statementName);
81  return new Package(intval($row['package_pk']), $packageName, array());
82  }
83 
88  public function addUploadToPackage($uploadId, Package $package)
89  {
90  $statementName = __METHOD__;
91 
92  $this->dbManager->prepare($statementName,
93  "INSERT INTO upload_packages (package_fk, upload_fk) VALUES($1, $2)");
94  $res = $this->dbManager->execute($statementName, array($package->getId(), $uploadId));
95  $this->dbManager->freeResult($res);
96  }
97 }
__construct(DbManager $dbManager, Logger $logger)
Definition: PackageDao.php:36
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
addUploadToPackage($uploadId, Package $package)
Definition: PackageDao.php:88