00001 <?php
00019 class SMWRecordDescription extends SMWConjunction {
00020
00021 public function getQueryString( $asvalue = false ) {
00022 if ( !$asvalue ) {
00023 return '';
00024 }
00025 $fields = array();
00026 $maxpos = - 1;
00027 foreach ( $this->m_descriptions as $desc ) {
00028 if ( $desc instanceof SMWRecordFieldDescription ) {
00029 $fields[$desc->getPosition()] = $desc->getDescription()->getQueryString( true );
00030 if ( $maxpos < $desc->getPosition() ) {
00031 $maxpos = $desc->getPosition();
00032 }
00033 }
00034 }
00035 if ( $maxpos < 0 ) {
00036 return '+';
00037 } else {
00038 $result = '';
00039 for ( $i = 0; $i <= $maxpos; $i++ ) {
00040 $result .= ( $result != '' ? '; ' : '' ) . ( array_key_exists( $i, $fields ) ? $fields[$i] : '?' );
00041 }
00042 return $result;
00043 }
00044 }
00045
00046 public function prune( &$maxsize, &$maxdepth, &$log ) {
00047 if ( $maxsize <= 0 ) {
00048 $log[] = $this->getQueryString();
00049 return new SMWThingDescription();
00050 }
00051 $prunelog = array();
00052 $newdepth = $maxdepth;
00053 $result = new SMWRecordDescription();
00054 foreach ( $this->m_descriptions as $desc ) {
00055 $restdepth = $maxdepth;
00056 $result->addDescription( $desc->prune( $maxsize, $restdepth, $prunelog ) );
00057 $newdepth = min( $newdepth, $restdepth );
00058 }
00059 if ( count( $result->getDescriptions() ) > 0 ) {
00060 $log = array_merge( $log, $prunelog );
00061 $maxdepth = $newdepth;
00062 if ( count( $result->getDescriptions() ) == 1 ) {
00063 $descriptions = $result->getDescriptions();
00064 $result = array_shift( $descriptions );
00065 }
00066 $result->setPrintRequests( $this->getPrintRequests() );
00067 return $result;
00068 } else {
00069 $log[] = $this->getQueryString();
00070 $result = new SMWThingDescription();
00071 $result->setPrintRequests( $this->getPrintRequests() );
00072 return $result;
00073 }
00074 }
00075 }
00076
00077 class SMWRecordFieldDescription extends SMWSomeProperty {
00078 protected $m_position;
00079
00080 public function __construct( $position, SMWDescription $description ) {
00081 parent::__construct( new SMWDIProperty( '_' . ( $position + 1 ) ), $description );
00082 $this->m_position = $position;
00083 }
00084
00085 public function getPosition() {
00086 return $this->m_position;
00087 }
00088
00089 public function getQueryString( $asvalue = false ) {
00090 if ( !$asvalue ) {
00091 return '';
00092 }
00093 $prefix = '';
00094 for ( $i = 0; $i < $this->m_position; $i++ ) {
00095 $prefix .= '?; ';
00096 }
00097 return $prefix . $this->m_description->getQueryString( true );
00098 }
00099
00100 public function prune( &$maxsize, &$maxdepth, &$log ) {
00101 if ( ( $maxsize <= 0 ) || ( $maxdepth <= 0 ) ) {
00102 $log[] = $this->getQueryString();
00103 return new SMWThingDescription();
00104 }
00105 $maxsize--;
00106 $maxdepth--;
00107 $result = new SMWRecordFieldDescription( $this->m_position, $this->m_description->prune( $maxsize, $maxdepth, $log ) );
00108 $result->setPrintRequests( $this->getPrintRequests() );
00109 return $result;
00110 }
00111 }