00001 <?php
00015 class SMWTypeListValue extends SMWDataValue {
00016
00021 protected $m_typevalues;
00022
00023 protected function parseUserValue( $value ) {
00024 $this->m_typevalues = array();
00025 $types = explode( ';', $value );
00026 foreach ( $types as $type ) {
00027 $tval = SMWDataValueFactory::newTypeIDValue( '__typ', $type );
00028 $this->m_typevalues[] = $tval;
00029 }
00030 $this->setDataItemFromTypeValues();
00031 }
00032
00038 protected function loadDataItem( SMWDataItem $dataItem ) {
00039 if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
00040 $this->m_dataitem = $dataItem;
00041 $this->m_typevalues = array();
00042 $ids = explode( ';', $dataItem->getString() );
00043 foreach ( $ids as $id ) {
00044 $this->m_typevalues[] = SMWDataValueFactory::newTypeIDValue( '__typ', SMWDataValueFactory::findTypeLabel( $id ) );
00045 }
00046 $this->m_caption = false;
00047 return true;
00048 } else {
00049 return false;
00050 }
00051 }
00052
00061 protected function setDataItemFromTypeValues() {
00062 $stringvalue = '';
00063 foreach ( $this->m_typevalues as $tv ) {
00064 if ( $stringvalue != '' ) $stringvalue .= ';';
00065 $stringvalue .= $tv->getDBkey();
00066 }
00067 try {
00068 $this->m_dataitem = new SMWDIString( $stringvalue, $this->m_typeid );
00069 } catch ( SMWStringLengthException $e ) {
00070 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
00071 $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $stringvalue . '"' ) );
00072 $this->m_dataitem = new SMWDIString( 'ERROR', $this->m_typeid );
00073 }
00074 }
00075
00076 public function getShortWikiText( $linked = null ) {
00077 return ( $this->m_caption !== false ) ? $this->m_caption : $this->makeOutputText( 0, $linked );
00078 }
00079
00080 public function getShortHTMLText( $linker = null ) {
00081 return ( $this->m_caption !== false ) ? $this->m_caption : $this->makeOutputText( 1, $linker );
00082 }
00083
00084 public function getLongWikiText( $linked = null ) {
00085 return $this->makeOutputText( 2, $linked );
00086 }
00087
00088 public function getLongHTMLText( $linker = null ) {
00089 return $this->makeOutputText( 3, $linker );
00090 }
00091
00092 public function getWikiValue() {
00093 return $this->makeOutputText( 4 );
00094 }
00095
00096 public function getTypeValues() {
00097 return $this->m_typevalues;
00098 }
00099
00101
00102 protected function makeOutputText( $type = 0, $linker = null ) {
00103 if ( !$this->isValid() ) {
00104 return ( ( $type == 0 ) || ( $type == 1 ) ) ? '' : $this->getErrorText();
00105 }
00106 $result = '';
00107 $sep = ( $type == 4 ) ? '; ' : ', ';
00108 foreach ( $this->m_typevalues as $tv ) {
00109 if ( $result != '' ) $result .= $sep;
00110 $result .= $this->makeValueOutputText( $type, $tv, $linker );
00111 }
00112 return $result;
00113 }
00114
00115 protected function makeValueOutputText( $type, $datavalue, $linker ) {
00116 switch ( $type ) {
00117 case 0: return $datavalue->getShortWikiText( $linker );
00118 case 1: return $datavalue->getShortHTMLText( $linker );
00119 case 2: return $datavalue->getLongWikiText( $linker );
00120 case 3: return $datavalue->getLongHTMLText( $linker );
00121 case 4: return $datavalue->getWikiValue();
00122 }
00123 }
00124
00125 }