Example #1
0
 public function table($options = array())
 {
     $model = OntoWiki::getInstance()->selectedModel;
     $titleHelper = new OntoWiki_Model_TitleHelper($model);
     // check for options and assign local vars or default values
     $class = isset($options['class']) ? $options['class'] : '';
     $id = isset($options['id']) ? $options['id'] : '';
     $tag = isset($options['tag']) ? $options['tag'] : 'span';
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $iprefix = isset($options['iprefix']) ? $options['iprefix'] : '';
     $isuffix = isset($options['isuffix']) ? $options['isuffix'] : '';
     // choose, which uri to use: option over helper default over view value
     $uri = isset($this->resourceUri) ? $this->resourceUri : null;
     $uri = isset($options['selectedResource']) ? (string) $options['selectedResource'] : $uri;
     $uri = isset($options['uri']) ? (string) $options['uri'] : $uri;
     $uri = Erfurt_Uri::getFromQnameOrUri($uri, $model);
     // choose, which properties to use (todo: allow multple properties)
     $contentProperties = isset($options['property']) ? array($options['property']) : null;
     $contentProperties = !$contentProperties ? $this->contentProperties : $contentProperties;
     foreach ($contentProperties as $key => $value) {
         try {
             $validatedValue = Erfurt_Uri::getFromQnameOrUri($value, $model);
             $contentProperties[$key] = $validatedValue;
         } catch (Exception $e) {
             unset($contentProperties[$key]);
         }
     }
     // create description from resource URI
     $resource = new OntoWiki_Resource($uri, $model);
     $description = $resource->getDescription();
     $description = $description[$uri];
     // get the table size
     $tableRows = 0;
     // the URI of the main content property
     $tableColumns = 0;
     // the URI of the main content property
     foreach ($contentProperties as $contentProperty) {
         if (isset($description[$contentProperty . 'Rows'])) {
             $tableRows = (int) $description[$contentProperty . 'Rows'][0]['value'];
         }
         if (isset($description[$contentProperty . 'Columns'])) {
             $tableColumns = (int) $description[$contentProperty . 'Columns'][0]['value'];
         }
         if (null != $tableRows && null != $tableColumns) {
             $mainProperty = $contentProperty;
             break;
         }
     }
     $content = '';
     // filter and render the table
     if (0 < $tableRows && 0 < $tableColumns) {
         $content .= '<table id=' . $id . '><thead>';
         for ($row = 1; $row <= $tableRows; $row++) {
             $content .= '<tr id="R' . $row . '">';
             for ($column = 1; $column <= $tableColumns; $column++) {
                 $content .= (1 == $row ? '<th' : '<td') . ' id="R' . $row . 'C' . $column . '">';
                 $currentMainProperty = $mainProperty . 'R' . $row . 'C' . $column;
                 unset($firstLiteral);
                 // search for language tag
                 foreach ($description[$currentMainProperty] as $literalNumber => $literal) {
                     $currentLanguage = OntoWiki::getInstance()->getConfig()->languages->locale;
                     if (isset($literal['lang']) && $currentLanguage == $literal['lang']) {
                         $firstLiteral = $description[$currentMainProperty][$literalNumber];
                         break;
                     }
                 }
                 if (!isset($firstLiteral)) {
                     $firstLiteral = $description[$currentMainProperty][0];
                 }
                 $cellContent = $firstLiteral['value'];
                 // execute the helper markup on the content (after the extensions)
                 $cellContent = $this->view->executeHelperMarkup($cellContent);
                 // filter by using available extensions
                 if (isset($firstLiteral['datatype'])) {
                     $datatype = $firstLiteral['datatype'];
                     $cellContent = $this->view->displayLiteralPropertyValue($cellContent, $currentMainProperty, $datatype);
                 } else {
                     $cellContent = $this->view->displayLiteralPropertyValue($cellContent, $currentMainProperty);
                 }
                 $curie = $this->view->curie($currentMainProperty);
                 $cellContent = $iprefix . $cellContent . $isuffix;
                 $content .= "{$prefix}<{$tag} class='{$class}' property='{$curie}'>{$cellContent}</{$tag}>{$suffix}";
                 $content .= 1 == $row ? '</th>' : '</td>';
             }
             $content .= '</tr>';
             $content .= 1 == $row ? '</thead><tbody>' : '';
         }
         $content .= '</tbody></table>';
     }
     return $content;
 }
 public function navigationList($options = array())
 {
     $owapp = OntoWiki::getInstance();
     $store = $owapp->erfurt->getStore();
     $this->model = $owapp->selectedModel;
     $titleHelper = new OntoWiki_Model_TitleHelper($this->model);
     if (!isset($options['navResource']) || !$options['navResource']) {
         if (isset($options['navProperty'])) {
             $this->_navProperty = $options['navProperty'];
             $resource = new OntoWiki_Resource($this->resourceUri, $this->model);
             $description = $resource->getDescription();
             $description = $description[(string) $resource];
             if (isset($description[$this->_navProperty])) {
                 $this->_navResource = $description[$this->_navProperty][0]['value'];
             } else {
                 return '';
             }
         } else {
             return '';
         }
     } else {
         $this->_navResource = $options['navResource'];
     }
     // overwrite standard options with given ones, if given as option
     $this->_listTag = isset($options['listTag']) ? $options['listTag'] : $this->_listTag;
     $this->_listClass = isset($options['listClass']) ? $options['listClass'] : $this->_listClass;
     $this->_activeItemClass = isset($options['activeItemClass']) ? $options['activeItemClass'] : $this->_activeItemClass;
     $this->_activeUrl = isset($options['activeUrl']) ? $options['activeUrl'] : $this->_activeUrl;
     $this->_prefix = isset($options['prefix']) ? $options['prefix'] : $this->_prefix;
     $this->_suffix = isset($options['suffix']) ? $options['suffix'] : $this->_suffix;
     $this->_navClass = isset($options['navClass']) ? $options['navClass'] : $this->_navClass;
     $this->_navId = isset($options['navId']) ? $options['navId'] : $this->_navId;
     $this->_subheadTag = isset($options['subheadTag']) ? $options['subheadTag'] : $this->_subheadTag;
     $this->_subheadClass = isset($options['subheadClass']) ? $options['subheadClass'] : $this->_subheadClass;
     $this->_subheadSkipLink = isset($options['subheadSkipLink']) ? $options['subheadSkipLink'] : $this->_subheadSkipLink;
     $this->_sublistTag = isset($options['sublistTag']) ? $options['sublistTag'] : $this->_listTag;
     // takes the list tag for default
     $this->_sublistClass = isset($options['sublistClass']) ? $options['sublistClass'] : $this->_sublistClass;
     if (isset($options['titleProperty'])) {
         $titleHelper->prependTitleProperty($options['titleProperty']);
     } else {
         $titleHelper->prependTitleProperty($this->_menuLabel);
     }
     $navigation = $this->_getMenu($this->_navResource, $this->model, $titleHelper);
     $navigation = $this->_setTitles($navigation, $titleHelper);
     return $this->render($navigation);
 }
Example #3
0
 protected function _getDescription($model, $options)
 {
     // choose, which uri to use: option over helper default over view value
     $uri = isset($this->resourceUri) ? $this->resourceUri : null;
     $uri = isset($options['selectedResource']) ? (string) $options['selectedResource'] : $uri;
     $uri = isset($options['uri']) ? (string) $options['uri'] : $uri;
     $uri = Erfurt_Uri::getFromQnameOrUri($uri, $model);
     // create description from resource URI
     $resource = new OntoWiki_Resource($uri, $model);
     $description = $resource->getDescription();
     $description = $description[$uri];
     return $description;
 }
Example #4
0
 public function img($options = array())
 {
     $owapp = OntoWiki::getInstance();
     $store = $owapp->erfurt->getStore();
     $model = $owapp->selectedModel;
     $extManager = $owapp->extensionManager;
     // check for options and assign local vars or null
     $src = isset($options['src']) ? (string) $options['src'] : null;
     $class = isset($options['class']) ? ' class="' . $options['class'] . '"' : '';
     $alt = isset($options['alt']) ? ' alt="' . $options['alt'] . '"' : '';
     $filter = isset($options['filter']) ? $options['filter'] : null;
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $nordfa = isset($options['nordfa']) ? true : false;
     // choose, which uri to use: option over helper default over view value
     $uri = isset($this->resourceUri) ? $this->resourceUri : null;
     $uri = isset($options['selectedResource']) ? (string) $options['selectedResource'] : $uri;
     $uri = isset($options['uri']) ? (string) $options['uri'] : $uri;
     // in case qname is given, transform to full URI
     $uri = Erfurt_Uri::getFromQnameOrUri($uri, $model);
     // look for a valid image url somewhere
     if ($src == null) {
         // choose, which properties to use for lookup (todo: allow multple properties)
         $properties = isset($options['property']) ? array($options['property']) : null;
         $properties = !$properties ? $this->_properties : $properties;
         // validate each given property
         foreach ($properties as $key => $value) {
             try {
                 $validatedValue = Erfurt_Uri::getFromQnameOrUri($value, $model);
                 $properties[$key] = $validatedValue;
             } catch (Exception $e) {
                 // unset invalid properties
                 unset($properties[$key]);
             }
         }
         // create description from resource URI
         $resource = new OntoWiki_Resource($uri, $model);
         $description = $resource->getDescription();
         $description = $description[$uri];
         // select the used property
         $imgProperty = null;
         foreach ($properties as $property) {
             if (isset($description[$property])) {
                 $imgProperty = $property;
                 break;
             }
         }
         if ($imgProperty != null) {
             //search for language tag
             foreach ($description[$imgProperty] as $literalNumber => $literal) {
                 $currentLanguage = OntoWiki::getInstance()->getConfig()->languages->locale;
                 if (isset($literal['lang']) && $currentLanguage == $literal['lang']) {
                     $imgSrc = $description[$imgProperty][$literalNumber]['value'];
                     break;
                 }
             }
             if (!isset($imgSrc)) {
                 $imgSrc = $description[$imgProperty][0]['value'];
             }
         } else {
             // we do not have an image src
             return '';
         }
     } else {
         $imgSrc = $src;
     }
     // modify the image imgSrc for the IPC extension
     // @todo: use an event here
     if ($filter && $extManager->isExtensionRegistered('ipc')) {
         $ipcSrc = $owapp->config->urlBase . '/ipc/get';
         $ipcSrc = $ipcSrc . '?img=' . urlencode($imgSrc) . '&filter=' . urlencode($filter);
         $imgSrc = $ipcSrc;
     }
     // build the image tag for output
     $return = $prefix;
     $return .= '<img' . $class . $alt;
     if ($nordfa == false) {
         $return .= !$src ? ' about="' . $this->view->curie($uri) . '"' : '';
         $return .= !$src ? ' property="' . $this->view->curie($imgProperty) . '"' : '';
         // this property is needed since ipc maybe rewrites the src
         $return .= !$src ? ' resource="' . htmlentities($imgSrc) . '"' : '';
         if (isset($options['attributes']) && is_array($options['attributes'])) {
             foreach ($options['attributes'] as $key => $value) {
                 $return .= ' ' . $key . '="' . $value . '"';
             }
         }
     }
     $return .= ' src="' . htmlentities($imgSrc) . '" />';
     $return .= $suffix;
     return $return;
 }