private function getFileVersions() { $uh = UserHelper::instance(); $content = '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions') . '</h3>'; $version_factory = new Docman_VersionFactory(); $approvalFactory = Docman_ApprovalTableFactoriesFactory::getFromItem($this->item); $versions = $version_factory->getAllVersionForItem($this->item); if ($versions) { if (count($versions)) { $titles = array(); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_version'); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_date'); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_author'); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_label'); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_changelog'); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_approval'); $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_delete_version'); $content .= html_build_list_table_top($titles, false, false, false); $odd_even = array('boxitem', 'boxitemalt'); $i = 0; foreach ($versions as $key => $nop) { $download = Docman_View_View::buildUrl($this->url, array('action' => 'show', 'id' => $this->item->getId(), 'version_number' => $versions[$key]->getNumber())); $delete = Docman_View_View::buildUrl($this->url, array('action' => 'confirmDelete', 'id' => $this->item->getId(), 'version' => $versions[$key]->getNumber())); $user = $versions[$key]->getAuthorId() ? $uh->getDisplayNameFromUserId($versions[$key]->getAuthorId()) : $GLOBALS['Language']->getText('plugin_docman', 'details_history_anonymous'); $content .= '<tr class="' . $odd_even[$i++ % count($odd_even)] . '">'; $content .= '<td align="center"><a href="' . $download . '">' . $versions[$key]->getNumber() . '</a></td>'; $content .= '<td>' . html_time_ago($versions[$key]->getDate()) . '</td>'; $content .= '<td>' . $this->hp->purify($user) . '</td>'; $content .= '<td>' . $this->hp->purify($versions[$key]->getLabel()) . '</td>'; $content .= '<td>' . $this->hp->purify($versions[$key]->getChangelog(), CODENDI_PURIFIER_LIGHT) . '</td>'; $table = $approvalFactory->getTableFromVersion($versions[$key]); if ($table != null) { $appTable = Docman_View_View::buildUrl($this->url, array('action' => 'details', 'section' => 'approval', 'id' => $this->item->getId(), 'version' => $versions[$key]->getNumber())); $content .= '<td align="center"><a href="' . $appTable . '">' . ($titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_approval_show') . '</a></td>'); } else { $content .= '<td></td>'; } $content .= '<td align="center"><a href="' . $delete . '"><img src="' . util_get_image_theme("ic/trash.png") . '" height="16" width="16" border="0"></a></td>'; $content .= '</tr>'; } $content .= '</table>'; } else { $content .= '<div>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_no') . '</div>'; } } else { $content .= '<div>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_versions_error') . '</div>'; } return $content; }
/** * */ function __construct($item, $versionNumber = null) { parent::__construct($item); $dao = $this->_getDao(); $vFactory = new Docman_VersionFactory(); $dar = $dao->getLatestTableByItemId($item->getId(), 'ver.number'); if ($dar && !$dar->isError() && $dar->rowCount() == 1) { $row = $dar->getRow(); $lastVersionNumber = $row['number']; $lastItemVersion = $vFactory->getSpecificVersion($item, $lastVersionNumber); if ($versionNumber !== null && $lastItemVersion->getNumber() != $versionNumber) { $this->itemVersion = $vFactory->getSpecificVersion($item, $versionNumber); $this->customizable = false; } else { $this->itemVersion = $lastItemVersion; } } else { $this->itemVersion = $item->getCurrentVersion(); } }
$groupId = $request->getValidated('group_id', 'uint', 0); $id = $request->getValidated('id', 'uint', 0); if ($request->existAndNonEmpty('func')) { switch ($func) { case 'confirm_restore_item': $itemFactory = new Docman_ItemFactory($groupId); $item = $itemFactory->getItemFromDb($id, array('ignore_deleted' => true)); if ($itemFactory->restore($item)) { $url = $p->getPluginPath() . '/?group_id=' . $groupId . '&action=details&id=' . $id . '§ion=properties'; $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docman', 'item_restored', array($url)), CODENDI_PURIFIER_DISABLED); $GLOBALS['Response']->redirect('/admin/show_pending_documents.php?group_id=' . $groupId . '&focus=item'); } else { exit_error($Language->getText('plugin_docman', 'error'), $Language->getText('plugin_docman', 'item_not_restored')); } break; case 'confirm_restore_version': $versionFactory = new Docman_VersionFactory(); $version = $versionFactory->getSpecificVersionById($id); if ($versionFactory->restore($version)) { $url = $p->getPluginPath() . '/?group_id=' . $groupId . '&action=details&id=' . $version->getItemId() . '§ion=history'; $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docman', 'version_restored', array($url)), CODENDI_PURIFIER_DISABLED); $GLOBALS['Response']->redirect('/admin/show_pending_documents.php?group_id=' . $groupId . '&focus=version'); } else { exit_error($Language->getText('plugin_docman', 'error'), $Language->getText('plugin_docman', 'version_not_restored')); } break; default: break; } exit; }
/** * Remind a user about the document he is supposed to review * * @param Docman_ApprovalTable $table Approval table * @param Integer $reviewerId Id of the reviewer * * @return Boolean */ private function notifyIndividual(Docman_ApprovalTable $table, $reviewerId) { $hp = Codendi_HTMLPurifier::instance(); $um = UserManager::instance(); $reviewer = $um->getUserById($reviewerId); if (!$reviewer->getEmail()) { return; } if ($table instanceof Docman_ApprovalTableFile) { $versionFactory = new Docman_VersionFactory(); $version = $versionFactory->getSpecificVersionById($table->getVersionId(), 'plugin_docman_version'); $itemId = ""; if ($version) { $itemId = $version->getItemId(); } } elseif ($table) { $itemId = $table->getItemId(); } if (!$itemId) { return; } $itemFactory = new Docman_ItemFactory(); $docmanItem = $itemFactory->getItemFromDb($itemId); if (!$docmanItem) { return; } $subject = $GLOBALS['Language']->getText('plugin_docman', 'approval_reminder_mail_subject', array($GLOBALS['sys_name'], $docmanItem->getTitle())); $mailMgr = new MailManager(); $mailPrefs = $mailMgr->getMailPreferencesByUser($reviewer); if ($mailPrefs == Codendi_Mail_Interface::FORMAT_HTML) { $html_body = $this->getBodyHtml($table, $docmanItem); } $text_body = $this->getBodyText($table, $docmanItem); $mail_notification_builder = new MailNotificationBuilder(new MailBuilder(TemplateRendererFactory::build())); return $mail_notification_builder->buildAndSendEmail($this->getItemProject($docmanItem), array($reviewer->getEmail()), $subject, $html_body, $text_body, $this->getReviewUrl($docmanItem), DocmanPlugin::TRUNCATED_SERVICE_NAME, new MailEnhancer()); }
/** * @return Docman_Version */ protected function getVersion(Docman_Item $item, $version_number) { return $this->version_factory->getSpecificVersion($item, $version_number); }
/** * Hook to purge deleted items if their agony ends today * * @param Array $params * * @return void */ function purgeFiles(array $params) { require_once 'Docman_ItemFactory.class.php'; $itemFactory = new Docman_ItemFactory(); $itemFactory->purgeDeletedItems($params['time']); require_once 'Docman_VersionFactory.class.php'; $versionFactory = new Docman_VersionFactory(); $versionFactory->purgeDeletedVersions($params['time']); }
public function getAllChildrenFromParent(Docman_Item $item) { $children = array(); $item_iterator = $this->getChildrenFromParent($item); foreach ($item_iterator as $child) { $item_type = $this->getItemTypeForItem($child); if ($item_type === PLUGIN_DOCMAN_ITEM_TYPE_FILE || $item_type === PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE) { $docman_version_factory = new Docman_VersionFactory(); $item_current_version = $docman_version_factory->getCurrentVersionForItem($child); $child->setCurrentVersion($item_current_version); } $children[] = $child; if ($item_type === PLUGIN_DOCMAN_ITEM_TYPE_FOLDER) { $children = array_merge($children, $this->getAllChildrenFromParent($child)); } } return $children; }
/** * Remind a user about the document he is supposed to review * * @param Docman_ApprovalTable $table Approval table * @param Integer $reviewerId Id of the reviewer * * @return Boolean */ private function notifyIndividual(Docman_ApprovalTable $table, $reviewerId) { $hp = Codendi_HTMLPurifier::instance(); $um = UserManager::instance(); $reviewer = $um->getUserById($reviewerId); if ($table instanceof Docman_ApprovalTableFile) { $versionFactory = new Docman_VersionFactory(); $version = $versionFactory->getSpecificVersionById($table->getVersionId(), 'plugin_docman_version'); $itemId = $version->getItemId(); } else { $itemId = $table->getItemId(); } $itemFactory = new Docman_ItemFactory(); $docmanItem = $itemFactory->getItemFromDb($itemId); $subject = $GLOBALS['Language']->getText('plugin_docman', 'approval_reminder_mail_subject', array($GLOBALS['sys_name'], $docmanItem->getTitle())); $mailMgr = new MailManager(); $mailPrefs = $mailMgr->getMailPreferencesByUser($reviewer); $mail = new Codendi_Mail(); $mail->getLookAndFeelTemplate()->set('title', $hp->purify($subject)); $mail->setFrom($GLOBALS['sys_noreply']); $mail->setTo($reviewer->getEmail()); $mail->setSubject($subject); if ($mailPrefs == Codendi_Mail_Interface::FORMAT_HTML) { $htmlBody = $this->getBodyHtml($table, $docmanItem); $mail->setBodyHtml($htmlBody); } $txtBody = $this->getBodyText($table, $docmanItem); $mail->setBodyText($txtBody); return $mail->send(); }
public function visitFile(Docman_File $item) { $this->statistics['nb_file']++; $n = $this->visitDocument($item); // Dump all versions $versionFactory = new Docman_VersionFactory(); $versions = array_reverse($versionFactory->getAllVersionForItem($item)); if (count($versions) > 0) { $vNode = $this->doc->createElement('versions'); foreach ($versions as $version) { $this->statistics['nb_version']++; $vNode->appendChild($this->createVersion($version)); } $n->appendChild($vNode); } return $n; }