Ejemplo n.º 1
0
 /**
  * This is what Datamanager calls to actually create a document
  */
 public function &dm2_create_callback(&$datamanager)
 {
     $document = new org_openpsa_documents_document_dba();
     $document->topic = $this->_request_data['directory']->id;
     $document->orgOpenpsaAccesstype = org_openpsa_core_acl::ACCESS_WGPRIVATE;
     if (!$document->create()) {
         debug_print_r('We operated on this object:', $document);
         throw new midcom_error("Failed to create a new document. Error: " . midcom_connection::get_error_string());
     }
     $this->_document = $document;
     return $document;
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_view($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $qb = org_openpsa_documents_document_dba::new_query_builder();
     //check if there is another output-mode wanted
     if (isset($args[0])) {
         $this->_output_mode = $args[0];
     }
     if (isset($args[1])) {
         $current_topic = midcom_db_topic::get_cached($args[1]);
     } else {
         $current_topic = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_CONTENTTOPIC);
     }
     switch ($this->_output_mode) {
         case 'xml':
             $current_component = $current_topic->component;
             $parent_link = "";
             $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
             //check if id of a topic is passed
             if (isset($_POST['nodeid'])) {
                 $root_topic = new midcom_db_topic((int) $_POST['nodeid']);
                 while ($root_topic->get_parent()->component == $current_component && $root_topic->id != $current_topic->id) {
                     $parent_link = $root_topic->name . "/" . $parent_link;
                     $root_topic = $root_topic->get_parent();
                 }
                 $root_topic = new midcom_db_topic((int) $_POST['nodeid']);
                 $this->_request_data['parent_link'] = $parent_link;
             } else {
                 $root_topic = $current_topic;
                 $current_topic = $current_topic->get_parent();
                 if ($current_topic->get_parent()) {
                     $this->_request_data['parent_directory'] = $current_topic;
                     $parent_link = substr($prefix, 0, strlen($prefix) - (strlen($root_topic->name) + 1));
                 }
                 $this->_request_data['parent_up_link'] = $parent_link;
             }
             //show only documents of the right topic
             $qb->add_constraint('topic', '=', $root_topic->id);
             //get needed directories
             $this->_prepare_directories($root_topic, $current_component);
             //set header & style for xml
             midcom::get()->header("Content-type: text/xml; charset=UTF-8");
             midcom::get()->skip_page_style = true;
             break;
             //html
         //html
         default:
             $qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_DOCUMENT);
             $qb->add_constraint('topic', '=', $this->_request_data['directory']->id);
             $this->_prepare_output();
             break;
     }
     $this->_request_data['current_guid'] = $current_topic->guid;
     $qb->add_constraint('nextVersion', '=', 0);
     $qb->add_order('title');
     $this->_documents = $qb->execute();
 }
Ejemplo n.º 3
0
 public function testCRUD()
 {
     $user = $this->create_user(true);
     midcom::get('auth')->request_sudo('org.openpsa.documents');
     $topic = $this->create_object('org_openpsa_documents_directory', array('name' => 'TEST_' . __CLASS__ . time()));
     $document = new org_openpsa_documents_document_dba();
     $document->topic = $topic->id;
     $stat = $document->create();
     $this->assertTrue($stat);
     $this->register_object($document);
     $document->refresh();
     $this->assertEquals('Document #' . $document->id, $document->title);
     $this->assertEquals($user->id, $document->author);
     $stat = $document->update();
     $this->assertTrue($stat);
     $stat = $document->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Ejemplo n.º 4
0
 /**
  * Prepare the indexer client
  */
 public function _on_reindex($topic, $config, &$indexer)
 {
     $qb_documents = org_openpsa_documents_document_dba::new_query_builder();
     $qb_documents->add_constraint('topic', '=', $topic->id);
     $qb_documents->add_constraint('nextVersion', '=', 0);
     $qb_documents->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_DOCUMENT);
     $schemadb_documents = midcom_helper_datamanager2_schema::load_database($config->get('schemadb_document'));
     $qb_directories = org_openpsa_documents_directory::new_query_builder();
     $qb_directories->add_constraint('up', '=', $topic->id);
     $qb_directories->add_constraint('component', '=', $this->_component);
     $schemadb_directories = midcom_helper_datamanager2_schema::load_database($config->get('schemadb_directory'));
     $indexer = new org_openpsa_documents_midcom_indexer($topic, $indexer);
     $indexer->add_query('documents', $qb_documents, $schemadb_documents);
     $indexer->add_query('directories', $qb_directories, $schemadb_directories);
     return $indexer;
 }
Ejemplo n.º 5
0
 function get_leaves()
 {
     $leaves = array();
     return $leaves;
     // OLD STUFF:
     // List the documents
     $qb = org_openpsa_documents_document_dba::new_query_builder();
     $qb->add_constraint('topic', '=', $this->_topic->id);
     $qb->add_constraint('nextVersion', '=', 0);
     $qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_DOCUMENT);
     $ret = $qb->execute();
     if (is_array($ret) && count($ret) > 0) {
         foreach ($ret as $document) {
             $leaves[$document->id] = array(MIDCOM_NAV_URL => 'document/' . $document->guid . '/', MIDCOM_NAV_NAME => $document->title != "" ? $document->title : "document #" . $document->id, MIDCOM_NAV_OBJECT => $document, MIDCOM_NAV_GUID => $document->guid);
         }
     }
     return $leaves;
 }
Ejemplo n.º 6
0
<?php

$view = $data['document_dm'];
$att = $data['document_attachment'];
$document_type = midcom_helper_misc::filesize_to_string($att['filesize']) . ' ' . org_openpsa_documents_document_dba::get_file_type($att['mimetype']);
$nap = new midcom_helper_nav();
$node = $nap->get_node($nap->get_current_node());
$score = round($data['document_search']->score * 100);
$url = $data['document_search']->topic_url . 'document/' . $data['document']->guid . '/';
// MIME type
$icon = MIDCOM_STATIC_URL . '/stock-icons/mime/gnome-text-blank.png';
if ($att) {
    $icon = midcom_helper_misc::get_mime_icon($att['mimetype']);
}
?>
<dt><a href="&(url);"><?php 
echo $view['title'];
?>
</a></dt>
<dd>
<?php 
if ($icon) {
    ?>
    <div class="icon"><a style="text-decoration: none;" href="&(node[MIDCOM_NAV_FULLURL]);document/<?php 
    echo $data['document']->guid;
    ?>
/"><img src="&(icon);" <?php 
    if ($view['document']) {
        echo 'title="' . $document_type . '" ';
    }
    ?>
Ejemplo n.º 7
0
 function backup_version()
 {
     // Instantiate the backup object
     $backup = new org_openpsa_documents_document_dba();
     $properties = $this->get_properties();
     // Copy current properties
     foreach ($properties as $key) {
         if ($key != 'guid' && $key != 'id' && $key != 'metadata') {
             $backup->{$key} = $this->{$key};
         }
     }
     $backup->nextVersion = $this->id;
     $stat = $backup->create();
     if (!$stat) {
         return $stat;
     }
     $backup = new org_openpsa_documents_document_dba($backup->id);
     // Copy parameters
     $params = $this->list_parameters();
     if ($params) {
         foreach ($params as $domain => $array) {
             foreach ($array as $name => $value) {
                 if ($name == 'identifier') {
                     $value = $identifier = md5(time() . $backup_attachment->name);
                 }
                 $backup->set_parameter($domain, $name, $value);
             }
         }
     }
     // Find the attachment
     $attachments = $this->list_attachments();
     if (!$attachments) {
         return $stat;
     }
     foreach ($attachments as $original_attachment) {
         $backup_attachment = $backup->create_attachment($original_attachment->name, $original_attachment->title, $original_attachment->mimetype);
         $original_handle = $original_attachment->open('r');
         if (!$backup_attachment || !$original_handle) {
             // Failed to copy the attachment, abort
             return $backup->delete();
         }
         // Copy the contents
         $backup_handle = $backup_attachment->open('w');
         while (!feof($original_handle)) {
             fwrite($backup_handle, fread($original_handle, 4096), 4096);
         }
         fclose($original_handle);
         // Copy attachment parameters
         $params = $original_attachment->list_parameters();
         if ($params) {
             foreach ($params as $domain => $array) {
                 foreach ($array as $name => $value) {
                     if ($name == 'identifier') {
                         $value = md5(time() . $backup_attachment->name);
                         $backup->set_parameter('midcom.helper.datamanager2.type.blobs', 'guids_document', $value . ":" . $backup_attachment->guid);
                     }
                     $backup_attachment->set_parameter($domain, $name, $value);
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 public static function render_fileinfo($object, $field)
 {
     $output = '';
     $identifiers = explode(',', $object->get_parameter('midcom.helper.datamanager2.type.blobs', 'guids_' . $field));
     if (empty($identifiers)) {
         return $output;
     }
     $host_prefix = midcom::get()->get_host_prefix();
     foreach ($identifiers as $identifier) {
         $parts = explode(':', $identifier);
         if (sizeof($parts) != 2) {
             continue;
         }
         $guid = $parts[1];
         try {
             $attachment = new midcom_db_attachment($guid);
             $url = $host_prefix . '/midcom-serveattachmentguid-' . $attachment->guid . '/' . $attachment->name;
             $stat = $attachment->stat();
             $filesize = midcom_helper_misc::filesize_to_string($stat[7]);
             $mimetype = org_openpsa_documents_document_dba::get_file_type($attachment->mimetype);
             $mimetype_icon = midcom_helper_misc::get_mime_icon($attachment->mimetype);
             $output .= '<span class="org_openpsa_helpers_fileinfo">';
             $output .= '<a href="' . $url . '" class="icon"><img src="' . $mimetype_icon . '" alt="' . $mimetype . '" /></a>';
             $output .= '<a href="' . $url . '" class="filename">' . $attachment->name . '</a>';
             $output .= '<span class="mimetype">' . $mimetype . '</span>';
             $output .= '<span class="filesize">' . $filesize . '</span>';
             $output .= "</span>\n";
         } catch (midcom_error $e) {
             $e->log();
             continue;
         }
         $output .= '';
     }
     return $output;
 }
Ejemplo n.º 9
0
 private function _add_version_navigation()
 {
     $previous_version = false;
     $next_version = false;
     $qb = org_openpsa_documents_document_dba::new_query_builder();
     if ($this->_document->nextVersion) {
         $qb->add_constraint('nextVersion', '=', $this->_document->nextVersion);
         $qb->add_constraint('metadata.created', '<', gmstrftime('%Y-%m-%d %T', $this->_document->metadata->created));
     } else {
         $qb->add_constraint('nextVersion', '=', $this->_document->id);
     }
     $version = $qb->count() + 1;
     if ($version > 1) {
         $qb->add_order('metadata.created', 'DESC');
         $qb->set_limit(1);
         $results = $qb->execute();
         $previous_version = $results[0];
     }
     if ($this->_document->nextVersion != 0) {
         $qb = org_openpsa_documents_document_dba::new_query_builder();
         $qb->begin_group('OR');
         $qb->add_constraint('nextVersion', '=', $this->_document->nextVersion);
         $qb->add_constraint('id', '=', $this->_document->nextVersion);
         $qb->end_group();
         $qb->add_constraint('metadata.revised', '>', gmstrftime('%Y-%m-%d %T', $this->_document->metadata->created));
         $qb->add_order('nextVersion', 'DESC');
         $qb->add_order('metadata.created', 'ASC');
         $qb->set_limit(1);
         $results = $qb->execute();
         $next_version = $results[0];
         $current_version = org_openpsa_documents_document_dba::get_cached($this->_document->nextVersion);
         $this->add_breadcrumb('document/' . $current_version->guid . '/', $current_version->title);
         $this->add_breadcrumb('', sprintf($this->_l10n->get('version %s (%s)'), $version, strftime('%x %X', $this->_document->metadata->revised)));
     } else {
         $this->add_breadcrumb('document/' . $this->_document->guid . '/', $this->_document->title);
     }
     if ($next_version) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "document/{$next_version->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('next version'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/up.png'));
     }
     if ($previous_version) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "document/{$previous_version->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('previous version'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/down.png'));
     }
 }