function _getStatisticsFields($params)
 {
     $html = '';
     if (is_a($this->item, 'Docman_Folder')) {
         $if = Docman_ItemFactory::instance($this->_controller->getGroupId());
         $stats = $if->getFolderStats($this->item, $this->_controller->getUser());
         $size = $this->convertBytesToHumanReadable($stats['size']);
         // Summary
         $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_statistics_summary') . '</h3>';
         $html .= '<table class="docman_item_details_properties">';
         $html .= $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_statistics_size'), $size);
         $html .= $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_statistics_children_count'), $stats['count']);
         $html .= '</table>';
         // Details
         if ($stats['count'] > 0) {
             $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_statistics_details') . '</h3>';
             $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docman', 'details_statistics_details_description') . '</p>';
             $html .= '<table class="docman_item_details_properties">';
             arsort($stats['types']);
             foreach ($stats['types'] as $type => $stat) {
                 $html .= $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_statistics_item_type_' . strtolower($type)), $stat);
             }
             $html .= '</table>';
         }
     }
     return $html;
 }
 /**
  * Process the system event
  *
  * @return bool
  */
 public function process()
 {
     try {
         $project_id = (int) $this->getRequiredParameter(0);
         if ($this->system_event_manager->isProjectReindexationAlreadyQueued($project_id)) {
             $this->done('Skipped duplicate event');
             $this->logger->debug("Skipped duplicate event for project {$project_id} : " . self::NAME);
             return true;
         }
         $item_factory = Docman_ItemFactory::instance($project_id);
         $items = new Docman_ProjectItemsBatchIterator($item_factory, $project_id);
         $notindexed_collector = new FullTextSearch_NotIndexedCollector();
         $this->actions->reIndexProjectDocuments($items, $project_id, $notindexed_collector);
         if (!$notindexed_collector->isAtLeastOneIndexed()) {
             $this->error('Nothing has been indexed. See syslog for details.');
             return false;
         } else {
             if ($notindexed_collector->isAtLeastOneNotIndexed()) {
                 $this->warning('Some items were not indexed: [' . implode(', ', $notindexed_collector->getIds()) . ']. See syslog for details.');
             } else {
                 $this->done();
             }
         }
         return true;
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     return false;
 }
 function visitFolder(&$item, $params = array())
 {
     if ($this->dPm->userCanWrite($this->user, $item->getId())) {
         $this->actions['canNewDocument'] = true;
         $this->actions['canNewFolder'] = true;
         $pasteItemId = $this->if->getCutPreference($this->user, $item->getGroupId());
         $itemFactory = Docman_ItemFactory::instance($item->getGroupId());
         $parents = $itemFactory->getParents($item->getId());
         $this->actions['parents'] = $parents;
         if ($this->if->getCopyPreference($this->user) !== false || $pasteItemId !== false && $pasteItemId != $item->getId() && !(isset($parents[$pasteItemId]) && $parents[$pasteItemId])) {
             $this->actions['canPaste'] = true;
         }
     }
     $actions = $this->visitItem($item, $params);
     // Cannot lock nor unlock a folder yet.
     $this->actions['canUnlock'] = false;
     $this->actions['canLock'] = false;
     return $this->actions;
 }
 function getDropDownWidget($parentItem)
 {
     $itemFactory =& Docman_ItemFactory::instance($parentItem->getGroupId());
     $brotherIter = $itemFactory->getChildrenFromParent($parentItem);
     $vals = array('beginning', 'end', '--');
     $texts = array($GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_beg'), $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_end'), '----');
     $i = 3;
     $pm =& Docman_PermissionsManager::instance($parentItem->getGroupId());
     $um =& UserManager::instance();
     $user =& $um->getCurrentUser();
     $hp = Codendi_HTMLPurifier::instance();
     $brotherIter->rewind();
     while ($brotherIter->valid()) {
         $item = $brotherIter->current();
         if ($pm->userCanWrite($user, $item->getId())) {
             $vals[$i] = $item->getRank() + 1;
             $texts[$i] = $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_after') . ' ' . $hp->purify($item->getTitle(), CODENDI_PURIFIER_CONVERT_HTML);
             $i++;
         }
         $brotherIter->next();
     }
     // Cannot use html_build_select_box_from_arrays because of to lasy == operator
     // In this case because of cast string values are converted to 0 on cmp. So if
     // there is a rank == 0 ... so bad :/
     $html = '';
     $html = $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_position') . ' ';
     $html .= '<select name="' . $this->dropDownName . '">' . "\n";
     $maxOpts = count($vals);
     for ($i = 0; $i < $maxOpts; $i++) {
         $selected = '';
         if ($vals[$i] === $this->selectedValue) {
             $selected = ' selected="selected"';
         }
         $html .= '<option value="' . $vals[$i] . '"' . $selected . '>' . $texts[$i] . '</option>' . "\n";
     }
     $html .= '</select>';
     return $html;
 }
 private function indexAllProjectDocuments(Docman_ProjectItemsBatchIterator $document_iterator, $project_id, FullTextSearch_NotIndexedCollector $notindexed_collector)
 {
     $this->logger->debug('indexing all project documents #' . $project_id);
     $this->initializeProjetMapping($project_id);
     $document_iterator->rewind();
     $docman_item_factory = Docman_ItemFactory::instance($project_id);
     while ($batch = $document_iterator->next()) {
         $this->indexBatch($batch, $notindexed_collector);
     }
 }
 function visitFolder(&$item, $params = array())
 {
     $content = '';
     if ($this->_controller->userCanWrite($this->item->getid())) {
         $content .= '<dt>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newdocument') . '</dt><dd>';
         $content .= $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newdocument_cancreate', Docman_View_View::buildUrl($this->url, array('action' => 'newDocument', 'id' => $item->getId())));
         $content .= '</dd>';
         $content .= '<dt>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newfolder') . '</dt><dd>';
         $content .= $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newfolder_cancreate', Docman_View_View::buildUrl($this->url, array('action' => 'newFolder', 'id' => $item->getId())));
         //{{{ Paste
         $itemFactory = Docman_ItemFactory::instance($item->getGroupId());
         $copiedItemId = $itemFactory->getCopyPreference($this->_controller->getUser());
         $cutItemId = $itemFactory->getCutPreference($this->_controller->getUser(), $item->getGroupId());
         $srcItem = null;
         if ($copiedItemId !== false && $cutItemId === false) {
             $srcItem = $itemFactory->getItemFromDb($copiedItemId);
         } elseif ($copiedItemId === false && $cutItemId !== false && $item->getId() != $cutItemId) {
             $srcItem = $itemFactory->getItemFromDb($cutItemId);
         }
         if ($srcItem && !$itemFactory->isInSubTree($this->item->getId(), $srcItem->getId())) {
             $content .= '</dd>';
             $content .= '<dt>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_paste') . '</dt><dd>';
             $copyurl = Docman_View_View::buildUrl($this->url, array('action' => 'action_paste', 'id' => $this->item->getId()));
             $content .= $GLOBALS['Language']->getText('plugin_docman', 'details_actions_paste_canpaste', array($copyurl, $this->hp->purify($srcItem->getTitle(), CODEX_PURIFIER_CONVERT_HTML)));
         }
         //}}}
     }
     $content .= '</dd>';
     return $content;
 }
Example #7
0
 private function getParentItem(Docman_Item $item, Project $project)
 {
     if (!$item->getParentId()) {
         return;
     }
     return Docman_ItemFactory::instance($project->getID())->getItemFromDb($item->getParentId());
 }
 function _getReviewCurrentVersion()
 {
     $version = null;
     $itemFactory = Docman_ItemFactory::instance($this->item->getGroupId());
     $itemType = $itemFactory->getItemTypeForItem($this->item);
     // Get current version for file, embeddedfile and wiki
     switch ($itemType) {
         case PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE:
         case PLUGIN_DOCMAN_ITEM_TYPE_FILE:
             $currentVersion = $this->item->getCurrentVersion();
             $version = $currentVersion->getNumber();
             break;
         case PLUGIN_DOCMAN_ITEM_TYPE_WIKI:
             $version = $itemFactory->getCurrentWikiVersion($this->item);
             break;
     }
     return $version;
 }
 /**
  * Return an item factory
  *
  * @param Integer $groupId
  * @return Docman_ItemFactory
  */
 function _getItemFactory($groupId = 0)
 {
     return Docman_ItemFactory::instance($groupId);
 }
 public function itReturnsGroupsOfParentIfChildIsPublic()
 {
     $parent = $this->anItem();
     $parent_id = $parent->getId();
     $this->docman_item->setParentId($parent_id);
     $parent_permissions = array(101, 102, ProjectUGroup::REGISTERED);
     $child_permissions = array(1);
     stub(Docman_ItemFactory::instance($this->project->getID()))->getItemFromDb($parent_id)->returns($parent);
     stub($this->permissions_manager)->getAuthorizedUGroupIdsForProject($this->project, $parent_id, self::PERMISSIONS_TYPE)->returns($parent_permissions);
     stub($this->permissions_manager)->getAuthorizedUGroupIdsForProject($this->project, $this->item_id, self::PERMISSIONS_TYPE)->returns($child_permissions);
     $expected = $this->literalizer->ugroupIdsToString($parent_permissions, $this->project);
     $permissions = $this->docman_permissions->exportPermissions($this->docman_item);
     $this->assertEqual($expected, $permissions);
 }
 /**
  * Return an item (we don't know the group_id)
  * @param int $item_id the id of the item to retrieve
  * @return Docman_Item
  */
 protected function getItem($item_id)
 {
     $item = null;
     $dao = new Docman_ItemDao(CodendiDataAccess::instance());
     if ($row = $dao->searchByid($item_id)->getRow()) {
         $item = Docman_ItemFactory::instance($row['group_id'])->getItemFromRow($row);
         $dPm = Docman_PermissionsManager::instance($row['group_id']);
         $user = UserManager::instance()->getCurrentUser();
         if (!$dPm->userCanRead($user, $item->getId())) {
             $item = false;
         }
     }
     return $item;
 }