*
* Copyright 2006 (c) Fabien Regnier - Sogeti
* Copyright 2010-2011, Franck Villaume - Capgemini
+ * Copyright 2012-2013, Franck Villaume - TrivialDev
* http://fusionforge.org
*
* This file is part of FusionForge. FusionForge is free software;
*/
class projects_hierarchyPlugin extends Plugin {
- function projects_hierarchyPlugin() {
+ function __construct() {
$this->Plugin();
$this->name = 'projects-hierarchy';
$this->text = _('Project Hierarchy'); // To show in the tabs, use...
$this->_addHook('display_hierarchy'); // to see the tree of projects
$this->_addHook('group_delete'); // clean tables on delete
$this->_addHook('project_admin_plugins'); // to show up in the admin page fro group
- $this->_addHook('site_admin_option_hook'); // to provide a link to the site wide administrative pages of plugin
+ $this->_addHook('site_admin_option_hook'); // to provide a link to the site wide administrative pages of plugin
+ $this->_addHook('display_hierarchy_submenu'); // to display a submenu in software map if projects-hierarchy plugin is used
+ $this->_addHook('docmansearch_has_hierarchy'); // used by the search menu in docman
}
function CallHook($hookname, &$params) {
break;
}
case "group_delete": {
- if ($params['group']->usesPlugins($this->name)) {
- if ($this->remove($params['group_id'])) {
- $returned = true;
- }
- } else {
- $returned = true;
- }
+ $this->remove($params['group_id']);
+ $returned = true;
break;
}
case "site_admin_option_hook": {
$group = group_get_object($group_id);
if ($group->usesPlugin($this->name)) {
echo '<p>';
- echo util_make_link('/plugins/'.$this->name.'/?group_id='.$group_id.'&type=admin&pluginname='.$this->name, _('Hierarchy Admin'));
+ echo util_make_link('/plugins/'.$this->name.'/?group_id='.$group_id.'&type=admin&pluginname='.$this->name, _('Hierarchy Admin'), array('class'=>'tabtitle', 'title'=>_('Configure the projets-hierarchy plugin (docman, tree, delegate, globalconf features)')));
echo '</p>';
}
$returned = true;
break;
}
+ case "display_hierarchy_submenu": {
+ $globalConf = $this->getGlobalconf();
+ if ($globalConf['tree']) {
+ // Use to display a submenu in software map page if at least one project has a valid relationship
+ $res1 = db_query_params('SELECT g.group_name FROM plugins p, group_plugin gp, groups g WHERE plugin_name = $1 and gp.group_id = g.group_id and p.plugin_id = gp.plugin_id',
+ array($this->name));
+ if ($res1) {
+ if (db_numrows($res1) > 0) {
+ $res2 = db_query_params('SELECT count(*) as used FROM plugin_projects_hierarchy_relationship where status = $1',
+ array('t'));
+ if ($res2)
+ $row = db_fetch_array($res2);
+ if ($row['used']) {
+ $hierarchy_used = true;
+ }
+ }
+ }
+ if (isset($hierarchy_used)) {
+ $hierarMenuTitle[] = _('Per Category');
+ $hierarMenuTitle[] = _('Per Hierarchy');
+ $hierarMenuAttr[] = array('title' => _('Browse per category the available projects. Some projects might not appear here they do not choose any categories'), 'class' => 'tabtitle-nw');
+ $hierarMenuAttr[] = array('title' => _('Browse per hierarchy. Projects can share relationship between projects, as father and sons'), 'class' => 'tabtitle');
+ $hierarMenuUrl[] = '/softwaremap/trove_list.php?cat=c';
+ $hierarMenuUrl[] = '/softwaremap/trove_list.php?cat=h';
+ echo ($HTML->subMenu($hierarMenuTitle, $hierarMenuUrl, $hierarMenuAttr));
+ }
+ }
+ $returned = true;
+ break;
+ }
+ case "docmansearch_has_hierarchy": {
+ if ($params['includesubprojects']) {
+ $group_id = $params['group_id'];
+ $group = group_get_object($group_id);
+ if ($group->usesPlugin($this->name)) {
+ $arrayChilds= $this->getFamily($group_id, 'child', true, 'validated');
+ foreach ( $arrayChilds as $childId ) {
+ $params['qpa'] = db_construct_qpa($params['qpa'], ' OR group_id = $1', array($childId));
+ }
+ }
+ }
+ $returned = true;
+ break;
+ }
}
return $returned;
}
where p1.group_id=plugin_projects_hierarchy_relationship.project_id
and p2.group_id=plugin_projects_hierarchy_relationship.sub_project_id
and plugin_projects_hierarchy_relationship.status=$1
+ and (select tree from plugin_projects_hierarchy where project_id = p2.group_id)
order by father_name, son_name',
array('t'));
echo db_error();
// value = list of sons
$tree = array();
while ($row = db_fetch_array($res)) {
- if (forge_check_perm('project_read', $row['father_id'])) {
+ if (forge_check_perm('project_read', $row['father_id']) && forge_check_perm('project_read', $row['son_id'])) {
$tree[$row['father_id']][] = $row['son_id'];
//get the unix name of the project
$project_name[$row['father_id']][0] = $row['father_name'];
$returnTree .= '<table ><tr><td>';
$returnTree .= '<script type="text/javascript">';
$returnTree .= 'd = new dTree(\'d\');';
- $returnTree .= 'd.add(0,-1,\'Project Tree\');';
+ $returnTree .= 'd.add(0,-1,\'Project Hierarchy Tree\');';
reset($arbre);
//construction automatique de l'arbre format : (num_fils, num_pere,nom,nom_unix)
while (list($key2, $sons2) = each($arbre)) {
if (db_affected_rows($res))
return true;
} else {
- $qpa = db_construct_qpa(false, 'DELETE FROM plugin_projects_hierarchy_relationship WHERE ',
- array($status));
+ $qpa = db_construct_qpa(false, 'DELETE FROM plugin_projects_hierarchy_relationship WHERE ');
switch ($relation) {
case "parent": {
$qpa = db_construct_qpa($qpa, 'project_id = $1 AND sub_project_id = $2',
* @access public
*/
function getAdminOptionLink() {
- return util_make_link('/plugins/'.$this->name.'/?type=globaladmin&pluginname='.$this->name,_('Global Hierarchy admin'));
+ return util_make_link('/plugins/'.$this->name.'/?type=globaladmin',_('Global Hierarchy admin'), array('class'=>'tabtitle', 'title'=>_('Configure the projets-hierarchy plugin (docman, tree, delegate, globalconf features)')));
}
/**
* getHeader - initialize header and js
* @param string type : user, project (aka group)
+ * @param array params
* @return bool success or not
*/
- function getHeader($type) {
+ function getHeader($type, $params=NULL) {
global $gfplugins;
$returned = false;
switch ($type) {
}
case 'admin':
default: {
- $params['toptab']=$this->name;
site_project_header($params);
$returned = true;
break;
return $returnArr;
}
+ /**
+ * getConf - return the configuration defined at project level
+ *
+ * @param integer the group id
+ * @return array the configuration array
+ */
+ function getConf($project_id) {
+ $resConf = db_query_params('SELECT * from plugin_projects_hierarchy where project_id=$1',array($project_id));
+ if (!$resConf) {
+ return false;
+ }
+
+ $row = db_numrows($resConf);
+
+ if ($row == null || count($row) > 2) {
+ return false;
+ }
+
+ $resArr = db_fetch_array($resConf);
+ $returnArr = array();
+
+ foreach($resArr as $column => $value) {
+ if ($value == 't') {
+ $returnArr[$column] = true;
+ } else {
+ $returnArr[$column] = false;
+ }
+ }
+
+ return $returnArr;
+ }
+
+
function getProjectAdminView() {
global $gfplugins, $use_tooltips;
include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
$res = db_query_params('insert into plugin_projects_hierarchy_global (tree, docman, delegate)
values ($1, $2, $3)',
+ array(
+ $confArr['tree'],
+ $confArr['docman'],
+ $confArr['delegate']
+ ));
+ if (!$res)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * updateConf - update the configuration in database for this project
+ *
+ * @param array configuration array (tree, docman, delegate)
+ * @return bool true on success
+ */
+ function updateConf($project_id, $confArr) {
+ if (!isset($confArr['tree']) || !isset($confArr['docman']) || !isset($confArr['delegate']) || !isset($confArr['globalconf']))
+ return false;
+
+ $res = db_query_params('update plugin_projects_hierarchy
+ set (tree, docman, delegate, globalconf) = ($1, $2, $3, $4)
+ where project_id = $5',
array(
$confArr['tree'],
$confArr['docman'],
$confArr['delegate'],
+ $confArr['globalconf'],
+ $project_id
));
if (!$res)
return false;
WHERE status = $1
AND group_id != $2
AND group_id <> ALL ($3)
- AND group_id IN (select group_id from group_plugin,plugins where group_plugin.plugin_id = plugins.plugin_id and plugins.plugin_name = $4);',
+ AND group_id IN (select group_id from group_plugin,plugins where group_plugin.plugin_id = plugins.plugin_id and plugins.plugin_name = $4)
+ AND group_id NOT IN (select sub_project_id from plugin_projects_hierarchy_relationship);',
array('A',
$group_id,
db_int_array_to_any_clause($family),
$this->name));
return html_build_select_box($son, $name, $selected, false);
}
+
+ /**
+ * isUsed - is this plugin used by other projects than the current family ?
+ *
+ * @return bool yes or no
+ */
+ function isUsed($group_id) {
+ $sons = $this->getFamily($group_id, 'child', true, 'any');
+ $parent = $this->getFamily($group_id, 'parent', true, 'any');
+ $family = array_merge($parent, $sons);
+ $used =false;
+ $res1 = db_query_params('SELECT g.group_name FROM plugins p, group_plugin gp, groups g
+ WHERE plugin_name = $1
+ AND gp.group_id = g.group_id
+ AND p.plugin_id = gp.plugin_id
+ AND g.group_id <> ALL ($2)',
+ array($this->name, db_int_array_to_any_clause($family))
+ );
+ if ($res1) {
+ // we want at least more than ourself
+ if (db_numrows($res1) > 1) {
+ $used = true;
+ }
+ }
+ return $used;
+ }
}
// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
-
-?>