Campustream 1.0
A social network MQP for WPI
application/lib/PhlockDB/Phlock/QueryTerm.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class Phlock_QueryTerm {
00004         
00005         private $source;
00006         private $graph_id;
00007         private $destination;
00008         private $states;
00009         
00010         public function __construct($source, $graph_id, $destination, array $states = null) {
00011                 $this->source = $source;
00012                 $this->graph_id = $graph_id;
00013                 $this->destination = $destination;
00014                 $this->states = $states;
00015         }
00016         
00017         public function toThrift() {
00018                 $forward = is_numeric($this->source);
00019                 if ($forward) {
00020                         $source_id = $this->source;
00021                         $destination_ids = $this->destination;
00022                 } else {
00023                         $source_id = $this->destination;
00024                         $destination_ids = $this->source;
00025                 }
00026                 if ($destination_ids) {
00027                         $destination_ids = $this->packDestinationIds(is_array($destination_ids) ? $destination_ids : array($destination_ids));
00028                 }
00029                 $term = new Flock_QueryTerm(array(
00030                         'source_id'=>$source_id,
00031                         'graph_id'=>$this->graph_id,
00032                         'is_forward'=>$forward,
00033                         'destination_ids'=>$destination_ids,
00034                         'states'=>$this->states
00035                 ));
00036                 return $term;
00037         }
00038         
00039         private function packDestinationIds(array $ids) {
00040                 $pack = '';
00041                 foreach ($ids as $id) {
00042                         for ($i = 0; $i < 8; $i++) {
00043                                 $pack .= chr($id & 0xff);
00044                                 $id = $id >> 8;
00045                         }
00046                 }
00047                 return $pack;
00048         }
00049 }