Commit b9d519d64ecde24dcc17aef49b9eed8b81755101

Authored by michael
1 parent 2c1a1760

refactored html from browseBL into browseUI


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@613 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/browseBL.php
... ... @@ -48,15 +48,7 @@ if (checkSession()) {
48 48 $oDocBrowser = new DocumentBrowser();
49 49 // instantiate my content pattern
50 50 $oContent = new PatternCustom();
51   -
52   - $oContent->addHtml(
53   - startTable("0", "100%") .
54   - // pending documents
55   - startTableRowCell() .
56   - startTable("0", "100%") .
57   - tableRow("left", "", tableData(browseTypeSelect($fBrowseType))) .
58   - tableRow("", "", tabledata("")) .
59   - tableRow("", "", tabledata("")));
  51 +
60 52 // instantiate data arrays
61 53 $folders = NULL;
62 54 $categories = NULL;
... ... @@ -69,107 +61,32 @@ if (checkSession()) {
69 61 } else {
70 62 $results = $oDocBrowser->browseByFolder($fFolderID);
71 63 }
72   - if ($results) {
73   - $default->log->debug("browseBL.php: retrieved results from folder browse=" . arrayToString($results));
74   - $folderID = $results["folders"][0]->getID();
75   -
76   - // the first folder in the list is the folder we're in so display the path to this folder
77   - // as the heading
78   - $default->log->debug("browseBL.php: folder path array for folderID=$folderID=" . arrayToString(Folder::getFolderPathAsArray($folderID)));
79   - $oContent->addHtml(tableRow("", "", tableData(displayFolderPathLink(Folder::getFolderPathAsArray($folderID)))));
80   -
81   - // empty row for spacing
82   - $oContent->addHtml(tableRow("", "", tableData(" ")));
83   -
84   - // now loop through the rest of the folders and display links
85   - for ($i=1; $i<count($results["folders"]); $i++) {
86   - $sRow = displayFolderLink($results["folders"][$i]);
87   - $oContent->addHtml(tableRow("", "", tableData($sRow)));
88   - }
89   -
90   - // loop through the files and display links
91   - for ($i=0; $i<count($results["documents"]); $i++) {
92   - $sDocumentLink = displayDocumentLink($results["documents"][$i]);
93   - $oContent->addHtml(tableRow("", "", tableData($sDocumentLink)));
94   - }
95   - } else {
96   - // empty row for spacing
97   - $oContent->addHtml(tableRow("", "", tableData("&nbsp;")));
98   - $oContent->addHtml(tablerow("", "", tableData($_SESSION["errorMessage"])));
99   - }
100   -
101 64 break;
102 65  
103 66 case "category" :
104 67 if (!$fCategoryName) {
105 68 $results = $oDocBrowser->browseByCategory();
106   -
107   - // we have a list of categories
108   - // so loop through them and display
109   - $oContent->addHtml(tableRow("", "", tableData(displayCategoryLink("Categories"))));
110   -
111   - // empty row for spacing
112   - $oContent->addHtml(tableRow("", "", tableData("&nbsp;")));
113   -
114   - for ($i=0; $i<count($results["categories"]); $i++) {
115   - $oContent->addHtml(tableRow("", "", tableData(displayCategoryLink($results["categories"][$i]))));
116   - }
117   -
118 69 } else {
119 70 $results = $oDocBrowser->browseByCategory($fCategoryName);
120   - // display category heading
121   - $oContent->addHtml(tableRow("", "", tableData(displayCategoryPathLink($results["categories"][0]))));
122   -
123   - // empty row for spacing
124   - $oContent->addHtml(tableRow("", "", tableData("&nbsp;")));
125   -
126   - // now loop through the documents in the category (TODO: if any)
127   - // and display them
128   - for ($i=0; $i<count($results["documents"]); $i++) {
129   - $sDocumentLink = displayDocumentLink($results["documents"][$i], true);
130   - $oContent->addHtml(tableRow("", "", tableData($sDocumentLink)));
131   - }
132 71 }
133   -
134 72 break;
135 73  
136 74 case "documentType" :
137 75 if (!$fDocumentTypeID) {
138 76 $results = $oDocBrowser->browseByDocumentType();
139   -
140   - // we have a list of document types
141   - // so loop through them and display
142   - $oContent->addHtml(tableRow("", "", tableData(displayDocumentTypeLink(array("name"=>"Document Types")))));
143   -
144   - // empty row for spacing
145   - $oContent->addHtml(tableRow("", "", tableData("&nbsp;")));
146   -
147   - for ($i=0; $i<count($results["documentTypes"]); $i++) {
148   - $oContent->addHtml(tableRow("", "", tableData(displayDocumentTypeLink($results["documentTypes"][$i]))));
149   - }
150   -
151 77 } else {
152 78 $results = $oDocBrowser->browseByDocumentType($fDocumentTypeID);
153   - // display document type heading
154   - $oContent->addHtml(tableRow("", "", tableData(displayDocumentTypePathLink($results["documentTypes"][0]))));
155   -
156   - // empty row for spacing
157   - $oContent->addHtml(tableRow("", "", tableData("&nbsp;")));
158   -
159   - // now loop through the documents in the category (TODO: if any)
160   - // and display them
161   - for ($i=0; $i<count($results["documents"]); $i++) {
162   - $sDocumentLink = displayDocumentLink($results["documents"][$i], true);
163   - $oContent->addHtml(tableRow("", "", tableData($sDocumentLink)));
164   - }
165 79 }
166 80 break;
167 81 }
168   -
169   - $oContent->addHtml(
170   - stopTable() .
171   - endTableRowCell() .
172   - stopTable());
  82 +
  83 + if ($results) {
  84 + // display the list of categories
  85 + $oContent->addHtml(renderPage($results, $fBrowseType));
  86 +
  87 + } else {
  88 + $main->setErrorMessage("There are no document types to display");
  89 + }
173 90  
174 91 $main->setCentralPayload($oContent);
175 92 $main->setFormAction($_SERVER["PHP_SELF"]);
... ...
presentation/lookAndFeel/knowledgeTree/documentmanagement/browseUI.inc
... ... @@ -3,6 +3,7 @@
3 3 require_once("$default->owl_fs_root/presentation/Html.inc");
4 4 require_once("$default->owl_ui_directory/foldermanagement/folderUI.inc");
5 5 require_once("$default->owl_ui_directory/documentmanagement/documentUI.inc");
  6 +require_once("$default->owl_ui_directory/foldermanagement/addFolderUI.inc");
6 7  
7 8 /**
8 9 * $Id$
... ... @@ -22,7 +23,7 @@ require_once(&quot;$default-&gt;owl_ui_directory/documentmanagement/documentUI.inc&quot;);
22 23 *
23 24 * @param string the selected browse by option
24 25 */
25   -function browseTypeSelect($sBrowseType) {
  26 +function renderBrowseTypeSelect($sBrowseType) {
26 27 return "<span class=\"browseTypeSelect\">\n
27 28 \tView documents by: <input type=\"radio\" name=\"fBrowseType\" onChange=\"document.forms[0].submit()\" value=\"folder\"" .
28 29 ((($sBrowseType=="folder") || (strlen($sBrowseType)==0)) ? "checked" : "") . "> Folders\n" .
... ... @@ -37,8 +38,14 @@ function browseTypeSelect($sBrowseType) {
37 38 *
38 39 * @param string the category name to display
39 40 */
40   -function displayCategoryPathLink($sCategoryName) {
41   - return displayCategoryLink("Categories") . " > " . displayCategoryLink($sCategoryName);
  41 +function displayCategoryPathLink($aCategories) {
  42 + // if the first value in arr["categories"] == Categories then we've got a list of categories
  43 + if ($aCategories[0] == "Categories") {
  44 + return displayCategoryLink($aCategories[0]);
  45 + } else {
  46 + // else the first entry is the category name, so build a little path
  47 + return displayCategoryLink("Categories") . " > " . displayCategoryLink($aCategories[0]);
  48 + }
42 49 }
43 50  
44 51 /**
... ... @@ -54,13 +61,36 @@ function displayCategoryLink($sCategoryName) {
54 61 $sCategoryName);
55 62 }
56 63  
  64 +function renderCategoryResults($aResults) {
  65 + $sToRender = "";
  66 +
  67 + // if the first value in arr["categories"] == Categories then we've got a list of categories
  68 + if ($aResults["categories"][0] == "Categories") {
  69 + // loop through categories and display them
  70 + for ($i=1; $i<count($aResults["categories"]); $i++) {
  71 + $sToRender .= "<tr><td>" . displayCategoryLink($aResults["categories"][$i]) . "</td></tr>";
  72 + }
  73 + } else {
  74 + // else the first entry is the category name, so display the documents in the category
  75 + // with full paths
  76 + $sToRender .= renderDocumentList($aResults["documents"], true);
  77 + }
  78 + return $sToRender;
  79 +}
  80 +
57 81 /**
58 82 * Displays the passed document type path as a link
59 83 *
60 84 * @param string the document type to display
61 85 */
62   -function displayDocumentTypePathLink($aDocumentType) {
63   - return displayDocumentTypeLink(array("name"=>"Document Types")) . " > " . displayDocumentTypeLink($aDocumentType);
  86 +function displayDocumentTypePathLink($aDocumentTypes) {
  87 + // if the first value in arr["categories"] == Categories then we've got a list of categories
  88 + if ($aDocumentTypes[0]["name"] == "Document Types") {
  89 + return displayDocumentTypeLink($aDocumentTypes[0]);
  90 + } else {
  91 + // else the first entry is the category name, so build a little path
  92 + return displayDocumentTypeLink(array("name"=>"Document Types")) . " > " . displayDocumentTypeLink($aDocumentTypes[0]);
  93 + }
64 94 }
65 95  
66 96 /**
... ... @@ -76,4 +106,77 @@ function displayDocumentTypeLink($aDocumentType) {
76 106 $aDocumentType["name"]);
77 107 }
78 108  
  109 +
  110 +function renderDocumentTypeResults($aResults) {
  111 + $sToRender = "";
  112 +
  113 + // if the first value in arr["documentTypes"] == Document Types then we've got a list of document types
  114 + if ($aResults["documentTypes"][0]["name"] == "Document Types") {
  115 + // loop through document types and display them
  116 + for ($i=1; $i<count($aResults["documentTypes"]); $i++) {
  117 + $sToRender .= "<tr><td>" . displayDocumentTypeLink($aResults["documentTypes"][$i]) . "</td></tr>";
  118 + }
  119 + } else {
  120 + // else the first entry is the document type name, so display the documents in the document type
  121 + // with full paths
  122 + $sToRender .= renderDocumentList($aResults["documents"], true);
  123 + }
  124 + return $sToRender;
  125 +}
  126 +
  127 +
  128 +function renderFolderResults($aResults) {
  129 + global $default;
  130 + $sToRender = "";
  131 + // now loop through the rest of the folders and display links
  132 + for ($i=1; $i<count($aResults["folders"]); $i++) {
  133 + $sRow = displayFolderLink($aResults["folders"][$i]);
  134 + $sToRender .= "<tr><td>" . $sRow . "</td></tr>";
  135 + }
  136 +
  137 + $sToRender .= "<tr><td>&nbsp;</td></tr>";
  138 + $sToRender .= "<tr><td>" . renderDocumentList($aResults["documents"]) . "</td></tr>";
  139 +
  140 + return $sToRender;
  141 +}
  142 +
  143 +function renderDocumentList($aDocuments, $bDisplayFullPath = false) {
  144 + // loop through the files and display links
  145 + for ($i=0; $i<count($aDocuments); $i++) {
  146 + $sToRender .= "<tr><td>" . displayDocumentLink($aDocuments[$i], $bDisplayFullPath) . "</td></tr>";
  147 + }
  148 + return $sToRender;
  149 +}
  150 +
  151 +function renderPage($aResults, $sBrowseType) {
  152 + // browse type select
  153 + $sToRender = "<table border=\"0\" width=\"100%\">\n";
  154 + $sToRender .= "\t<tr><td>" . renderBrowseTypeSelect($sBrowseType) . "</tr></td>";
  155 + $sToRender .= "\t</table>";
  156 +
  157 + // current path
  158 + $sToRender .= "<table border=\"1\" width=\"100%\">\n";
  159 + $sToRender .= "\t<tr><td>";
  160 + switch ($sBrowseType) {
  161 + case "folder" : $sToRender .= displayFolderPathLink(Folder::getFolderPathAsArray($aResults["folders"][0]->getID())); break;
  162 + case "category" : $sToRender .= displayCategoryPathLink($aResults["categories"]); break;
  163 + case "documentType" : $sToRender .= displayDocumentTypePathLink($aResults["documentTypes"]); break;
  164 + }
  165 + $sToRender .= "</tr></td>\n";
  166 + $sToRender .= "\t</table>";
  167 +
  168 + // display folders|documents
  169 + $sToRender .= "<table border=\"0\">\n";
  170 + $sToRender .= "<tr><td>\n";
  171 + switch ($sBrowseType) {
  172 + case "folder" : $sToRender .= renderFolderResults($aResults); break;
  173 + case "category" : $sToRender .= renderCategoryResults($aResults); break;
  174 + case "documentType" : $sToRender .= renderDocumentTypeResults($aResults); break;
  175 + }
  176 + $sToRender .= "</tr></td>\n";
  177 + $sToRender .= "\t</table>";
  178 +
  179 + return $sToRender;
  180 +}
  181 +
79 182 ?>
... ...