Commit efa78dfa2893d4926618d7f34cb1094f389b8d67

Authored by Brad Shuttleworth
1 parent 4287235b

formatting...


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5328 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 107 additions and 103 deletions
view.php
@@ -232,7 +232,8 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { @@ -232,7 +232,8 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
232 "FROM " . KTUtil::getTableName("document_transactions") . " AS DT INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " . 232 "FROM " . KTUtil::getTableName("document_transactions") . " AS DT INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " .
233 "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " . 233 "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " .
234 "WHERE DT.document_id = ? ORDER BY DT.datetime DESC"; 234 "WHERE DT.document_id = ? ORDER BY DT.datetime DESC";
235 - $aParams = array($document_id); 235 + $aParams = array($document_id);
  236 +
236 $res = DBUtil::getResultArray(array($sQuery, $aParams)); 237 $res = DBUtil::getResultArray(array($sQuery, $aParams));
237 if (PEAR::isError($res)) { 238 if (PEAR::isError($res)) {
238 var_dump($res); // FIXME be graceful on failure. 239 var_dump($res); // FIXME be graceful on failure.
@@ -313,133 +314,136 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { @@ -313,133 +314,136 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
313 // this gets in: 314 // this gets in:
314 // fDocumentId (document to compare against) 315 // fDocumentId (document to compare against)
315 // fComparisonVersion (the metadata_version of the appropriate document) 316 // fComparisonVersion (the metadata_version of the appropriate document)
316 - function do_viewComparison() { 317 + function do_viewComparison() {
317 318
318 - $document_data = array();  
319 - $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId');  
320 - if ($document_id === null) {  
321 - $this->oPage->addError('No document was requested. Please <a href="' . KTBrowseUtil::getBrowseBaseUrl() . '">browse</a> for one.');  
322 - return $this->do_error();  
323 - }  
324 - $document_data["document_id"] = $document_id;  
325 - 319 + $document_data = array();
  320 + $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId');
  321 + if ($document_id === null) {
  322 + $this->oPage->addError('No document was requested. Please <a href="' . KTBrowseUtil::getBrowseBaseUrl() . '">browse</a> for one.');
  323 + return $this->do_error();
  324 + }
  325 +
  326 + $document_data["document_id"] = $document_id;
326 327
327 - $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion'); 328 + $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion');
328 329
329 - // try get the document.  
330 - $oDocument =& Document::get($document_id, $base_version);  
331 - if (PEAR::isError($oDocument)) {  
332 - $this->oPage->addError('The base document you attempted to retrieve is invalid. Please <a href="' . KTBrowseUtil::getBrowseBaseUrl() . '">browse</a> for one.');  
333 - return $this->do_error();  
334 - }  
335 - if (!Permission::userHasDocumentReadPermission($oDocument)) {  
336 - // FIXME inconsistent.  
337 - $this->oPage->addError(_kt('You are not allowed to view this document'));  
338 - return $this->do_error();  
339 - }  
340 - $this->oDocument =& $oDocument;  
341 - $this->oPage->setSecondaryTitle($oDocument->getName());  
342 - $aOptions = array( 330 + // try get the document.
  331 + $oDocument =& Document::get($document_id, $base_version);
  332 + if (PEAR::isError($oDocument)) {
  333 + $this->oPage->addError('The base document you attempted to retrieve is invalid. Please <a href="' . KTBrowseUtil::getBrowseBaseUrl() . '">browse</a> for one.');
  334 + return $this->do_error();
  335 + }
  336 +
  337 + if (!Permission::userHasDocumentReadPermission($oDocument)) {
  338 + // FIXME inconsistent.
  339 + $this->oPage->addError(_kt('You are not allowed to view this document'));
  340 + return $this->do_error();
  341 + }
  342 +
  343 + $this->oDocument =& $oDocument;
  344 + $this->oPage->setSecondaryTitle($oDocument->getName());
  345 + $aOptions = array(
343 "documentaction" => "viewDocument", 346 "documentaction" => "viewDocument",
344 "folderaction" => "browse", 347 "folderaction" => "browse",
345 ); 348 );
  349 +
346 $this->aBreadcrumbs = array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions)); 350 $this->aBreadcrumbs = array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions));
347 - $this->oPage->setBreadcrumbDetails(_kt("compare versions")); 351 + $this->oPage->setBreadcrumbDetails(_kt("compare versions"));
348 352
349 - $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion');  
350 - if ($comparison_version=== null) {  
351 - $this->oPage->addError('No comparison version was requested. Please <a href="' . KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id) . '">select a version</a>.');  
352 - return $this->do_error();  
353 - } 353 + $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion');
  354 + if ($comparison_version=== null) {
  355 + $this->oPage->addError('No comparison version was requested. Please <a href="' . KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id) . '">select a version</a>.');
  356 + return $this->do_error();
  357 + }
354 358
355 - $oComparison =& Document::get($oDocument->getId(), $comparison_version);  
356 - if (PEAR::isError($oComparison)) {  
357 - $this->errorRedirectToMain(_kt('Invalid document to compare against.'));  
358 - }  
359 - $comparison_data = array();  
360 - $comparison_data['document_id'] = $oComparison->getId();  
361 -  
362 - $document_data["document"] = $oDocument;  
363 - $comparison_data['document'] = $oComparison; 359 + $oComparison =& Document::get($oDocument->getId(), $comparison_version);
  360 + if (PEAR::isError($oComparison)) {
  361 + $this->errorRedirectToMain(_kt('Invalid document to compare against.'));
  362 + }
  363 + $comparison_data = array();
  364 + $comparison_data['document_id'] = $oComparison->getId();
  365 +
  366 + $document_data["document"] = $oDocument;
  367 + $comparison_data['document'] = $oComparison;
364 368
365 - $document_data["document_type"] =& DocumentType::get($oDocument->getDocumentTypeID());  
366 - $comparison_data["document_type"] =& DocumentType::get($oComparison->getDocumentTypeID()); 369 + $document_data["document_type"] =& DocumentType::get($oDocument->getDocumentTypeID());
  370 + $comparison_data["document_type"] =& DocumentType::get($oComparison->getDocumentTypeID());
367 371
368 - // follow twice: once for normal, once for comparison.  
369 - $is_valid_doctype = true; 372 + // follow twice: once for normal, once for comparison.
  373 + $is_valid_doctype = true;
370 374
371 - if (PEAR::isError($document_data["document_type"])) {  
372 - $this->oPage->addError('The document you requested has an invalid <strong>document type</strong>. Unfortunately, this means that we cannot effectively display it.');  
373 - $is_valid_doctype = false;  
374 - } 375 + if (PEAR::isError($document_data["document_type"])) {
  376 + $this->oPage->addError('The document you requested has an invalid <strong>document type</strong>. Unfortunately, this means that we cannot effectively display it.');
  377 + $is_valid_doctype = false;
  378 + }
375 379
376 - // we want to grab all the md for this doc, since its faster that way.  
377 - $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($oDocument->getMetadataVersionId()))); 380 + // we want to grab all the md for this doc, since its faster that way.
  381 + $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($oDocument->getMetadataVersionId())));
378 382
379 - $field_values = array();  
380 - foreach ($mdlist as $oFieldLink) { 383 + $field_values = array();
  384 + foreach ($mdlist as $oFieldLink) {
381 $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); 385 $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
382 - }  
383 -  
384 - $document_data["field_values"] = $field_values;  
385 -  
386 - $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version))); 386 + }
  387 +
  388 + $document_data["field_values"] = $field_values;
  389 + $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version)));
387 390
388 - $field_values = array();  
389 - foreach ($mdlist as $oFieldLink) { 391 + $field_values = array();
  392 + foreach ($mdlist as $oFieldLink) {
390 $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); 393 $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
391 - } 394 + }
392 395
393 - $comparison_data["field_values"] = $field_values; 396 + $comparison_data["field_values"] = $field_values;
394 397
395 398
396 399
397 - // Fieldset generation.  
398 - //  
399 - // we need to create a set of FieldsetDisplay objects  
400 - // that adapt the Fieldsets associated with this lot  
401 - // to the view (i.e. ZX3). Unfortunately, we don't have  
402 - // any of the plumbing to do it, so we handle this here.  
403 - $fieldsets = array();  
404 -  
405 - // we always have a generic.  
406 - array_push($fieldsets, new GenericFieldsetDisplay()); 400 + // Fieldset generation.
  401 + //
  402 + // we need to create a set of FieldsetDisplay objects
  403 + // that adapt the Fieldsets associated with this lot
  404 + // to the view (i.e. ZX3). Unfortunately, we don't have
  405 + // any of the plumbing to do it, so we handle this here.
  406 + $fieldsets = array();
407 407
408 - // FIXME can we key this on fieldset namespace? or can we have duplicates?  
409 - // now we get the other fieldsets, IF there is a valid doctype.  
410 - if ($is_valid_doctype) {  
411 - // these are the _actual_ fieldsets.  
412 - $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();  
413 -  
414 - // and the generics  
415 - $activesets = KTFieldset::getGenericFieldsets();  
416 - foreach ($activesets as $oFieldset) {  
417 - $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());  
418 - array_push($fieldsets, new $displayClass($oFieldset));  
419 - } 408 + // we always have a generic.
  409 + array_push($fieldsets, new GenericFieldsetDisplay());
  410 +
  411 + // FIXME can we key this on fieldset namespace? or can we have duplicates?
  412 + // now we get the other fieldsets, IF there is a valid doctype.
  413 +
  414 + if ($is_valid_doctype) {
  415 + // these are the _actual_ fieldsets.
  416 + $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
  417 +
  418 + // and the generics
  419 + $activesets = KTFieldset::getGenericFieldsets();
  420 + foreach ($activesets as $oFieldset) {
  421 + $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
  422 + array_push($fieldsets, new $displayClass($oFieldset));
  423 + }
420 424
421 - $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID());  
422 - foreach ($activesets as $oFieldset) {  
423 - $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());  
424 - array_push($fieldsets, new $displayClass($oFieldset));  
425 - }  
426 - } 425 + $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID());
  426 + foreach ($activesets as $oFieldset) {
  427 + $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
  428 + array_push($fieldsets, new $displayClass($oFieldset));
  429 + }
  430 + }
427 431
428 - // FIXME handle ad-hoc fieldsets.  
429 - $this->addPortlets(); 432 + // FIXME handle ad-hoc fieldsets.
  433 + $this->addPortlets();
430 $oTemplating =& KTTemplating::getSingleton(); 434 $oTemplating =& KTTemplating::getSingleton();
431 - $oTemplate = $oTemplating->loadTemplate("kt3/compare_document");  
432 - $aTemplateData = array(  
433 - "context" => $this,  
434 - "document_id" => $document_id,  
435 - "document" => $oDocument,  
436 - "document_data" => $document_data,  
437 - "comparison_data" => $comparison_data,  
438 - "comparison_document" => $oComparison,  
439 - "fieldsets" => $fieldsets,  
440 - );  
441 - //var_dump($aTemplateData["comparison_data"]);  
442 - return $oTemplate->render($aTemplateData); 435 + $oTemplate = $oTemplating->loadTemplate("kt3/compare_document");
  436 + $aTemplateData = array(
  437 + "context" => $this,
  438 + "document_id" => $document_id,
  439 + "document" => $oDocument,
  440 + "document_data" => $document_data,
  441 + "comparison_data" => $comparison_data,
  442 + "comparison_document" => $oComparison,
  443 + "fieldsets" => $fieldsets,
  444 + );
  445 + //var_dump($aTemplateData["comparison_data"]);
  446 + return $oTemplate->render($aTemplateData);
443 } 447 }
444 448
445 /* we have a lot of error handling. this one is the absolute final failure. */ 449 /* we have a lot of error handling. this one is the absolute final failure. */