3 * Copyright 2011, Sabri LABBENE - Institut Télécom
5 * This file is part of FusionForge. FusionForge is free software;
6 * you can redistribute it and/or modify it under the terms of the
7 * GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the Licence, or (at your option)
11 * FusionForge is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 require_once 'globaldashboard/common/manage_accounts_db_utils.php';
22 require_once 'globaldashboard/include/globalDashboardConstants.php';
23 require_once 'common/widget/Widget.class.php';
24 require_once 'common/widget/WidgetLayoutManager.class.php';
27 class globalDashboard_Widget_MyProjects extends Widget {
29 function __construct($owner_type, $plugin) {
30 $this->plugin = $plugin;
31 $this->Widget('plugin_globalDashboard_MyProjects');
35 return _("Projects on remote Software Forges");
38 function getCategory() {
39 return _('Global Dashboard Plugin');
42 function getDescription() {
43 return _("Lists user projects hosted on remote forge systems");
46 function getContent() {
48 $user = session_get_user();
49 $MyProjects = $this->getUserRemoteProjects($user->getID());
52 if(is_array($MyProjects)) {
53 $tablearr = array(_('My remote projects'),'');
54 $html .= $HTML->listTableTop($tablearr);
56 foreach ($MyProjects as $account_id => $remote_account_projs) {
57 //$remote_account_projs = array("Proj1", "Proj2");
58 /*include_once("arc/ARC2.php");
59 require_once 'plugins/extsubproj/include/Graphite.php';
61 $parser = ARC2::getRDFParser();
62 //$parser->parse('https://vm2.localdomain/projects/coinsuper/');
65 $triples = $parser->getTriples();
67 $turtle = $parser->toTurtle($triples);
68 $datauri = $parser->toDataURI($turtle);
71 $graph = new Graphite();
72 //$graph->setDebug(1);
73 $graph->ns( "doap", "http://usefulinc.com/ns/doap#" );
74 $graph->load( $datauri );
75 //print $graph->resource('https://vm2.localdomain/projects/coinsuper/')->dumpText();
76 $projname = $graph->resource( $url )->get( "dosoapToArray()ap:name" );
78 $account = getDBStoredRemoteAccountById($account_id);
79 if ($account['forge_software'] == REMOTE_FORGE_SOFTWARE_FUSIONFORGE) {
80 $favicon_url = $account['forge_account_domain'] . '/images/icon.png';
81 } elseif ($account['forge_software'] == REMOTE_FORGE_SOFTWARE_CODENDI) {
82 $favicon_url = $account['forge_account_domain'] . '/favicon.ico';
86 foreach ($remote_account_projs as $remote_proj) {
87 $project_url = $account['forge_account_domain'] . '/projects/'. $remote_proj['unix_group_name'];
91 <img src="'. $favicon_url.'" /> <a class="resourceOslcPopupTrigger" href="'. $project_url .'">'. $remote_proj['group_name'] .'</a>
96 $html .= $HTML->listTableBottom();
103 * Fetches user remote projects from all forges
105 * @param integer $user_id
107 * @return array $projects
109 function getUserRemoteProjects($user_id){
111 $accounts = getDBStoredRemoteAccountsByUserId($user_id);
112 if (count($accounts) > 0) {
113 foreach ($accounts as $account) {
114 $fetch_method = $this->getProjectsFetchMethodForAccount($account["account_id"]);
115 switch ($fetch_method) {
116 case USER_PROJECTS_FETCH_METHOD_SOAP:
117 $projects = $this->getAccountRemoteProjectsBySOAP($account, $projects);
119 case USER_PROJECTS_FETCH_METHOD_OSLC:
120 //$projects = $this->getAccountRemoteProjectsByOSLC($account);
122 case USER_PROJECTS_FETCH_METHOD_FOAF:
123 $projects = $this->getAccountRemoteProjectsByFOAF($account);
133 function getAccountRemoteProjectsBySOAP($account, $projects) {
134 switch ($account['forge_software']) {
135 case REMOTE_FORGE_SOFTWARE_FUSIONFORGE:
136 $soap_client = new SoapClient($account['forge_account_soap_wsdl_uri'], array('trace'=>true, 'exceptions'=>true));
138 $session_ser = $soap_client->__soapCall("login", array("userid" => $account['forge_account_login_name'], "passwd" => $account['forge_account_password']));
139 //@FIXME: user_id here should be the one in the remote forge !!! Need extra soap call to get that id
140 $results = $soap_client->__soapCall("userGetGroups", array("session_ser" => $session_ser, "user_id" => $account['user_id']));
141 if (!is_a($results, "SoapFault") && $results) {
142 $projects[$account['account_id']] = $this->soapToArray($results);
146 case REMOTE_FORGE_SOFTWARE_CODENDI:
147 $soap_client = new SoapClient($account['forge_account_soap_wsdl_uri'], array('trace'=>true, 'exceptions'=>true));
149 $session = $soap_client->__soapCall("login", array("loginname" => $account['forge_account_login_name'], "passwd" => $account['forge_account_password']));
150 $results = $soap_client->__soapCall("getMyProjects", array("sessionKey" => $session->session_hash));
151 if (!is_a($results, "SoapFault") && $results) {
152 $projects[$account['account_id']] = $this->soapToArray($results);
161 * Gets the list of remote projects relative to an account from the account
163 * Projects are described using planetForge ontology in remote user account.
165 * @param array $account array of a DB stored remote account.
167 * @return array $projects array of remote projects.
169 function getAccountRemoteProjectsByFOAF($account){
172 include_once 'arc/ARC2.php';
173 require_once 'plugins/globaldashboard/include/Graphite.php';
175 $reader = ARC2::getComponent('Reader');
177 $parser = ARC2::getRDFParser();
179 $reader->setAcceptHeader('Accept: application/rdf+xml');
180 $parser->setReader($reader);
182 $parser->parse($account['forge_account_uri']);
184 if(! $parser->reader->errors) {
185 //print_r($parser); die();
186 $triples = $parser->getTriples();
188 $turtle = $parser->toTurtle($triples);
189 $datauri = $parser->toDataURI($turtle);
192 $graph = new Graphite();
193 //$graph->setDebug(1);
194 $graph->ns( "doap", "http://usefulinc.com/ns/doap#" );
195 $graph->ns( "planetforge", "http://coclico-project.org/ontology/planetforge#");
196 $graph->load( $datauri );
197 print $graph->resource( $account['forge_account_uri'] )->dumpText();
198 $project_name = $graph->resource( $account['forge_account_uri'] )->get( "doap:name" );
199 $project_url = $graph->resource( $account['forge_account_uri'] )->get( "planetforge:ForgeProject");
200 $projects[] = array("project_name" => $project_name, "project_url" => $project_url);
203 foreach ($parser->reader->errors as $error) {
207 //$projname = $account_url;
209 if (count($projects)){
210 $pm = PluginManager::instance();
211 $compact_preview_plugin = $pm->GetPluginObject('compactpreview');
212 if ($pm->isPluginAvailable($compact_preview_plugin)) {
213 if ($pm->PluginIsInstalled('compactpreview')) {
214 require_once 'plugins/compactpreview/include/CompactResource.class.php';
215 foreach ($projects as $project) {
216 $params = array('name' => $project["project_name"], 'url' => $project["project_url"]);
217 $cR = new OslcGroupCompactResource($params);
218 $project["project_link"] = $cR->getResourceLink();
228 * Converts an stdClass object to an array.
229 * @param stdClass $result
231 * @return array $array
233 function soapToArray($results) {
236 foreach($results as $result){
238 $array[$i]['group_name'] = $result->group_name;
239 $array[$i]['unix_group_name'] = $result->unix_group_name;
246 * Returns fetch method of remote projects related to an account
248 * @param integer $account_id
250 * @return integer $method value corresponding to fetch method
252 function getProjectsFetchMethodForAccount($account_id) {
253 return getDBFetchMethod($account_id, 'projects');