Transport\Entity\Transportations::reduceTransportations PHP Method

reduceTransportations() public static method

Converts a list of transportation strings into a bitmask accepted by the SBB.
public static reduceTransportations ( string[] $transportations = [], integer $limit = 16, boolean $lsb0 = true ) : string
$transportations string[] A list of transportations
$limit integer Maximum number of transportations (bits)
$lsb0 boolean Least significant bit first, LSB 0
return string A binary representation of the transportations given
    public static function reduceTransportations($transportations = [], $limit = 16, $lsb0 = true)
    {
        $dec = self::reduceTransportationsDec($transportations, $limit);
        $binary = sprintf('%0' . $limit . 'b', $dec);
        if ($lsb0) {
            // flip for SBB
            $binary = strrev($binary);
        }
        return $binary;
    }

Usage Example

Ejemplo n.º 1
0
 public function toXml()
 {
     if ($this->isArrivalTime == false) {
         $forwardCount = $this->limit;
         $backwardCount = 0;
     } else {
         $forwardCount = 0;
         $backwardCount = $this->limit;
     }
     $transportationsBinary = Transportations::reduceTransportations($this->transportations);
     $request = $this->createRequest();
     $con = $request->addChild('ConReq');
     $start = $con->addChild('Start');
     $this->srcLocation->toXml($start);
     $prod = $start->addChild('Prod');
     $prod['prod'] = $transportationsBinary;
     if ($this->direct) {
         $prod['direct'] = 1;
     }
     if ($this->sleeper) {
         $prod['sleeper'] = 1;
     }
     if ($this->couchette) {
         $prod['couchette'] = 1;
     }
     if ($this->bike) {
         $filterList = $con->addChild('FilterList');
         $attrFilter = $filterList->addChild('ConReqAttrFilter');
         $attrFilter['mode'] = '1';
         $attrFilter['type'] = 'EXC';
         $attrFilter['value'] = 'VN:VX';
     }
     $dest = $con->addChild('Dest');
     $this->dstLocation->toXml($dest);
     foreach ($this->viaLocations as $location) {
         $via = $con->addChild('Via');
         $location->toXml($via);
         $prod = $via->addChild('Prod');
         $prod['prod'] = $transportationsBinary;
     }
     $reqt = $con->addChild('ReqT');
     if ($this->isArrivalTime) {
         $reqt['a'] = 1;
     } else {
         $reqt['a'] = 0;
     }
     $reqt['date'] = date('Ymd', strtotime($this->date));
     $reqt['time'] = date('H:i', strtotime($this->time));
     $rflags = $con->addChild('RFlags');
     $rflags['b'] = $backwardCount;
     $rflags['f'] = $forwardCount;
     $rflags['sMode'] = $this->searchMode;
     if ($this->changeCount >= 0) {
         $rflags['nrChanges'] = $this->changeCount;
     }
     if ($this->changeExtensionPercent > 0) {
         $rflags['chExtension'] = $this->changeExtensionPercent;
     }
     return $request->asXML();
 }
All Usage Examples Of Transport\Entity\Transportations::reduceTransportations