PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions.ext/siocedit/SioceditController.php

https://code.google.com/p/ontowiki/
PHP | 275 lines | 100 code | 42 blank | 133 comment | 13 complexity | 46ef39dda5944c2efccdcfa64b1b2aa9 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * This file is part of the {@link http://ontowiki.net OntoWiki} project.
  4. *
  5. * @copyright Copyright (c) 2009, {@link http://aksw.org AKSW}
  6. * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
  7. * @version $Id:$
  8. */
  9. require_once 'OntoWiki/Controller/Component.php';
  10. /**
  11. * Component controller for the SIOC Editor.
  12. *
  13. * @copyright Copyright (c) 2009, {@link http://aksw.org AKSW}
  14. * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
  15. * @category OntoWiki
  16. * @package Extensions
  17. * @subpackage Siocedit
  18. * @author Christoph Rie?&#x; <c.riess.dev@googlemail.com>
  19. */
  20. class SioceditController extends OntoWiki_Controller_Component
  21. {
  22. /**
  23. * Subfolder for resources
  24. * @var string
  25. */
  26. const RESOURCES_DIR = 'resources/';
  27. /**
  28. * The currently selected model object
  29. * @var
  30. */
  31. protected $_model = null;
  32. /**
  33. * The currently selected resource object
  34. * @var
  35. */
  36. protected $_resource = null;
  37. /**
  38. * The currently selected resource's URI
  39. * @var
  40. */
  41. protected $_resourceUri = null;
  42. /**
  43. * TitleHelper object
  44. * @var
  45. */
  46. protected $_titleHelper = null;
  47. /**
  48. * Custom setup
  49. */
  50. public function init()
  51. {
  52. parent::init();
  53. $stylesheet = $this->_componentUrlBase
  54. . self::RESOURCES_DIR
  55. . 'styles.css';
  56. $this->view->headLink()->appendStylesheet($stylesheet);
  57. if ($this->_owApp->selectedModel instanceof Erfurt_Rdf_Model) {
  58. $this->_model = $this->_owApp->selectedModel;
  59. $this->_titleHelper = new OntoWiki_Model_TitleHelper($this->_model);
  60. }
  61. if ($this->_owApp->selectedResource instanceof Erfurt_Rdf_Resource) {
  62. $this->_resource = $this->_owApp->selectedResource;
  63. $this->_resourceUri = $this->_resource->getUri();
  64. $this->_titleHelper->addResource($this->_resourceUri);
  65. }
  66. // default title for now
  67. $this->view->placeholder('main.window.title')->append('SIOC : ' . $this->_resource->getTitle());
  68. // prepare namespaces
  69. $namespaces = $this->_model->getNamespaces();
  70. $graphBase = $this->_model->getBaseUri();
  71. if (!array_key_exists($graphBase, $namespaces)) {
  72. $namespaces = array_merge($namespaces, array($graphBase => OntoWiki_Utils::DEFAULT_BASE));
  73. }
  74. $this->view->namespaces = $namespaces;
  75. //set resourceUri
  76. $this->view->resourceUri = $this->_resourceUri;
  77. }
  78. /**
  79. * Displays a sioc:Post
  80. */
  81. public function postAction()
  82. {
  83. $data = array();
  84. $indirectdata = array();
  85. $property = '';
  86. foreach ($this->_sparqlData($this->_resourceUri) as $row) {
  87. if ($row['p']['type'] === 'uri') {
  88. $property = $row['p']['value'];
  89. if (array_key_exists($property, $data) ) {
  90. } else {
  91. $data[$property] = array();
  92. }
  93. } else {
  94. // do nothing
  95. }
  96. if ($row['o']['type'] === 'literal' ) {
  97. $data[$property][] = $row['o']['value'];
  98. } elseif ($row['o']['type'] === 'uri' ) {
  99. if (in_array($row['o']['value'], $data[$property]) ) {
  100. // no dupes
  101. } else {
  102. $data[$property][] = $row['o']['value'];
  103. }
  104. if ( !empty($row['x']['value']) ) {
  105. $indirectdata[$row['o']['value']][$row['x']['value']][] = $row['y']['value'];
  106. }
  107. } else {
  108. // do nothing
  109. }
  110. }
  111. /*
  112. // set up toolbar buttons
  113. if ($this->_model->isEditable()) {
  114. // TODO: check acl
  115. $toolbar = $this->_owApp->toolbar;
  116. $toolbar->appendButton(OntoWiki_Toolbar::EDIT, array('name' => 'Edit Properties'));
  117. $params = array(
  118. 'name' => 'Delete Resource',
  119. 'url' => $this->_config->urlBase . 'resource/delete/?r=' . urlencode((string) $this->_resourceUri)
  120. );
  121. $toolbar->appendButton(OntoWiki_Toolbar::SEPARATOR)
  122. ->appendButton(OntoWiki_Toolbar::DELETE, $params);
  123. $this->view->placeholder('main.window.toolbar')->set($toolbar);
  124. }
  125. $model = new OntoWiki_Model_Resource($this->_erfurt->getStore(), $this->_model, $this->_resourceUri);
  126. $values = $model->getValues();
  127. $predicates = $model->getPredicates();
  128. // generate uri array
  129. $siocNS = $this->_privateConfig->ns;
  130. $siocProperties = array ();
  131. foreach ($this->_privateConfig->property->post->toArray() as $key => $uri) {
  132. $siocProperties[$siocNS . $uri] = $key;
  133. }
  134. foreach ($this->_privateConfig->property->other->toArray() as $key => $uri) {
  135. $otherProperties[$uri] = $key;
  136. }
  137. $siocdata = array ();
  138. $otherdata = array ();
  139. $remaindata = array ();
  140. $propertydata = array ();
  141. foreach ( current($values) as $key => $row) {
  142. if ( array_key_exists($key, $siocProperties) ) {
  143. $siocdata[$siocProperties[$key]] = $row;
  144. $propertydata[$siocProperties[$key]]['curi'] = $predicates[(string) $this->_model][$key]['curi'];
  145. } elseif ( array_key_exists($key, $otherProperties) ) {
  146. $otherdata[$otherProperties[$key]] = $row;
  147. $propertydata[$otherProperties[$key]]['curi'] = $predicates[(string) $this->_model][$key]['curi'];
  148. } else {
  149. $remaindata[$key] = $row;
  150. }
  151. }
  152. $this->view->siocdata = $siocdata;
  153. $this->view->otherdata = $otherdata;
  154. $this->view->remaindata = $remaindata;
  155. $this->view->propertydata = $propertydata;*/
  156. }
  157. /**
  158. * Displays a sioc:Site
  159. */
  160. public function siteAction()
  161. {
  162. }
  163. /**
  164. * Displays a sioc:User
  165. */
  166. public function userAction()
  167. {
  168. }
  169. /**
  170. * Displays a sioc:Usergroup
  171. */
  172. public function usergroupAction()
  173. {
  174. }
  175. /**
  176. * Displays a sioc:Forum
  177. */
  178. public function forumAction()
  179. {
  180. }
  181. private function _sparqlData($uri, $inverse = false)
  182. {
  183. require_once 'Erfurt/Sparql/SimpleQuery.php';
  184. $query = new Erfurt_Sparql_SimpleQuery();
  185. $query->addFrom( (string) $this->_owApp->selectedModel )
  186. ->setProloguePart('SELECT *')
  187. ->setWherePart('WHERE {<' . $uri . '> ?p ?o . OPTIONAL {?o ?x ?y.} }');
  188. $results = $this->_erfurt->getStore()->sparqlQuery($query, array('result_format' => 'extended') );
  189. return $results['results']['bindings'];
  190. }
  191. /**
  192. * Dislays a foaf:Person instance.
  193. */
  194. public function personAction()
  195. {
  196. $this->view->placeholder('main.window.title')->append($this->_resource->getTitle());
  197. // $this->addModuleContext('main.window.properties');
  198. // set up toolbar buttons
  199. if ($this->_model->isEditable()) {
  200. // TODO: check acl
  201. $toolbar = $this->_owApp->toolbar;
  202. $toolbar->appendButton(OntoWiki_Toolbar::EDIT, array('name' => 'Edit Properties'));
  203. $params = array(
  204. 'name' => 'Delete Resource',
  205. 'url' => $this->_config->urlBase . 'resource/delete/?r=' . urlencode((string) $this->_resourceUri)
  206. );
  207. $toolbar->appendButton(OntoWiki_Toolbar::SEPARATOR)
  208. ->appendButton(OntoWiki_Toolbar::DELETE, $params);
  209. $this->view->placeholder('main.window.toolbar')->set($toolbar);
  210. }
  211. // set up model
  212. /*
  213. require_once $this->_componentRoot . 'models/FoafeditModel.php';
  214. $model = new FoafeditModel($this->_model, $this->_resource);
  215. $model->addProperties($this->_privateConfig->properties->toArray());
  216. // assign view values
  217. $this->view->assign($model->getPropertyValues());
  218. // set up view variables
  219. $this->view->uris = $this->_privateConfig->properties->toArray();
  220. $this->view->resourceUri = $this->_resource->getUri();
  221. $this->view->resourceName = $this->_titleHelper->getTitle($this->_resourceUri);*/
  222. }
  223. }