5 * Copyright 2014, Franck Villaume - TrivialDev
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require_once $gfcommon.'include/FFError.class.php';
24 require_once $gfcommon.'frs/FRSPackage.class.php';
26 class FRSPackageFactory extends FFError {
43 * @param Group $Group The Group object to which these FRSs are associated.
45 function __construct(& $Group) {
46 parent::__construct();
48 if (!$Group || !is_object($Group)) {
49 $this->setError(_('Invalid Project'));
52 if ($Group->isError()) {
53 $this->setError('FRSPackageFactory'._(': ').$Group->getErrorMessage());
56 if (!$Group->usesFRS()) {
57 $this->setError(sprintf(_('%s does not use the FRS tool'), $Group->getPublicName()));
60 $this->Group =& $Group;
64 * getGroup - get the Group object this FRSPackageFactory is associated with.
66 * @return object The Group object.
68 function &getGroup() {
73 * getFRSs - get an array of FRS objects for this Group.
75 * @param bool $status limite the search to active packages. Default is false.
76 * @return array The array of FRS objects.
78 function &getFRSs($status = false) {
79 if (isset($this->FRSs) && is_array($this->FRSs)) {
83 $this->FRSs = array();
84 $ids = $this->getAllPackagesIds($status);
86 foreach ($ids as $id) {
87 if (forge_check_perm('frs', $id, 'read')) {
88 $this->FRSs[] = frspackage_get_object($id);
95 * getAllPackagesIds - return a list of package ids.
97 * @param bool $status limite the search to active packages. Default is false.
98 * @return array The array of package object ids.
100 function &getAllPackagesIds($status = false) {
102 $qpa = db_construct_qpa();
103 $qpa = db_construct_qpa($qpa, 'SELECT package_id FROM frs_package WHERE group_id=$1 ',
104 array($this->Group->getID()));
106 $qpa = db_construct_qpa($qpa, 'AND status_id=$1', array(1));
108 $qpa = db_construct_qpa($qpa, 'ORDER BY package_id DESC');
109 $res = db_query_qpa($qpa);
111 while ($arr = db_fetch_array($res)) {
112 $result[] = $arr['package_id'];
119 * getPermissionOfASpecificUser - get the max level of permission of the current user
121 * @return int the value of permission
128 function getPermissionOfASpecificUser() {
133 $pkgids = $this->getAllPackagesIds();
134 foreach ($pkgids as $pkgid) {
135 if (forge_check_perm('frs', $pkgid, 'read')) {
138 if (forge_check_perm('frs', $pkgid, 'file')) {
141 if (forge_check_perm('frs', $pkgid, 'release')) {
144 if (forge_check_perm('frs', $pkgid, 'admin')) {
148 if (forge_check_perm('frs_admin', $this->Group->getID(), 'admin')) {
153 } elseif ($release) {