Ejemplo n.º 1
0
 /**
  *  Listing history for selected Resource
  */
 public function listAction()
 {
     $model = $this->_owApp->selectedModel;
     $translate = $this->_owApp->translate;
     $store = $this->_erfurt->getStore();
     $resource = $this->_owApp->selectedResource;
     $ac = $this->_erfurt->getAc();
     $params = $this->_request->getParams();
     $limit = 20;
     $rUriEncoded = urlencode((string) $resource);
     $mUriEncoded = urlencode((string) $model);
     $feedUrl = $this->_config->urlBase . "history/feed?r={$rUriEncoded}&mUriEncoded";
     $this->view->headLink()->appendAlternate($feedUrl, 'application/atom+xml', 'History Feed');
     // redirecting to home if no model/resource is selected
     if (empty($model) || empty($this->_owApp->selectedResource) && empty($params['r']) && $this->_owApp->lastRoute !== 'instances') {
         $this->_abort('No model/resource selected.', OntoWiki_Message::ERROR);
     }
     // getting page (from and for paging)
     if (!empty($params['page']) && (int) $params['page'] > 0) {
         $page = (int) $params['page'];
     } else {
         $page = 1;
     }
     // enabling versioning
     $versioning = $this->_erfurt->getVersioning();
     $versioning->setLimit($limit);
     if (!$versioning->isVersioningEnabled()) {
         $this->_abort('Versioning/History is currently disabled', null, false);
     }
     $singleResource = true;
     // setting if class or instances
     if ($this->_owApp->lastRoute === 'instances') {
         // setting default title
         $title = $resource->getTitle() ? $resource->getTitle() : OntoWiki_Utils::contractNamespace($resource->getIri());
         $windowTitle = $translate->_('Versions for elements of the list');
         $listHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('List');
         $listName = "instances";
         if ($listHelper->listExists($listName)) {
             $list = $listHelper->getList($listName);
             $list->setStore($store);
         } else {
             $this->_owApp->appendMessage(new OntoWiki_Message('something went wrong with the list of instances', OntoWiki_Message::ERROR));
         }
         $query = clone $list->getResourceQuery();
         $query->setLimit(0);
         $query->setOffset(0);
         //echo htmlentities($query);
         $results = $model->sparqlQuery($query);
         $resourceVar = $list->getResourceVar()->getName();
         $resources = array();
         foreach ($results as $result) {
             $resources[] = $result[$resourceVar];
         }
         //var_dump($resources);
         $historyArray = $versioning->getHistoryForResourceList($resources, (string) $this->_owApp->selectedModel, $page);
         //var_dump($historyArray);
         $singleResource = false;
     } else {
         // setting default title
         $title = $resource->getTitle() ? $resource->getTitle() : OntoWiki_Utils::contractNamespace($resource->getIri());
         $windowTitle = sprintf($translate->_('Versions for %1$s'), $title);
         $historyArray = $versioning->getHistoryForResource((string) $resource, (string) $this->_owApp->selectedModel, $page);
     }
     $historyArrayCount = count($historyArray);
     if ($historyArrayCount === $limit + 1) {
         $count = $page * $limit + 1;
         unset($historyArray[$limit]);
     } else {
         $count = ($page - 1) * $limit + $historyArrayCount;
     }
     $idArray = array();
     $userArray = $this->_erfurt->getUsers();
     $titleHelper = new OntoWiki_Model_TitleHelper();
     // Load IDs for rollback and Username Labels for view
     foreach ($historyArray as $key => $entry) {
         $idArray[] = (int) $entry['id'];
         if (!$singleResource) {
             $historyArray[$key]['url'] = $this->_config->urlBase . "view?r=" . urlencode($entry['resource']);
             $titleHelper->addResource($entry['resource']);
         }
         if ($entry['useruri'] == $this->_erfurt->getConfig()->ac->user->anonymousUser) {
             $userArray[$entry['useruri']] = 'Anonymous';
         } else {
             if ($entry['useruri'] == $this->_erfurt->getConfig()->ac->user->superAdmin) {
                 $userArray[$entry['useruri']] = 'SuperAdmin';
             } else {
                 if (is_array($userArray[$entry['useruri']])) {
                     if (isset($userArray[$entry['useruri']]['userName'])) {
                         $userArray[$entry['useruri']] = $userArray[$entry['useruri']]['userName'];
                     } else {
                         $titleHelper->addResource($entry['useruri']);
                         $userArray[$entry['useruri']] = $titleHelper->getTitle($entry['useruri']);
                     }
                 }
             }
         }
     }
     $this->view->userArray = $userArray;
     $this->view->idArray = $idArray;
     $this->view->historyArray = $historyArray;
     $this->view->singleResource = $singleResource;
     $this->view->titleHelper = $titleHelper;
     if (empty($historyArray)) {
         $this->_owApp->appendMessage(new OntoWiki_Message('No history for the selected resource(s).', OntoWiki_Message::INFO));
     }
     if ($this->_erfurt->getAc()->isActionAllowed('Rollback')) {
         $this->view->rollbackAllowed = true;
         // adding submit button for rollback-action
         $toolbar = $this->_owApp->toolbar;
         $toolbar->appendButton(OntoWiki_Toolbar::SUBMIT, array('name' => $translate->_('Rollback changes'), 'id' => 'history-rollback'));
         $this->view->placeholder('main.window.toolbar')->set($toolbar);
     } else {
         $this->view->rollbackAllowed = false;
     }
     // paging
     $statusBar = $this->view->placeholder('main.window.statusbar');
     // the normal page_param p collides with the generic-list param p
     OntoWiki_Pager::setOptions(array('page_param' => 'page'));
     $statusBar->append(OntoWiki_Pager::get($count, $limit));
     // setting view variables
     $url = new OntoWiki_Url(array('controller' => 'history', 'action' => 'rollback'));
     $this->view->placeholder('main.window.title')->set($windowTitle);
     $this->view->formActionUrl = (string) $url;
     $this->view->formMethod = 'post';
     // $this->view->formName      = 'instancelist';
     $this->view->formName = 'history-rollback';
     $this->view->formEncoding = 'multipart/form-data';
 }