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 {
45 * @param Group $Group The Group object to which these FRSs are associated.
47 function __construct(& $Group) {
50 if (!$Group || !is_object($Group)) {
51 $this->setError(_('No Valid Group Object'));
54 if ($Group->isError()) {
55 $this->setError('FRSPackageFactory'._(': ').$Group->getErrorMessage());
58 if (!$Group->usesFRS()) {
59 $this->setError(sprintf(_('%s does not use the FRS tool'), $Group->getPublicName()));
62 $this->Group =& $Group;
66 * getGroup - get the Group object this FRSPackageFactory is associated with.
68 * @return object The Group object.
70 function &getGroup() {
75 * getFRSs - get an array of FRS objects for this Group.
77 * @param bool $status limite the search to active packages. Default is false.
78 * @return array The array of FRS objects.
80 function &getFRSs($status = false) {
81 if (isset($this->FRSs) && is_array($this->FRSs)) {
85 $this->FRSs = array();
86 $ids = $this->getAllPackagesIds($status);
88 foreach ($ids as $id) {
89 if (forge_check_perm('frs', $id, 'read')) {
90 $this->FRSs[] =& frspackage_get_object($id);
97 * getAllPackagesIds - return a list of package ids.
99 * @param bool $status limite the search to active packages. Default is false.
100 * @return array The array of package object ids.
102 function &getAllPackagesIds($status = false) {
104 $qpa = db_construct_qpa();
105 $qpa = db_construct_qpa($qpa, 'SELECT package_id FROM frs_package WHERE group_id=$1 ',
106 array($this->Group->getID()));
108 $qpa = db_construct_qpa($qpa, 'AND status_id=$1', array(1));
110 $qpa = db_construct_qpa($qpa, 'ORDER BY package_id DESC');
111 $res = db_query_qpa($qpa);
113 while ($arr = db_fetch_array($res)) {
114 $result[] = $arr['package_id'];
121 * getPermissionOfASpecificUser - get the max level of permission of the current user
123 * @return integer the value of permission
130 function getPermissionOfASpecificUser() {
135 $pkgids = $this->getAllPackagesIds();
136 foreach ($pkgids as $pkgid) {
137 if (forge_check_perm('frs', $pkgid, 'read')) {
140 if (forge_check_perm('frs', $pkgid, 'file')) {
143 if (forge_check_perm('frs', $pkgid, 'release')) {
146 if (forge_check_perm('frs', $pkgid, 'admin')) {
150 if (forge_check_perm('frs_admin', $this->Group->getID(), 'admin')) {
155 } elseif ($release) {