/**
  * Retrieve all SMSs that were sent to a selected recipient. 
  * Select recipient by ID.
  * @param int|string $recipientId
  * @param boolean $unseen Optional. If you want to retrieve only unseen SMSs.
  * @return array(SMS)
  */
 public function get_all_recipient_SMSs($recipientId, $unseen = false)
 {
     $SMS = new ModelTemplate('SMS');
     $SMSs = null;
     if ($unseen) {
         $SMSs = $SMS->get_all(array('recipient_id', 'is_seen', 'is_resolved'), array($recipientId, 'false', 'false'));
     } else {
         $SMSs = $SMS->get_all(array('recipient_id', 'is_resolved'), array($recipientId, 'false'));
     }
     if ($SMSs) {
         $truckDriverCtr = new TruckDriver_Controller();
         $logisticianCtr = new Logistician_Controller();
         // Retrieve SMSs' senders and recipients.
         foreach ($SMSs as $key => &$SMS) {
             if ($sender = $truckDriverCtr->get_truck_driver_by_id($SMS->sender_id)) {
                 $SMS->sender_id = $sender;
             }
             if ($recipient = $logisticianCtr->get_logistician_by_id($SMS->recipient_id)) {
                 $SMS->recipient_id = $recipient;
             }
             // If no sender and recipient delete SMS.
             if (!($sender && $recipient)) {
                 unset($SMSs[$key]);
             }
         }
     }
     return $SMSs;
 }
 /**
  * Process the following URI:
  * api/v1/logistician/ - to get a logistician. 
  * api/v1/logistician/{id}/sms/ - to get all SMSs that the logistician has received.
  * api/v1/logistician/{id}/sms/unseen/ - to get only SMSs that are unseen.
  * api/v1/logistician/{id}/sms/count/ - count all SMSs that the logistician has received.
  * api/v1/logistician/{id}/sms/unseen/count/ - count only SMSs that are unseen.
  * 
  * To get a logistician, an Authorization header must be added to the request 
  * with {username}:{SHA 256 hashed password}.
  * @return Logistician
  */
 private function process_logistician_get()
 {
     // URI: api/v1/logistician/
     if (empty($this->arguments) && $this->verb === '') {
         // There should be an Authorization header in the request, to log in.
         $headers = apache_request_headers();
         if (isset($headers['Authorization'])) {
             // Username (plain text): Password (hashed with SHA 256).
             $credentials = explode(':', $headers['Authorization']);
             $logisticianCtr = new Logistician_Controller();
             // Return a logistician, if the credentials are valid, otherwise return null.
             if ($logistician = $logisticianCtr->get_logistician_by_credentials($credentials[0], $credentials[1])) {
                 return $logistician->get_all_fields();
             }
         }
     } elseif (count($this->arguments) > 1 && $this->arguments[1] === 'sms') {
         $SMSCtr = new SMS_Controller();
         // URI: api/v1/logistician/{id}/sms/ || api/v1/logistician/{id}/sms/unseen/
         if (count($this->arguments) === 2 || count($this->arguments) === 3 && $this->arguments[2] === 'unseen') {
             $SMSs = null;
             if ($this->arguments[1] === 'unseen') {
                 $SMSs = $SMSCtr->get_all_recipient_SMSs($this->arguments[0], 'true');
             } else {
                 $SMSs = $SMSCtr->get_all_recipient_SMSs($this->arguments[0]);
             }
             if ($SMSs) {
                 foreach ($SMSs as &$sms) {
                     $sms->sender_id = $sms->sender_id->get_all_fields();
                     $sms->recipient_id = $sms->recipient_id->get_all_fields();
                     $sms = $sms->get_all_fields();
                 }
             }
             return $SMSs;
         } elseif (count($this->arguments) === 3 && $this->arguments[2] === 'count' || count($this->arguments) === 4 && $this->arguments[3] === 'count') {
             if ($this->arguments[2] === 'unseen') {
                 return $SMSCtr->count_all_recipient_SMSs($this->arguments[0], 'true');
             } else {
                 return $SMSCtr->count_all_recipient_SMSs($this->arguments[0]);
             }
         }
     }
     return null;
 }