00001 <?php
00002
00015 class SMWParamFormat extends ItemParameterManipulation {
00016
00026 protected $printRequests = null;
00027
00033 public function __construct() {
00034 parent::__construct();
00035 }
00036
00042 public function doManipulation( &$value, Parameter $parameter, array &$parameters ) {
00043
00044 $value = self::getValidFormatName( $value );
00045
00046
00047 $queryPrinter = SMWQueryProcessor::getResultPrinter( $value );
00048
00049 $parameters = array_merge( $parameters, $queryPrinter->getValidatorParameters() );
00050 }
00051
00063 protected function getValidFormatName( $value ) {
00064 global $smwgResultFormats;
00065
00066 $value = strtolower( trim( $value ) );
00067
00068 if ( !array_key_exists( $value, $smwgResultFormats ) ) {
00069 $isAlias = self::resolveFormatAliases( $value );
00070
00071 if ( !$isAlias ) {
00072 $value = $this->getDefaultFormat();
00073 }
00074 }
00075
00076 return $value;
00077 }
00078
00088 public static function resolveFormatAliases( &$format ) {
00089 global $smwgResultAliases;
00090
00091 $isAlias = false;
00092
00093 foreach ( $smwgResultAliases as $mainFormat => $aliases ) {
00094 if ( in_array( $format, $aliases ) ) {
00095 $format = $mainFormat;
00096 $isAlias = true;
00097 break;
00098 }
00099 }
00100
00101 return $isAlias;
00102 }
00103
00112 protected function getDefaultFormat() {
00113 if ( is_null( $this->printRequests ) ) {
00114 return 'table';
00115 }
00116 else {
00117 $format = false;
00118
00125 wfRunHooks( 'SMWResultFormat', array( &$format, $this->printRequests, array() ) );
00126
00127
00128 if ( $format === false ) {
00129 $format = count( $this->printRequests ) == 1 ? 'list' : 'table';
00130 }
00131
00132 return $format;
00133 }
00134 }
00135
00144 public function setPrintRequests( array $printRequests ) {
00145 $this->printRequests = $printRequests;
00146 }
00147
00148 }