00001 <?php
00016 class SMWPropertyListValue extends SMWDataValue {
00017
00022 protected $m_diProperties;
00023
00024 protected function parseUserValue( $value ) {
00025 global $wgContLang;
00026
00027 $this->m_diProperties = array();
00028 $stringValue = '';
00029 $valueList = preg_split( '/[\s]*;[\s]*/u', trim( $value ) );
00030 foreach ( $valueList as $propertyName ) {
00031 $propertyNameParts = explode( ':', $propertyName, 2 );
00032 if ( count( $propertyNameParts ) > 1 ) {
00033 $namespace = smwfNormalTitleText( $propertyNameParts[0] );
00034 $propertyName = $propertyNameParts[1];
00035 $propertyNamespace = $wgContLang->getNsText( SMW_NS_PROPERTY );
00036 if ( $namespace != $propertyNamespace ) {
00037 $this->addError( wfMsgForContent( 'smw_wrong_namespace', $propertyNamespace ) );
00038 }
00039 }
00040
00041 $propertyName = smwfNormalTitleText( $propertyName );
00042
00043 try {
00044 $diProperty = SMWDIProperty::newFromUserLabel( $propertyName );
00045 } catch ( SMWDataItemException $e ) {
00046 $diProperty = new SMWDIProperty( 'Error' );
00047 $this->addError( wfMsgForContent( 'smw_noproperty', $propertyName ) );
00048 }
00049
00050 $this->m_diProperties[] = $diProperty;
00051 $stringValue .= ( $stringValue ? ';' : '' ) . $diProperty->getKey();
00052 }
00053
00054 try {
00055 $this->m_dataitem = new SMWDIString( $stringValue );
00056 } catch ( SMWStringLengthException $e ) {
00057 $this->m_dataitem = new SMWDIString( 'Error' );
00058 $this->addError( wfMsgForContent( 'smw_maxstring', $stringValue ) );
00059 }
00060 }
00061
00069 protected function loadDataItem( SMWDataItem $dataItem ) {
00070 if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
00071 $this->m_dataitem = $dataItem;
00072 $this->m_diProperties = array();
00073
00074 foreach ( explode( ';', $dataItem->getString() ) as $propertyKey ) {
00075 try {
00076 $this->m_diProperties[] = new SMWDIProperty( $propertyKey );
00077 } catch ( SMWDataItemException $e ) {
00078 $this->m_diProperties[] = new SMWDIProperty( 'Error' );
00079 $this->addError( wfMsgForContent( 'smw_parseerror' ) );
00080 }
00081 }
00082
00083 $this->m_caption = false;
00084
00085 return true;
00086 } else {
00087 return false;
00088 }
00089 }
00090
00091 public function getShortWikiText( $linked = null ) {
00092 return ( $this->m_caption !== false ) ? $this->m_caption : $this->makeOutputText( 2, $linked );
00093 }
00094
00095 public function getShortHTMLText( $linker = null ) {
00096 return ( $this->m_caption !== false ) ? $this->m_caption : $this->makeOutputText( 3, $linker );
00097 }
00098
00099 public function getLongWikiText( $linked = null ) {
00100 return $this->makeOutputText( 2, $linked );
00101 }
00102
00103 public function getLongHTMLText( $linker = null ) {
00104 return $this->makeOutputText( 3, $linker );
00105 }
00106
00107 public function getWikiValue() {
00108 return $this->makeOutputText( 4 );
00109 }
00110
00111 public function getPropertyDataItems() {
00112 return $this->m_diProperties;
00113 }
00114
00116
00117 protected function makeOutputText( $type, $linker = null ) {
00118 if ( !$this->isValid() ) {
00119 return ( ( $type == 0 ) || ( $type == 1 ) ) ? '' : $this->getErrorText();
00120 }
00121 $result = '';
00122 $sep = ( $type == 4 ) ? '; ' : ', ';
00123 foreach ( $this->m_diProperties as $diProperty ) {
00124 if ( $result !== '' ) $result .= $sep;
00125 $propertyValue = SMWDataValueFactory::newDataItemValue( $diProperty, null );
00126 $result .= $this->makeValueOutputText( $type, $propertyValue, $linker );
00127 }
00128 return $result;
00129 }
00130
00131 protected function makeValueOutputText( $type, $propertyValue, $linker ) {
00132 switch ( $type ) {
00133 case 0: return $propertyValue->getShortWikiText( $linker );
00134 case 1: return $propertyValue->getShortHTMLText( $linker );
00135 case 2: return $propertyValue->getLongWikiText( $linker );
00136 case 3: return $propertyValue->getLongHTMLText( $linker );
00137 case 4: return $propertyValue->getWikiValue();
00138 }
00139 }
00140
00141 }