00001 <?php
00013 class SMWBoolValue extends SMWDataValue {
00014
00019 protected $m_truecaption;
00020
00025 protected $m_falsecaption;
00026
00027 protected function parseUserValue( $value ) {
00028 $value = trim( $value );
00029 if ( $this->m_caption === false ) {
00030 $this->m_caption = $value;
00031 }
00032
00033 $lcv = strtolower( $value );
00034 $boolvalue = false;
00035 if ( $lcv === '1' ) {
00036 $boolvalue = true;
00037 } elseif ( $lcv === '0' ) {
00038 $boolvalue = false;
00039 } elseif ( in_array( $lcv, explode( ',', wfMsgForContent( 'smw_true_words' ) ), true ) ) {
00040 $boolvalue = true;
00041 } elseif ( in_array( $lcv, explode( ',', wfMsgForContent( 'smw_false_words' ) ), true ) ) {
00042 $boolvalue = false;
00043 } else {
00044 $this->addError( wfMsgForContent( 'smw_noboolean', $value ) );
00045 }
00046 $this->m_dataitem = new SMWDIBoolean( $boolvalue, $this->m_typeid );
00047 }
00048
00054 protected function loadDataItem( SMWDataItem $dataItem ) {
00055 if ( $dataItem->getDIType() == SMWDataItem::TYPE_BOOLEAN ) {
00056 $this->m_dataitem = $dataItem;
00057 $this->m_caption = $this->getStandardCaption( true );
00058 return true;
00059 } else {
00060 return false;
00061 }
00062 }
00063
00064 public function setOutputFormat( $formatstring ) {
00065 if ( $formatstring == $this->m_outformat ) return;
00066 unset( $this->m_truecaption );
00067 unset( $this->m_falsecaption );
00068 if ( $formatstring === '' ) {
00069
00070 } elseif ( strtolower( $formatstring ) == '-' ) {
00071 $this->m_truecaption = 'true';
00072 $this->m_falsecaption = 'false';
00073 } elseif ( strtolower( $formatstring ) == 'x' ) {
00074 $this->m_truecaption = '<span style="font-family: sans-serif; ">X</span>';
00075 $this->m_falsecaption = '';
00076 } else {
00077 $captions = explode( ',', $formatstring, 2 );
00078 if ( count( $captions ) == 2 ) {
00079 $this->m_truecaption = htmlspecialchars( trim( $captions[0] ) );
00080 $this->m_falsecaption = htmlspecialchars( trim( $captions[1] ) );
00081 }
00082 }
00083 $this->m_caption = $this->getStandardCaption( true );
00084 $this->m_outformat = $formatstring;
00085 }
00086
00087 public function getShortWikiText( $linked = null ) {
00088 return $this->m_caption;
00089 }
00090
00091 public function getShortHTMLText( $linker = null ) {
00092 return $this->m_caption;
00093 }
00094
00095 public function getLongWikiText( $linked = null ) {
00096 return $this->isValid() ? $this->getStandardCaption( true ) : $this->getErrorText();
00097 }
00098
00099 public function getLongHTMLText( $linker = null ) {
00100 return $this->isValid() ? $this->getStandardCaption( true ) : $this->getErrorText();
00101 }
00102
00103 public function getWikiValue() {
00104 return $this->getStandardCaption( false );
00105 }
00106
00107 public function getBoolean() {
00108 return $this->m_dataitem->getBoolean();
00109 }
00110
00117 protected function getStandardCaption( $useformat ) {
00118 if ( !$this->isValid() ) return false;
00119 if ( $useformat && ( isset( $this->m_truecaption ) ) ) {
00120 return $this->m_dataitem->getBoolean() ? $this->m_truecaption : $this->m_falsecaption;
00121 } else {
00122 $vals = explode( ',', wfMsgForContent( $this->m_dataitem->getBoolean() ? 'smw_true_words' : 'smw_false_words' ) );
00123 return reset( $vals );
00124 }
00125 }
00126
00127 }