00001 <?php
00002
00003 #doc
00004 # classname: TransNSDLSearchXML
00005 # scope: PUBLIC
00006 #
00007 #/doc
00008
00009 class TransSDRResourceResultSet extends STransObject
00010 {
00011
00012
00013
00014
00015 public function translate ($si)
00016 {
00017 if (parent::translate($si) == false) return false;
00018
00019 $results = $si->getSource();
00020
00021
00022
00023 # Start with a blank string to add output content to
00024 $output = "";
00025
00026 # add the header
00027 $output .= $this->addHeaderFooter($results);
00028 $output .= $this->addForwardBackButtons($results);
00029
00030
00031 if ($results->getTotalNumResults() == 0) {
00032 $output .= "<b>No matching results were found</b>.";
00033 }
00034
00035 $imageDir = opendir(SConfig::getOption('hpcu.contributors'));
00036 $contributorIcons = array();
00037
00038 while($imageName = readdir($imageDir)) {
00039
00040 $contributor = substr($imageName, 0, strripos($imageName, ".jpg"));
00041
00042 if (strlen($contributor) > 0) {
00043 array_push($contributorIcons, $contributor);
00044 }
00045 }
00046
00047
00048 # print the results
00049 $counter = 0;
00050
00051 while ($doc = $results->nextRow()) {
00052 $output .= $this->renderResultDocument($doc, $counter, $contributorIcons);
00053 $counter++;
00054 }
00055
00056 # add the footer
00057 $output .= $this->addForwardBackButtons($results);
00058 $output .= $this->addHeaderFooter($results);
00059
00060
00061 $this->sendToTarget($si, $output);
00062 parent::translate($si);
00063 }
00064
00065
00066
00067 protected function addHeaderFooter($results) {
00068 global $PATH;
00069
00070 $ss = 'search string goes here ';
00071 $sr = $results->getStartingResult();
00072 $numSkipped = $results->getStartingResult();
00073 $numReturned = $results->getNumReturned();
00074 $total = $results->getTotalNumResults();
00075 $numPerPage = $results->getNumPerPage();
00076
00077 $first = $numSkipped + 1;
00078 $min = min($numSkipped + $numReturned, $total);
00079
00080 if ($ss == "" && isset($_GET['ss'])) { $ss = $_GET['ss']; }
00081 if ($sr == "" && isset($_GET['sr'])) { $sr = $_GET['sr']; }
00082
00083 $action = SWATFunctions::stripArgs($_SERVER['REQUEST_URI']);
00084
00085 $linkbase = explode("?", $_SERVER['REQUEST_URI']);
00086 $args = (count($linkbase) == 2) ? $linkbase[1] : "";
00087 $cserdLink = $PATH['fedsearch'] . "?ss=" . $ss;
00088 $nsdlLink = $PATH['fedsearch'] . "nsdl/?ss=" . $ss;
00089 $title = 'Search HPCU Catalog';
00090
00091 $resultsString = '';
00092
00093
00094
00095 $title = 'Quick Search Results';
00096 $resultsString = <<<END
00097 <tr>
00098 <td colspan="2" style="padding: 10px; background: #FFFFFF;">
00099 <table border="0" cellspacing="0" cellpadding="0" width="100%">
00100 <tr>
00101 <td>Searched for: <b>$ss</b></td>
00102 <td align="right">Results <b>$first - $min</b> of <b>$total</b></td>
00103 </tr>
00104 </table>
00105 </td>
00106 </tr>
00107 END;
00108
00109
00110
00111 $html =<<<END
00112
00113 <table border="0" cellspacing="0" cellpadding="0" style="padding: 0px; background: #F3F6FF; border: 1px solid #CCC; margin: 10px 0px 10px 0px; width: 100%">
00114 <tr>
00115 <td class="header" width="100%" style="padding: 10px;">
00116 <b>$title</b>
00117 <td align="right" nowrap="nowrap" style="padding: 10px;">
00118 <form method="get" action="$action">
00119 <input type="text" name="ss" size="30" maxlength="120" value="$ss" />
00120 <input type="submit" value="Search" />
00121 </form>
00122 </td>
00123 </tr>
00124 $resultsString
00125 </table>
00126
00127 END;
00128 return $html;
00129 }
00130
00131
00132 #
00133 #
00134 protected function addForwardBackButtons($results) {
00135
00136 $sr = $results->getStartingResult();
00137 if ($ss == "" && isset($_GET['ss'])) { $ss = $_GET['ss']; }
00138 if ($sr == "" && isset($_GET['sr'])) { $sr = $_GET['sr']; }
00139
00140 $numSkipped = $results->getStartingResult();
00141 $numReturned = $results->getNumReturned();
00142 $totalNumResults = $results->getTotalNumResults();
00143 $numPerPage = $results->getNumPerPage();
00144
00145
00146 $output = "";
00147 # Display forward and back buttons:
00148
00149 if (($numSkipped + $numReturned) < ($totalNumResults)) {
00150 $newUrl = $this->buildCWISURL($ss, $sr + $numPerPage);
00151 $output .= '<div style="float:right; width: 300px; text-align:right"><a href="' . $newUrl . '">Next ' . $numPerPage . ' Results →</a></div>';
00152 }
00153
00154 if (($numSkipped) > 0) {
00155 $newUrl = $this->buildCWISURL($ss, $sr - $numPerPage);
00156 $output .= '<a href="' . $newUrl . '">← Prev ' . $numPerPage . ' Results</a>';
00157 }
00158
00159 $output .= "<br />";
00160 return $output;
00161 }
00162
00163 #
00164 #
00165 protected function renderResultDocument($doc, $counter, $contributors) {
00166 global $PATH, $prm, $PROJECT_ROOT;
00167
00168 $url = $doc->getResourceIdentifier();
00169 $cserdId = $doc->getCserdId();
00170
00171 $rating = round($doc->getAverageReviewRating());
00172
00173 $ratingImage = '';
00174 $reviewCount = '0 Reviews';
00175 $reviewString = '';
00176
00177 $contributorIcon = '';
00178 foreach ($contributors as $contributor) {
00179 if (stripos($url, $contributor)) {
00180
00181 $contributorIcon = "
00182 <div style='float:right; cursor:pointer;' onclick=\"location.href='http://$contributor';\" >
00183 <img style='max-height:35px;' src='$PATH[contributors]$contributor.jpg' alt='$contributor'/>
00184 </div>";
00185
00186 break;
00187 }
00188 }
00189
00190 if ($numReviews != 0) {
00191 $reviewString = " and Reviews";
00192 $image = "<img src=$PATH[rating]stars-$rating.gif>";
00193 $reviewCount = "$numReviews Review";
00194 if ($numReviews != 1) {
00195 $reviewCount .= "s";
00196 }
00197 $ratingImage = $image . " ($reviewCount)";
00198 }
00199
00200
00201 $title = $doc->getTitle();
00202 $descrip = $doc->getDescription();
00203
00204 if (isset($_GET['ss']) && (strlen($_GET['ss']) > 2)){
00205 $terms = explode(' ', $_GET['ss']);
00206
00207 foreach ($terms as $term) {
00208 if (strlen($term) > 2) {
00209 $title = $this->wrapFoundTerms($term, $title);
00210 $descrip = $this->wrapFoundTerms($term, $descrip);
00211 }
00212 }
00213 }
00214
00215
00216
00217
00218
00219 $type = "";
00220 if (preg_match("/activities/", $url)) {
00221 $type = '<span style="color:#F26B6B;font-weight:bold;">(Activity)</span>';
00222 } else if (preg_match("/lessons/", $url)) {
00223 $type = '<span style="color:#78C370;font-weight:bold;">(Lesson)</span>';
00224 } else if (preg_match("/discussions/", $url)){
00225 $type = '<span style="color:#5E8AE0;font-weight:bold;">(Discussion)</span>';
00226 }
00227
00228 $evenOddClass = ($counter % 2 == 0) ? 'ResultsListItemEven' : 'ResultsListItemOdd';
00229 $mdLink = SiteURL::get(SiteURL::VIEW_CATALOG_ITEM, array('cserdId' => $cserdId));
00230
00231 return <<<END
00232 <div class="$evenOddClass">
00233 <div>
00234 <img style='float:right' src="$brandSrc" alt="$brandAlt" />
00235 $contributorIcon
00236 </div>
00237 <div class="ResultsListItemTitle">
00238 <a href="$url" target="_blank" >$title</a>
00239 </div>
00240 <div style="clear:both"></div>
00241 <span class="resultDescription">
00242 $descrip
00243 </span>
00244 <br />
00245 <a href="$mdLink">View Metadata$reviewString</a> $ratingImage
00246 </div>
00247 <div style='clear:both;'></div>
00248 END;
00249 }
00250
00251 protected function buildCWISURL($ss, $sr) {
00252 $base = SWATFunctions::stripArgs($_SERVER['REQUEST_URI']);
00253 if ($sr < 0) $sr = 0;
00254 $ssString = '';
00255 if ($ss != '')
00256 $ssString = "ss=$ss&";
00257 return $base . "?" . $ssString . "sr=" . $sr;
00258 }
00259
00260 protected function wrapFoundTerms($term, $data) {
00261 return preg_replace("/($term)/i", "<span class=\"highlightedSearchTerm\">$1</span>", $data);
00262 }
00263
00264 }
00265
00266 ?>