1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2013-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class buildRepository extends simplePlugin
{
var $mainTab = TRUE;
var $objectclasses = array('fdBuildRepository');
public static function plInfo()
{
return array(
'plShortName' => _('Build repository'),
'plDescription' => _('Build repository'),
'plObjectType' => array('buildRepository' => array(
'name' => _('Build repository'),
'filter' => 'objectClass=fdBuildRepository',
'aclCategory' => 'repository',
'ou' => get_ou('repositoryRDN'),
'icon' => 'geticon.php?context=applications&icon=repository&size=16'
)),
'plForeignKeys' => array(
'fdRepoAdmin' => 'user',
'fdRepoUploader' => 'user',
'fdRepoUser' => 'user',
'fdRepoDistributionSection' => array(
array('repositoryDistribution', 'cn', '(fdRepoDistributionSection=%oldvalue%|*)'),
array('repositorySection', 'cn', '(fdRepoDistributionSection=*|%oldvalue%)'),
),
),
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
);
}
static function getAttributesInfo ()
{
global $config;
return array(
'main' => array(
'name' => _('Build repository'),
'attrs' => array(
new BaseSelectorAttribute (get_ou('repositoryRDN')),
new HostNameAttribute (
_('Name'), _('Unique name for this repository'),
'cn', TRUE
),
new TextAreaAttribute (
_('Description'), _('Description of this repository'),
'description', FALSE
),
new SetAttribute (
new SelectAttribute (
_('Distribution sections'), _('The distribution sections this repository provides'),
'fdRepoDistributionSection', TRUE,
array()
)
),
new BooleanAttribute (
_('Private'), _('Is this repository private or public?'),
'fdRepoPrivate', FALSE
),
new SelectAttribute (
_('Type'), _('Repository type'),
'fdRepoType', TRUE,
$config->get_cfg_value('repositoryTypes', array('debian'))
)
)
),
'users' => array(
'name' => _('Members'),
'attrs' => array(
new UsersAttribute (
_('Admins'), _('Admins of this repository'),
'fdRepoAdmin', FALSE
),
new UsersAttribute(
_('Uploaders'), _('Uploaders of this repository'),
'fdRepoUploader', FALSE
),
new UsersAttribute(
_('Users'), _('Users of this repository'),
'fdRepoUser', FALSE
),
)
)
);
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['cn']->setUnique(TRUE);
$distros = objects::ls('repoDistribution', array('cn' => '1', 'fdRepoSection' => '*'));
$choices = array();
foreach ($distros as $infos) {
foreach ($infos['fdRepoSection'] as $section) {
$choices[] = $infos['cn'].'|'.$section;
}
}
$this->attributesAccess['fdRepoDistributionSection']->attribute->setChoices(array_values($choices));
}
function foreignKeyCheck ($field, $fieldvalue, $source)
{
if ($field == 'fdRepoDistributionSection') {
$values = $this->fdRepoDistributionSection;
foreach ($values as $value) {
if (($source['CLASS'] == 'repositoryDistribution') && preg_match('/^'.preg_quote($fieldvalue, '/').'\|/', $value)) {
return TRUE;
}
if (($source['CLASS'] == 'repositorySection') && preg_match('/\|'.preg_quote($fieldvalue, '/').'$/', $value)) {
return TRUE;
}
}
} else {
return parent::foreignKeyCheck ($field, $fieldvalue, $source);
}
}
function foreignKeyUpdate($field, $oldvalue, $newvalue, $source)
{
if ($field == 'fdRepoDistributionSection') {
$values = $this->fdRepoDistributionSection;
foreach ($values as $key => $value) {
if (($source['CLASS'] == 'repositoryDistribution') && preg_match('/^'.preg_quote($oldvalue, '/').'\|/', $value)) {
if ($newvalue === NULL) {
unset($values[$key]);
} else {
$values[$key] = preg_replace('/^'.preg_quote($oldvalue, '/').'/', $newvalue, $value);
}
}
if (($source['CLASS'] == 'repositorySection') && preg_match('/\|'.preg_quote($oldvalue, '/').'$/', $value)) {
if ($newvalue === NULL) {
unset($values[$key]);
} else {
$values[$key] = preg_replace('/'.preg_quote($oldvalue, '/').'$/', $newvalue, $value);
}
}
}
$this->fdRepoDistributionSection = $values;
} else {
return parent::foreignKeyUpdate($field, $oldvalue, $newvalue, $source);
}
}
}
?>
|