OptomPortalConnection::signatureSearch PHP Method

signatureSearch() public method

Search the API for signatures.
public signatureSearch ( $start_date = null, $uniqueId = null ) : mixed
return mixed
    public function signatureSearch($start_date = null, $uniqueId = null)
    {
        if ($uniqueId && $this->client) {
            $this->client->setUri($this->config['uri'] . str_replace('searches', $uniqueId, $this->config['endpoints']['signatures']));
            $method = 'GET';
            // just to make sure that start date is not specified
            $start_date = null;
        } else {
            if ($this->client) {
                $this->client->setUri($this->config['uri'] . $this->config['endpoints']['signatures']);
                $method = 'POST';
            }
        }
        if ($start_date && $this->client) {
            $this->client->setParameterPost(array('start_date' => $start_date));
        }
        if ($this->client) {
            $response = $this->client->request($method);
            return json_decode($response->getBody(), true);
        }
    }

Usage Example

Example #1
0
 public function actionGetSignatureFromPortal()
 {
     if (Yii::app()->user->id) {
         // TODO: query the portal here:
         // TODO: get current unique ID for the user
         // TODO: query the portal with the current unique ID
         // TODO: if successfull save the signature as a ProtectedFile
         // from the portal we receive binary data:
         $user = User::model()->findByPk(Yii::app()->user->id);
         $portal_conn = new OptomPortalConnection();
         if ($portal_conn) {
             $signature_data = $portal_conn->signatureSearch(null, $user->generateUniqueCodeWithChecksum($this->getUniqueCodeForUser()));
             if (is_array($signature_data) && isset($signature_data["image"])) {
                 $signature_file = $portal_conn->createNewSignatureImage($signature_data["image"], Yii::app()->user->id);
                 if ($signature_file) {
                     $user->signature_file_id = $signature_file->id;
                     if ($user->save()) {
                         echo true;
                     }
                 }
             }
         }
     }
     echo false;
 }