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';
26 class globalDashboard_Widget_MyProjects extends Widget {
28 function __construct($owner_type, $plugin) {
29 $this->plugin = $plugin;
30 $this->Widget('plugin_globalDashboard_MyProjects');
34 return _("Projects on remote Software Forges");
37 function getCategory() {
38 return _('Global Dashboard Plugin');
41 function getDescription() {
42 return _("Lists user projects hosted on remote forge systems");
45 function getContent() {
47 $user = session_get_user();
48 $MyProjects = $this->getUserRemoteProjects($user->getID());
51 if(is_array($MyProjects)) {
52 $tablearr = array(_('My remote projects'),'');
53 $html .= $HTML->listTableTop($tablearr);
55 foreach ($MyProjects as $account_id => $remote_account_projs) {
56 //$remote_account_projs = array("Proj1", "Proj2");
57 /*include_once("arc/ARC2.php");
58 require_once 'plugins/extsubproj/include/Graphite.php';
60 $parser = ARC2::getRDFParser();
61 //$parser->parse('https://vm2.localdomain/projects/coinsuper/');
64 $triples = $parser->getTriples();
66 $turtle = $parser->toTurtle($triples);
67 $datauri = $parser->toDataURI($turtle);
69 $graph = new Graphite();
70 //$graph->setDebug(1);
71 $graph->ns( "doap", "http://usefulinc.com/ns/doap#" );
72 $graph->load( $datauri );
73 //print $graph->resource('https://vm2.localdomain/projects/coinsuper/')->dumpText();
74 $projname = $graph->resource( $url )->get( "dosoapToArray()ap:name" );
76 $account = getDBStoredRemoteAccountById($account_id);
77 if ($account['forge_software'] == REMOTE_FORGE_SOFTWARE_FUSIONFORGE) {
78 $favicon_url = $account['forge_account_domain'] . '/images/icon.png';
79 } elseif ($account['forge_software'] == REMOTE_FORGE_SOFTWARE_CODENDI) {
80 $favicon_url = $account['forge_account_domain'] . '/favicon.ico';
84 foreach ($remote_account_projs as $remote_proj) {
85 $project_url = $account['forge_account_domain'] . '/projects/'. $remote_proj['unix_group_name'];
89 <img src="'. $favicon_url.'" /> <a class="resourceOslcPopupTrigger" href="'. $project_url .'">'. $remote_proj['group_name'] .'</a>
94 $html .= $HTML->listTableBottom();
101 * Fetches user remote projects from all forges
103 * @param integer $user_id
105 * @return array $projects
107 function getUserRemoteProjects($user_id){
109 $accounts = getDBStoredRemoteAccountsByUserId($user_id);
110 if (count($accounts) > 0) {
111 foreach ($accounts as $account) {
112 $fetch_method = $this->getProjectsFetchMethodForAccount($account["account_id"]);
113 switch ($fetch_method) {
114 case USER_PROJECTS_FETCH_METHOD_SOAP:
115 $projects = $this->getAccountRemoteProjectsBySOAP($account, $projects);
117 case USER_PROJECTS_FETCH_METHOD_OSLC:
118 //$projects = $this->getAccountRemoteProjectsByOSLC($account);
120 case USER_PROJECTS_FETCH_METHOD_FOAF:
121 $projects = $this->getAccountRemoteProjectsByFOAF($account);
131 function getAccountRemoteProjectsBySOAP($account, $projects) {
132 switch ($account['forge_software']) {
133 case REMOTE_FORGE_SOFTWARE_FUSIONFORGE:
134 $soap_client = new SoapClient($account['forge_account_soap_wsdl_uri'], array('trace'=>true, 'exceptions'=>true));
136 $session_ser = $soap_client->__soapCall("login", array("userid" => $account['forge_account_login_name'], "passwd" => $account['forge_account_password']));
137 //@FIXME: user_id here should be the one in the remote forge !!! Need extra soap call to get that id
138 $results = $soap_client->__soapCall("userGetGroups", array("session_ser" => $session_ser, "user_id" => $account['user_id']));
139 if (!is_a($results, "SoapFault") && $results) {
140 $projects[$account['account_id']] = $this->soapToArray($results);
144 case REMOTE_FORGE_SOFTWARE_CODENDI:
145 $soap_client = new SoapClient($account['forge_account_soap_wsdl_uri'], array('trace'=>true, 'exceptions'=>true));
147 $session = $soap_client->__soapCall("login", array("loginname" => $account['forge_account_login_name'], "passwd" => $account['forge_account_password']));
148 $results = $soap_client->__soapCall("getMyProjects", array("sessionKey" => $session->session_hash));
149 if (!is_a($results, "SoapFault") && $results) {
150 $projects[$account['account_id']] = $this->soapToArray($results);
159 * Gets the list of remote projects relative to an account from the account
161 * Projects are described using planetForge ontology in remote user account.
163 * @param array $account array of a DB stored remote account.
165 * @return array $projects array of remote projects.
167 function getAccountRemoteProjectsByFOAF($account){
170 include_once 'arc/ARC2.php';
171 require_once 'plugins/globaldashboard/include/Graphite.php';
173 $reader = ARC2::getComponent('Reader');
175 $parser = ARC2::getRDFParser();
177 $reader->setAcceptHeader('Accept: application/rdf+xml');
178 $parser->setReader($reader);
180 $parser->parse($account['forge_account_uri']);
182 if(! $parser->reader->errors) {
183 //print_r($parser); die();
184 $triples = $parser->getTriples();
186 $turtle = $parser->toTurtle($triples);
187 $datauri = $parser->toDataURI($turtle);
189 $graph = new Graphite();
190 //$graph->setDebug(1);
191 $graph->ns( "doap", "http://usefulinc.com/ns/doap#" );
192 $graph->ns( "planetforge", "http://coclico-project.org/ontology/planetforge#");
193 $graph->load( $datauri );
194 print $graph->resource( $account['forge_account_uri'] )->dumpText();
195 $project_name = $graph->resource( $account['forge_account_uri'] )->get( "doap:name" );
196 $project_url = $graph->resource( $account['forge_account_uri'] )->get( "planetforge:ForgeProject");
197 $projects[] = array("project_name" => $project_name, "project_url" => $project_url);
200 foreach ($parser->reader->errors as $error) {
204 //$projname = $account_url;
206 if (count($projects)){
207 $pm = PluginManager::instance();
208 $compact_preview_plugin = $pm->GetPluginObject('compactpreview');
209 if ($pm->isPluginAvailable($compact_preview_plugin)) {
210 if ($pm->PluginIsInstalled('compactpreview')) {
211 require_once 'plugins/compactpreview/include/CompactResource.class.php';
212 foreach ($projects as $project) {
213 $params = array('name' => $project["project_name"], 'url' => $project["project_url"]);
214 $cR = new OslcGroupCompactResource($params);
215 $project["project_link"] = $cR->getResourceLink();
225 * Converts an stdClass object to an array.
226 * @param stdClass $result
228 * @return array $array
230 function soapToArray($results) {
233 foreach($results as $result){
235 $array[$i]['group_name'] = $result->group_name;
236 $array[$i]['unix_group_name'] = $result->unix_group_name;
243 * Returns fetch method of remote projects related to an account
245 * @param integer $account_id
247 * @return integer $method value corresponding to fetch method
249 function getProjectsFetchMethodForAccount($account_id) {
250 return getDBFetchMethod($account_id, 'projects');