/extensions.ext/foafprofileviewer/FoafprofileviewerController.php

https://code.google.com/p/ontowiki/ · PHP · 140 lines · 112 code · 14 blank · 14 comment · 13 complexity · a8eef73defe132c526a13476571838a7 MD5 · raw file

  1. <?php
  2. require_once 'OntoWiki/Controller/Component.php';
  3. /**
  4. * Controller for OntoWiki foaf component to display a foaf profile
  5. *
  6. * @category OntoWiki
  7. * @package OntoWiki_extensions_components_foafprofileviewer
  8. * @author Jonas Brekle <jonas.brekle@gmail.com>
  9. * @copyright Copyright (c) 2008, {@link http://aksw.org AKSW}
  10. * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
  11. * @version $$
  12. */
  13. class FoafprofileviewerController extends OntoWiki_Controller_Component
  14. {
  15. public function displayAction() {
  16. OntoWiki_Navigation::disableNavigation();
  17. $translate = $this->_owApp->translate;
  18. $store = $this->_erfurt->getStore();
  19. $model = $this->_owApp->selectedModel;
  20. $titleHelper = new OntoWiki_Model_TitleHelper($model);
  21. $prefixes = 'PREFIX foaf:<http://xmlns.com/foaf/0.1/>
  22. PREFIX dc:<http://purl.org/dc/elements/1.1/>
  23. PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> ';
  24. $query = $prefixes.'SELECT ?about ?date ?comment WHERE {
  25. <'.((string) $model).'> a foaf:PersonalProfileDocument .
  26. <'.((string) $model).'> foaf:primaryTopic ?about
  27. OPTIONAL{<'.((string) $model).'> dc:date ?date}
  28. OPTIONAL{<'.((string) $model).'> rdfs:comment ?comment}
  29. }';
  30. $result = $store->sparqlQuery($query);
  31. $titleHelper->addResource((string) $model);
  32. $this->view->hasError = false;
  33. if(isset($result[0])){
  34. $about = $result[0]['about'];
  35. $titleHelper->addResource($about);
  36. $this->view->about = $titleHelper->getTitle($about);
  37. $this->view->aboutUri = $about;
  38. if(isset($result[0]['date'])){
  39. if (($timestamp = strtotime($result[0]['date'])) === false) {
  40. $this->view->date = $result[0]['date']; //unparsed
  41. } else {
  42. $this->view->date = date('l dS \o\f F Y h:i:s A', $timestamp);
  43. }
  44. }
  45. if(isset($result[0]['comment'])){
  46. $this->view->comment = $result[0]['comment'];
  47. }
  48. $this->view->graph = $model;
  49. $resource = new OntoWiki_Model_Resource($model->getStore(), $model, $about, 100);
  50. $results = $resource->getValues();
  51. //var_dump($this->_privateConfig);
  52. $output = "";
  53. $titleHelper = new OntoWiki_Model_TitleHelper($model);
  54. $selProps = array();
  55. $simpleProps = array();
  56. foreach($this->_privateConfig->foafProperties->basic as $key => $value){
  57. $simpleProps[$key] = $value;
  58. }
  59. $personProps = array();
  60. foreach($this->_privateConfig->foafProperties->Persons as $key => $value){
  61. $personProps[$key] = $value;
  62. }
  63. $projectProps = array();
  64. foreach($this->_privateConfig->foafProperties->Projects as $key => $value){
  65. $projectProps[$key] = $value;
  66. }
  67. $selProps["basic"] = array();
  68. $selProps["persons"] = array();
  69. $selProps["projects"] = array();
  70. foreach($results[(string) ($model->getModelIri())] as $property => $values){
  71. if(in_array($property, $simpleProps) ||
  72. in_array($property, $personProps) ||
  73. in_array($property, $projectProps)){
  74. $titleHelper->addResource($property);
  75. //sort by cat
  76. if(in_array($property, $simpleProps)){
  77. $cat = 'basic';
  78. } elseif(in_array($property, $personProps)){
  79. $cat = 'persons';
  80. } elseif (in_array($property, $projectProps)) {
  81. $cat = 'projects';
  82. }
  83. $selProps[$cat][$property] = $values;
  84. //fill titlehelper
  85. foreach($values as $value){
  86. if(isset($value['url'])){
  87. $titleHelper->addResource($value['uri']);
  88. }
  89. }
  90. }
  91. }
  92. //add pics to side window (where modules reside)
  93. foreach($this->_privateConfig->foafProperties->Pics as $picPropUri){
  94. if(isset($results[(string) ($model->getModelIri())][$picPropUri])){
  95. foreach($results[(string) ($model->getModelIri())][$picPropUri] as $value){
  96. $this->view->placeholder('main.window.innerwindows')->append($value['object'].'<br/>');
  97. }
  98. }
  99. }
  100. $this->view->selProps = $selProps;
  101. $this->view->titleHelper = $titleHelper;
  102. $this->view->urlBase = $this->_config->urlBase;
  103. $this->view->modelUri = (string) $model;
  104. foreach($this->_privateConfig->foafPropertyGivenName as $givenProp){
  105. if(isset($results[(string) ($model->getModelIri())][$givenProp])){
  106. $this->view->aboutGivenName = $results[(string) ($model->getModelIri())][$givenProp][0]['content'];
  107. }
  108. }
  109. foreach($this->_privateConfig->foafPropertySurname as $surProp){
  110. if(isset($results[(string) ($model->getModelIri())][$surProp])){
  111. $this->view->aboutSurName = $results[(string) ($model->getModelIri())][$surProp][0]['content'];
  112. }
  113. }
  114. if(isset($results[(string) ($model->getModelIri())][$this->_privateConfig->foafPropertyNickName])){
  115. $this->view->aboutNickName = $results[(string) ($model->getModelIri())][$this->_privateConfig->foafPropertyNickName][0]['content'];
  116. }
  117. } else {
  118. $this->view->hasError = true;
  119. $this->_owApp->appendMessage(
  120. new OntoWiki_Message('The document does not contain a foaf profile', OntoWiki_Message::ERROR)
  121. );
  122. }
  123. $windowTitle = $translate->_('View FOAF Profile: '.$titleHelper->getTitle((string) $model));
  124. $this->view->placeholder('main.window.title')->set($windowTitle);
  125. }
  126. }