00001 <?php
00002
00008 abstract class SDRHelpers extends SObject {
00009
00010 const SNAPDIR = "http://www.shodor.org/media/content//sdr/";
00011
00012
00013 public static $GET_ATTRS = array(
00014 'reviewId' => array( 'type' => SValidation::TYPE_NUMBER,
00015 'null' => false),
00016 'cserdId' => array( 'type' => SValidation::TYPE_NUMBER,
00017 'null' => false),
00018 'form' => array( 'type' => SValidation::TYPE_ALPHA,
00019 'null' => false),
00020 'ss' => array( 'type' => SValidation::TYPE_STRING,
00021 'null' => true),
00022 'sr' => array( 'type' => SValidation::TYPE_NUMBER,
00023 'null' => true),
00024 'orderBy' => array( 'type' => SValidation::TYPE_ALPHA,
00025 'null' => true)
00026 );
00027
00028
00034 public static function getResourceFromSDR($id) {
00035 $ss = new SDRSearchService();
00036 $resource = $ss->getResource($id, array('extra' => array('metadata')));
00037 if (!$resource) {
00038 return null;
00039 }
00040 return $resource;
00041 }
00042
00048 public static function getRatingImageTag($rating){
00049 if ($rating == 0) return '<small>(Not Rated)</small>';
00050 $ratingPath = self::SNAPDIR . "rating/stars-" . (int)$rating;
00051 $ratingAlt = self::getRatingText($rating);
00052 return "<img src='$ratingPath' alt='User Rating: $ratingAlt'/>";
00053 }
00054
00060 public static function getRatingText($rating){
00061 return (($rating == 0) ? '' : $rating . ' / 5');
00062 }
00063
00068 public static function urlParser($addArgs = null, $removeArgs = null) {
00069
00070 $url = $_SERVER['REQUEST_URI'];
00071
00072
00073 $parts = explode('?', $url);
00074 $urlBase = $parts[0];
00075
00076
00077 $urlArgs = self::parseArguments($addArgs, $removeArgs);
00078
00079
00080 $newURL = $urlBase;
00081
00082
00083 if (count($urlArgs) > 0) {
00084 $newURL .= "?";
00085 }
00086
00087
00088 foreach ($urlArgs as $key => $value) {
00089 if ($value == '')
00090 $newURL .= "$key&";
00091 else
00092 $newURL .= "$key=$value&";
00093 }
00094
00095
00096 if (count($urlArgs) > 0) {
00097 $newURL = substr($newURL, 0, -1);
00098 }
00099
00100 return $newURL;
00101 }
00102
00107 public static function parseArguments($addArgs = null, $removeArgs = null) {
00108
00109 $url = $_SERVER['REQUEST_URI'];
00110
00111
00112 $parts = explode('?', $url);
00113
00114 $urlArgs = array();
00115
00116 if (isset($parts[1])) {
00117 $argParts = explode('&', $parts[1]);
00118 foreach($argParts as $argPart) {
00119 $defParts = explode('=', $argPart);
00120 if (isset($defParts[1]))
00121 $urlArgs[$defParts[0]] = $defParts[1];
00122 else
00123 $urlArgs[$defParts[0]] = '';
00124 }
00125 }
00126
00127 if ($addArgs != null) {
00128 foreach($addArgs as $key => $value) {
00129 $urlArgs[$key] = $value;
00130 }
00131 }
00132
00133
00134 if ($removeArgs != null) {
00135 foreach($removeArgs as $key => $value) {
00136 unset($urlArgs[$key]);
00137 }
00138 }
00139
00140 return $urlArgs;
00141 }
00142
00143 }
00144
00145 ?>