'adms' => 'http://www.w3.org/ns/adms#',
'foaf' => 'http://xmlns.com/foaf/0.1/',
'schema' => 'http://schema.org/',
- 'rad' => 'http://www.w3.org/ns/rad#'
+ 'rad' => 'http://www.w3.org/ns/rad#',
+ 'ldp' => 'http://www.w3.org/ns/ldp#'
);
//$this->trovecat_id_index = array();
*
* @return array the namespaces associative array
*/
- private function admsswNameSpaces() {
+ public function admsswNameSpaces() {
return $this->ns;
}
// Project list / SoftwareRepository related methods
//
+ /**
+ * Returns the number of projects in a project index
+ */
+ public function getProjectListSize() {
+ // same as for trove's full list
+ $projects = get_public_active_projects_asc();
+ return count($projects);
+ }
+
/**
* Provides a Graphite graph for resource(s) representing the ADMS.SW SoftwareRepository
*
* @param string URI of the document to use
* @param bool are projects to be fully described or just a URI of their resource
+ * @param $chunk number of the chunk to be returned in case of paging
+ * @param $chunksize size of chunks in case of paging
*/
- public function getProjectListResourcesGraph($documenturi, $detailed=false) {
+ public function getProjectListResourcesGraph($documenturi, $detailed=false, $chunk=null, $chunksize=null) {
// Construct an ARC2_Resource containing the project's RDF (DOAP) description
$ns = $this->admsswNameSpaces();
// same as for trove's full list
$projects = get_public_active_projects_asc();
+
+
+ if ( isset($chunk) && isset($chunksize) ) {
+ // TODO : do some checks on $chunk $chunksize values
+ // if ( ($chunk < 1) && ($chunksize >= 1) ) {
+ // // error
+ // }
+ $projects_chunks = array_chunk($projects, $chunksize);
+ $projects = $projects_chunks[$chunk-1];
+ }
+
$proj_uris = array();
foreach ($projects as $row_grp) {
$proj_uri = util_make_url_g(strtolower($row_grp['unix_group_name']),$row_grp['group_id']).'#project';
$plugin = plugin_get_object($pluginname);
+// page length
+$pl = 3;
+
+$uricomplement = '';
+
+$p = 0;
+if ( null !== getStringFromRequest('theFirstPage', null)) {
+ $p = 1;
+ $uricomplement = '?theFirstPage';
+}
+else {
+ $p = getIntFromRequest('p', 0);
+ if ($p > 0) {
+ $uricomplement = '?p=' . $p;
+ }
+}
+
+$projectsnum = $plugin->getProjectListSize();
+
+// force paging if too many projects
+if ( ($projectsnum > $pl) && ! ($p > 0) ) {
+// $p = 1;
+ header("Location: ?theFirstPage");
+ header($_SERVER["SERVER_PROTOCOL"]." 303 See Other",true,303);
+ exit;
+}
+
// if not HTML
if($content_type != $default_content_type) {
-
+
+ $chunksize = null;
+ $chunk = null;
+
+ $documenturi = util_make_url('/plugins/'.$pluginname.'/full.php');
+ $pageuri = '';
+
+ // if paging is requested
+ if ($p > 0) {
+ $maxpage = (int) ($projectsnum / $pl);
+ if ($p > $maxpage) {
+ header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found",true,404);
+ printf("Page %d requested is beyond the maximum %d !", $p, $maxpage);
+ exit;
+ }
+ $chunksize = $pl;
+ $chunk = $p;
+ $pageuri = $documenturi . $uricomplement;
+ }
+
// process as in content_negociated_projects_list but with full details
- $graph = $plugin->getProjectListResourcesGraph(util_make_url('/plugins/'.$pluginname.'/full.php'), true);
+ $graph = $plugin->getProjectListResourcesGraph($documenturi, true, $chunk, $chunksize);
+
+ if ($p > 0) {
+ $ns = $plugin->admsswNameSpaces();
+ $conf = array(
+ 'ns' => $ns
+ );
+
+ $res = ARC2::getResource($conf);
+ $res->setURI( $pageuri );
+ rdfutils_setPropToUri($res, 'rdf:type', 'ldp:Page');
+
+ if($p < ( (int) ($projectsnum / $pl) ) ) {
+ $nextpageuri = $documenturi . '?p=' . (string) ($p + 1);
+ rdfutils_setPropToUri($res, 'ldp:nextPage', $nextpageuri);
+ }
+ else {
+ rdfutils_setPropToUri($res, 'ldp:nextPage', 'rdf:nil');
+ }
+ rdfutils_setPropToUri($res, 'ldp:pageOf', $documenturi);
+
+ $count = $graph->addTriples( ARC2::getTriplesFromIndex($res->index) );
+ }
// We can support only RDF as RDF+XML or Turtle
if ($content_type == 'text/turtle' || $content_type == 'application/rdf+xml') {