commit 5febd4d014e5ad150852dce87ac359fabb472118 Author: root Date: Thu Feb 6 10:09:26 2020 +0000 Init commit diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..e69de29 diff --git a/Twilio/Deserialize.php b/Twilio/Deserialize.php new file mode 100644 index 0000000..171137d --- /dev/null +++ b/Twilio/Deserialize.php @@ -0,0 +1,22 @@ +statusCode = $statusCode; + parent::__construct($message, $code); + } + + /** + * Get the HTTP Status Code of the RestException + * @return int HTTP Status Code + */ + public function getStatusCode() { + return $this->statusCode; + } + + +} \ No newline at end of file diff --git a/Twilio/Exceptions/TwilioException.php b/Twilio/Exceptions/TwilioException.php new file mode 100644 index 0000000..fc0a53b --- /dev/null +++ b/Twilio/Exceptions/TwilioException.php @@ -0,0 +1,9 @@ +curlOptions = $options; + $this->debugHttp = getenv('DEBUG_HTTP_TRAFFIC') === 'true'; + } + + public function request($method, $url, $params = array(), $data = array(), + $headers = array(), $user = null, $password = null, + $timeout = null) { + $options = $this->options($method, $url, $params, $data, $headers, + $user, $password, $timeout); + + $this->lastRequest = $options; + $this->lastResponse = null; + + try { + if (!$curl = curl_init()) { + throw new EnvironmentException('Unable to initialize cURL'); + } + + if (!curl_setopt_array($curl, $options)) { + throw new EnvironmentException(curl_error($curl)); + } + + if (!$response = curl_exec($curl)) { + throw new EnvironmentException(curl_error($curl)); + } + + $parts = explode("\r\n\r\n", $response, 3); + list($head, $body) = ($parts[0] == 'HTTP/1.1 100 Continue') + ? array($parts[1], $parts[2]) + : array($parts[0], $parts[1]); + + if ($this->debugHttp) { + $u = parse_url($url); + $hdrLine = $method . ' ' . $u['path']; + if (isset($u['query']) && strlen($u['query']) > 0 ) { + $hdrLine = $hdrLine . '?' . $u['query']; + } + error_log($hdrLine); + foreach ($headers as $key => $value) { + error_log("$key: $value"); + } + if ($method === 'POST') { + error_log("\n" . $options[CURLOPT_POSTFIELDS] . "\n"); + } + } + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + $responseHeaders = array(); + $headerLines = explode("\r\n", $head); + array_shift($headerLines); + foreach ($headerLines as $line) { + list($key, $value) = explode(':', $line, 2); + $responseHeaders[$key] = $value; + } + + curl_close($curl); + + if (isset($buffer) && is_resource($buffer)) { + fclose($buffer); + } + + if ($this->debugHttp) { + error_log("HTTP/1.1 $statusCode"); + foreach ($responseHeaders as $key => $value) { + error_log("$key: $value"); + } + error_log("\n$body"); + } + + $this->lastResponse = new Response($statusCode, $body, $responseHeaders); + + return $this->lastResponse; + } catch (\ErrorException $e) { + if (isset($curl) && is_resource($curl)) { + curl_close($curl); + } + + if (isset($buffer) && is_resource($buffer)) { + fclose($buffer); + } + + throw $e; + } + } + + public function options($method, $url, $params = array(), $data = array(), + $headers = array(), $user = null, $password = null, + $timeout = null) { + + $timeout = is_null($timeout) + ? self::DEFAULT_TIMEOUT + : $timeout; + $options = $this->curlOptions + array( + CURLOPT_URL => $url, + CURLOPT_HEADER => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_INFILESIZE => Null, + CURLOPT_HTTPHEADER => array(), + CURLOPT_TIMEOUT => $timeout, + ); + + foreach ($headers as $key => $value) { + $options[CURLOPT_HTTPHEADER][] = "$key: $value"; + } + + if ($user && $password) { + $options[CURLOPT_HTTPHEADER][] = 'Authorization: Basic ' . base64_encode("$user:$password"); + } + + $body = $this->buildQuery($params); + if ($body) { + $options[CURLOPT_URL] .= '?' . $body; + } + + switch (strtolower(trim($method))) { + case 'get': + $options[CURLOPT_HTTPGET] = true; + break; + case 'post': + $options[CURLOPT_POST] = true; + $options[CURLOPT_POSTFIELDS] = $this->buildQuery($data); + + break; + case 'put': + $options[CURLOPT_PUT] = true; + if ($data) { + if ($buffer = fopen('php://memory', 'w+')) { + $dataString = $this->buildQuery($data); + fwrite($buffer, $dataString); + fseek($buffer, 0); + $options[CURLOPT_INFILE] = $buffer; + $options[CURLOPT_INFILESIZE] = strlen($dataString); + } else { + throw new EnvironmentException('Unable to open a temporary file'); + } + } + break; + case 'head': + $options[CURLOPT_NOBODY] = true; + break; + default: + $options[CURLOPT_CUSTOMREQUEST] = strtoupper($method); + } + + return $options; + } + + public function buildQuery($params) { + $parts = array(); + + if (is_string($params)) { + return $params; + } + + $params = $params ?: array(); + + foreach ($params as $key => $value) { + if (is_array($value)) { + foreach ($value as $item) { + $parts[] = urlencode((string)$key) . '=' . urlencode((string)$item); + } + } else { + $parts[] = urlencode((string)$key) . '=' . urlencode((string)$value); + } + } + + return implode('&', $parts); + } +} diff --git a/Twilio/Http/Response.php b/Twilio/Http/Response.php new file mode 100644 index 0000000..cf9f01c --- /dev/null +++ b/Twilio/Http/Response.php @@ -0,0 +1,43 @@ +statusCode = $statusCode; + $this->content = $content; + $this->headers = $headers; + } + + /** + * @return mixed + */ + public function getContent() { + return json_decode($this->content, true); + } + + /** + * @return mixed + */ + public function getStatusCode() { + return $this->statusCode; + } + + public function getHeaders() { + return $this->headers; + } + + public function ok() { + return $this->getStatusCode() < 400; + } + + public function __toString() { + return '[Response] HTTP ' . $this->getStatusCode() . ' ' . $this->content; + } +} diff --git a/Twilio/InstanceContext.php b/Twilio/InstanceContext.php new file mode 100644 index 0000000..341af53 --- /dev/null +++ b/Twilio/InstanceContext.php @@ -0,0 +1,19 @@ +version = $version; + } + + public function __toString() { + return '[InstanceContext]'; + } +} \ No newline at end of file diff --git a/Twilio/InstanceResource.php b/Twilio/InstanceResource.php new file mode 100644 index 0000000..2b802b2 --- /dev/null +++ b/Twilio/InstanceResource.php @@ -0,0 +1,24 @@ +version = $version; + } + + public function toArray() { + return $this->properties; + } + + public function __toString() { + return '[InstanceResource]'; + } +} \ No newline at end of file diff --git a/Twilio/Jwt/AccessToken.php b/Twilio/Jwt/AccessToken.php new file mode 100644 index 0000000..795ff1d --- /dev/null +++ b/Twilio/Jwt/AccessToken.php @@ -0,0 +1,142 @@ +signingKeySid = $signingKeySid; + $this->accountSid = $accountSid; + $this->secret = $secret; + $this->ttl = $ttl; + + if (!is_null($identity)) { + $this->identity = $identity; + } + + $this->grants = array(); + $this->customClaims = array(); + } + + /** + * Set the identity of this access token + * + * @param string $identity identity of the grant + * + * @return $this updated access token + */ + public function setIdentity($identity) { + $this->identity = $identity; + return $this; + } + + /** + * Returns the identity of the grant + * + * @return string the identity + */ + public function getIdentity() { + return $this->identity; + } + + /** + * Set the nbf of this access token + * + * @param integer $nbf nbf in epoch seconds of the grant + * + * @return $this updated access token + */ + public function setNbf($nbf) { + $this->nbf = $nbf; + return $this; + } + + /** + * Returns the nbf of the grant + * + * @return integer the nbf in epoch seconds + */ + public function getNbf() { + return $this->nbf; + } + + /** + * Add a grant to the access token + * + * @param Grant $grant to be added + * + * @return $this the updated access token + */ + public function addGrant(Grant $grant) { + $this->grants[] = $grant; + return $this; + } + + /** + * Allows to set custom claims, which then will be encoded into JWT payload. + * + * @param string $name + * @param string $value + */ + public function addClaim($name, $value) { + $this->customClaims[$name] = $value; + } + + public function toJWT($algorithm = 'HS256') { + $header = array( + 'cty' => 'twilio-fpa;v=1', + 'typ' => 'JWT' + ); + + $now = time(); + + $grants = array(); + if ($this->identity) { + $grants['identity'] = $this->identity; + } + + foreach ($this->grants as $grant) { + $payload = $grant->getPayload(); + if (empty($payload)) { + $payload = json_decode('{}'); + } + + $grants[$grant->getGrantKey()] = $payload; + } + + if (empty($grants)) { + $grants = json_decode('{}'); + } + + $payload = array_merge($this->customClaims, array( + 'jti' => $this->signingKeySid . '-' . $now, + 'iss' => $this->signingKeySid, + 'sub' => $this->accountSid, + 'exp' => $now + $this->ttl, + 'grants' => $grants + )); + + if (!is_null($this->nbf)) { + $payload['nbf'] = $this->nbf; + } + + return JWT::encode($payload, $this->secret, $algorithm, $header); + } + + public function __toString() { + return $this->toJWT(); + } +} diff --git a/Twilio/Jwt/Client/ScopeURI.php b/Twilio/Jwt/Client/ScopeURI.php new file mode 100644 index 0000000..604af3b --- /dev/null +++ b/Twilio/Jwt/Client/ScopeURI.php @@ -0,0 +1,67 @@ +:? + * + * For example: + * scope:client:incoming?name=jonas + */ +class ScopeURI { + public $service; + public $privilege; + public $params; + + public function __construct($service, $privilege, $params = array()) { + $this->service = $service; + $this->privilege = $privilege; + $this->params = $params; + } + + public function toString() { + $uri = "scope:{$this->service}:{$this->privilege}"; + if (count($this->params)) { + $uri .= "?" . http_build_query($this->params, '', '&'); + } + return $uri; + } + + /** + * Parse a scope URI into a ScopeURI object + * + * @param string $uri The scope URI + * @return ScopeURI The parsed scope uri + * @throws \UnexpectedValueException + */ + public static function parse($uri) { + if (strpos($uri, 'scope:') !== 0) { + throw new \UnexpectedValueException( + 'Not a scope URI according to scheme'); + } + + $parts = explode('?', $uri, 1); + $params = null; + + if (count($parts) > 1) { + parse_str($parts[1], $params); + } + + $parts = explode(':', $parts[0], 2); + + if (count($parts) != 3) { + throw new \UnexpectedValueException( + 'Not enough parts for scope URI'); + } + + list($scheme, $service, $privilege) = $parts; + return new ScopeURI($service, $privilege, $params); + } +} \ No newline at end of file diff --git a/Twilio/Jwt/ClientToken.php b/Twilio/Jwt/ClientToken.php new file mode 100644 index 0000000..bfbbbeb --- /dev/null +++ b/Twilio/Jwt/ClientToken.php @@ -0,0 +1,128 @@ +accountSid = $accountSid; + $this->authToken = $authToken; + $this->scopes = array(); + $this->clientName = false; + $this->customClaims = array(); + } + + /** + * If the user of this token should be allowed to accept incoming + * connections then configure the TwilioCapability through this method and + * specify the client name. + * + * @param $clientName + * @throws \InvalidArgumentException + */ + public function allowClientIncoming($clientName) { + + // clientName must be a non-zero length alphanumeric string + if (preg_match('/\W/', $clientName)) { + throw new \InvalidArgumentException( + 'Only alphanumeric characters allowed in client name.'); + } + + if (strlen($clientName) == 0) { + throw new \InvalidArgumentException( + 'Client name must not be a zero length string.'); + } + + $this->clientName = $clientName; + $this->allow('client', 'incoming', + array('clientName' => $clientName)); + } + + /** + * Allow the user of this token to make outgoing connections. + * + * @param string $appSid the application to which this token grants access + * @param mixed[] $appParams signed parameters that the user of this token + * cannot overwrite. + */ + public function allowClientOutgoing($appSid, array $appParams = array()) { + $this->allow('client', 'outgoing', array( + 'appSid' => $appSid, + 'appParams' => http_build_query($appParams, '', '&'))); + } + + /** + * Allow the user of this token to access their event stream. + * + * @param mixed[] $filters key/value filters to apply to the event stream + */ + public function allowEventStream(array $filters = array()) { + $this->allow('stream', 'subscribe', array( + 'path' => '/2010-04-01/Events', + 'params' => http_build_query($filters, '', '&'), + )); + } + + /** + * Allows to set custom claims, which then will be encoded into JWT payload. + * + * @param string $name + * @param string $value + */ + public function addClaim($name, $value) { + $this->customClaims[$name] = $value; + } + + /** + * Generates a new token based on the credentials and permissions that + * previously has been granted to this token. + * + * @param int $ttl the expiration time of the token (in seconds). Default + * value is 3600 (1hr) + * @return ClientToken the newly generated token that is valid for $ttl + * seconds + */ + public function generateToken($ttl = 3600) { + $payload = array_merge($this->customClaims, array( + 'scope' => array(), + 'iss' => $this->accountSid, + 'exp' => time() + $ttl, + )); + $scopeStrings = array(); + + foreach ($this->scopes as $scope) { + if ($scope->privilege == "outgoing" && $this->clientName) + $scope->params["clientName"] = $this->clientName; + $scopeStrings[] = $scope->toString(); + } + + $payload['scope'] = implode(' ', $scopeStrings); + return JWT::encode($payload, $this->authToken, 'HS256'); + } + + protected function allow($service, $privilege, $params) { + $this->scopes[] = new ScopeURI($service, $privilege, $params); + } +} diff --git a/Twilio/Jwt/Grants/ChatGrant.php b/Twilio/Jwt/Grants/ChatGrant.php new file mode 100644 index 0000000..cdec819 --- /dev/null +++ b/Twilio/Jwt/Grants/ChatGrant.php @@ -0,0 +1,128 @@ +serviceSid; + } + + /** + * Set the service sid of this grant + * + * @param string $serviceSid service sid of the grant + * + * @return $this updated grant + */ + public function setServiceSid($serviceSid) { + $this->serviceSid = $serviceSid; + return $this; + } + + /** + * Returns the endpoint id of the grant + * + * @return string the endpoint id + */ + public function getEndpointId() { + return $this->endpointId; + } + + /** + * Set the endpoint id of the grant + * + * @param string $endpointId endpoint id of the grant + * + * @return $this updated grant + */ + public function setEndpointId($endpointId) { + $this->endpointId = $endpointId; + return $this; + } + + /** + * Returns the deployment role sid of the grant + * + * @return string the deployment role sid + */ + public function getDeploymentRoleSid() { + return $this->deploymentRoleSid; + } + + /** + * Set the role sid of the grant + * + * @param string $deploymentRoleSid role sid of the grant + * + * @return $this updated grant + */ + public function setDeploymentRoleSid($deploymentRoleSid) { + $this->deploymentRoleSid = $deploymentRoleSid; + return $this; + } + + /** + * Returns the push credential sid of the grant + * + * @return string the push credential sid + */ + public function getPushCredentialSid() { + return $this->pushCredentialSid; + } + + /** + * Set the credential sid of the grant + * + * @param string $pushCredentialSid push credential sid of the grant + * + * @return $this updated grant + */ + public function setPushCredentialSid($pushCredentialSid) { + $this->pushCredentialSid = $pushCredentialSid; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() { + return "chat"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() { + $payload = array(); + if ($this->serviceSid) { + $payload['service_sid'] = $this->serviceSid; + } + if ($this->endpointId) { + $payload['endpoint_id'] = $this->endpointId; + } + if ($this->deploymentRoleSid) { + $payload['deployment_role_sid'] = $this->deploymentRoleSid; + } + if ($this->pushCredentialSid) { + $payload['push_credential_sid'] = $this->pushCredentialSid; + } + + return $payload; + } +} \ No newline at end of file diff --git a/Twilio/Jwt/Grants/ConversationsGrant.php b/Twilio/Jwt/Grants/ConversationsGrant.php new file mode 100644 index 0000000..bb249c1 --- /dev/null +++ b/Twilio/Jwt/Grants/ConversationsGrant.php @@ -0,0 +1,55 @@ +configurationProfileSid; + } + + /** + * @param string $configurationProfileSid the configuration profile sid + * we want to enable for this grant + * + * @return $this updated grant + */ + public function setConfigurationProfileSid($configurationProfileSid) { + $this->configurationProfileSid = $configurationProfileSid; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() { + return "rtc"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() { + $payload = array(); + if ($this->configurationProfileSid) { + $payload['configuration_profile_sid'] = $this->configurationProfileSid; + } + return $payload; + } +} diff --git a/Twilio/Jwt/Grants/Grant.php b/Twilio/Jwt/Grants/Grant.php new file mode 100644 index 0000000..0bd4e2b --- /dev/null +++ b/Twilio/Jwt/Grants/Grant.php @@ -0,0 +1,21 @@ +serviceSid; + } + + /** + * Set the service sid of this grant + * + * @param string $serviceSid service sid of the grant + * + * @return $this updated grant + */ + public function setServiceSid($serviceSid) { + $this->serviceSid = $serviceSid; + return $this; + } + + /** + * Returns the endpoint id of the grant + * + * @return string the endpoint id + */ + public function getEndpointId() { + return $this->endpointId; + } + + /** + * Set the endpoint id of the grant + * + * @param string $endpointId endpoint id of the grant + * + * @return $this updated grant + */ + public function setEndpointId($endpointId) { + $this->endpointId = $endpointId; + return $this; + } + + /** + * Returns the deployment role sid of the grant + * + * @return string the deployment role sid + */ + public function getDeploymentRoleSid() { + return $this->deploymentRoleSid; + } + + /** + * Set the role sid of the grant + * + * @param string $deploymentRoleSid role sid of the grant + * + * @return $this updated grant + */ + public function setDeploymentRoleSid($deploymentRoleSid) { + $this->deploymentRoleSid = $deploymentRoleSid; + return $this; + } + + /** + * Returns the push credential sid of the grant + * + * @return string the push credential sid + */ + public function getPushCredentialSid() { + return $this->pushCredentialSid; + } + + /** + * Set the credential sid of the grant + * + * @param string $pushCredentialSid push credential sid of the grant + * + * @return $this updated grant + */ + public function setPushCredentialSid($pushCredentialSid) { + $this->pushCredentialSid = $pushCredentialSid; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() { + return "ip_messaging"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() { + $payload = array(); + if ($this->serviceSid) { + $payload['service_sid'] = $this->serviceSid; + } + if ($this->endpointId) { + $payload['endpoint_id'] = $this->endpointId; + } + if ($this->deploymentRoleSid) { + $payload['deployment_role_sid'] = $this->deploymentRoleSid; + } + if ($this->pushCredentialSid) { + $payload['push_credential_sid'] = $this->pushCredentialSid; + } + + return $payload; + } +} \ No newline at end of file diff --git a/Twilio/Jwt/Grants/SyncGrant.php b/Twilio/Jwt/Grants/SyncGrant.php new file mode 100644 index 0000000..0d5fafe --- /dev/null +++ b/Twilio/Jwt/Grants/SyncGrant.php @@ -0,0 +1,138 @@ +serviceSid; + } + + /** + * Set the service sid of this grant + * + * @param string $serviceSid service sid of the grant + * + * @return Services_Twilio_Auth_SyncGrant updated grant + */ + public function setServiceSid($serviceSid) + { + $this->serviceSid = $serviceSid; + return $this; + } + + /** + * Returns the endpoint id of the grant + * + * @return string the endpoint id + */ + public function getEndpointId() + { + return $this->endpointId; + } + + /** + * Set the endpoint id of the grant + * + * @param string $endpointId endpoint id of the grant + * + * @return Services_Twilio_Auth_SyncGrant updated grant + */ + public function setEndpointId($endpointId) + { + $this->endpointId = $endpointId; + return $this; + } + + /** + * Returns the deployment role sid of the grant + * + * @return string the deployment role sid + */ + public function getDeploymentRoleSid() + { + return $this->deploymentRoleSid; + } + + /** + * Set the role sid of the grant + * + * @param string $deploymentRoleSid role sid of the grant + * + * @return Services_Twilio_Auth_SyncGrant updated grant + */ + public function setDeploymentRoleSid($deploymentRoleSid) + { + $this->deploymentRoleSid = $deploymentRoleSid; + return $this; + } + + /** + * Returns the push credential sid of the grant + * + * @return string the push credential sid + */ + public function getPushCredentialSid() + { + return $this->pushCredentialSid; + } + + /** + * Set the credential sid of the grant + * + * @param string $pushCredentialSid push credential sid of the grant + * + * @return Services_Twilio_Auth_SyncGrant updated grant + */ + public function setPushCredentialSid($pushCredentialSid) + { + $this->pushCredentialSid = $pushCredentialSid; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() + { + return "data_sync"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() + { + $payload = array(); + if ($this->serviceSid) { + $payload['service_sid'] = $this->serviceSid; + } + if ($this->endpointId) { + $payload['endpoint_id'] = $this->endpointId; + } + if ($this->deploymentRoleSid) { + $payload['deployment_role_sid'] = $this->deploymentRoleSid; + } + if ($this->pushCredentialSid) { + $payload['push_credential_sid'] = $this->pushCredentialSid; + } + + return $payload; + } + +} diff --git a/Twilio/Jwt/Grants/TaskRouterGrant.php b/Twilio/Jwt/Grants/TaskRouterGrant.php new file mode 100644 index 0000000..1eb9a7e --- /dev/null +++ b/Twilio/Jwt/Grants/TaskRouterGrant.php @@ -0,0 +1,110 @@ +workspaceSid; + } + + /** + * Set the workspace sid of this grant + * + * @param string $workspaceSid workspace sid of the grant + * + * @return Services_Twilio_Auth_TaskRouterGrant updated grant + */ + public function setWorkspaceSid($workspaceSid) + { + $this->workspaceSid = $workspaceSid; + return $this; + } + + /** + * Returns the worker sid + * + * @return string the worker sid + */ + public function getWorkerSid() + { + return $this->workerSid; + } + + /** + * Set the worker sid of this grant + * + * @param string $worker worker sid of the grant + * + * @return Services_Twilio_Auth_TaskRouterGrant updated grant + */ + public function setWorkerSid($workerSid) + { + $this->workerSid = $workerSid; + return $this; + } + + /** + * Returns the role + * + * @return string the role + */ + public function getRole() + { + return $this->role; + } + + /** + * Set the role of this grant + * + * @param string $role role of the grant + * + * @return Services_Twilio_Auth_TaskRouterGrant updated grant + */ + public function setRole($role) + { + $this->role = $role; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() + { + return "task_router"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() + { + $payload = array(); + if ($this->workspaceSid) { + $payload['workspace_sid'] = $this->workspaceSid; + } + if ($this->workerSid) { + $payload['worker_sid'] = $this->workerSid; + } + if ($this->role) { + $payload['role'] = $this->role; + } + + return $payload; + } + +} diff --git a/Twilio/Jwt/Grants/VideoGrant.php b/Twilio/Jwt/Grants/VideoGrant.php new file mode 100644 index 0000000..53bb3b8 --- /dev/null +++ b/Twilio/Jwt/Grants/VideoGrant.php @@ -0,0 +1,80 @@ +configurationProfileSid; + } + + /** + * Set the configuration profile sid of the grant + * @deprecated in favor of setRoom/getRoom + * + * @param string $configurationProfileSid configuration profile sid of grant + * + * @return $this updated grant + */ + public function setConfigurationProfileSid($configurationProfileSid) { + trigger_error('Configuration profile sid is deprecated, use room instead.', E_USER_NOTICE); + $this->configurationProfileSid = $configurationProfileSid; + return $this; + } + + /** + * Returns the room + * + * @return string room name or sid set in this grant + */ + public function getRoom() { + return $this->room; + } + + /** + * Set the room to allow access to in the grant + * + * @param string $roomSidOrName room sid or name + * @return $this updated grant + */ + public function setRoom($roomSidOrName) { + $this->room = $roomSidOrName; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() { + return "video"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() { + $payload = array(); + if ($this->configurationProfileSid) { + $payload['configuration_profile_sid'] = $this->configurationProfileSid; + } + if ($this->room) { + $payload['room'] = $this->room; + } + return $payload; + } + +} \ No newline at end of file diff --git a/Twilio/Jwt/Grants/VoiceGrant.php b/Twilio/Jwt/Grants/VoiceGrant.php new file mode 100644 index 0000000..aa9c142 --- /dev/null +++ b/Twilio/Jwt/Grants/VoiceGrant.php @@ -0,0 +1,178 @@ +incomingAllow; + } + + /** + * Set whether incoming is allowed + * + * @param boolean $incomingAllow whether incoming is allowed + * + * @return $this updated grant + */ + public function setIncomingAllow($incomingAllow) + { + $this->incomingAllow = $incomingAllow; + return $this; + } + + /** + * Returns the outgoing application sid + * + * @return string the outgoing application sid + */ + public function getOutgoingApplicationSid() + { + return $this->outgoingApplicationSid; + } + + /** + * Set the outgoing application sid of the grant + * + * @param string $outgoingApplicationSid outgoing application sid of grant + * + * @return $this updated grant + */ + public function setOutgoingApplicationSid($outgoingApplicationSid) + { + $this->outgoingApplicationSid = $outgoingApplicationSid; + return $this; + } + + /** + * Returns the outgoing application params + * + * @return array the outgoing application params + */ + public function getOutgoingApplicationParams() + { + return $this->outgoingApplicationParams; + } + + /** + * Set the outgoing application of the the grant + * + * @param string $sid outgoing application sid of the grant + * @param string $params params to pass the the application + * + * @return $this updated grant + */ + public function setOutgoingApplication($sid, $params) { + $this->outgoingApplicationSid = $sid; + $this->outgoingApplicationParams = $params; + return $this; + } + + /** + * Returns the push credential sid + * + * @return string the push credential sid + */ + public function getPushCredentialSid() + { + return $this->pushCredentialSid; + } + + /** + * Set the push credential sid + * + * @param string $pushCredentialSid + * + * @return $this updated grant + */ + public function setPushCredentialSid($pushCredentialSid) + { + $this->pushCredentialSid = $pushCredentialSid; + return $this; + } + + /** + * Returns the endpoint id + * + * @return string the endpoint id + */ + public function getEndpointId() + { + return $this->endpointId; + } + + /** + * Set the endpoint id + * + * @param string $endpointId endpoint id + * + * @return $this updated grant + */ + public function setEndpointId($endpointId) + { + $this->endpointId = $endpointId; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() + { + return "voice"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() + { + $payload = array(); + if ($this->incomingAllow == true) { + $incoming = array(); + $incoming['allow'] = true; + $payload['incoming'] = $incoming; + } + + if ($this->outgoingApplicationSid) { + $outgoing = array(); + $outgoing['application_sid'] = $this->outgoingApplicationSid; + + if ($this->outgoingApplicationParams) { + $outgoing['params'] = $this->outgoingApplicationParams; + } + + $payload['outgoing'] = $outgoing; + } + + if ($this->pushCredentialSid) { + $payload['push_credential_sid'] = $this->pushCredentialSid; + } + + if ($this->endpointId) { + $payload['endpoint_id'] = $this->endpointId; + } + + return $payload; + } + + +} diff --git a/Twilio/Jwt/JWT.php b/Twilio/Jwt/JWT.php new file mode 100644 index 0000000..de212f5 --- /dev/null +++ b/Twilio/Jwt/JWT.php @@ -0,0 +1,156 @@ + + */ +class JWT { + /** + * @param string $jwt The JWT + * @param string|null $key The secret key + * @param bool $verify Don't skip verification process + * @return object The JWT's payload as a PHP object + * @throws \DomainException + * @throws \UnexpectedValueException + */ + public static function decode($jwt, $key = null, $verify = true) { + $tks = explode('.', $jwt); + if (count($tks) != 3) { + throw new \UnexpectedValueException('Wrong number of segments'); + } + list($headb64, $payloadb64, $cryptob64) = $tks; + if (null === ($header = self::jsonDecode(self::urlsafeB64Decode($headb64))) + ) { + throw new \UnexpectedValueException('Invalid segment encoding'); + } + if (null === $payload = self::jsonDecode(self::urlsafeB64Decode($payloadb64)) + ) { + throw new \UnexpectedValueException('Invalid segment encoding'); + } + $sig = self::urlsafeB64Decode($cryptob64); + if ($verify) { + if (empty($header->alg)) { + throw new \DomainException('Empty algorithm'); + } + if ($sig != self::sign("$headb64.$payloadb64", $key, $header->alg)) { + throw new \UnexpectedValueException('Signature verification failed'); + } + } + return $payload; + } + + /** + * @param object|array $payload PHP object or array + * @param string $key The secret key + * @param string $algo The signing algorithm + * @param array $additionalHeaders Additional keys/values to add to the header + * + * @return string A JWT + */ + public static function encode($payload, $key, $algo = 'HS256', $additionalHeaders = array()) { + $header = array('typ' => 'JWT', 'alg' => $algo); + $header = $header + $additionalHeaders; + + $segments = array(); + $segments[] = self::urlsafeB64Encode(self::jsonEncode($header)); + $segments[] = self::urlsafeB64Encode(self::jsonEncode($payload)); + $signing_input = implode('.', $segments); + + $signature = self::sign($signing_input, $key, $algo); + $segments[] = self::urlsafeB64Encode($signature); + + return implode('.', $segments); + } + + /** + * @param string $msg The message to sign + * @param string $key The secret key + * @param string $method The signing algorithm + * @return string An encrypted message + * @throws \DomainException + */ + public static function sign($msg, $key, $method = 'HS256') { + $methods = array( + 'HS256' => 'sha256', + 'HS384' => 'sha384', + 'HS512' => 'sha512', + ); + if (empty($methods[$method])) { + throw new \DomainException('Algorithm not supported'); + } + return hash_hmac($methods[$method], $msg, $key, true); + } + + /** + * @param string $input JSON string + * @return object Object representation of JSON string + * @throws \DomainException + */ + public static function jsonDecode($input) { + $obj = json_decode($input); + if (function_exists('json_last_error') && $errno = json_last_error()) { + self::handleJsonError($errno); + } else if ($obj === null && $input !== 'null') { + throw new \DomainException('Null result with non-null input'); + } + return $obj; + } + + /** + * @param object|array $input A PHP object or array + * @return string JSON representation of the PHP object or array + * @throws \DomainException + */ + public static function jsonEncode($input) { + $json = json_encode($input); + if (function_exists('json_last_error') && $errno = json_last_error()) { + self::handleJsonError($errno); + } else if ($json === 'null' && $input !== null) { + throw new \DomainException('Null result with non-null input'); + } + return $json; + } + + /** + * @param string $input A base64 encoded string + * + * @return string A decoded string + */ + public static function urlsafeB64Decode($input) { + $padlen = 4 - strlen($input) % 4; + $input .= str_repeat('=', $padlen); + return base64_decode(strtr($input, '-_', '+/')); + } + + /** + * @param string $input Anything really + * + * @return string The base64 encode of what you passed in + */ + public static function urlsafeB64Encode($input) { + return str_replace('=', '', strtr(base64_encode($input), '+/', '-_')); + } + + /** + * @param int $errno An error number from json_last_error() + * + * @throws \DomainException + */ + private static function handleJsonError($errno) { + $messages = array( + JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', + JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', + JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON' + ); + throw new \DomainException(isset($messages[$errno]) + ? $messages[$errno] + : 'Unknown JSON error: ' . $errno + ); + } +} \ No newline at end of file diff --git a/Twilio/Jwt/TaskRouter/CapabilityToken.php b/Twilio/Jwt/TaskRouter/CapabilityToken.php new file mode 100644 index 0000000..57115cb --- /dev/null +++ b/Twilio/Jwt/TaskRouter/CapabilityToken.php @@ -0,0 +1,160 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class CapabilityToken { + protected $accountSid; + protected $authToken; + private $friendlyName; + /** @var Policy[] $policies */ + private $policies; + + protected $baseUrl = 'https://taskrouter.twilio.com/v1'; + protected $baseWsUrl = 'https://event-bridge.twilio.com/v1/wschannels'; + protected $version = 'v1'; + + protected $workspaceSid; + protected $channelId; + protected $resourceUrl; + + protected $required = array("required" => true); + protected $optional = array("required" => false); + + public function __construct($accountSid, $authToken, $workspaceSid, $channelId, $resourceUrl = null, $overrideBaseUrl = null, $overrideBaseWSUrl = null) { + $this->accountSid = $accountSid; + $this->authToken = $authToken; + $this->friendlyName = $channelId; + $this->policies = array(); + + $this->workspaceSid = $workspaceSid; + $this->channelId = $channelId; + if (isset($overrideBaseUrl)) { + $this->baseUrl = $overrideBaseUrl; + } + if (isset($overrideBaseWSUrl)) { + $this->baseWsUrl = $overrideBaseWSUrl; + } + $this->baseUrl = $this->baseUrl . '/Workspaces/' . $workspaceSid; + + $this->validateJWT(); + + if (!isset($resourceUrl)) { + $this->setupResource(); + } + + //add permissions to GET and POST to the event-bridge channel + $this->allow($this->baseWsUrl . "/" . $this->accountSid . "/" . $this->channelId, "GET", null, null); + $this->allow($this->baseWsUrl . "/" . $this->accountSid . "/" . $this->channelId, "POST", null, null); + + //add permissions to fetch the instance resource + $this->allow($this->resourceUrl, "GET", null, null); + } + + protected function setupResource() { + + } + + public function addPolicyDeconstructed($url, $method, $queryFilter = array(), $postFilter = array(), $allow = true) { + $policy = new Policy($url, $method, $queryFilter, $postFilter, $allow); + array_push($this->policies, $policy); + return $policy; + } + + public function allow($url, $method, $queryFilter = array(), $postFilter = array()) { + $this->addPolicyDeconstructed($url, $method, $queryFilter, $postFilter, true); + } + + public function deny($url, $method, $queryFilter = array(), $postFilter = array()) { + $this->addPolicyDeconstructed($url, $method, $queryFilter, $postFilter, false); + } + + private function validateJWT() { + if (!isset($this->accountSid) || substr($this->accountSid, 0, 2) != 'AC') { + throw new \Exception("Invalid AccountSid provided: " . $this->accountSid); + } + if (!isset($this->workspaceSid) || substr($this->workspaceSid, 0, 2) != 'WS') { + throw new \Exception("Invalid WorkspaceSid provided: " . $this->workspaceSid); + } + if (!isset($this->channelId)) { + throw new \Exception("ChannelId not provided"); + } + $prefix = substr($this->channelId, 0, 2); + if ($prefix != 'WS' && $prefix != 'WK' && $prefix != 'WQ') { + throw new \Exception("Invalid ChannelId provided: " . $this->channelId); + } + } + + public function allowFetchSubresources() { + $method = 'GET'; + $queryFilter = array(); + $postFilter = array(); + $this->allow($this->resourceUrl . '/**', $method, $queryFilter, $postFilter); + } + + public function allowUpdates() { + $method = 'POST'; + $queryFilter = array(); + $postFilter = array(); + $this->allow($this->resourceUrl, $method, $queryFilter, $postFilter); + } + + public function allowUpdatesSubresources() { + $method = 'POST'; + $queryFilter = array(); + $postFilter = array(); + $this->allow($this->resourceUrl . '/**', $method, $queryFilter, $postFilter); + } + + public function allowDelete() { + $method = 'DELETE'; + $queryFilter = array(); + $postFilter = array(); + $this->allow($this->resourceUrl, $method, $queryFilter, $postFilter); + } + + public function allowDeleteSubresources() { + $method = 'DELETE'; + $queryFilter = array(); + $postFilter = array(); + $this->allow($this->resourceUrl . '/**', $method, $queryFilter, $postFilter); + } + + public function generateToken($ttl = 3600, $extraAttributes = array()) { + $payload = array( + 'version' => $this->version, + 'friendly_name' => $this->friendlyName, + 'iss' => $this->accountSid, + 'exp' => time() + $ttl, + 'account_sid' => $this->accountSid, + 'channel' => $this->channelId, + 'workspace_sid' => $this->workspaceSid + ); + + if (substr($this->channelId, 0, 2) == 'WK') { + $payload['worker_sid'] = $this->channelId; + } else if (substr($this->channelId, 0, 2) == 'WQ') { + $payload['taskqueue_sid'] = $this->channelId; + } + + foreach ($extraAttributes as $key => $value) { + $payload[$key] = $value; + } + + $policyStrings = array(); + foreach ($this->policies as $policy) { + $policyStrings[] = $policy->toArray(); + } + + $payload['policies'] = $policyStrings; + return JWT::encode($payload, $this->authToken, 'HS256'); + } +} \ No newline at end of file diff --git a/Twilio/Jwt/TaskRouter/Policy.php b/Twilio/Jwt/TaskRouter/Policy.php new file mode 100644 index 0000000..2de1751 --- /dev/null +++ b/Twilio/Jwt/TaskRouter/Policy.php @@ -0,0 +1,54 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class Policy { + private $url; + private $method; + private $queryFilter; + private $postFilter; + private $allow; + + public function __construct($url, $method, $queryFilter = array(), $postFilter = array(), $allow = true) { + $this->url = $url; + $this->method = $method; + $this->queryFilter = $queryFilter; + $this->postFilter = $postFilter; + $this->allow = $allow; + } + + public function addQueryFilter($queryFilter) { + array_push($this->queryFilter, $queryFilter); + } + + public function addPostFilter($postFilter) { + array_push($this->postFilter, $postFilter); + } + + public function toArray() { + $policy_array = array('url' => $this->url, 'method' => $this->method, 'allow' => $this->allow); + if (!is_null($this->queryFilter)) { + if (count($this->queryFilter) > 0) { + $policy_array['query_filter'] = $this->queryFilter; + } else { + $policy_array['query_filter'] = new \stdClass(); + } + } + if (!is_null($this->postFilter)) { + if (count($this->postFilter) > 0) { + $policy_array['post_filter'] = $this->postFilter; + } else { + $policy_array['post_filter'] = new \stdClass(); + } + } + return $policy_array; + } +} \ No newline at end of file diff --git a/Twilio/Jwt/TaskRouter/TaskQueueCapability.php b/Twilio/Jwt/TaskRouter/TaskQueueCapability.php new file mode 100644 index 0000000..b780fd3 --- /dev/null +++ b/Twilio/Jwt/TaskRouter/TaskQueueCapability.php @@ -0,0 +1,20 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class TaskQueueCapability extends CapabilityToken { + public function __construct($accountSid, $authToken, $workspaceSid, $taskQueueSid, $overrideBaseUrl = null, $overrideBaseWSUrl = null) { + parent::__construct($accountSid, $authToken, $workspaceSid, $taskQueueSid, null, $overrideBaseUrl, $overrideBaseWSUrl); + } + + protected function setupResource() { + $this->resourceUrl = $this->baseUrl . '/TaskQueues/' . $this->channelId; + } +} \ No newline at end of file diff --git a/Twilio/Jwt/TaskRouter/WorkerCapability.php b/Twilio/Jwt/TaskRouter/WorkerCapability.php new file mode 100644 index 0000000..2954832 --- /dev/null +++ b/Twilio/Jwt/TaskRouter/WorkerCapability.php @@ -0,0 +1,48 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class WorkerCapability extends CapabilityToken { + private $tasksUrl; + private $workerReservationsUrl; + private $activityUrl; + + public function __construct($accountSid, $authToken, $workspaceSid, $workerSid, $overrideBaseUrl = null, $overrideBaseWSUrl = null) { + parent::__construct($accountSid, $authToken, $workspaceSid, $workerSid, null, $overrideBaseUrl, $overrideBaseWSUrl); + + $this->tasksUrl = $this->baseUrl . '/Tasks/**'; + $this->activityUrl = $this->baseUrl . '/Activities'; + $this->workerReservationsUrl = $this->resourceUrl . '/Reservations/**'; + + //add permissions to fetch the list of activities, tasks, and worker reservations + $this->allow($this->activityUrl, "GET", null, null); + $this->allow($this->tasksUrl, "GET", null, null); + $this->allow($this->workerReservationsUrl, "GET", null, null); + } + + protected function setupResource() { + $this->resourceUrl = $this->baseUrl . '/Workers/' . $this->channelId; + } + + public function allowActivityUpdates() { + $method = 'POST'; + $queryFilter = array(); + $postFilter = array("ActivitySid" => $this->required); + $this->allow($this->resourceUrl, $method, $queryFilter, $postFilter); + } + + public function allowReservationUpdates() { + $method = 'POST'; + $queryFilter = array(); + $postFilter = array(); + $this->allow($this->tasksUrl, $method, $queryFilter, $postFilter); + $this->allow($this->workerReservationsUrl, $method, $queryFilter, $postFilter); + } +} \ No newline at end of file diff --git a/Twilio/Jwt/TaskRouter/WorkspaceCapability.php b/Twilio/Jwt/TaskRouter/WorkspaceCapability.php new file mode 100644 index 0000000..2b3c6a5 --- /dev/null +++ b/Twilio/Jwt/TaskRouter/WorkspaceCapability.php @@ -0,0 +1,15 @@ +resourceUrl = $this->baseUrl; + } +} \ No newline at end of file diff --git a/Twilio/Options.php b/Twilio/Options.php new file mode 100644 index 0000000..45e3d7f --- /dev/null +++ b/Twilio/Options.php @@ -0,0 +1,13 @@ +options); + } +} \ No newline at end of file diff --git a/Twilio/Rest/Api.php b/Twilio/Rest/Api.php new file mode 100644 index 0000000..a68d552 --- /dev/null +++ b/Twilio/Rest/Api.php @@ -0,0 +1,449 @@ +baseUrl = 'https://api.twilio.com'; + } + + /** + * @return \Twilio\Rest\Api\V2010 Version v2010 of api + */ + protected function getV2010() { + if (!$this->_v2010) { + $this->_v2010 = new V2010($this); + } + return $this->_v2010; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Api\V2010\AccountContext Account provided as the + * authenticating account + */ + protected function getAccount() { + return $this->v2010->account; + } + + /** + * @return \Twilio\Rest\Api\V2010\AccountList + */ + protected function getAccounts() { + return $this->v2010->accounts; + } + + /** + * @param string $sid Fetch by unique Account Sid + * @return \Twilio\Rest\Api\V2010\AccountContext + */ + protected function contextAccounts($sid) { + return $this->v2010->accounts($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\AddressList + */ + protected function getAddresses() { + return $this->v2010->account->addresses; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Api\V2010\Account\AddressContext + */ + protected function contextAddresses($sid) { + return $this->v2010->account->addresses($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ApplicationList + */ + protected function getApplications() { + return $this->v2010->account->applications; + } + + /** + * @param string $sid Fetch by unique Application Sid + * @return \Twilio\Rest\Api\V2010\Account\ApplicationContext + */ + protected function contextApplications($sid) { + return $this->v2010->account->applications($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppList + */ + protected function getAuthorizedConnectApps() { + return $this->v2010->account->authorizedConnectApps; + } + + /** + * @param string $connectAppSid The connect_app_sid + * @return \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppContext + */ + protected function contextAuthorizedConnectApps($connectAppSid) { + return $this->v2010->account->authorizedConnectApps($connectAppSid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryList + */ + protected function getAvailablePhoneNumbers() { + return $this->v2010->account->availablePhoneNumbers; + } + + /** + * @param string $countryCode The country_code + * @return \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryContext + */ + protected function contextAvailablePhoneNumbers($countryCode) { + return $this->v2010->account->availablePhoneNumbers($countryCode); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\CallList + */ + protected function getCalls() { + return $this->v2010->account->calls; + } + + /** + * @param string $sid Call Sid that uniquely identifies the Call to fetch + * @return \Twilio\Rest\Api\V2010\Account\CallContext + */ + protected function contextCalls($sid) { + return $this->v2010->account->calls($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ConferenceList + */ + protected function getConferences() { + return $this->v2010->account->conferences; + } + + /** + * @param string $sid Fetch by unique conference Sid + * @return \Twilio\Rest\Api\V2010\Account\ConferenceContext + */ + protected function contextConferences($sid) { + return $this->v2010->account->conferences($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ConnectAppList + */ + protected function getConnectApps() { + return $this->v2010->account->connectApps; + } + + /** + * @param string $sid Fetch by unique connect-app Sid + * @return \Twilio\Rest\Api\V2010\Account\ConnectAppContext + */ + protected function contextConnectApps($sid) { + return $this->v2010->account->connectApps($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberList + */ + protected function getIncomingPhoneNumbers() { + return $this->v2010->account->incomingPhoneNumbers; + } + + /** + * @param string $sid Fetch by unique incoming-phone-number Sid + * @return \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberContext + */ + protected function contextIncomingPhoneNumbers($sid) { + return $this->v2010->account->incomingPhoneNumbers($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\KeyList + */ + protected function getKeys() { + return $this->v2010->account->keys; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Api\V2010\Account\KeyContext + */ + protected function contextKeys($sid) { + return $this->v2010->account->keys($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\MessageList + */ + protected function getMessages() { + return $this->v2010->account->messages; + } + + /** + * @param string $sid Fetch by unique message Sid + * @return \Twilio\Rest\Api\V2010\Account\MessageContext + */ + protected function contextMessages($sid) { + return $this->v2010->account->messages($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\NewKeyList + */ + protected function getNewKeys() { + return $this->v2010->account->newKeys; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\NewSigningKeyList + */ + protected function getNewSigningKeys() { + return $this->v2010->account->newSigningKeys; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\NotificationList + */ + protected function getNotifications() { + return $this->v2010->account->notifications; + } + + /** + * @param string $sid Fetch by unique notification Sid + * @return \Twilio\Rest\Api\V2010\Account\NotificationContext + */ + protected function contextNotifications($sid) { + return $this->v2010->account->notifications($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdList + */ + protected function getOutgoingCallerIds() { + return $this->v2010->account->outgoingCallerIds; + } + + /** + * @param string $sid Fetch by unique outgoing-caller-id Sid + * @return \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdContext + */ + protected function contextOutgoingCallerIds($sid) { + return $this->v2010->account->outgoingCallerIds($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\QueueList + */ + protected function getQueues() { + return $this->v2010->account->queues; + } + + /** + * @param string $sid Fetch by unique queue Sid + * @return \Twilio\Rest\Api\V2010\Account\QueueContext + */ + protected function contextQueues($sid) { + return $this->v2010->account->queues($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\RecordingList + */ + protected function getRecordings() { + return $this->v2010->account->recordings; + } + + /** + * @param string $sid Fetch by unique recording SID + * @return \Twilio\Rest\Api\V2010\Account\RecordingContext + */ + protected function contextRecordings($sid) { + return $this->v2010->account->recordings($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\SigningKeyList + */ + protected function getSigningKeys() { + return $this->v2010->account->signingKeys; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Api\V2010\Account\SigningKeyContext + */ + protected function contextSigningKeys($sid) { + return $this->v2010->account->signingKeys($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\SipList + */ + protected function getSip() { + return $this->v2010->account->sip; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ShortCodeList + */ + protected function getShortCodes() { + return $this->v2010->account->shortCodes; + } + + /** + * @param string $sid Fetch by unique short-code Sid + * @return \Twilio\Rest\Api\V2010\Account\ShortCodeContext + */ + protected function contextShortCodes($sid) { + return $this->v2010->account->shortCodes($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\TokenList + */ + protected function getTokens() { + return $this->v2010->account->tokens; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\TranscriptionList + */ + protected function getTranscriptions() { + return $this->v2010->account->transcriptions; + } + + /** + * @param string $sid Fetch by unique transcription SID + * @return \Twilio\Rest\Api\V2010\Account\TranscriptionContext + */ + protected function contextTranscriptions($sid) { + return $this->v2010->account->transcriptions($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\UsageList + */ + protected function getUsage() { + return $this->v2010->account->usage; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ValidationRequestList + */ + protected function getValidationRequests() { + return $this->v2010->account->validationRequests; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Api]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat.php b/Twilio/Rest/Chat.php new file mode 100644 index 0000000..1a139df --- /dev/null +++ b/Twilio/Rest/Chat.php @@ -0,0 +1,133 @@ +baseUrl = 'https://chat.twilio.com'; + } + + /** + * @return \Twilio\Rest\Chat\V1 Version v1 of chat + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * @return \Twilio\Rest\Chat\V2 Version v2 of chat + */ + protected function getV2() { + if (!$this->_v2) { + $this->_v2 = new V2($this); + } + return $this->_v2; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Chat\V2\CredentialList + */ + protected function getCredentials() { + return $this->v2->credentials; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Chat\V2\CredentialContext + */ + protected function contextCredentials($sid) { + return $this->v2->credentials($sid); + } + + /** + * @return \Twilio\Rest\Chat\V2\ServiceList + */ + protected function getServices() { + return $this->v2->services; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Chat\V2\ServiceContext + */ + protected function contextServices($sid) { + return $this->v2->services($sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Chat]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat/V1/CredentialContext.php b/Twilio/Rest/Chat/V1/CredentialContext.php new file mode 100644 index 0000000..a08df26 --- /dev/null +++ b/Twilio/Rest/Chat/V1/CredentialContext.php @@ -0,0 +1,104 @@ +solution = array('sid' => $sid, ); + + $this->uri = '/Credentials/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a CredentialInstance + * + * @return CredentialInstance Fetched CredentialInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new CredentialInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Update the CredentialInstance + * + * @param array|Options $options Optional Arguments + * @return CredentialInstance Updated CredentialInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'Certificate' => $options['certificate'], + 'PrivateKey' => $options['privateKey'], + 'Sandbox' => Serialize::booleanToString($options['sandbox']), + 'ApiKey' => $options['apiKey'], + 'Secret' => $options['secret'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new CredentialInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Deletes the CredentialInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Chat.V1.CredentialContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat/V1/Service/Channel/InviteInstance.php b/Twilio/Rest/Chat/V1/Service/Channel/InviteInstance.php new file mode 100644 index 0000000..317eda1 --- /dev/null +++ b/Twilio/Rest/Chat/V1/Service/Channel/InviteInstance.php @@ -0,0 +1,138 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'channelSid' => Values::array_get($payload, 'channel_sid'), + 'serviceSid' => Values::array_get($payload, 'service_sid'), + 'identity' => Values::array_get($payload, 'identity'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'roleSid' => Values::array_get($payload, 'role_sid'), + 'createdBy' => Values::array_get($payload, 'created_by'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array( + 'serviceSid' => $serviceSid, + 'channelSid' => $channelSid, + 'sid' => $sid ?: $this->properties['sid'], + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Chat\V1\Service\Channel\InviteContext Context for this + * InviteInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new InviteContext( + $this->version, + $this->solution['serviceSid'], + $this->solution['channelSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a InviteInstance + * + * @return InviteInstance Fetched InviteInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the InviteInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Chat.V1.InviteInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat/V1/Service/Channel/InviteOptions.php b/Twilio/Rest/Chat/V1/Service/Channel/InviteOptions.php new file mode 100644 index 0000000..bd8f5fe --- /dev/null +++ b/Twilio/Rest/Chat/V1/Service/Channel/InviteOptions.php @@ -0,0 +1,104 @@ +options['roleSid'] = $roleSid; + } + + /** + * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/role) assigned to this member. + * + * @param string $roleSid The Role assigned to this member. + * @return $this Fluent Builder + */ + public function setRoleSid($roleSid) { + $this->options['roleSid'] = $roleSid; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Chat.V1.CreateInviteOptions ' . implode(' ', $options) . ']'; + } +} + +class ReadInviteOptions extends Options { + /** + * @param string $identity A unique string identifier for this User in this + * Service. + */ + public function __construct($identity = Values::NONE) { + $this->options['identity'] = $identity; + } + + /** + * A unique string identifier for this [User](https://www.twilio.com/docs/api/chat/rest/v1/user) in this [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See the [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details. + * + * @param string $identity A unique string identifier for this User in this + * Service. + * @return $this Fluent Builder + */ + public function setIdentity($identity) { + $this->options['identity'] = $identity; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Chat.V1.ReadInviteOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat/V1/Service/Channel/MessageList.php b/Twilio/Rest/Chat/V1/Service/Channel/MessageList.php new file mode 100644 index 0000000..da7443c --- /dev/null +++ b/Twilio/Rest/Chat/V1/Service/Channel/MessageList.php @@ -0,0 +1,182 @@ +solution = array('serviceSid' => $serviceSid, 'channelSid' => $channelSid, ); + + $this->uri = '/Services/' . rawurlencode($serviceSid) . '/Channels/' . rawurlencode($channelSid) . '/Messages'; + } + + /** + * Create a new MessageInstance + * + * @param string $body The body + * @param array|Options $options Optional Arguments + * @return MessageInstance Newly created MessageInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($body, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'Body' => $body, + 'From' => $options['from'], + 'Attributes' => $options['attributes'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new MessageInstance( + $this->version, + $payload, + $this->solution['serviceSid'], + $this->solution['channelSid'] + ); + } + + /** + * Streams MessageInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads MessageInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return MessageInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of MessageInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of MessageInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'Order' => $options['order'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new MessagePage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of MessageInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of MessageInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new MessagePage($this->version, $response, $this->solution); + } + + /** + * Constructs a MessageContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Chat\V1\Service\Channel\MessageContext + */ + public function getContext($sid) { + return new MessageContext( + $this->version, + $this->solution['serviceSid'], + $this->solution['channelSid'], + $sid + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Chat.V1.MessageList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat/V1/Service/ChannelContext.php b/Twilio/Rest/Chat/V1/Service/ChannelContext.php new file mode 100644 index 0000000..820079c --- /dev/null +++ b/Twilio/Rest/Chat/V1/Service/ChannelContext.php @@ -0,0 +1,211 @@ +solution = array('serviceSid' => $serviceSid, 'sid' => $sid, ); + + $this->uri = '/Services/' . rawurlencode($serviceSid) . '/Channels/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a ChannelInstance + * + * @return ChannelInstance Fetched ChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ChannelInstance( + $this->version, + $payload, + $this->solution['serviceSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the ChannelInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Update the ChannelInstance + * + * @param array|Options $options Optional Arguments + * @return ChannelInstance Updated ChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'UniqueName' => $options['uniqueName'], + 'Attributes' => $options['attributes'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new ChannelInstance( + $this->version, + $payload, + $this->solution['serviceSid'], + $this->solution['sid'] + ); + } + + /** + * Access the members + * + * @return \Twilio\Rest\Chat\V1\Service\Channel\MemberList + */ + protected function getMembers() { + if (!$this->_members) { + $this->_members = new MemberList( + $this->version, + $this->solution['serviceSid'], + $this->solution['sid'] + ); + } + + return $this->_members; + } + + /** + * Access the messages + * + * @return \Twilio\Rest\Chat\V1\Service\Channel\MessageList + */ + protected function getMessages() { + if (!$this->_messages) { + $this->_messages = new MessageList( + $this->version, + $this->solution['serviceSid'], + $this->solution['sid'] + ); + } + + return $this->_messages; + } + + /** + * Access the invites + * + * @return \Twilio\Rest\Chat\V1\Service\Channel\InviteList + */ + protected function getInvites() { + if (!$this->_invites) { + $this->_invites = new InviteList( + $this->version, + $this->solution['serviceSid'], + $this->solution['sid'] + ); + } + + return $this->_invites; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Chat.V1.ChannelContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Chat/V2.php b/Twilio/Rest/Chat/V2.php new file mode 100644 index 0000000..fc82859 --- /dev/null +++ b/Twilio/Rest/Chat/V2.php @@ -0,0 +1,100 @@ +version = 'v2'; + } + + /** + * @return \Twilio\Rest\Chat\V2\CredentialList + */ + protected function getCredentials() { + if (!$this->_credentials) { + $this->_credentials = new CredentialList($this); + } + return $this->_credentials; + } + + /** + * @return \Twilio\Rest\Chat\V2\ServiceList + */ + protected function getServices() { + if (!$this->_services) { + $this->_services = new ServiceList($this); + } + return $this->_services; + } + + /** + * Magic getter to lazy load root resources + * + * @param string $name Resource to return + * @return \Twilio\ListResource The requested resource + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown resource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Chat.V2]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Client.php b/Twilio/Rest/Client.php new file mode 100644 index 0000000..40088ab --- /dev/null +++ b/Twilio/Rest/Client.php @@ -0,0 +1,855 @@ +username = $username; + } else { + if (array_key_exists(self::ENV_ACCOUNT_SID, $environment)) { + $this->username = $environment[self::ENV_ACCOUNT_SID]; + } + } + + if ($password) { + $this->password = $password; + } else { + if (array_key_exists(self::ENV_AUTH_TOKEN, $environment)) { + $this->password = $environment[self::ENV_AUTH_TOKEN]; + } + } + + if (!$this->username || !$this->password) { + throw new ConfigurationException("Credentials are required to create a Client"); + } + + $this->accountSid = $accountSid ?: $this->username; + $this->region = $region; + + if ($httpClient) { + $this->httpClient = $httpClient; + } else { + $this->httpClient = new CurlClient(); + } + } + + /** + * Makes a request to the Twilio API using the configured http client + * Authentication information is automatically added if none is provided + * + * @param string $method HTTP Method + * @param string $uri Fully qualified url + * @param string[] $params Query string parameters + * @param string[] $data POST body data + * @param string[] $headers HTTP Headers + * @param string $username User for Authentication + * @param string $password Password for Authentication + * @param int $timeout Timeout in seconds + * @return \Twilio\Http\Response Response from the Twilio API + */ + public function request($method, $uri, $params = array(), $data = array(), $headers = array(), $username = null, $password = null, $timeout = null) { + $username = $username ? $username : $this->username; + $password = $password ? $password : $this->password; + + $headers['User-Agent'] = 'twilio-php/' . VersionInfo::string() . + ' (PHP ' . phpversion() . ')'; + $headers['Accept-Charset'] = 'utf-8'; + + if ($method == 'POST' && !array_key_exists('Content-Type', $headers)) { + $headers['Content-Type'] = 'application/x-www-form-urlencoded'; + } + + if (!array_key_exists('Accept', $headers)) { + $headers['Accept'] = 'application/json'; + } + + if ($this->region) { + list($head, $tail) = explode('.', $uri, 2); + + if (strpos($tail, $this->region) !== 0) { + $uri = implode('.', array($head, $this->region, $tail)); + } + } + + return $this->getHttpClient()->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + } + + /** + * Retrieve the Username + * + * @return string Current Username + */ + public function getUsername() { + return $this->username; + } + + /** + * Retrieve the Password + * + * @return string Current Password + */ + public function getPassword() { + return $this->password; + } + + /** + * Retrieve the AccountSid + * + * @return string Current AccountSid + */ + public function getAccountSid() { + return $this->accountSid; + } + + /** + * Retrieve the Region + * + * @return string Current Region + */ + public function getRegion() { + return $this->region; + } + + /** + * Retrieve the HttpClient + * + * @return \Twilio\Http\Client Current HttpClient + */ + public function getHttpClient() { + return $this->httpClient; + } + + /** + * Set the HttpClient + * + * @param \Twilio\Http\Client $httpClient HttpClient to use + */ + public function setHttpClient(HttpClient $httpClient) { + $this->httpClient = $httpClient; + } + + /** + * Access the Accounts Twilio Domain + * + * @return \Twilio\Rest\Accounts Accounts Twilio Domain + */ + protected function getAccounts() { + if (!$this->_accounts) { + $this->_accounts = new Accounts($this); + } + return $this->_accounts; + } + + /** + * Access the Api Twilio Domain + * + * @return \Twilio\Rest\Api Api Twilio Domain + */ + protected function getApi() { + if (!$this->_api) { + $this->_api = new Api($this); + } + return $this->_api; + } + + /** + * @return \Twilio\Rest\Api\V2010\AccountContext Account provided as the + * authenticating account + */ + public function getAccount() { + return $this->api->v2010->account; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\AddressList + */ + protected function getAddresses() { + return $this->api->v2010->account->addresses; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Api\V2010\Account\AddressContext + */ + protected function contextAddresses($sid) { + return $this->api->v2010->account->addresses($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ApplicationList + */ + protected function getApplications() { + return $this->api->v2010->account->applications; + } + + /** + * @param string $sid Fetch by unique Application Sid + * @return \Twilio\Rest\Api\V2010\Account\ApplicationContext + */ + protected function contextApplications($sid) { + return $this->api->v2010->account->applications($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppList + */ + protected function getAuthorizedConnectApps() { + return $this->api->v2010->account->authorizedConnectApps; + } + + /** + * @param string $connectAppSid The connect_app_sid + * @return \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppContext + */ + protected function contextAuthorizedConnectApps($connectAppSid) { + return $this->api->v2010->account->authorizedConnectApps($connectAppSid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryList + */ + protected function getAvailablePhoneNumbers() { + return $this->api->v2010->account->availablePhoneNumbers; + } + + /** + * @param string $countryCode The country_code + * @return \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryContext + */ + protected function contextAvailablePhoneNumbers($countryCode) { + return $this->api->v2010->account->availablePhoneNumbers($countryCode); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\CallList + */ + protected function getCalls() { + return $this->api->v2010->account->calls; + } + + /** + * @param string $sid Call Sid that uniquely identifies the Call to fetch + * @return \Twilio\Rest\Api\V2010\Account\CallContext + */ + protected function contextCalls($sid) { + return $this->api->v2010->account->calls($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ConferenceList + */ + protected function getConferences() { + return $this->api->v2010->account->conferences; + } + + /** + * @param string $sid Fetch by unique conference Sid + * @return \Twilio\Rest\Api\V2010\Account\ConferenceContext + */ + protected function contextConferences($sid) { + return $this->api->v2010->account->conferences($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ConnectAppList + */ + protected function getConnectApps() { + return $this->api->v2010->account->connectApps; + } + + /** + * @param string $sid Fetch by unique connect-app Sid + * @return \Twilio\Rest\Api\V2010\Account\ConnectAppContext + */ + protected function contextConnectApps($sid) { + return $this->api->v2010->account->connectApps($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberList + */ + protected function getIncomingPhoneNumbers() { + return $this->api->v2010->account->incomingPhoneNumbers; + } + + /** + * @param string $sid Fetch by unique incoming-phone-number Sid + * @return \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberContext + */ + protected function contextIncomingPhoneNumbers($sid) { + return $this->api->v2010->account->incomingPhoneNumbers($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\KeyList + */ + protected function getKeys() { + return $this->api->v2010->account->keys; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Api\V2010\Account\KeyContext + */ + protected function contextKeys($sid) { + return $this->api->v2010->account->keys($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\MessageList + */ + protected function getMessages() { + return $this->api->v2010->account->messages; + } + + /** + * @param string $sid Fetch by unique message Sid + * @return \Twilio\Rest\Api\V2010\Account\MessageContext + */ + protected function contextMessages($sid) { + return $this->api->v2010->account->messages($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\NewKeyList + */ + protected function getNewKeys() { + return $this->api->v2010->account->newKeys; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\NewSigningKeyList + */ + protected function getNewSigningKeys() { + return $this->api->v2010->account->newSigningKeys; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\NotificationList + */ + protected function getNotifications() { + return $this->api->v2010->account->notifications; + } + + /** + * @param string $sid Fetch by unique notification Sid + * @return \Twilio\Rest\Api\V2010\Account\NotificationContext + */ + protected function contextNotifications($sid) { + return $this->api->v2010->account->notifications($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdList + */ + protected function getOutgoingCallerIds() { + return $this->api->v2010->account->outgoingCallerIds; + } + + /** + * @param string $sid Fetch by unique outgoing-caller-id Sid + * @return \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdContext + */ + protected function contextOutgoingCallerIds($sid) { + return $this->api->v2010->account->outgoingCallerIds($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\QueueList + */ + protected function getQueues() { + return $this->api->v2010->account->queues; + } + + /** + * @param string $sid Fetch by unique queue Sid + * @return \Twilio\Rest\Api\V2010\Account\QueueContext + */ + protected function contextQueues($sid) { + return $this->api->v2010->account->queues($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\RecordingList + */ + protected function getRecordings() { + return $this->api->v2010->account->recordings; + } + + /** + * @param string $sid Fetch by unique recording SID + * @return \Twilio\Rest\Api\V2010\Account\RecordingContext + */ + protected function contextRecordings($sid) { + return $this->api->v2010->account->recordings($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\SigningKeyList + */ + protected function getSigningKeys() { + return $this->api->v2010->account->signingKeys; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Api\V2010\Account\SigningKeyContext + */ + protected function contextSigningKeys($sid) { + return $this->api->v2010->account->signingKeys($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\SipList + */ + protected function getSip() { + return $this->api->v2010->account->sip; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ShortCodeList + */ + protected function getShortCodes() { + return $this->api->v2010->account->shortCodes; + } + + /** + * @param string $sid Fetch by unique short-code Sid + * @return \Twilio\Rest\Api\V2010\Account\ShortCodeContext + */ + protected function contextShortCodes($sid) { + return $this->api->v2010->account->shortCodes($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\TokenList + */ + protected function getTokens() { + return $this->api->v2010->account->tokens; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\TranscriptionList + */ + protected function getTranscriptions() { + return $this->api->v2010->account->transcriptions; + } + + /** + * @param string $sid Fetch by unique transcription SID + * @return \Twilio\Rest\Api\V2010\Account\TranscriptionContext + */ + protected function contextTranscriptions($sid) { + return $this->api->v2010->account->transcriptions($sid); + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\UsageList + */ + protected function getUsage() { + return $this->api->v2010->account->usage; + } + + /** + * @return \Twilio\Rest\Api\V2010\Account\ValidationRequestList + */ + protected function getValidationRequests() { + return $this->api->v2010->account->validationRequests; + } + + /** + * Access the Chat Twilio Domain + * + * @return \Twilio\Rest\Chat Chat Twilio Domain + */ + protected function getChat() { + if (!$this->_chat) { + $this->_chat = new Chat($this); + } + return $this->_chat; + } + + /** + * Access the Fax Twilio Domain + * + * @return \Twilio\Rest\Fax Fax Twilio Domain + */ + protected function getFax() { + if (!$this->_fax) { + $this->_fax = new Fax($this); + } + return $this->_fax; + } + + /** + * Access the IpMessaging Twilio Domain + * + * @return \Twilio\Rest\IpMessaging IpMessaging Twilio Domain + */ + protected function getIpMessaging() { + if (!$this->_ipMessaging) { + $this->_ipMessaging = new IpMessaging($this); + } + return $this->_ipMessaging; + } + + /** + * Access the Lookups Twilio Domain + * + * @return \Twilio\Rest\Lookups Lookups Twilio Domain + */ + protected function getLookups() { + if (!$this->_lookups) { + $this->_lookups = new Lookups($this); + } + return $this->_lookups; + } + + /** + * Access the Monitor Twilio Domain + * + * @return \Twilio\Rest\Monitor Monitor Twilio Domain + */ + protected function getMonitor() { + if (!$this->_monitor) { + $this->_monitor = new Monitor($this); + } + return $this->_monitor; + } + + /** + * Access the Notify Twilio Domain + * + * @return \Twilio\Rest\Notify Notify Twilio Domain + */ + protected function getNotify() { + if (!$this->_notify) { + $this->_notify = new Notify($this); + } + return $this->_notify; + } + + /** + * Access the Preview Twilio Domain + * + * @return \Twilio\Rest\Preview Preview Twilio Domain + */ + protected function getPreview() { + if (!$this->_preview) { + $this->_preview = new Preview($this); + } + return $this->_preview; + } + + /** + * Access the Pricing Twilio Domain + * + * @return \Twilio\Rest\Pricing Pricing Twilio Domain + */ + protected function getPricing() { + if (!$this->_pricing) { + $this->_pricing = new Pricing($this); + } + return $this->_pricing; + } + + /** + * Access the Proxy Twilio Domain + * + * @return \Twilio\Rest\Proxy Proxy Twilio Domain + */ + protected function getProxy() { + if (!$this->_proxy) { + $this->_proxy = new Proxy($this); + } + return $this->_proxy; + } + + /** + * Access the Taskrouter Twilio Domain + * + * @return \Twilio\Rest\Taskrouter Taskrouter Twilio Domain + */ + protected function getTaskrouter() { + if (!$this->_taskrouter) { + $this->_taskrouter = new Taskrouter($this); + } + return $this->_taskrouter; + } + + /** + * Access the Trunking Twilio Domain + * + * @return \Twilio\Rest\Trunking Trunking Twilio Domain + */ + protected function getTrunking() { + if (!$this->_trunking) { + $this->_trunking = new Trunking($this); + } + return $this->_trunking; + } + + /** + * Access the Video Twilio Domain + * + * @return \Twilio\Rest\Video Video Twilio Domain + */ + protected function getVideo() { + if (!$this->_video) { + $this->_video = new Video($this); + } + return $this->_video; + } + + /** + * Access the Messaging Twilio Domain + * + * @return \Twilio\Rest\Messaging Messaging Twilio Domain + */ + protected function getMessaging() { + if (!$this->_messaging) { + $this->_messaging = new Messaging($this); + } + return $this->_messaging; + } + + /** + * Access the Wireless Twilio Domain + * + * @return \Twilio\Rest\Wireless Wireless Twilio Domain + */ + protected function getWireless() { + if (!$this->_wireless) { + $this->_wireless = new Wireless($this); + } + return $this->_wireless; + } + + /** + * Access the Sync Twilio Domain + * + * @return \Twilio\Rest\Sync Sync Twilio Domain + */ + protected function getSync() { + if (!$this->_sync) { + $this->_sync = new Sync($this); + } + return $this->_sync; + } + + /** + * Access the Studio Twilio Domain + * + * @return \Twilio\Rest\Studio Studio Twilio Domain + */ + protected function getStudio() { + if (!$this->_studio) { + $this->_studio = new Studio($this); + } + return $this->_studio; + } + + /** + * Access the Verify Twilio Domain + * + * @return \Twilio\Rest\Verify Verify Twilio Domain + */ + protected function getVerify() { + if (!$this->_verify) { + $this->_verify = new Verify($this); + } + return $this->_verify; + } + + /** + * Magic getter to lazy load domains + * + * @param string $name Domain to return + * @return \Twilio\Domain The requested domain + * @throws TwilioException For unknown domains + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown domain ' . $name); + } + + /** + * Magic call to lazy load contexts + * + * @param string $name Context to return + * @param mixed[] $arguments Context to return + * @return \Twilio\InstanceContext The requested context + * @throws TwilioException For unknown contexts + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Client ' . $this->getAccountSid() . ']'; + } + + /** + * Validates connection to new SSL certificate endpoint + * + * @param CurlClient $client + * @throws TwilioException if request fails + */ + public function validateSslCertificate($client) { + $response = $client->request('GET', 'https://api.twilio.com:8443'); + + if ($response->getStatusCode() < 200 || $response->getStatusCode() > 300) { + throw new TwilioException("Failed to validate SSL certificate"); + } + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1.php b/Twilio/Rest/Fax/V1.php new file mode 100644 index 0000000..2e819ce --- /dev/null +++ b/Twilio/Rest/Fax/V1.php @@ -0,0 +1,86 @@ +version = 'v1'; + } + + /** + * @return \Twilio\Rest\Fax\V1\FaxList + */ + protected function getFaxes() { + if (!$this->_faxes) { + $this->_faxes = new FaxList($this); + } + return $this->_faxes; + } + + /** + * Magic getter to lazy load root resources + * + * @param string $name Resource to return + * @return \Twilio\ListResource The requested resource + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown resource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Fax.V1]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/Fax/FaxMediaContext.php b/Twilio/Rest/Fax/V1/Fax/FaxMediaContext.php new file mode 100644 index 0000000..c185816 --- /dev/null +++ b/Twilio/Rest/Fax/V1/Fax/FaxMediaContext.php @@ -0,0 +1,82 @@ +solution = array('faxSid' => $faxSid, 'sid' => $sid, ); + + $this->uri = '/Faxes/' . rawurlencode($faxSid) . '/Media/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a FaxMediaInstance + * + * @return FaxMediaInstance Fetched FaxMediaInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new FaxMediaInstance( + $this->version, + $payload, + $this->solution['faxSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the FaxMediaInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Fax.V1.FaxMediaContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/Fax/FaxMediaInstance.php b/Twilio/Rest/Fax/V1/Fax/FaxMediaInstance.php new file mode 100644 index 0000000..bed9f9d --- /dev/null +++ b/Twilio/Rest/Fax/V1/Fax/FaxMediaInstance.php @@ -0,0 +1,127 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'faxSid' => Values::array_get($payload, 'fax_sid'), + 'contentType' => Values::array_get($payload, 'content_type'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('faxSid' => $faxSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Fax\V1\Fax\FaxMediaContext Context for this + * FaxMediaInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new FaxMediaContext( + $this->version, + $this->solution['faxSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a FaxMediaInstance + * + * @return FaxMediaInstance Fetched FaxMediaInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the FaxMediaInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Fax.V1.FaxMediaInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/Fax/FaxMediaList.php b/Twilio/Rest/Fax/V1/Fax/FaxMediaList.php new file mode 100644 index 0000000..d00b65d --- /dev/null +++ b/Twilio/Rest/Fax/V1/Fax/FaxMediaList.php @@ -0,0 +1,140 @@ +solution = array('faxSid' => $faxSid, ); + + $this->uri = '/Faxes/' . rawurlencode($faxSid) . '/Media'; + } + + /** + * Streams FaxMediaInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads FaxMediaInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return FaxMediaInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of FaxMediaInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of FaxMediaInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new FaxMediaPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of FaxMediaInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of FaxMediaInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new FaxMediaPage($this->version, $response, $this->solution); + } + + /** + * Constructs a FaxMediaContext + * + * @param string $sid A string that uniquely identifies this fax media + * @return \Twilio\Rest\Fax\V1\Fax\FaxMediaContext + */ + public function getContext($sid) { + return new FaxMediaContext($this->version, $this->solution['faxSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Fax.V1.FaxMediaList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/Fax/FaxMediaPage.php b/Twilio/Rest/Fax/V1/Fax/FaxMediaPage.php new file mode 100644 index 0000000..85b2b74 --- /dev/null +++ b/Twilio/Rest/Fax/V1/Fax/FaxMediaPage.php @@ -0,0 +1,37 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new FaxMediaInstance($this->version, $payload, $this->solution['faxSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Fax.V1.FaxMediaPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/FaxContext.php b/Twilio/Rest/Fax/V1/FaxContext.php new file mode 100644 index 0000000..32798ef --- /dev/null +++ b/Twilio/Rest/Fax/V1/FaxContext.php @@ -0,0 +1,152 @@ +solution = array('sid' => $sid, ); + + $this->uri = '/Faxes/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a FaxInstance + * + * @return FaxInstance Fetched FaxInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new FaxInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Update the FaxInstance + * + * @param array|Options $options Optional Arguments + * @return FaxInstance Updated FaxInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array('Status' => $options['status'], )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new FaxInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Deletes the FaxInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the media + * + * @return \Twilio\Rest\Fax\V1\Fax\FaxMediaList + */ + protected function getMedia() { + if (!$this->_media) { + $this->_media = new FaxMediaList($this->version, $this->solution['sid']); + } + + return $this->_media; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Fax.V1.FaxContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/FaxInstance.php b/Twilio/Rest/Fax/V1/FaxInstance.php new file mode 100644 index 0000000..0d33aa7 --- /dev/null +++ b/Twilio/Rest/Fax/V1/FaxInstance.php @@ -0,0 +1,166 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'from' => Values::array_get($payload, 'from'), + 'to' => Values::array_get($payload, 'to'), + 'quality' => Values::array_get($payload, 'quality'), + 'mediaSid' => Values::array_get($payload, 'media_sid'), + 'mediaUrl' => Values::array_get($payload, 'media_url'), + 'numPages' => Values::array_get($payload, 'num_pages'), + 'duration' => Values::array_get($payload, 'duration'), + 'status' => Values::array_get($payload, 'status'), + 'direction' => Values::array_get($payload, 'direction'), + 'apiVersion' => Values::array_get($payload, 'api_version'), + 'price' => Values::array_get($payload, 'price'), + 'priceUnit' => Values::array_get($payload, 'price_unit'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'links' => Values::array_get($payload, 'links'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Fax\V1\FaxContext Context for this FaxInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new FaxContext($this->version, $this->solution['sid']); + } + + return $this->context; + } + + /** + * Fetch a FaxInstance + * + * @return FaxInstance Fetched FaxInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the FaxInstance + * + * @param array|Options $options Optional Arguments + * @return FaxInstance Updated FaxInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the FaxInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the media + * + * @return \Twilio\Rest\Fax\V1\Fax\FaxMediaList + */ + protected function getMedia() { + return $this->proxy()->media; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Fax.V1.FaxInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/FaxList.php b/Twilio/Rest/Fax/V1/FaxList.php new file mode 100644 index 0000000..ccbf08d --- /dev/null +++ b/Twilio/Rest/Fax/V1/FaxList.php @@ -0,0 +1,183 @@ +solution = array(); + + $this->uri = '/Faxes'; + } + + /** + * Streams FaxInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads FaxInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return FaxInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of FaxInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of FaxInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'From' => $options['from'], + 'To' => $options['to'], + 'DateCreatedOnOrBefore' => Serialize::iso8601DateTime($options['dateCreatedOnOrBefore']), + 'DateCreatedAfter' => Serialize::iso8601DateTime($options['dateCreatedAfter']), + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new FaxPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of FaxInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of FaxInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new FaxPage($this->version, $response, $this->solution); + } + + /** + * Create a new FaxInstance + * + * @param string $to The phone number or SIP address to send the fax to + * @param string $mediaUrl URL that points to the fax media + * @param array|Options $options Optional Arguments + * @return FaxInstance Newly created FaxInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($to, $mediaUrl, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'To' => $to, + 'MediaUrl' => $mediaUrl, + 'Quality' => $options['quality'], + 'StatusCallback' => $options['statusCallback'], + 'From' => $options['from'], + 'SipAuthUsername' => $options['sipAuthUsername'], + 'SipAuthPassword' => $options['sipAuthPassword'], + 'StoreMedia' => Serialize::booleanToString($options['storeMedia']), + 'Ttl' => $options['ttl'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new FaxInstance($this->version, $payload); + } + + /** + * Constructs a FaxContext + * + * @param string $sid A string that uniquely identifies this fax. + * @return \Twilio\Rest\Fax\V1\FaxContext + */ + public function getContext($sid) { + return new FaxContext($this->version, $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Fax.V1.FaxList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/FaxOptions.php b/Twilio/Rest/Fax/V1/FaxOptions.php new file mode 100644 index 0000000..d51ed19 --- /dev/null +++ b/Twilio/Rest/Fax/V1/FaxOptions.php @@ -0,0 +1,276 @@ +options['from'] = $from; + $this->options['to'] = $to; + $this->options['dateCreatedOnOrBefore'] = $dateCreatedOnOrBefore; + $this->options['dateCreatedAfter'] = $dateCreatedAfter; + } + + /** + * Filters the returned list to only include faxes sent from the supplied number, given in E.164 format. + * + * @param string $from Include only faxes sent from + * @return $this Fluent Builder + */ + public function setFrom($from) { + $this->options['from'] = $from; + return $this; + } + + /** + * Filters the returned list to only include faxes sent to the supplied number, given in E.164 format. + * + * @param string $to Include only faxes sent to + * @return $this Fluent Builder + */ + public function setTo($to) { + $this->options['to'] = $to; + return $this; + } + + /** + * Filters the returned list to only include faxes created on or before the supplied date, given in ISO 8601 format. + * + * @param \DateTime $dateCreatedOnOrBefore Include only faxes created on or + * before + * @return $this Fluent Builder + */ + public function setDateCreatedOnOrBefore($dateCreatedOnOrBefore) { + $this->options['dateCreatedOnOrBefore'] = $dateCreatedOnOrBefore; + return $this; + } + + /** + * Filters the returned list to only include faxes created after the supplied date, given in ISO 8601 format. + * + * @param \DateTime $dateCreatedAfter Include only faxes created after + * @return $this Fluent Builder + */ + public function setDateCreatedAfter($dateCreatedAfter) { + $this->options['dateCreatedAfter'] = $dateCreatedAfter; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Fax.V1.ReadFaxOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateFaxOptions extends Options { + /** + * @param string $quality The quality of this fax + * @param string $statusCallback URL for fax status callbacks + * @param string $from Twilio number from which to originate the fax + * @param string $sipAuthUsername Username for SIP authentication + * @param string $sipAuthPassword Password for SIP authentication + * @param boolean $storeMedia Whether or not to store media + * @param integer $ttl How many minutes to attempt a fax + */ + public function __construct($quality = Values::NONE, $statusCallback = Values::NONE, $from = Values::NONE, $sipAuthUsername = Values::NONE, $sipAuthPassword = Values::NONE, $storeMedia = Values::NONE, $ttl = Values::NONE) { + $this->options['quality'] = $quality; + $this->options['statusCallback'] = $statusCallback; + $this->options['from'] = $from; + $this->options['sipAuthUsername'] = $sipAuthUsername; + $this->options['sipAuthPassword'] = $sipAuthPassword; + $this->options['storeMedia'] = $storeMedia; + $this->options['ttl'] = $ttl; + } + + /** + * A [quality value](https://www.twilio.com/docs/api/fax/rest/faxes#fax-quality-values), which defaults to `fine` + * + * @param string $quality The quality of this fax + * @return $this Fluent Builder + */ + public function setQuality($quality) { + $this->options['quality'] = $quality; + return $this; + } + + /** + * A [status callback](https://www.twilio.com/docs/api/fax/rest/faxes#fax-status-callback) URL that will receive a POST when the status of the fax changes + * + * @param string $statusCallback URL for fax status callbacks + * @return $this Fluent Builder + */ + public function setStatusCallback($statusCallback) { + $this->options['statusCallback'] = $statusCallback; + return $this; + } + + /** + * The phone number to use as the caller id, E.164-formatted. If using a phone number, it must be a Twilio number or a verified outgoing caller id for your account. If sending to a SIP address, this can be any alphanumeric string (plus the characters `+`, `_`, `.`, and `-`) to use in the From header of the SIP request. + * + * @param string $from Twilio number from which to originate the fax + * @return $this Fluent Builder + */ + public function setFrom($from) { + $this->options['from'] = $from; + return $this; + } + + /** + * The username to use for authentication when sending to a SIP address. + * + * @param string $sipAuthUsername Username for SIP authentication + * @return $this Fluent Builder + */ + public function setSipAuthUsername($sipAuthUsername) { + $this->options['sipAuthUsername'] = $sipAuthUsername; + return $this; + } + + /** + * The password to use for authentication when sending to a SIP address. + * + * @param string $sipAuthPassword Password for SIP authentication + * @return $this Fluent Builder + */ + public function setSipAuthPassword($sipAuthPassword) { + $this->options['sipAuthPassword'] = $sipAuthPassword; + return $this; + } + + /** + * Whether or not to store a copy of the sent media on Twilio's servers for later retrieval (defaults to `true`) + * + * @param boolean $storeMedia Whether or not to store media + * @return $this Fluent Builder + */ + public function setStoreMedia($storeMedia) { + $this->options['storeMedia'] = $storeMedia; + return $this; + } + + /** + * How many minutes from when a fax was initiated should Twilio attempt to send a fax. + * + * @param integer $ttl How many minutes to attempt a fax + * @return $this Fluent Builder + */ + public function setTtl($ttl) { + $this->options['ttl'] = $ttl; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Fax.V1.CreateFaxOptions ' . implode(' ', $options) . ']'; + } +} + +class UpdateFaxOptions extends Options { + /** + * @param string $status The updated status of this fax + */ + public function __construct($status = Values::NONE) { + $this->options['status'] = $status; + } + + /** + * The updated status of this fax. The only valid option is `canceled`. This may fail if the status has already started transmission. + * + * @param string $status The updated status of this fax + * @return $this Fluent Builder + */ + public function setStatus($status) { + $this->options['status'] = $status; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Fax.V1.UpdateFaxOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Fax/V1/FaxPage.php b/Twilio/Rest/Fax/V1/FaxPage.php new file mode 100644 index 0000000..66458d7 --- /dev/null +++ b/Twilio/Rest/Fax/V1/FaxPage.php @@ -0,0 +1,37 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new FaxInstance($this->version, $payload); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Fax.V1.FaxPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Lookups.php b/Twilio/Rest/Lookups.php new file mode 100644 index 0000000..5f6cebe --- /dev/null +++ b/Twilio/Rest/Lookups.php @@ -0,0 +1,103 @@ +baseUrl = 'https://lookups.twilio.com'; + } + + /** + * @return \Twilio\Rest\Lookups\V1 Version v1 of lookups + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Lookups\V1\PhoneNumberList + */ + protected function getPhoneNumbers() { + return $this->v1->phoneNumbers; + } + + /** + * @param string $phoneNumber The phone_number + * @return \Twilio\Rest\Lookups\V1\PhoneNumberContext + */ + protected function contextPhoneNumbers($phoneNumber) { + return $this->v1->phoneNumbers($phoneNumber); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Lookups]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Notify.php b/Twilio/Rest/Notify.php new file mode 100644 index 0000000..8b8d02e --- /dev/null +++ b/Twilio/Rest/Notify.php @@ -0,0 +1,120 @@ +baseUrl = 'https://notify.twilio.com'; + } + + /** + * @return \Twilio\Rest\Notify\V1 Version v1 of notify + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Notify\V1\CredentialList + */ + protected function getCredentials() { + return $this->v1->credentials; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Notify\V1\CredentialContext + */ + protected function contextCredentials($sid) { + return $this->v1->credentials($sid); + } + + /** + * @return \Twilio\Rest\Notify\V1\ServiceList + */ + protected function getServices() { + return $this->v1->services; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Notify\V1\ServiceContext + */ + protected function contextServices($sid) { + return $this->v1->services($sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Notify]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Pricing.php b/Twilio/Rest/Pricing.php new file mode 100644 index 0000000..e087d02 --- /dev/null +++ b/Twilio/Rest/Pricing.php @@ -0,0 +1,123 @@ +baseUrl = 'https://pricing.twilio.com'; + } + + /** + * @return \Twilio\Rest\Pricing\V1 Version v1 of pricing + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * @return \Twilio\Rest\Pricing\V2 Version v2 of pricing + */ + protected function getV2() { + if (!$this->_v2) { + $this->_v2 = new V2($this); + } + return $this->_v2; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Pricing\V1\MessagingList + */ + protected function getMessaging() { + return $this->v1->messaging; + } + + /** + * @return \Twilio\Rest\Pricing\V1\PhoneNumberList + */ + protected function getPhoneNumbers() { + return $this->v1->phoneNumbers; + } + + /** + * @return \Twilio\Rest\Pricing\V2\VoiceList + */ + protected function getVoice() { + return $this->v2->voice; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Pricing]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Proxy.php b/Twilio/Rest/Proxy.php new file mode 100644 index 0000000..9a2459e --- /dev/null +++ b/Twilio/Rest/Proxy.php @@ -0,0 +1,103 @@ +baseUrl = 'https://proxy.twilio.com'; + } + + /** + * @return \Twilio\Rest\Proxy\V1 Version v1 of proxy + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Proxy\V1\ServiceList + */ + protected function getServices() { + return $this->v1->services; + } + + /** + * @param string $sid A string that uniquely identifies this Service. + * @return \Twilio\Rest\Proxy\V1\ServiceContext + */ + protected function contextServices($sid) { + return $this->v1->services($sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Proxy]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio.php b/Twilio/Rest/Studio.php new file mode 100644 index 0000000..4016de8 --- /dev/null +++ b/Twilio/Rest/Studio.php @@ -0,0 +1,103 @@ +baseUrl = 'https://studio.twilio.com'; + } + + /** + * @return \Twilio\Rest\Studio\V1 Version v1 of studio + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Studio\V1\FlowList + */ + protected function getFlows() { + return $this->v1->flows; + } + + /** + * @param string $sid A string that uniquely identifies this Flow. + * @return \Twilio\Rest\Studio\V1\FlowContext + */ + protected function contextFlows($sid) { + return $this->v1->flows($sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1.php b/Twilio/Rest/Studio/V1.php new file mode 100644 index 0000000..19e7760 --- /dev/null +++ b/Twilio/Rest/Studio/V1.php @@ -0,0 +1,86 @@ +version = 'v1'; + } + + /** + * @return \Twilio\Rest\Studio\V1\FlowList + */ + protected function getFlows() { + if (!$this->_flows) { + $this->_flows = new FlowList($this); + } + return $this->_flows; + } + + /** + * Magic getter to lazy load root resources + * + * @param string $name Resource to return + * @return \Twilio\ListResource The requested resource + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown resource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextContext.php b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextContext.php new file mode 100644 index 0000000..172e010 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextContext.php @@ -0,0 +1,69 @@ +solution = array('flowSid' => $flowSid, 'engagementSid' => $engagementSid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Engagements/' . rawurlencode($engagementSid) . '/Context'; + } + + /** + * Fetch a EngagementContextInstance + * + * @return EngagementContextInstance Fetched EngagementContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new EngagementContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['engagementSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.EngagementContextContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextInstance.php b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextInstance.php new file mode 100644 index 0000000..35045bc --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextInstance.php @@ -0,0 +1,109 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'context' => Values::array_get($payload, 'context'), + 'engagementSid' => Values::array_get($payload, 'engagement_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('flowSid' => $flowSid, 'engagementSid' => $engagementSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\EngagementContextContext Context for this EngagementContextInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new EngagementContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a EngagementContextInstance + * + * @return EngagementContextInstance Fetched EngagementContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.EngagementContextInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextList.php b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextList.php new file mode 100644 index 0000000..3965e0d --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextList.php @@ -0,0 +1,52 @@ +solution = array('flowSid' => $flowSid, 'engagementSid' => $engagementSid, ); + } + + /** + * Constructs a EngagementContextContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\EngagementContextContext + */ + public function getContext() { + return new EngagementContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.EngagementContextList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextPage.php b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextPage.php new file mode 100644 index 0000000..ffa5490 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/EngagementContextPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new EngagementContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['engagementSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.EngagementContextPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextContext.php b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextContext.php new file mode 100644 index 0000000..b74b488 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextContext.php @@ -0,0 +1,75 @@ +solution = array( + 'flowSid' => $flowSid, + 'engagementSid' => $engagementSid, + 'stepSid' => $stepSid, + ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Engagements/' . rawurlencode($engagementSid) . '/Steps/' . rawurlencode($stepSid) . '/Context'; + } + + /** + * Fetch a StepContextInstance + * + * @return StepContextInstance Fetched StepContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new StepContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['stepSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.StepContextContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextInstance.php b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextInstance.php new file mode 100644 index 0000000..09e20d7 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextInstance.php @@ -0,0 +1,117 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'context' => Values::array_get($payload, 'context'), + 'engagementSid' => Values::array_get($payload, 'engagement_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'stepSid' => Values::array_get($payload, 'step_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array( + 'flowSid' => $flowSid, + 'engagementSid' => $engagementSid, + 'stepSid' => $stepSid, + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\Step\StepContextContext Context for this StepContextInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new StepContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['stepSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a StepContextInstance + * + * @return StepContextInstance Fetched StepContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.StepContextInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextList.php b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextList.php new file mode 100644 index 0000000..2db4d02 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextList.php @@ -0,0 +1,58 @@ +solution = array( + 'flowSid' => $flowSid, + 'engagementSid' => $engagementSid, + 'stepSid' => $stepSid, + ); + } + + /** + * Constructs a StepContextContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\Step\StepContextContext + */ + public function getContext() { + return new StepContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['stepSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.StepContextList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextPage.php b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextPage.php new file mode 100644 index 0000000..4e99f12 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/Step/StepContextPage.php @@ -0,0 +1,40 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new StepContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['stepSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.StepContextPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/StepContext.php b/Twilio/Rest/Studio/V1/Flow/Engagement/StepContext.php new file mode 100644 index 0000000..ddfdc17 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/StepContext.php @@ -0,0 +1,130 @@ +solution = array('flowSid' => $flowSid, 'engagementSid' => $engagementSid, 'sid' => $sid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Engagements/' . rawurlencode($engagementSid) . '/Steps/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a StepInstance + * + * @return StepInstance Fetched StepInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new StepInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['sid'] + ); + } + + /** + * Access the stepContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\Step\StepContextList + */ + protected function getStepContext() { + if (!$this->_stepContext) { + $this->_stepContext = new StepContextList( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['sid'] + ); + } + + return $this->_stepContext; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.StepContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/StepInstance.php b/Twilio/Rest/Studio/V1/Flow/Engagement/StepInstance.php new file mode 100644 index 0000000..3bbbe6c --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/StepInstance.php @@ -0,0 +1,142 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'engagementSid' => Values::array_get($payload, 'engagement_sid'), + 'name' => Values::array_get($payload, 'name'), + 'context' => Values::array_get($payload, 'context'), + 'transitionedFrom' => Values::array_get($payload, 'transitioned_from'), + 'transitionedTo' => Values::array_get($payload, 'transitioned_to'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array( + 'flowSid' => $flowSid, + 'engagementSid' => $engagementSid, + 'sid' => $sid ?: $this->properties['sid'], + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\StepContext Context for this + * StepInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new StepContext( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a StepInstance + * + * @return StepInstance Fetched StepInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Access the stepContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\Step\StepContextList + */ + protected function getStepContext() { + return $this->proxy()->stepContext; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.StepInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/StepList.php b/Twilio/Rest/Studio/V1/Flow/Engagement/StepList.php new file mode 100644 index 0000000..cac2e32 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/StepList.php @@ -0,0 +1,143 @@ +solution = array('flowSid' => $flowSid, 'engagementSid' => $engagementSid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Engagements/' . rawurlencode($engagementSid) . '/Steps'; + } + + /** + * Streams StepInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads StepInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return StepInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of StepInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of StepInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new StepPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of StepInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of StepInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new StepPage($this->version, $response, $this->solution); + } + + /** + * Constructs a StepContext + * + * @param string $sid Step Sid. + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\StepContext + */ + public function getContext($sid) { + return new StepContext( + $this->version, + $this->solution['flowSid'], + $this->solution['engagementSid'], + $sid + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.StepList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Engagement/StepPage.php b/Twilio/Rest/Studio/V1/Flow/Engagement/StepPage.php new file mode 100644 index 0000000..615522c --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Engagement/StepPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new StepInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['engagementSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.StepPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/EngagementContext.php b/Twilio/Rest/Studio/V1/Flow/EngagementContext.php new file mode 100644 index 0000000..ef88307 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/EngagementContext.php @@ -0,0 +1,154 @@ +solution = array('flowSid' => $flowSid, 'sid' => $sid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Engagements/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a EngagementInstance + * + * @return EngagementInstance Fetched EngagementInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new EngagementInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the EngagementInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the steps + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\StepList + */ + protected function getSteps() { + if (!$this->_steps) { + $this->_steps = new StepList($this->version, $this->solution['flowSid'], $this->solution['sid']); + } + + return $this->_steps; + } + + /** + * Access the engagementContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\EngagementContextList + */ + protected function getEngagementContext() { + if (!$this->_engagementContext) { + $this->_engagementContext = new EngagementContextList( + $this->version, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + return $this->_engagementContext; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.EngagementContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/EngagementInstance.php b/Twilio/Rest/Studio/V1/Flow/EngagementInstance.php new file mode 100644 index 0000000..c70bdd7 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/EngagementInstance.php @@ -0,0 +1,154 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'contactSid' => Values::array_get($payload, 'contact_sid'), + 'contactChannelAddress' => Values::array_get($payload, 'contact_channel_address'), + 'context' => Values::array_get($payload, 'context'), + 'status' => Values::array_get($payload, 'status'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('flowSid' => $flowSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\EngagementContext Context for this + * EngagementInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new EngagementContext( + $this->version, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a EngagementInstance + * + * @return EngagementInstance Fetched EngagementInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the EngagementInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the steps + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\StepList + */ + protected function getSteps() { + return $this->proxy()->steps; + } + + /** + * Access the engagementContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Engagement\EngagementContextList + */ + protected function getEngagementContext() { + return $this->proxy()->engagementContext; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.EngagementInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/EngagementList.php b/Twilio/Rest/Studio/V1/Flow/EngagementList.php new file mode 100644 index 0000000..ef8e55e --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/EngagementList.php @@ -0,0 +1,168 @@ +solution = array('flowSid' => $flowSid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Engagements'; + } + + /** + * Streams EngagementInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads EngagementInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return EngagementInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of EngagementInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of EngagementInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new EngagementPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of EngagementInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of EngagementInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new EngagementPage($this->version, $response, $this->solution); + } + + /** + * Create a new EngagementInstance + * + * @param string $to The Contact phone number to start a Studio Flow Engagement. + * @param string $from The Twilio phone number to send messages or initiate + * calls from during the Flow Engagement. + * @param array|Options $options Optional Arguments + * @return EngagementInstance Newly created EngagementInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($to, $from, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'To' => $to, + 'From' => $from, + 'Parameters' => Serialize::jsonObject($options['parameters']), + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new EngagementInstance($this->version, $payload, $this->solution['flowSid']); + } + + /** + * Constructs a EngagementContext + * + * @param string $sid Engagement Sid. + * @return \Twilio\Rest\Studio\V1\Flow\EngagementContext + */ + public function getContext($sid) { + return new EngagementContext($this->version, $this->solution['flowSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.EngagementList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/EngagementOptions.php b/Twilio/Rest/Studio/V1/Flow/EngagementOptions.php new file mode 100644 index 0000000..bc9ca01 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/EngagementOptions.php @@ -0,0 +1,61 @@ +options['parameters'] = $parameters; + } + + /** + * JSON data that will be added to your flow's context and can accessed as variables inside your flow. For example, if you pass in Parameters={'name':'Zeke'} then inside a widget you can reference the variable {{flow.data.name}} which will return the string 'Zeke'. Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode your JSON string. + * + * @param array $parameters JSON data that will be added to your flow's context + * and can accessed as variables inside your flow. + * @return $this Fluent Builder + */ + public function setParameters($parameters) { + $this->options['parameters'] = $parameters; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Studio.V1.CreateEngagementOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/EngagementPage.php b/Twilio/Rest/Studio/V1/Flow/EngagementPage.php new file mode 100644 index 0000000..3a6b2dc --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/EngagementPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new EngagementInstance($this->version, $payload, $this->solution['flowSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.EngagementPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextContext.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextContext.php new file mode 100644 index 0000000..4b4c772 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextContext.php @@ -0,0 +1,69 @@ +solution = array('flowSid' => $flowSid, 'executionSid' => $executionSid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Executions/' . rawurlencode($executionSid) . '/Context'; + } + + /** + * Fetch a ExecutionContextInstance + * + * @return ExecutionContextInstance Fetched ExecutionContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ExecutionContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['executionSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionContextContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextInstance.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextInstance.php new file mode 100644 index 0000000..1088f20 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextInstance.php @@ -0,0 +1,109 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'context' => Values::array_get($payload, 'context'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'executionSid' => Values::array_get($payload, 'execution_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('flowSid' => $flowSid, 'executionSid' => $executionSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionContextContext Context for this ExecutionContextInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ExecutionContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ExecutionContextInstance + * + * @return ExecutionContextInstance Fetched ExecutionContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionContextInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextList.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextList.php new file mode 100644 index 0000000..f8bbdd5 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextList.php @@ -0,0 +1,52 @@ +solution = array('flowSid' => $flowSid, 'executionSid' => $executionSid, ); + } + + /** + * Constructs a ExecutionContextContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionContextContext + */ + public function getContext() { + return new ExecutionContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionContextList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextPage.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextPage.php new file mode 100644 index 0000000..91901e9 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionContextPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ExecutionContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['executionSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionContextPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextContext.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextContext.php new file mode 100644 index 0000000..a2c6d9e --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextContext.php @@ -0,0 +1,75 @@ +solution = array( + 'flowSid' => $flowSid, + 'executionSid' => $executionSid, + 'stepSid' => $stepSid, + ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Executions/' . rawurlencode($executionSid) . '/Steps/' . rawurlencode($stepSid) . '/Context'; + } + + /** + * Fetch a ExecutionStepContextInstance + * + * @return ExecutionStepContextInstance Fetched ExecutionStepContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ExecutionStepContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['stepSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionStepContextContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextInstance.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextInstance.php new file mode 100644 index 0000000..7ae50d6 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextInstance.php @@ -0,0 +1,118 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'context' => Values::array_get($payload, 'context'), + 'executionSid' => Values::array_get($payload, 'execution_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'stepSid' => Values::array_get($payload, 'step_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array( + 'flowSid' => $flowSid, + 'executionSid' => $executionSid, + 'stepSid' => $stepSid, + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStep\ExecutionStepContextContext Context for this + * ExecutionStepContextInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ExecutionStepContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['stepSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ExecutionStepContextInstance + * + * @return ExecutionStepContextInstance Fetched ExecutionStepContextInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionStepContextInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextList.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextList.php new file mode 100644 index 0000000..139d755 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextList.php @@ -0,0 +1,58 @@ +solution = array( + 'flowSid' => $flowSid, + 'executionSid' => $executionSid, + 'stepSid' => $stepSid, + ); + } + + /** + * Constructs a ExecutionStepContextContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStep\ExecutionStepContextContext + */ + public function getContext() { + return new ExecutionStepContextContext( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['stepSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionStepContextList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextPage.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextPage.php new file mode 100644 index 0000000..19ae005 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStep/ExecutionStepContextPage.php @@ -0,0 +1,40 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ExecutionStepContextInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['stepSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionStepContextPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepContext.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepContext.php new file mode 100644 index 0000000..16cfebb --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepContext.php @@ -0,0 +1,130 @@ +solution = array('flowSid' => $flowSid, 'executionSid' => $executionSid, 'sid' => $sid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Executions/' . rawurlencode($executionSid) . '/Steps/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a ExecutionStepInstance + * + * @return ExecutionStepInstance Fetched ExecutionStepInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ExecutionStepInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['sid'] + ); + } + + /** + * Access the stepContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStep\ExecutionStepContextList + */ + protected function getStepContext() { + if (!$this->_stepContext) { + $this->_stepContext = new ExecutionStepContextList( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['sid'] + ); + } + + return $this->_stepContext; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionStepContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepInstance.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepInstance.php new file mode 100644 index 0000000..cb5dad1 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepInstance.php @@ -0,0 +1,143 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'executionSid' => Values::array_get($payload, 'execution_sid'), + 'name' => Values::array_get($payload, 'name'), + 'context' => Values::array_get($payload, 'context'), + 'transitionedFrom' => Values::array_get($payload, 'transitioned_from'), + 'transitionedTo' => Values::array_get($payload, 'transitioned_to'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array( + 'flowSid' => $flowSid, + 'executionSid' => $executionSid, + 'sid' => $sid ?: $this->properties['sid'], + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStepContext Context + * for this + * ExecutionStepInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ExecutionStepContext( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ExecutionStepInstance + * + * @return ExecutionStepInstance Fetched ExecutionStepInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Access the stepContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStep\ExecutionStepContextList + */ + protected function getStepContext() { + return $this->proxy()->stepContext; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionStepInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepList.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepList.php new file mode 100644 index 0000000..016debd --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepList.php @@ -0,0 +1,143 @@ +solution = array('flowSid' => $flowSid, 'executionSid' => $executionSid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Executions/' . rawurlencode($executionSid) . '/Steps'; + } + + /** + * Streams ExecutionStepInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads ExecutionStepInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return ExecutionStepInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of ExecutionStepInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of ExecutionStepInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new ExecutionStepPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of ExecutionStepInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of ExecutionStepInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new ExecutionStepPage($this->version, $response, $this->solution); + } + + /** + * Constructs a ExecutionStepContext + * + * @param string $sid Step Sid. + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStepContext + */ + public function getContext($sid) { + return new ExecutionStepContext( + $this->version, + $this->solution['flowSid'], + $this->solution['executionSid'], + $sid + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionStepList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepPage.php b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepPage.php new file mode 100644 index 0000000..42fe6ab --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/Execution/ExecutionStepPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ExecutionStepInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['executionSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionStepPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/ExecutionContext.php b/Twilio/Rest/Studio/V1/Flow/ExecutionContext.php new file mode 100644 index 0000000..0a0102b --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/ExecutionContext.php @@ -0,0 +1,158 @@ +solution = array('flowSid' => $flowSid, 'sid' => $sid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Executions/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a ExecutionInstance + * + * @return ExecutionInstance Fetched ExecutionInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ExecutionInstance( + $this->version, + $payload, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the ExecutionInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the steps + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStepList + */ + protected function getSteps() { + if (!$this->_steps) { + $this->_steps = new ExecutionStepList( + $this->version, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + return $this->_steps; + } + + /** + * Access the executionContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionContextList + */ + protected function getExecutionContext() { + if (!$this->_executionContext) { + $this->_executionContext = new ExecutionContextList( + $this->version, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + return $this->_executionContext; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/ExecutionInstance.php b/Twilio/Rest/Studio/V1/Flow/ExecutionInstance.php new file mode 100644 index 0000000..c3c53b6 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/ExecutionInstance.php @@ -0,0 +1,154 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'flowSid' => Values::array_get($payload, 'flow_sid'), + 'contactSid' => Values::array_get($payload, 'contact_sid'), + 'contactChannelAddress' => Values::array_get($payload, 'contact_channel_address'), + 'context' => Values::array_get($payload, 'context'), + 'status' => Values::array_get($payload, 'status'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('flowSid' => $flowSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\Flow\ExecutionContext Context for this + * ExecutionInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ExecutionContext( + $this->version, + $this->solution['flowSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ExecutionInstance + * + * @return ExecutionInstance Fetched ExecutionInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the ExecutionInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the steps + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionStepList + */ + protected function getSteps() { + return $this->proxy()->steps; + } + + /** + * Access the executionContext + * + * @return \Twilio\Rest\Studio\V1\Flow\Execution\ExecutionContextList + */ + protected function getExecutionContext() { + return $this->proxy()->executionContext; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.ExecutionInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/ExecutionList.php b/Twilio/Rest/Studio/V1/Flow/ExecutionList.php new file mode 100644 index 0000000..2da52cc --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/ExecutionList.php @@ -0,0 +1,168 @@ +solution = array('flowSid' => $flowSid, ); + + $this->uri = '/Flows/' . rawurlencode($flowSid) . '/Executions'; + } + + /** + * Streams ExecutionInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads ExecutionInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return ExecutionInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of ExecutionInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of ExecutionInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new ExecutionPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of ExecutionInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of ExecutionInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new ExecutionPage($this->version, $response, $this->solution); + } + + /** + * Create a new ExecutionInstance + * + * @param string $to The Contact phone number to start a Studio Flow Execution. + * @param string $from The Twilio phone number to send messages or initiate + * calls from during the Flow Execution. + * @param array|Options $options Optional Arguments + * @return ExecutionInstance Newly created ExecutionInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($to, $from, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'To' => $to, + 'From' => $from, + 'Parameters' => Serialize::jsonObject($options['parameters']), + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new ExecutionInstance($this->version, $payload, $this->solution['flowSid']); + } + + /** + * Constructs a ExecutionContext + * + * @param string $sid Execution Sid. + * @return \Twilio\Rest\Studio\V1\Flow\ExecutionContext + */ + public function getContext($sid) { + return new ExecutionContext($this->version, $this->solution['flowSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/ExecutionOptions.php b/Twilio/Rest/Studio/V1/Flow/ExecutionOptions.php new file mode 100644 index 0000000..7c6b64d --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/ExecutionOptions.php @@ -0,0 +1,61 @@ +options['parameters'] = $parameters; + } + + /** + * JSON data that will be added to your flow's context and can accessed as variables inside your flow. For example, if you pass in Parameters={'name':'Zeke'} then inside a widget you can reference the variable {{flow.data.name}} which will return the string 'Zeke'. Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode your JSON string. + * + * @param array $parameters JSON data that will be added to your flow's context + * and can accessed as variables inside your flow. + * @return $this Fluent Builder + */ + public function setParameters($parameters) { + $this->options['parameters'] = $parameters; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Studio.V1.CreateExecutionOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/Flow/ExecutionPage.php b/Twilio/Rest/Studio/V1/Flow/ExecutionPage.php new file mode 100644 index 0000000..1fc7a78 --- /dev/null +++ b/Twilio/Rest/Studio/V1/Flow/ExecutionPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ExecutionInstance($this->version, $payload, $this->solution['flowSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.ExecutionPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/FlowContext.php b/Twilio/Rest/Studio/V1/FlowContext.php new file mode 100644 index 0000000..cc9e928 --- /dev/null +++ b/Twilio/Rest/Studio/V1/FlowContext.php @@ -0,0 +1,144 @@ +solution = array('sid' => $sid, ); + + $this->uri = '/Flows/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a FlowInstance + * + * @return FlowInstance Fetched FlowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new FlowInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Deletes the FlowInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the engagements + * + * @return \Twilio\Rest\Studio\V1\Flow\EngagementList + */ + protected function getEngagements() { + if (!$this->_engagements) { + $this->_engagements = new EngagementList($this->version, $this->solution['sid']); + } + + return $this->_engagements; + } + + /** + * Access the executions + * + * @return \Twilio\Rest\Studio\V1\Flow\ExecutionList + */ + protected function getExecutions() { + if (!$this->_executions) { + $this->_executions = new ExecutionList($this->version, $this->solution['sid']); + } + + return $this->_executions; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.FlowContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/FlowInstance.php b/Twilio/Rest/Studio/V1/FlowInstance.php new file mode 100644 index 0000000..d001027 --- /dev/null +++ b/Twilio/Rest/Studio/V1/FlowInstance.php @@ -0,0 +1,144 @@ +properties = array( + 'sid' => Values::array_get($payload, 'sid'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'status' => Values::array_get($payload, 'status'), + 'version' => Values::array_get($payload, 'version'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Studio\V1\FlowContext Context for this FlowInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new FlowContext($this->version, $this->solution['sid']); + } + + return $this->context; + } + + /** + * Fetch a FlowInstance + * + * @return FlowInstance Fetched FlowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the FlowInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the engagements + * + * @return \Twilio\Rest\Studio\V1\Flow\EngagementList + */ + protected function getEngagements() { + return $this->proxy()->engagements; + } + + /** + * Access the executions + * + * @return \Twilio\Rest\Studio\V1\Flow\ExecutionList + */ + protected function getExecutions() { + return $this->proxy()->executions; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Studio.V1.FlowInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/FlowList.php b/Twilio/Rest/Studio/V1/FlowList.php new file mode 100644 index 0000000..2c82d07 --- /dev/null +++ b/Twilio/Rest/Studio/V1/FlowList.php @@ -0,0 +1,136 @@ +solution = array(); + + $this->uri = '/Flows'; + } + + /** + * Streams FlowInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads FlowInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return FlowInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of FlowInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of FlowInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new FlowPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of FlowInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of FlowInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new FlowPage($this->version, $response, $this->solution); + } + + /** + * Constructs a FlowContext + * + * @param string $sid A string that uniquely identifies this Flow. + * @return \Twilio\Rest\Studio\V1\FlowContext + */ + public function getContext($sid) { + return new FlowContext($this->version, $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.FlowList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Studio/V1/FlowPage.php b/Twilio/Rest/Studio/V1/FlowPage.php new file mode 100644 index 0000000..3b2664b --- /dev/null +++ b/Twilio/Rest/Studio/V1/FlowPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new FlowInstance($this->version, $payload); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Studio.V1.FlowPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter.php b/Twilio/Rest/Taskrouter.php new file mode 100644 index 0000000..a87d8eb --- /dev/null +++ b/Twilio/Rest/Taskrouter.php @@ -0,0 +1,103 @@ +baseUrl = 'https://taskrouter.twilio.com'; + } + + /** + * @return \Twilio\Rest\Taskrouter\V1 Version v1 of taskrouter + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Taskrouter\V1\WorkspaceList + */ + protected function getWorkspaces() { + return $this->v1->workspaces; + } + + /** + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\WorkspaceContext + */ + protected function contextWorkspaces($sid) { + return $this->v1->workspaces($sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1.php b/Twilio/Rest/Taskrouter/V1.php new file mode 100644 index 0000000..b429504 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1.php @@ -0,0 +1,86 @@ +version = 'v1'; + } + + /** + * @return \Twilio\Rest\Taskrouter\V1\WorkspaceList + */ + protected function getWorkspaces() { + if (!$this->_workspaces) { + $this->_workspaces = new WorkspaceList($this); + } + return $this->_workspaces; + } + + /** + * Magic getter to lazy load root resources + * + * @param string $name Resource to return + * @return \Twilio\ListResource The requested resource + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown resource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/ActivityContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityContext.php new file mode 100644 index 0000000..d630926 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityContext.php @@ -0,0 +1,107 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Activities/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a ActivityInstance + * + * @return ActivityInstance Fetched ActivityInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ActivityInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Update the ActivityInstance + * + * @param array|Options $options Optional Arguments + * @return ActivityInstance Updated ActivityInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array('FriendlyName' => $options['friendlyName'], )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new ActivityInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the ActivityInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.ActivityContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/ActivityInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityInstance.php new file mode 100644 index 0000000..9868da2 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityInstance.php @@ -0,0 +1,141 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'available' => Values::array_get($payload, 'available'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'sid' => Values::array_get($payload, 'sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\ActivityContext Context for + * this + * ActivityInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ActivityContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ActivityInstance + * + * @return ActivityInstance Fetched ActivityInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the ActivityInstance + * + * @param array|Options $options Optional Arguments + * @return ActivityInstance Updated ActivityInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the ActivityInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.ActivityInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/ActivityList.php b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityList.php new file mode 100644 index 0000000..6fdc79f --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityList.php @@ -0,0 +1,173 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Activities'; + } + + /** + * Streams ActivityInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads ActivityInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return ActivityInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of ActivityInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of ActivityInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'Available' => $options['available'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new ActivityPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of ActivityInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of ActivityInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new ActivityPage($this->version, $response, $this->solution); + } + + /** + * Create a new ActivityInstance + * + * @param string $friendlyName A human-readable name for the Activity, such as + * 'On Call', 'Break', 'Email', etc. + * @param array|Options $options Optional Arguments + * @return ActivityInstance Newly created ActivityInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($friendlyName, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $friendlyName, + 'Available' => Serialize::booleanToString($options['available']), + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new ActivityInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Constructs a ActivityContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\ActivityContext + */ + public function getContext($sid) { + return new ActivityContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.ActivityList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/ActivityOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityOptions.php new file mode 100644 index 0000000..4f5d1bf --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityOptions.php @@ -0,0 +1,170 @@ +options['friendlyName'] = $friendlyName; + } + + /** + * A human-readable name for the Activity, such as 'on-call', 'break', 'email', etc. These names will be used to calculate and expose statistics about workers, and give you visibility into the state of each of your workers. + * + * @param string $friendlyName A human-readable name for the Activity, such as + * 'on-call', 'break', 'email', etc. + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateActivityOptions ' . implode(' ', $options) . ']'; + } +} + +class ReadActivityOptions extends Options { + /** + * @param string $friendlyName Filter by an Activity's friendly name + * @param string $available Filter by activities that are available or + * unavailable. + */ + public function __construct($friendlyName = Values::NONE, $available = Values::NONE) { + $this->options['friendlyName'] = $friendlyName; + $this->options['available'] = $available; + } + + /** + * Filter by an Activity's friendly name + * + * @param string $friendlyName Filter by an Activity's friendly name + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Filter by activities that are available or unavailable. (Note: This can be 'true', '1'' or 'yes' to indicate a true value. All other values will represent false) + * + * @param string $available Filter by activities that are available or + * unavailable. + * @return $this Fluent Builder + */ + public function setAvailable($available) { + $this->options['available'] = $available; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadActivityOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateActivityOptions extends Options { + /** + * @param boolean $available Boolean value indicating whether the worker should + * be eligible to receive a Task when they occupy + * this Activity. + */ + public function __construct($available = Values::NONE) { + $this->options['available'] = $available; + } + + /** + * Boolean value indicating whether the worker should be eligible to receive a Task when they occupy this Activity. For example, a call center might have an activity named 'On Call' with an availability set to 'false'. Note: This can be 'true', '1' or 'yes' to indicate a true value. All other values will represent false. Defaults to false. + * + * @param boolean $available Boolean value indicating whether the worker should + * be eligible to receive a Task when they occupy + * this Activity. + * @return $this Fluent Builder + */ + public function setAvailable($available) { + $this->options['available'] = $available; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.CreateActivityOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/ActivityPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityPage.php new file mode 100644 index 0000000..95c937b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/ActivityPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ActivityInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.ActivityPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/EventContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/EventContext.php new file mode 100644 index 0000000..ade9fed --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/EventContext.php @@ -0,0 +1,69 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Events/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a EventInstance + * + * @return EventInstance Fetched EventInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new EventInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.EventContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/EventInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/EventInstance.php new file mode 100644 index 0000000..e092032 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/EventInstance.php @@ -0,0 +1,131 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'actorSid' => Values::array_get($payload, 'actor_sid'), + 'actorType' => Values::array_get($payload, 'actor_type'), + 'actorUrl' => Values::array_get($payload, 'actor_url'), + 'description' => Values::array_get($payload, 'description'), + 'eventData' => Values::array_get($payload, 'event_data'), + 'eventDate' => Deserialize::dateTime(Values::array_get($payload, 'event_date')), + 'eventType' => Values::array_get($payload, 'event_type'), + 'resourceSid' => Values::array_get($payload, 'resource_sid'), + 'resourceType' => Values::array_get($payload, 'resource_type'), + 'resourceUrl' => Values::array_get($payload, 'resource_url'), + 'sid' => Values::array_get($payload, 'sid'), + 'source' => Values::array_get($payload, 'source'), + 'sourceIpAddress' => Values::array_get($payload, 'source_ip_address'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\EventContext Context for this + * EventInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new EventContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a EventInstance + * + * @return EventInstance Fetched EventInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.EventInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/EventList.php b/Twilio/Rest/Taskrouter/V1/Workspace/EventList.php new file mode 100644 index 0000000..7fad151 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/EventList.php @@ -0,0 +1,152 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Events'; + } + + /** + * Streams EventInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads EventInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return EventInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of EventInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of EventInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'EventType' => $options['eventType'], + 'Minutes' => $options['minutes'], + 'ReservationSid' => $options['reservationSid'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskQueueSid' => $options['taskQueueSid'], + 'TaskSid' => $options['taskSid'], + 'WorkerSid' => $options['workerSid'], + 'WorkflowSid' => $options['workflowSid'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new EventPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of EventInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of EventInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new EventPage($this->version, $response, $this->solution); + } + + /** + * Constructs a EventContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\EventContext + */ + public function getContext($sid) { + return new EventContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.EventList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/EventOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/EventOptions.php new file mode 100644 index 0000000..cdda416 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/EventOptions.php @@ -0,0 +1,179 @@ +options['endDate'] = $endDate; + $this->options['eventType'] = $eventType; + $this->options['minutes'] = $minutes; + $this->options['reservationSid'] = $reservationSid; + $this->options['startDate'] = $startDate; + $this->options['taskQueueSid'] = $taskQueueSid; + $this->options['taskSid'] = $taskSid; + $this->options['workerSid'] = $workerSid; + $this->options['workflowSid'] = $workflowSid; + } + + /** + * Filter events by an end date. This is helpful for defining a range of events to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $endDate Filter events by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter events by those of a certain event type + * + * @param string $eventType Filter events by those of a certain event type + * @return $this Fluent Builder + */ + public function setEventType($eventType) { + $this->options['eventType'] = $eventType; + return $this; + } + + /** + * Filter events by up to 'x' minutes in the past. This is helpful for events for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter events by up to 'x' minutes in the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter events by those pertaining to a particular reservation + * + * @param string $reservationSid Filter events by those pertaining to a + * particular reservation + * @return $this Fluent Builder + */ + public function setReservationSid($reservationSid) { + $this->options['reservationSid'] = $reservationSid; + return $this; + } + + /** + * Filter events by a start date. This is helpful for defining a range of events to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $startDate Filter events by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter events by those pertaining to a particular queue + * + * @param string $taskQueueSid Filter events by those pertaining to a + * particular queue + * @return $this Fluent Builder + */ + public function setTaskQueueSid($taskQueueSid) { + $this->options['taskQueueSid'] = $taskQueueSid; + return $this; + } + + /** + * Filter events by those pertaining to a particular task + * + * @param string $taskSid Filter events by those pertaining to a particular task + * @return $this Fluent Builder + */ + public function setTaskSid($taskSid) { + $this->options['taskSid'] = $taskSid; + return $this; + } + + /** + * Filter events by those pertaining to a particular worker + * + * @param string $workerSid Filter events by those pertaining to a particular + * worker + * @return $this Fluent Builder + */ + public function setWorkerSid($workerSid) { + $this->options['workerSid'] = $workerSid; + return $this; + } + + /** + * The workflow_sid + * + * @param string $workflowSid The workflow_sid + * @return $this Fluent Builder + */ + public function setWorkflowSid($workflowSid) { + $this->options['workflowSid'] = $workflowSid; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadEventOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/EventPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/EventPage.php new file mode 100644 index 0000000..6eab3c8 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/EventPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new EventInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.EventPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationContext.php new file mode 100644 index 0000000..bc2526d --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationContext.php @@ -0,0 +1,153 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskSid' => $taskSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Tasks/' . rawurlencode($taskSid) . '/Reservations/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a ReservationInstance + * + * @return ReservationInstance Fetched ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ReservationInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskSid'], + $this->solution['sid'] + ); + } + + /** + * Update the ReservationInstance + * + * @param array|Options $options Optional Arguments + * @return ReservationInstance Updated ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'ReservationStatus' => $options['reservationStatus'], + 'WorkerActivitySid' => $options['workerActivitySid'], + 'Instruction' => $options['instruction'], + 'DequeuePostWorkActivitySid' => $options['dequeuePostWorkActivitySid'], + 'DequeueFrom' => $options['dequeueFrom'], + 'DequeueRecord' => $options['dequeueRecord'], + 'DequeueTimeout' => $options['dequeueTimeout'], + 'DequeueTo' => $options['dequeueTo'], + 'DequeueStatusCallbackUrl' => $options['dequeueStatusCallbackUrl'], + 'CallFrom' => $options['callFrom'], + 'CallRecord' => $options['callRecord'], + 'CallTimeout' => $options['callTimeout'], + 'CallTo' => $options['callTo'], + 'CallUrl' => $options['callUrl'], + 'CallStatusCallbackUrl' => $options['callStatusCallbackUrl'], + 'CallAccept' => Serialize::booleanToString($options['callAccept']), + 'RedirectCallSid' => $options['redirectCallSid'], + 'RedirectAccept' => Serialize::booleanToString($options['redirectAccept']), + 'RedirectUrl' => $options['redirectUrl'], + 'To' => $options['to'], + 'From' => $options['from'], + 'StatusCallback' => $options['statusCallback'], + 'StatusCallbackMethod' => $options['statusCallbackMethod'], + 'StatusCallbackEvent' => Serialize::map($options['statusCallbackEvent'], function($e) { return $e; }), + 'Timeout' => $options['timeout'], + 'Record' => Serialize::booleanToString($options['record']), + 'Muted' => Serialize::booleanToString($options['muted']), + 'Beep' => $options['beep'], + 'StartConferenceOnEnter' => Serialize::booleanToString($options['startConferenceOnEnter']), + 'EndConferenceOnExit' => Serialize::booleanToString($options['endConferenceOnExit']), + 'WaitUrl' => $options['waitUrl'], + 'WaitMethod' => $options['waitMethod'], + 'EarlyMedia' => Serialize::booleanToString($options['earlyMedia']), + 'MaxParticipants' => $options['maxParticipants'], + 'ConferenceStatusCallback' => $options['conferenceStatusCallback'], + 'ConferenceStatusCallbackMethod' => $options['conferenceStatusCallbackMethod'], + 'ConferenceStatusCallbackEvent' => Serialize::map($options['conferenceStatusCallbackEvent'], function($e) { return $e; }), + 'ConferenceRecord' => $options['conferenceRecord'], + 'ConferenceTrim' => $options['conferenceTrim'], + 'RecordingChannels' => $options['recordingChannels'], + 'RecordingStatusCallback' => $options['recordingStatusCallback'], + 'RecordingStatusCallbackMethod' => $options['recordingStatusCallbackMethod'], + 'ConferenceRecordingStatusCallback' => $options['conferenceRecordingStatusCallback'], + 'ConferenceRecordingStatusCallbackMethod' => $options['conferenceRecordingStatusCallbackMethod'], + 'Region' => $options['region'], + 'SipAuthUsername' => $options['sipAuthUsername'], + 'SipAuthPassword' => $options['sipAuthPassword'], + 'DequeueStatusCallbackEvent' => Serialize::map($options['dequeueStatusCallbackEvent'], function($e) { return $e; }), + 'PostWorkActivitySid' => $options['postWorkActivitySid'], + 'SupervisorMode' => $options['supervisorMode'], + 'Supervisor' => $options['supervisor'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new ReservationInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskSid'], + $this->solution['sid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.ReservationContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationInstance.php new file mode 100644 index 0000000..a340cdc --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationInstance.php @@ -0,0 +1,144 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'reservationStatus' => Values::array_get($payload, 'reservation_status'), + 'sid' => Values::array_get($payload, 'sid'), + 'taskSid' => Values::array_get($payload, 'task_sid'), + 'workerName' => Values::array_get($payload, 'worker_name'), + 'workerSid' => Values::array_get($payload, 'worker_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array( + 'workspaceSid' => $workspaceSid, + 'taskSid' => $taskSid, + 'sid' => $sid ?: $this->properties['sid'], + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Task\ReservationContext Context + * for + * this + * ReservationInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ReservationContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ReservationInstance + * + * @return ReservationInstance Fetched ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the ReservationInstance + * + * @param array|Options $options Optional Arguments + * @return ReservationInstance Updated ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.ReservationInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationList.php new file mode 100644 index 0000000..cdc3ac8 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationList.php @@ -0,0 +1,150 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskSid' => $taskSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Tasks/' . rawurlencode($taskSid) . '/Reservations'; + } + + /** + * Streams ReservationInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads ReservationInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return ReservationInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of ReservationInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of ReservationInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'ReservationStatus' => $options['reservationStatus'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new ReservationPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of ReservationInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of ReservationInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new ReservationPage($this->version, $response, $this->solution); + } + + /** + * Constructs a ReservationContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Task\ReservationContext + */ + public function getContext($sid) { + return new ReservationContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskSid'], + $sid + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.ReservationList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationOptions.php new file mode 100644 index 0000000..f489e4a --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationOptions.php @@ -0,0 +1,897 @@ +options['reservationStatus'] = $reservationStatus; + } + + /** + * Returns the list of reservations for a task with a specified ReservationStatus + * + * @param string $reservationStatus Returns the list of reservations for a task + * with a specified ReservationStatus + * @return $this Fluent Builder + */ + public function setReservationStatus($reservationStatus) { + $this->options['reservationStatus'] = $reservationStatus; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadReservationOptions ' . implode(' ', $options) . ']'; + } +} + +class UpdateReservationOptions extends Options { + /** + * @param string $reservationStatus New reservation status + * @param string $workerActivitySid New worker activity sid if rejecting a + * reservation + * @param string $instruction Assignment instruction for reservation + * @param string $dequeuePostWorkActivitySid New worker activity sid after + * executing a Dequeue instruction + * @param string $dequeueFrom Caller ID for the call to the worker when + * executing a Dequeue instruction + * @param string $dequeueRecord Attribute to record both legs of a call when + * executing a Dequeue instruction + * @param integer $dequeueTimeout Timeout for call when executing a Dequeue + * instruction + * @param string $dequeueTo Contact URI of the worker when executing a Dequeue + * instruction + * @param string $dequeueStatusCallbackUrl Callback URL for completed call + * event when executing a Dequeue + * instruction + * @param string $callFrom Caller ID for the outbound call when executing a + * Call instruction + * @param string $callRecord Attribute to record both legs of a call when + * executing a Call instruction + * @param integer $callTimeout Timeout for call when executing a Call + * instruction + * @param string $callTo Contact URI of the worker when executing a Call + * instruction + * @param string $callUrl TwiML URI executed on answering the worker's leg as a + * result of the Call instruction + * @param string $callStatusCallbackUrl Callback URL for completed call event + * when executing a Call instruction + * @param boolean $callAccept Flag to determine if reservation should be + * accepted when executing a Call instruction + * @param string $redirectCallSid Call sid of the call parked in the queue when + * executing a Redirect instruction + * @param boolean $redirectAccept Flag to determine if reservation should be + * accepted when executing a Redirect instruction + * @param string $redirectUrl TwiML URI to redirect the call to when executing + * the Redirect instruction + * @param string $to Contact URI of the worker when executing a Conference + * instruction + * @param string $from Caller ID for the call to the worker when executing a + * Conference instruction + * @param string $statusCallback The status_callback + * @param string $statusCallbackMethod The status_callback_method + * @param string $statusCallbackEvent The status_callback_event + * @param integer $timeout Timeout for call when executing a Conference + * instruction + * @param boolean $record The record + * @param boolean $muted The muted + * @param string $beep The beep + * @param boolean $startConferenceOnEnter The start_conference_on_enter + * @param boolean $endConferenceOnExit The end_conference_on_exit + * @param string $waitUrl The wait_url + * @param string $waitMethod The wait_method + * @param boolean $earlyMedia The early_media + * @param integer $maxParticipants The max_participants + * @param string $conferenceStatusCallback The conference_status_callback + * @param string $conferenceStatusCallbackMethod The + * conference_status_callback_method + * @param string $conferenceStatusCallbackEvent The + * conference_status_callback_event + * @param string $conferenceRecord The conference_record + * @param string $conferenceTrim The conference_trim + * @param string $recordingChannels The recording_channels + * @param string $recordingStatusCallback The recording_status_callback + * @param string $recordingStatusCallbackMethod The + * recording_status_callback_method + * @param string $conferenceRecordingStatusCallback The + * conference_recording_status_callback + * @param string $conferenceRecordingStatusCallbackMethod The + * conference_recording_status_callback_method + * @param string $region The region + * @param string $sipAuthUsername The sip_auth_username + * @param string $sipAuthPassword The sip_auth_password + * @param string $dequeueStatusCallbackEvent Call progress events sent via + * webhooks as a result of a Dequeue + * instruction + * @param string $postWorkActivitySid New worker activity sid after executing a + * Conference instruction + * @param string $supervisorMode Supervisor mode when executing the Supervise + * instruction + * @param string $supervisor Supervisor sid/uri when executing the Supervise + * instruction + */ + public function __construct($reservationStatus = Values::NONE, $workerActivitySid = Values::NONE, $instruction = Values::NONE, $dequeuePostWorkActivitySid = Values::NONE, $dequeueFrom = Values::NONE, $dequeueRecord = Values::NONE, $dequeueTimeout = Values::NONE, $dequeueTo = Values::NONE, $dequeueStatusCallbackUrl = Values::NONE, $callFrom = Values::NONE, $callRecord = Values::NONE, $callTimeout = Values::NONE, $callTo = Values::NONE, $callUrl = Values::NONE, $callStatusCallbackUrl = Values::NONE, $callAccept = Values::NONE, $redirectCallSid = Values::NONE, $redirectAccept = Values::NONE, $redirectUrl = Values::NONE, $to = Values::NONE, $from = Values::NONE, $statusCallback = Values::NONE, $statusCallbackMethod = Values::NONE, $statusCallbackEvent = Values::NONE, $timeout = Values::NONE, $record = Values::NONE, $muted = Values::NONE, $beep = Values::NONE, $startConferenceOnEnter = Values::NONE, $endConferenceOnExit = Values::NONE, $waitUrl = Values::NONE, $waitMethod = Values::NONE, $earlyMedia = Values::NONE, $maxParticipants = Values::NONE, $conferenceStatusCallback = Values::NONE, $conferenceStatusCallbackMethod = Values::NONE, $conferenceStatusCallbackEvent = Values::NONE, $conferenceRecord = Values::NONE, $conferenceTrim = Values::NONE, $recordingChannels = Values::NONE, $recordingStatusCallback = Values::NONE, $recordingStatusCallbackMethod = Values::NONE, $conferenceRecordingStatusCallback = Values::NONE, $conferenceRecordingStatusCallbackMethod = Values::NONE, $region = Values::NONE, $sipAuthUsername = Values::NONE, $sipAuthPassword = Values::NONE, $dequeueStatusCallbackEvent = Values::NONE, $postWorkActivitySid = Values::NONE, $supervisorMode = Values::NONE, $supervisor = Values::NONE) { + $this->options['reservationStatus'] = $reservationStatus; + $this->options['workerActivitySid'] = $workerActivitySid; + $this->options['instruction'] = $instruction; + $this->options['dequeuePostWorkActivitySid'] = $dequeuePostWorkActivitySid; + $this->options['dequeueFrom'] = $dequeueFrom; + $this->options['dequeueRecord'] = $dequeueRecord; + $this->options['dequeueTimeout'] = $dequeueTimeout; + $this->options['dequeueTo'] = $dequeueTo; + $this->options['dequeueStatusCallbackUrl'] = $dequeueStatusCallbackUrl; + $this->options['callFrom'] = $callFrom; + $this->options['callRecord'] = $callRecord; + $this->options['callTimeout'] = $callTimeout; + $this->options['callTo'] = $callTo; + $this->options['callUrl'] = $callUrl; + $this->options['callStatusCallbackUrl'] = $callStatusCallbackUrl; + $this->options['callAccept'] = $callAccept; + $this->options['redirectCallSid'] = $redirectCallSid; + $this->options['redirectAccept'] = $redirectAccept; + $this->options['redirectUrl'] = $redirectUrl; + $this->options['to'] = $to; + $this->options['from'] = $from; + $this->options['statusCallback'] = $statusCallback; + $this->options['statusCallbackMethod'] = $statusCallbackMethod; + $this->options['statusCallbackEvent'] = $statusCallbackEvent; + $this->options['timeout'] = $timeout; + $this->options['record'] = $record; + $this->options['muted'] = $muted; + $this->options['beep'] = $beep; + $this->options['startConferenceOnEnter'] = $startConferenceOnEnter; + $this->options['endConferenceOnExit'] = $endConferenceOnExit; + $this->options['waitUrl'] = $waitUrl; + $this->options['waitMethod'] = $waitMethod; + $this->options['earlyMedia'] = $earlyMedia; + $this->options['maxParticipants'] = $maxParticipants; + $this->options['conferenceStatusCallback'] = $conferenceStatusCallback; + $this->options['conferenceStatusCallbackMethod'] = $conferenceStatusCallbackMethod; + $this->options['conferenceStatusCallbackEvent'] = $conferenceStatusCallbackEvent; + $this->options['conferenceRecord'] = $conferenceRecord; + $this->options['conferenceTrim'] = $conferenceTrim; + $this->options['recordingChannels'] = $recordingChannels; + $this->options['recordingStatusCallback'] = $recordingStatusCallback; + $this->options['recordingStatusCallbackMethod'] = $recordingStatusCallbackMethod; + $this->options['conferenceRecordingStatusCallback'] = $conferenceRecordingStatusCallback; + $this->options['conferenceRecordingStatusCallbackMethod'] = $conferenceRecordingStatusCallbackMethod; + $this->options['region'] = $region; + $this->options['sipAuthUsername'] = $sipAuthUsername; + $this->options['sipAuthPassword'] = $sipAuthPassword; + $this->options['dequeueStatusCallbackEvent'] = $dequeueStatusCallbackEvent; + $this->options['postWorkActivitySid'] = $postWorkActivitySid; + $this->options['supervisorMode'] = $supervisorMode; + $this->options['supervisor'] = $supervisor; + } + + /** + * New reservation status + * + * @param string $reservationStatus New reservation status + * @return $this Fluent Builder + */ + public function setReservationStatus($reservationStatus) { + $this->options['reservationStatus'] = $reservationStatus; + return $this; + } + + /** + * New worker activity sid if rejecting a reservation + * + * @param string $workerActivitySid New worker activity sid if rejecting a + * reservation + * @return $this Fluent Builder + */ + public function setWorkerActivitySid($workerActivitySid) { + $this->options['workerActivitySid'] = $workerActivitySid; + return $this; + } + + /** + * Assignment instruction for reservation + * + * @param string $instruction Assignment instruction for reservation + * @return $this Fluent Builder + */ + public function setInstruction($instruction) { + $this->options['instruction'] = $instruction; + return $this; + } + + /** + * New worker activity sid after executing a Dequeue instruction + * + * @param string $dequeuePostWorkActivitySid New worker activity sid after + * executing a Dequeue instruction + * @return $this Fluent Builder + */ + public function setDequeuePostWorkActivitySid($dequeuePostWorkActivitySid) { + $this->options['dequeuePostWorkActivitySid'] = $dequeuePostWorkActivitySid; + return $this; + } + + /** + * Caller ID for the call to the worker when executing a Dequeue instruction + * + * @param string $dequeueFrom Caller ID for the call to the worker when + * executing a Dequeue instruction + * @return $this Fluent Builder + */ + public function setDequeueFrom($dequeueFrom) { + $this->options['dequeueFrom'] = $dequeueFrom; + return $this; + } + + /** + * Attribute to record both legs of a call when executing a Dequeue instruction + * + * @param string $dequeueRecord Attribute to record both legs of a call when + * executing a Dequeue instruction + * @return $this Fluent Builder + */ + public function setDequeueRecord($dequeueRecord) { + $this->options['dequeueRecord'] = $dequeueRecord; + return $this; + } + + /** + * Timeout for call when executing a Dequeue instruction + * + * @param integer $dequeueTimeout Timeout for call when executing a Dequeue + * instruction + * @return $this Fluent Builder + */ + public function setDequeueTimeout($dequeueTimeout) { + $this->options['dequeueTimeout'] = $dequeueTimeout; + return $this; + } + + /** + * Contact URI of the worker when executing a Dequeue instruction + * + * @param string $dequeueTo Contact URI of the worker when executing a Dequeue + * instruction + * @return $this Fluent Builder + */ + public function setDequeueTo($dequeueTo) { + $this->options['dequeueTo'] = $dequeueTo; + return $this; + } + + /** + * Callback URL for completed call event when executing a Dequeue instruction + * + * @param string $dequeueStatusCallbackUrl Callback URL for completed call + * event when executing a Dequeue + * instruction + * @return $this Fluent Builder + */ + public function setDequeueStatusCallbackUrl($dequeueStatusCallbackUrl) { + $this->options['dequeueStatusCallbackUrl'] = $dequeueStatusCallbackUrl; + return $this; + } + + /** + * Caller ID for the outbound call when executing a Call instruction + * + * @param string $callFrom Caller ID for the outbound call when executing a + * Call instruction + * @return $this Fluent Builder + */ + public function setCallFrom($callFrom) { + $this->options['callFrom'] = $callFrom; + return $this; + } + + /** + * Attribute to record both legs of a call when executing a Call instruction + * + * @param string $callRecord Attribute to record both legs of a call when + * executing a Call instruction + * @return $this Fluent Builder + */ + public function setCallRecord($callRecord) { + $this->options['callRecord'] = $callRecord; + return $this; + } + + /** + * Timeout for call when executing a Call instruction + * + * @param integer $callTimeout Timeout for call when executing a Call + * instruction + * @return $this Fluent Builder + */ + public function setCallTimeout($callTimeout) { + $this->options['callTimeout'] = $callTimeout; + return $this; + } + + /** + * Contact URI of the worker when executing a Call instruction + * + * @param string $callTo Contact URI of the worker when executing a Call + * instruction + * @return $this Fluent Builder + */ + public function setCallTo($callTo) { + $this->options['callTo'] = $callTo; + return $this; + } + + /** + * TwiML URI executed on answering the worker's leg as a result of the Call instruction + * + * @param string $callUrl TwiML URI executed on answering the worker's leg as a + * result of the Call instruction + * @return $this Fluent Builder + */ + public function setCallUrl($callUrl) { + $this->options['callUrl'] = $callUrl; + return $this; + } + + /** + * Callback URL for completed call event when executing a Call instruction + * + * @param string $callStatusCallbackUrl Callback URL for completed call event + * when executing a Call instruction + * @return $this Fluent Builder + */ + public function setCallStatusCallbackUrl($callStatusCallbackUrl) { + $this->options['callStatusCallbackUrl'] = $callStatusCallbackUrl; + return $this; + } + + /** + * Flag to determine if reservation should be accepted when executing a Call instruction + * + * @param boolean $callAccept Flag to determine if reservation should be + * accepted when executing a Call instruction + * @return $this Fluent Builder + */ + public function setCallAccept($callAccept) { + $this->options['callAccept'] = $callAccept; + return $this; + } + + /** + * Call sid of the call parked in the queue when executing a Redirect instruction + * + * @param string $redirectCallSid Call sid of the call parked in the queue when + * executing a Redirect instruction + * @return $this Fluent Builder + */ + public function setRedirectCallSid($redirectCallSid) { + $this->options['redirectCallSid'] = $redirectCallSid; + return $this; + } + + /** + * Flag to determine if reservation should be accepted when executing a Redirect instruction + * + * @param boolean $redirectAccept Flag to determine if reservation should be + * accepted when executing a Redirect instruction + * @return $this Fluent Builder + */ + public function setRedirectAccept($redirectAccept) { + $this->options['redirectAccept'] = $redirectAccept; + return $this; + } + + /** + * TwiML URI to redirect the call to when executing the Redirect instruction + * + * @param string $redirectUrl TwiML URI to redirect the call to when executing + * the Redirect instruction + * @return $this Fluent Builder + */ + public function setRedirectUrl($redirectUrl) { + $this->options['redirectUrl'] = $redirectUrl; + return $this; + } + + /** + * Contact URI of the worker when executing a Conference instruction + * + * @param string $to Contact URI of the worker when executing a Conference + * instruction + * @return $this Fluent Builder + */ + public function setTo($to) { + $this->options['to'] = $to; + return $this; + } + + /** + * Caller ID for the call to the worker when executing a Conference instruction + * + * @param string $from Caller ID for the call to the worker when executing a + * Conference instruction + * @return $this Fluent Builder + */ + public function setFrom($from) { + $this->options['from'] = $from; + return $this; + } + + /** + * The status_callback + * + * @param string $statusCallback The status_callback + * @return $this Fluent Builder + */ + public function setStatusCallback($statusCallback) { + $this->options['statusCallback'] = $statusCallback; + return $this; + } + + /** + * The status_callback_method + * + * @param string $statusCallbackMethod The status_callback_method + * @return $this Fluent Builder + */ + public function setStatusCallbackMethod($statusCallbackMethod) { + $this->options['statusCallbackMethod'] = $statusCallbackMethod; + return $this; + } + + /** + * The status_callback_event + * + * @param string $statusCallbackEvent The status_callback_event + * @return $this Fluent Builder + */ + public function setStatusCallbackEvent($statusCallbackEvent) { + $this->options['statusCallbackEvent'] = $statusCallbackEvent; + return $this; + } + + /** + * Timeout for call when executing a Conference instruction + * + * @param integer $timeout Timeout for call when executing a Conference + * instruction + * @return $this Fluent Builder + */ + public function setTimeout($timeout) { + $this->options['timeout'] = $timeout; + return $this; + } + + /** + * The record + * + * @param boolean $record The record + * @return $this Fluent Builder + */ + public function setRecord($record) { + $this->options['record'] = $record; + return $this; + } + + /** + * The muted + * + * @param boolean $muted The muted + * @return $this Fluent Builder + */ + public function setMuted($muted) { + $this->options['muted'] = $muted; + return $this; + } + + /** + * The beep + * + * @param string $beep The beep + * @return $this Fluent Builder + */ + public function setBeep($beep) { + $this->options['beep'] = $beep; + return $this; + } + + /** + * The start_conference_on_enter + * + * @param boolean $startConferenceOnEnter The start_conference_on_enter + * @return $this Fluent Builder + */ + public function setStartConferenceOnEnter($startConferenceOnEnter) { + $this->options['startConferenceOnEnter'] = $startConferenceOnEnter; + return $this; + } + + /** + * The end_conference_on_exit + * + * @param boolean $endConferenceOnExit The end_conference_on_exit + * @return $this Fluent Builder + */ + public function setEndConferenceOnExit($endConferenceOnExit) { + $this->options['endConferenceOnExit'] = $endConferenceOnExit; + return $this; + } + + /** + * The wait_url + * + * @param string $waitUrl The wait_url + * @return $this Fluent Builder + */ + public function setWaitUrl($waitUrl) { + $this->options['waitUrl'] = $waitUrl; + return $this; + } + + /** + * The wait_method + * + * @param string $waitMethod The wait_method + * @return $this Fluent Builder + */ + public function setWaitMethod($waitMethod) { + $this->options['waitMethod'] = $waitMethod; + return $this; + } + + /** + * The early_media + * + * @param boolean $earlyMedia The early_media + * @return $this Fluent Builder + */ + public function setEarlyMedia($earlyMedia) { + $this->options['earlyMedia'] = $earlyMedia; + return $this; + } + + /** + * The max_participants + * + * @param integer $maxParticipants The max_participants + * @return $this Fluent Builder + */ + public function setMaxParticipants($maxParticipants) { + $this->options['maxParticipants'] = $maxParticipants; + return $this; + } + + /** + * The conference_status_callback + * + * @param string $conferenceStatusCallback The conference_status_callback + * @return $this Fluent Builder + */ + public function setConferenceStatusCallback($conferenceStatusCallback) { + $this->options['conferenceStatusCallback'] = $conferenceStatusCallback; + return $this; + } + + /** + * The conference_status_callback_method + * + * @param string $conferenceStatusCallbackMethod The + * conference_status_callback_method + * @return $this Fluent Builder + */ + public function setConferenceStatusCallbackMethod($conferenceStatusCallbackMethod) { + $this->options['conferenceStatusCallbackMethod'] = $conferenceStatusCallbackMethod; + return $this; + } + + /** + * The conference_status_callback_event + * + * @param string $conferenceStatusCallbackEvent The + * conference_status_callback_event + * @return $this Fluent Builder + */ + public function setConferenceStatusCallbackEvent($conferenceStatusCallbackEvent) { + $this->options['conferenceStatusCallbackEvent'] = $conferenceStatusCallbackEvent; + return $this; + } + + /** + * The conference_record + * + * @param string $conferenceRecord The conference_record + * @return $this Fluent Builder + */ + public function setConferenceRecord($conferenceRecord) { + $this->options['conferenceRecord'] = $conferenceRecord; + return $this; + } + + /** + * The conference_trim + * + * @param string $conferenceTrim The conference_trim + * @return $this Fluent Builder + */ + public function setConferenceTrim($conferenceTrim) { + $this->options['conferenceTrim'] = $conferenceTrim; + return $this; + } + + /** + * The recording_channels + * + * @param string $recordingChannels The recording_channels + * @return $this Fluent Builder + */ + public function setRecordingChannels($recordingChannels) { + $this->options['recordingChannels'] = $recordingChannels; + return $this; + } + + /** + * The recording_status_callback + * + * @param string $recordingStatusCallback The recording_status_callback + * @return $this Fluent Builder + */ + public function setRecordingStatusCallback($recordingStatusCallback) { + $this->options['recordingStatusCallback'] = $recordingStatusCallback; + return $this; + } + + /** + * The recording_status_callback_method + * + * @param string $recordingStatusCallbackMethod The + * recording_status_callback_method + * @return $this Fluent Builder + */ + public function setRecordingStatusCallbackMethod($recordingStatusCallbackMethod) { + $this->options['recordingStatusCallbackMethod'] = $recordingStatusCallbackMethod; + return $this; + } + + /** + * The conference_recording_status_callback + * + * @param string $conferenceRecordingStatusCallback The + * conference_recording_status_callback + * @return $this Fluent Builder + */ + public function setConferenceRecordingStatusCallback($conferenceRecordingStatusCallback) { + $this->options['conferenceRecordingStatusCallback'] = $conferenceRecordingStatusCallback; + return $this; + } + + /** + * The conference_recording_status_callback_method + * + * @param string $conferenceRecordingStatusCallbackMethod The + * conference_recording_status_callback_method + * @return $this Fluent Builder + */ + public function setConferenceRecordingStatusCallbackMethod($conferenceRecordingStatusCallbackMethod) { + $this->options['conferenceRecordingStatusCallbackMethod'] = $conferenceRecordingStatusCallbackMethod; + return $this; + } + + /** + * The region + * + * @param string $region The region + * @return $this Fluent Builder + */ + public function setRegion($region) { + $this->options['region'] = $region; + return $this; + } + + /** + * The sip_auth_username + * + * @param string $sipAuthUsername The sip_auth_username + * @return $this Fluent Builder + */ + public function setSipAuthUsername($sipAuthUsername) { + $this->options['sipAuthUsername'] = $sipAuthUsername; + return $this; + } + + /** + * The sip_auth_password + * + * @param string $sipAuthPassword The sip_auth_password + * @return $this Fluent Builder + */ + public function setSipAuthPassword($sipAuthPassword) { + $this->options['sipAuthPassword'] = $sipAuthPassword; + return $this; + } + + /** + * Call progress events sent via webhooks as a result of a Dequeue instruction + * + * @param string $dequeueStatusCallbackEvent Call progress events sent via + * webhooks as a result of a Dequeue + * instruction + * @return $this Fluent Builder + */ + public function setDequeueStatusCallbackEvent($dequeueStatusCallbackEvent) { + $this->options['dequeueStatusCallbackEvent'] = $dequeueStatusCallbackEvent; + return $this; + } + + /** + * New worker activity sid after executing a Conference instruction + * + * @param string $postWorkActivitySid New worker activity sid after executing a + * Conference instruction + * @return $this Fluent Builder + */ + public function setPostWorkActivitySid($postWorkActivitySid) { + $this->options['postWorkActivitySid'] = $postWorkActivitySid; + return $this; + } + + /** + * Supervisor mode when executing the Supervise instruction + * + * @param string $supervisorMode Supervisor mode when executing the Supervise + * instruction + * @return $this Fluent Builder + */ + public function setSupervisorMode($supervisorMode) { + $this->options['supervisorMode'] = $supervisorMode; + return $this; + } + + /** + * Supervisor sid/uri when executing the Supervise instruction + * + * @param string $supervisor Supervisor sid/uri when executing the Supervise + * instruction + * @return $this Fluent Builder + */ + public function setSupervisor($supervisor) { + $this->options['supervisor'] = $supervisor; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateReservationOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationPage.php new file mode 100644 index 0000000..237413e --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Task/ReservationPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ReservationInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.ReservationPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelContext.php new file mode 100644 index 0000000..96fac00 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelContext.php @@ -0,0 +1,69 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskChannels/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a TaskChannelInstance + * + * @return TaskChannelInstance Fetched TaskChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TaskChannelInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskChannelContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelInstance.php new file mode 100644 index 0000000..442dfad --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelInstance.php @@ -0,0 +1,118 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'sid' => Values::array_get($payload, 'sid'), + 'uniqueName' => Values::array_get($payload, 'unique_name'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskChannelContext Context for + * this + * TaskChannelInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TaskChannelContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a TaskChannelInstance + * + * @return TaskChannelInstance Fetched TaskChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskChannelInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelList.php new file mode 100644 index 0000000..5ea0a47 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelList.php @@ -0,0 +1,137 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskChannels'; + } + + /** + * Streams TaskChannelInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads TaskChannelInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return TaskChannelInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of TaskChannelInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of TaskChannelInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new TaskChannelPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of TaskChannelInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of TaskChannelInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new TaskChannelPage($this->version, $response, $this->solution); + } + + /** + * Constructs a TaskChannelContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskChannelContext + */ + public function getContext($sid) { + return new TaskChannelContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskChannelList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelPage.php new file mode 100644 index 0000000..daec8de --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskChannelPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskChannelInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskChannelPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php new file mode 100644 index 0000000..c38a638 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php @@ -0,0 +1,171 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Tasks/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a TaskInstance + * + * @return TaskInstance Fetched TaskInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TaskInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Update the TaskInstance + * + * @param array|Options $options Optional Arguments + * @return TaskInstance Updated TaskInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'Attributes' => $options['attributes'], + 'AssignmentStatus' => $options['assignmentStatus'], + 'Reason' => $options['reason'], + 'Priority' => $options['priority'], + 'TaskChannel' => $options['taskChannel'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new TaskInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the TaskInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the reservations + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Task\ReservationList + */ + protected function getReservations() { + if (!$this->_reservations) { + $this->_reservations = new ReservationList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_reservations; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskInstance.php new file mode 100644 index 0000000..2e25f94 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskInstance.php @@ -0,0 +1,174 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'age' => Values::array_get($payload, 'age'), + 'assignmentStatus' => Values::array_get($payload, 'assignment_status'), + 'attributes' => Values::array_get($payload, 'attributes'), + 'addons' => Values::array_get($payload, 'addons'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'priority' => Values::array_get($payload, 'priority'), + 'reason' => Values::array_get($payload, 'reason'), + 'sid' => Values::array_get($payload, 'sid'), + 'taskQueueSid' => Values::array_get($payload, 'task_queue_sid'), + 'taskQueueFriendlyName' => Values::array_get($payload, 'task_queue_friendly_name'), + 'taskChannelSid' => Values::array_get($payload, 'task_channel_sid'), + 'taskChannelUniqueName' => Values::array_get($payload, 'task_channel_unique_name'), + 'timeout' => Values::array_get($payload, 'timeout'), + 'workflowSid' => Values::array_get($payload, 'workflow_sid'), + 'workflowFriendlyName' => Values::array_get($payload, 'workflow_friendly_name'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskContext Context for this + * TaskInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TaskContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a TaskInstance + * + * @return TaskInstance Fetched TaskInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the TaskInstance + * + * @param array|Options $options Optional Arguments + * @return TaskInstance Updated TaskInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the TaskInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the reservations + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Task\ReservationList + */ + protected function getReservations() { + return $this->proxy()->reservations; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskList.php new file mode 100644 index 0000000..0e9a4c7 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskList.php @@ -0,0 +1,180 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Tasks'; + } + + /** + * Streams TaskInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads TaskInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return TaskInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of TaskInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of TaskInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'Priority' => $options['priority'], + 'AssignmentStatus' => Serialize::map($options['assignmentStatus'], function($e) { return $e; }), + 'WorkflowSid' => $options['workflowSid'], + 'WorkflowName' => $options['workflowName'], + 'TaskQueueSid' => $options['taskQueueSid'], + 'TaskQueueName' => $options['taskQueueName'], + 'EvaluateTaskAttributes' => $options['evaluateTaskAttributes'], + 'Ordering' => $options['ordering'], + 'HasAddons' => Serialize::booleanToString($options['hasAddons']), + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new TaskPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of TaskInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of TaskInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new TaskPage($this->version, $response, $this->solution); + } + + /** + * Create a new TaskInstance + * + * @param array|Options $options Optional Arguments + * @return TaskInstance Newly created TaskInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'Timeout' => $options['timeout'], + 'Priority' => $options['priority'], + 'TaskChannel' => $options['taskChannel'], + 'WorkflowSid' => $options['workflowSid'], + 'Attributes' => $options['attributes'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new TaskInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Constructs a TaskContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskContext + */ + public function getContext($sid) { + return new TaskContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskOptions.php new file mode 100644 index 0000000..dc832e2 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskOptions.php @@ -0,0 +1,437 @@ +options['attributes'] = $attributes; + $this->options['assignmentStatus'] = $assignmentStatus; + $this->options['reason'] = $reason; + $this->options['priority'] = $priority; + $this->options['taskChannel'] = $taskChannel; + } + + /** + * The user-defined JSON data describing the custom attributes of this task. + * + * @param string $attributes The user-defined JSON data describing the custom + * attributes of this task. + * @return $this Fluent Builder + */ + public function setAttributes($attributes) { + $this->options['attributes'] = $attributes; + return $this; + } + + /** + * A 'pending' or 'reserved' Task may be canceled by posting AssignmentStatus='canceled'. Post AssignmentStatus='wrapping' to move Task to 'wrapup' state and AssignmentStatus='completed' to move a Task to 'completed' state. + * + * @param string $assignmentStatus A 'pending' or 'reserved' Task may be + * canceled by posting + * AssignmentStatus='canceled'. + * @return $this Fluent Builder + */ + public function setAssignmentStatus($assignmentStatus) { + $this->options['assignmentStatus'] = $assignmentStatus; + return $this; + } + + /** + * This is only required if the Task is canceled or completed. This logs the reason the task was either canceled or completed and queues the task for deletion after 5 minutes. + * + * @param string $reason This is only required if the Task is canceled or + * completed. + * @return $this Fluent Builder + */ + public function setReason($reason) { + $this->options['reason'] = $reason; + return $this; + } + + /** + * Override priority for the Task. When supplied, the Task will take on the given priority unless it matches a Workflow Target with a Priority set. + * + * @param integer $priority Override priority for the Task. + * @return $this Fluent Builder + */ + public function setPriority($priority) { + $this->options['priority'] = $priority; + return $this; + } + + /** + * The task_channel + * + * @param string $taskChannel The task_channel + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateTaskOptions ' . implode(' ', $options) . ']'; + } +} + +class ReadTaskOptions extends Options { + /** + * @param integer $priority Retrieve the list of all Tasks in the workspace + * with the specified priority. + * @param string $assignmentStatus Returns the list of all Tasks in the + * workspace with the specified + * AssignmentStatus. + * @param string $workflowSid Returns the list of Tasks that are being + * controlled by the Workflow with the specified Sid + * value. + * @param string $workflowName Returns the list of Tasks that are being + * controlled by the Workflow with the specified + * FriendlyName value. + * @param string $taskQueueSid Returns the list of Tasks that are currently + * waiting in the TaskQueue identified by the Sid + * specified. + * @param string $taskQueueName Returns the list of Tasks that are currently + * waiting in the TaskQueue identified by the + * FriendlyName specified. + * @param string $evaluateTaskAttributes Provide a task attributes expression, + * and this will return tasks which match + * the attributes. + * @param string $ordering Use this parameter to control the order of the Tasks + * returned. + * @param boolean $hasAddons The has_addons + */ + public function __construct($priority = Values::NONE, $assignmentStatus = Values::NONE, $workflowSid = Values::NONE, $workflowName = Values::NONE, $taskQueueSid = Values::NONE, $taskQueueName = Values::NONE, $evaluateTaskAttributes = Values::NONE, $ordering = Values::NONE, $hasAddons = Values::NONE) { + $this->options['priority'] = $priority; + $this->options['assignmentStatus'] = $assignmentStatus; + $this->options['workflowSid'] = $workflowSid; + $this->options['workflowName'] = $workflowName; + $this->options['taskQueueSid'] = $taskQueueSid; + $this->options['taskQueueName'] = $taskQueueName; + $this->options['evaluateTaskAttributes'] = $evaluateTaskAttributes; + $this->options['ordering'] = $ordering; + $this->options['hasAddons'] = $hasAddons; + } + + /** + * Retrieve the list of all Tasks in the workspace with the specified priority. + * + * @param integer $priority Retrieve the list of all Tasks in the workspace + * with the specified priority. + * @return $this Fluent Builder + */ + public function setPriority($priority) { + $this->options['priority'] = $priority; + return $this; + } + + /** + * Returns the list of all Tasks in the workspace with the specified AssignmentStatus. Allowed AssignmentStatus values are pending, reserved, assigned, canceled, and completed. + * + * @param string $assignmentStatus Returns the list of all Tasks in the + * workspace with the specified + * AssignmentStatus. + * @return $this Fluent Builder + */ + public function setAssignmentStatus($assignmentStatus) { + $this->options['assignmentStatus'] = $assignmentStatus; + return $this; + } + + /** + * Returns the list of Tasks that are being controlled by the Workflow with the specified Sid value. + * + * @param string $workflowSid Returns the list of Tasks that are being + * controlled by the Workflow with the specified Sid + * value. + * @return $this Fluent Builder + */ + public function setWorkflowSid($workflowSid) { + $this->options['workflowSid'] = $workflowSid; + return $this; + } + + /** + * Returns the list of Tasks that are being controlled by the Workflow with the specified FriendlyName value. + * + * @param string $workflowName Returns the list of Tasks that are being + * controlled by the Workflow with the specified + * FriendlyName value. + * @return $this Fluent Builder + */ + public function setWorkflowName($workflowName) { + $this->options['workflowName'] = $workflowName; + return $this; + } + + /** + * Returns the list of Tasks that are currently waiting in the TaskQueue identified by the Sid specified. + * + * @param string $taskQueueSid Returns the list of Tasks that are currently + * waiting in the TaskQueue identified by the Sid + * specified. + * @return $this Fluent Builder + */ + public function setTaskQueueSid($taskQueueSid) { + $this->options['taskQueueSid'] = $taskQueueSid; + return $this; + } + + /** + * Returns the list of Tasks that are currently waiting in the TaskQueue identified by the FriendlyName specified. + * + * @param string $taskQueueName Returns the list of Tasks that are currently + * waiting in the TaskQueue identified by the + * FriendlyName specified. + * @return $this Fluent Builder + */ + public function setTaskQueueName($taskQueueName) { + $this->options['taskQueueName'] = $taskQueueName; + return $this; + } + + /** + * Provide a task attributes expression, and this will return tasks which match the attributes. + * + * @param string $evaluateTaskAttributes Provide a task attributes expression, + * and this will return tasks which match + * the attributes. + * @return $this Fluent Builder + */ + public function setEvaluateTaskAttributes($evaluateTaskAttributes) { + $this->options['evaluateTaskAttributes'] = $evaluateTaskAttributes; + return $this; + } + + /** + * Use this parameter to control the order of the Tasks returned. The value should be passed in `Attribute:Order` format, where Attribute can be either `Priority` or `DateCreated` and Order can be either `asc` or `desc`. For example, `Priority:desc` returns Tasks ordered by Priority in descending order. To sort the Tasks by Priority and DateCreated pass `Priority:desc,DateCreated:asc`. By Default Tasks are returned sorted by DateCreated in ascending order. + * + * @param string $ordering Use this parameter to control the order of the Tasks + * returned. + * @return $this Fluent Builder + */ + public function setOrdering($ordering) { + $this->options['ordering'] = $ordering; + return $this; + } + + /** + * The has_addons + * + * @param boolean $hasAddons The has_addons + * @return $this Fluent Builder + */ + public function setHasAddons($hasAddons) { + $this->options['hasAddons'] = $hasAddons; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadTaskOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateTaskOptions extends Options { + /** + * @param integer $timeout The amount of time in seconds the task is allowed to + * live up to a maximum of 2 weeks. + * @param integer $priority Override priority for the Task. + * @param string $taskChannel When MultiTasking is enabled specify the type of + * the task by passing either TaskChannel Unique + * Name or Task Channel Sid. + * @param string $workflowSid The WorkflowSid for the Workflow that you would + * like to handle routing for this Task. + * @param string $attributes Url-encoded JSON string describing the attributes + * of this task. + */ + public function __construct($timeout = Values::NONE, $priority = Values::NONE, $taskChannel = Values::NONE, $workflowSid = Values::NONE, $attributes = Values::NONE) { + $this->options['timeout'] = $timeout; + $this->options['priority'] = $priority; + $this->options['taskChannel'] = $taskChannel; + $this->options['workflowSid'] = $workflowSid; + $this->options['attributes'] = $attributes; + } + + /** + * The amount of time in seconds the task is allowed to live up to a maximum of 2 weeks. Defaults to 24 hours. On timeout, `task.canceled` event will fire with description "Task TTL Exceeded". + * + * @param integer $timeout The amount of time in seconds the task is allowed to + * live up to a maximum of 2 weeks. + * @return $this Fluent Builder + */ + public function setTimeout($timeout) { + $this->options['timeout'] = $timeout; + return $this; + } + + /** + * Override priority for the Task. When supplied, the Task will take on the given priority unless it matches a Workflow Target with a Priority set. When not supplied, the Task will take on the priority of the matching Workflow Target. + * + * @param integer $priority Override priority for the Task. + * @return $this Fluent Builder + */ + public function setPriority($priority) { + $this->options['priority'] = $priority; + return $this; + } + + /** + * When MultiTasking is enabled specify the type of the task by passing either TaskChannel Unique Name or Task Channel Sid. Default value is "default" + * + * @param string $taskChannel When MultiTasking is enabled specify the type of + * the task by passing either TaskChannel Unique + * Name or Task Channel Sid. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * The WorkflowSid for the Workflow that you would like to handle routing for this Task. If there is only one Workflow defined for the Workspace that you are posting a task to, then this is an optional parameter, and that single workflow will be used. + * + * @param string $workflowSid The WorkflowSid for the Workflow that you would + * like to handle routing for this Task. + * @return $this Fluent Builder + */ + public function setWorkflowSid($workflowSid) { + $this->options['workflowSid'] = $workflowSid; + return $this; + } + + /** + * Url-encoded JSON string describing the attributes of this task. This data will be passed back to the Workflow's AssignmentCallbackURL when the Task is assigned to a Worker. An example task: `{ "task_type": "call", "twilio_call_sid": "CAxxx", "customer_ticket_number": "12345" }` + * + * @param string $attributes Url-encoded JSON string describing the attributes + * of this task. + * @return $this Fluent Builder + */ + public function setAttributes($attributes) { + $this->options['attributes'] = $attributes; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.CreateTaskOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskPage.php new file mode 100644 index 0000000..3359e3a --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsContext.php new file mode 100644 index 0000000..c6ca446 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsContext.php @@ -0,0 +1,81 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskQueues/' . rawurlencode($taskQueueSid) . '/CumulativeStatistics'; + } + + /** + * Fetch a TaskQueueCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueCumulativeStatisticsInstance Fetched + * TaskQueueCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TaskQueueCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueCumulativeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsInstance.php new file mode 100644 index 0000000..f41da2b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsInstance.php @@ -0,0 +1,146 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'avgTaskAcceptanceTime' => Values::array_get($payload, 'avg_task_acceptance_time'), + 'startTime' => Deserialize::dateTime(Values::array_get($payload, 'start_time')), + 'endTime' => Deserialize::dateTime(Values::array_get($payload, 'end_time')), + 'reservationsCreated' => Values::array_get($payload, 'reservations_created'), + 'reservationsAccepted' => Values::array_get($payload, 'reservations_accepted'), + 'reservationsRejected' => Values::array_get($payload, 'reservations_rejected'), + 'reservationsTimedOut' => Values::array_get($payload, 'reservations_timed_out'), + 'reservationsCanceled' => Values::array_get($payload, 'reservations_canceled'), + 'reservationsRescinded' => Values::array_get($payload, 'reservations_rescinded'), + 'splitByWaitTime' => Values::array_get($payload, 'split_by_wait_time'), + 'taskQueueSid' => Values::array_get($payload, 'task_queue_sid'), + 'waitDurationUntilAccepted' => Values::array_get($payload, 'wait_duration_until_accepted'), + 'waitDurationUntilCanceled' => Values::array_get($payload, 'wait_duration_until_canceled'), + 'tasksCanceled' => Values::array_get($payload, 'tasks_canceled'), + 'tasksCompleted' => Values::array_get($payload, 'tasks_completed'), + 'tasksDeleted' => Values::array_get($payload, 'tasks_deleted'), + 'tasksEntered' => Values::array_get($payload, 'tasks_entered'), + 'tasksMoved' => Values::array_get($payload, 'tasks_moved'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueCumulativeStatisticsContext Context for this + * TaskQueueCumulativeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TaskQueueCumulativeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a TaskQueueCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueCumulativeStatisticsInstance Fetched + * TaskQueueCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueCumulativeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsList.php new file mode 100644 index 0000000..c649ac6 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + } + + /** + * Constructs a TaskQueueCumulativeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueCumulativeStatisticsContext + */ + public function getContext() { + return new TaskQueueCumulativeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueCumulativeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsOptions.php new file mode 100644 index 0000000..2dbbda8 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsOptions.php @@ -0,0 +1,126 @@ +options['endDate'] = $endDate; + $this->options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchTaskQueueCumulativeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsPage.php new file mode 100644 index 0000000..0026a34 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueCumulativeStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskQueueCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueCumulativeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsContext.php new file mode 100644 index 0000000..1b488f0 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsContext.php @@ -0,0 +1,74 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskQueues/' . rawurlencode($taskQueueSid) . '/RealTimeStatistics'; + } + + /** + * Fetch a TaskQueueRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueRealTimeStatisticsInstance Fetched + * TaskQueueRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array('TaskChannel' => $options['taskChannel'], )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TaskQueueRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueRealTimeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsInstance.php new file mode 100644 index 0000000..49813fa --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsInstance.php @@ -0,0 +1,125 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'activityStatistics' => Values::array_get($payload, 'activity_statistics'), + 'longestTaskWaitingAge' => Values::array_get($payload, 'longest_task_waiting_age'), + 'taskQueueSid' => Values::array_get($payload, 'task_queue_sid'), + 'tasksByPriority' => Values::array_get($payload, 'tasks_by_priority'), + 'tasksByStatus' => Values::array_get($payload, 'tasks_by_status'), + 'totalAvailableWorkers' => Values::array_get($payload, 'total_available_workers'), + 'totalEligibleWorkers' => Values::array_get($payload, 'total_eligible_workers'), + 'totalTasks' => Values::array_get($payload, 'total_tasks'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueRealTimeStatisticsContext Context for this + * TaskQueueRealTimeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TaskQueueRealTimeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a TaskQueueRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueRealTimeStatisticsInstance Fetched + * TaskQueueRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueRealTimeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsList.php new file mode 100644 index 0000000..018cc5e --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + } + + /** + * Constructs a TaskQueueRealTimeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueRealTimeStatisticsContext + */ + public function getContext() { + return new TaskQueueRealTimeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueRealTimeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsOptions.php new file mode 100644 index 0000000..b832a64 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsOptions.php @@ -0,0 +1,61 @@ +options['taskChannel'] = $taskChannel; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchTaskQueueRealTimeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsPage.php new file mode 100644 index 0000000..635fa41 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueRealTimeStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskQueueRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueRealTimeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsContext.php new file mode 100644 index 0000000..8578061 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsContext.php @@ -0,0 +1,80 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskQueues/' . rawurlencode($taskQueueSid) . '/Statistics'; + } + + /** + * Fetch a TaskQueueStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueStatisticsInstance Fetched TaskQueueStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TaskQueueStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsInstance.php new file mode 100644 index 0000000..a6e8a19 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsInstance.php @@ -0,0 +1,114 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'cumulative' => Values::array_get($payload, 'cumulative'), + 'realtime' => Values::array_get($payload, 'realtime'), + 'taskQueueSid' => Values::array_get($payload, 'task_queue_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueStatisticsContext Context for this + * TaskQueueStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TaskQueueStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a TaskQueueStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueStatisticsInstance Fetched TaskQueueStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsList.php new file mode 100644 index 0000000..1b81888 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'taskQueueSid' => $taskQueueSid, ); + } + + /** + * Constructs a TaskQueueStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueStatisticsContext + */ + public function getContext() { + return new TaskQueueStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsOptions.php new file mode 100644 index 0000000..25a325e --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsOptions.php @@ -0,0 +1,126 @@ +options['endDate'] = $endDate; + $this->options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchTaskQueueStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsPage.php new file mode 100644 index 0000000..e7ad5d9 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueueStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskQueueStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['taskQueueSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsInstance.php new file mode 100644 index 0000000..35a92fb --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsInstance.php @@ -0,0 +1,76 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'cumulative' => Values::array_get($payload, 'cumulative'), + 'realtime' => Values::array_get($payload, 'realtime'), + 'taskQueueSid' => Values::array_get($payload, 'task_queue_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueuesStatisticsInstance]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsList.php new file mode 100644 index 0000000..5c37de6 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsList.php @@ -0,0 +1,141 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskQueues/Statistics'; + } + + /** + * Streams TaskQueuesStatisticsInstance records from the API as a generator + * stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads TaskQueuesStatisticsInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return TaskQueuesStatisticsInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of TaskQueuesStatisticsInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of TaskQueuesStatisticsInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'FriendlyName' => $options['friendlyName'], + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new TaskQueuesStatisticsPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of TaskQueuesStatisticsInstance records from the + * API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of TaskQueuesStatisticsInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new TaskQueuesStatisticsPage($this->version, $response, $this->solution); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueuesStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsOptions.php new file mode 100644 index 0000000..40da9f9 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsOptions.php @@ -0,0 +1,143 @@ +options['endDate'] = $endDate; + $this->options['friendlyName'] = $friendlyName; + $this->options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter the TaskQueue stats based on a TaskQueue's name (only for list resource) + * + * @param string $friendlyName Filter the TaskQueue stats based on a + * TaskQueue's name + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp. + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadTaskQueuesStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsPage.php new file mode 100644 index 0000000..b27bd92 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueue/TaskQueuesStatisticsPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskQueuesStatisticsInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueuesStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueContext.php new file mode 100644 index 0000000..f865532 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueContext.php @@ -0,0 +1,214 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskQueues/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a TaskQueueInstance + * + * @return TaskQueueInstance Fetched TaskQueueInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TaskQueueInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Update the TaskQueueInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueInstance Updated TaskQueueInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'TargetWorkers' => $options['targetWorkers'], + 'ReservationActivitySid' => $options['reservationActivitySid'], + 'AssignmentActivitySid' => $options['assignmentActivitySid'], + 'MaxReservedWorkers' => $options['maxReservedWorkers'], + 'TaskOrder' => $options['taskOrder'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new TaskQueueInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the TaskQueueInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueStatisticsList + */ + protected function getStatistics() { + if (!$this->_statistics) { + $this->_statistics = new TaskQueueStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_statistics; + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + if (!$this->_realTimeStatistics) { + $this->_realTimeStatistics = new TaskQueueRealTimeStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + if (!$this->_cumulativeStatistics) { + $this->_cumulativeStatistics = new TaskQueueCumulativeStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_cumulativeStatistics; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueInstance.php new file mode 100644 index 0000000..7cd5b27 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueInstance.php @@ -0,0 +1,185 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'assignmentActivitySid' => Values::array_get($payload, 'assignment_activity_sid'), + 'assignmentActivityName' => Values::array_get($payload, 'assignment_activity_name'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'maxReservedWorkers' => Values::array_get($payload, 'max_reserved_workers'), + 'reservationActivitySid' => Values::array_get($payload, 'reservation_activity_sid'), + 'reservationActivityName' => Values::array_get($payload, 'reservation_activity_name'), + 'sid' => Values::array_get($payload, 'sid'), + 'targetWorkers' => Values::array_get($payload, 'target_workers'), + 'taskOrder' => Values::array_get($payload, 'task_order'), + 'url' => Values::array_get($payload, 'url'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueueContext Context for + * this + * TaskQueueInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TaskQueueContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a TaskQueueInstance + * + * @return TaskQueueInstance Fetched TaskQueueInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the TaskQueueInstance + * + * @param array|Options $options Optional Arguments + * @return TaskQueueInstance Updated TaskQueueInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the TaskQueueInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueStatisticsList + */ + protected function getStatistics() { + return $this->proxy()->statistics; + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + return $this->proxy()->realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueue\TaskQueueCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + return $this->proxy()->cumulativeStatistics; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.TaskQueueInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueList.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueList.php new file mode 100644 index 0000000..1c73314 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueList.php @@ -0,0 +1,230 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/TaskQueues'; + } + + /** + * Streams TaskQueueInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads TaskQueueInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return TaskQueueInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of TaskQueueInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of TaskQueueInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'EvaluateWorkerAttributes' => $options['evaluateWorkerAttributes'], + 'WorkerSid' => $options['workerSid'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new TaskQueuePage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of TaskQueueInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of TaskQueueInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new TaskQueuePage($this->version, $response, $this->solution); + } + + /** + * Create a new TaskQueueInstance + * + * @param string $friendlyName Human readable description of this TaskQueue + * @param string $reservationActivitySid ActivitySID to assign workers once a + * task is reserved for them + * @param string $assignmentActivitySid ActivitySID to assign workers once a + * task is assigned for them + * @param array|Options $options Optional Arguments + * @return TaskQueueInstance Newly created TaskQueueInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($friendlyName, $reservationActivitySid, $assignmentActivitySid, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $friendlyName, + 'ReservationActivitySid' => $reservationActivitySid, + 'AssignmentActivitySid' => $assignmentActivitySid, + 'TargetWorkers' => $options['targetWorkers'], + 'MaxReservedWorkers' => $options['maxReservedWorkers'], + 'TaskOrder' => $options['taskOrder'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new TaskQueueInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Access the statistics + */ + protected function getStatistics() { + if (!$this->_statistics) { + $this->_statistics = new TaskQueuesStatisticsList($this->version, $this->solution['workspaceSid']); + } + + return $this->_statistics; + } + + /** + * Constructs a TaskQueueContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueueContext + */ + public function getContext($sid) { + return new TaskQueueContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueueList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueOptions.php new file mode 100644 index 0000000..316301c --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueueOptions.php @@ -0,0 +1,327 @@ +options['friendlyName'] = $friendlyName; + $this->options['targetWorkers'] = $targetWorkers; + $this->options['reservationActivitySid'] = $reservationActivitySid; + $this->options['assignmentActivitySid'] = $assignmentActivitySid; + $this->options['maxReservedWorkers'] = $maxReservedWorkers; + $this->options['taskOrder'] = $taskOrder; + } + + /** + * Human readable description of this TaskQueue (for example "Support – Tier 1", "Sales" or "Escalation") + * + * @param string $friendlyName Human readable description of this TaskQueue + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * A string describing the Worker selection criteria for any Tasks that enter this TaskQueue. For example '"language" == "spanish"' If no TargetWorkers parameter is provided, Tasks will wait in this queue until they are either deleted or moved to another queue. Additional examples on how to describing Worker selection criteria below. + * + * @param string $targetWorkers A string describing the Worker selection + * criteria for any Tasks that enter this + * TaskQueue. + * @return $this Fluent Builder + */ + public function setTargetWorkers($targetWorkers) { + $this->options['targetWorkers'] = $targetWorkers; + return $this; + } + + /** + * ActivitySID that will be assigned to Workers when they are reserved for a task from this TaskQueue. + * + * @param string $reservationActivitySid ActivitySID that will be assigned to + * Workers when they are reserved for a + * task from this TaskQueue. + * @return $this Fluent Builder + */ + public function setReservationActivitySid($reservationActivitySid) { + $this->options['reservationActivitySid'] = $reservationActivitySid; + return $this; + } + + /** + * ActivitySID that will be assigned to Workers when they are assigned a task from this TaskQueue. + * + * @param string $assignmentActivitySid ActivitySID that will be assigned to + * Workers when they are assigned a task + * from this TaskQueue. + * @return $this Fluent Builder + */ + public function setAssignmentActivitySid($assignmentActivitySid) { + $this->options['assignmentActivitySid'] = $assignmentActivitySid; + return $this; + } + + /** + * The maximum amount of workers to create reservations for the assignment of a task while in this queue. Maximum of 50. + * + * @param integer $maxReservedWorkers The maximum amount of workers to create + * reservations for the assignment of a task + * while in this queue. + * @return $this Fluent Builder + */ + public function setMaxReservedWorkers($maxReservedWorkers) { + $this->options['maxReservedWorkers'] = $maxReservedWorkers; + return $this; + } + + /** + * TaskOrder will determine which order the Tasks will be assigned to Workers. Set this parameter to LIFO to assign most recently created Task first or FIFO to assign the oldest Task. Default is FIFO. [Click here](https://www.twilio.com/docs/api/taskrouter/last-first-out-lifo) to learn more. + * + * @param string $taskOrder TaskOrder will determine which order the Tasks will + * be assigned to Workers. + * @return $this Fluent Builder + */ + public function setTaskOrder($taskOrder) { + $this->options['taskOrder'] = $taskOrder; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateTaskQueueOptions ' . implode(' ', $options) . ']'; + } +} + +class ReadTaskQueueOptions extends Options { + /** + * @param string $friendlyName Filter by a human readable description of a + * TaskQueue + * @param string $evaluateWorkerAttributes Provide a Worker attributes + * expression, and this will return the + * list of TaskQueues that would + * distribute tasks to a worker with + * these attributes. + * @param string $workerSid The worker_sid + */ + public function __construct($friendlyName = Values::NONE, $evaluateWorkerAttributes = Values::NONE, $workerSid = Values::NONE) { + $this->options['friendlyName'] = $friendlyName; + $this->options['evaluateWorkerAttributes'] = $evaluateWorkerAttributes; + $this->options['workerSid'] = $workerSid; + } + + /** + * Filter by a human readable description of a TaskQueue (for example "Customer Support" or "2014 Election Campaign") + * + * @param string $friendlyName Filter by a human readable description of a + * TaskQueue + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Provide a Worker attributes expression, and this will return the list of TaskQueues that would distribute tasks to a worker with these attributes. + * + * @param string $evaluateWorkerAttributes Provide a Worker attributes + * expression, and this will return the + * list of TaskQueues that would + * distribute tasks to a worker with + * these attributes. + * @return $this Fluent Builder + */ + public function setEvaluateWorkerAttributes($evaluateWorkerAttributes) { + $this->options['evaluateWorkerAttributes'] = $evaluateWorkerAttributes; + return $this; + } + + /** + * The worker_sid + * + * @param string $workerSid The worker_sid + * @return $this Fluent Builder + */ + public function setWorkerSid($workerSid) { + $this->options['workerSid'] = $workerSid; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadTaskQueueOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateTaskQueueOptions extends Options { + /** + * @param string $targetWorkers A string describing the Worker selection + * criteria for any Tasks that enter this + * TaskQueue. + * @param integer $maxReservedWorkers The maximum amount of workers to create + * reservations for the assignment of a task + * while in this queue. + * @param string $taskOrder TaskOrder will determine which order the Tasks will + * be assigned to Workers. + */ + public function __construct($targetWorkers = Values::NONE, $maxReservedWorkers = Values::NONE, $taskOrder = Values::NONE) { + $this->options['targetWorkers'] = $targetWorkers; + $this->options['maxReservedWorkers'] = $maxReservedWorkers; + $this->options['taskOrder'] = $taskOrder; + } + + /** + * A string describing the Worker selection criteria for any Tasks that enter this TaskQueue. For example `'"language" == "spanish"'` If no TargetWorkers parameter is provided, Tasks will wait in this TaskQueue until they are either deleted or moved to another TaskQueue. Additional examples on how to describing Worker selection criteria below. Defaults to 1==1. + * + * @param string $targetWorkers A string describing the Worker selection + * criteria for any Tasks that enter this + * TaskQueue. + * @return $this Fluent Builder + */ + public function setTargetWorkers($targetWorkers) { + $this->options['targetWorkers'] = $targetWorkers; + return $this; + } + + /** + * The maximum amount of workers to create reservations for the assignment of a task while in this queue. Defaults to 1, with a Maximum of 50. + * + * @param integer $maxReservedWorkers The maximum amount of workers to create + * reservations for the assignment of a task + * while in this queue. + * @return $this Fluent Builder + */ + public function setMaxReservedWorkers($maxReservedWorkers) { + $this->options['maxReservedWorkers'] = $maxReservedWorkers; + return $this; + } + + /** + * TaskOrder will determine which order the Tasks will be assigned to Workers. Set this parameter to LIFO to assign most recently created Task first or FIFO to assign the oldest Task. Default is FIFO. [Click here](https://www.twilio.com/docs/api/taskrouter/last-first-out-lifo) to learn more. + * + * @param string $taskOrder TaskOrder will determine which order the Tasks will + * be assigned to Workers. + * @return $this Fluent Builder + */ + public function setTaskOrder($taskOrder) { + $this->options['taskOrder'] = $taskOrder; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.CreateTaskQueueOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueuePage.php b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueuePage.php new file mode 100644 index 0000000..7e587c9 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/TaskQueuePage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TaskQueueInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.TaskQueuePage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationContext.php new file mode 100644 index 0000000..d78fe31 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationContext.php @@ -0,0 +1,151 @@ +solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/' . rawurlencode($workerSid) . '/Reservations/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a ReservationInstance + * + * @return ReservationInstance Fetched ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new ReservationInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $this->solution['sid'] + ); + } + + /** + * Update the ReservationInstance + * + * @param array|Options $options Optional Arguments + * @return ReservationInstance Updated ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'ReservationStatus' => $options['reservationStatus'], + 'WorkerActivitySid' => $options['workerActivitySid'], + 'Instruction' => $options['instruction'], + 'DequeuePostWorkActivitySid' => $options['dequeuePostWorkActivitySid'], + 'DequeueFrom' => $options['dequeueFrom'], + 'DequeueRecord' => $options['dequeueRecord'], + 'DequeueTimeout' => $options['dequeueTimeout'], + 'DequeueTo' => $options['dequeueTo'], + 'DequeueStatusCallbackUrl' => $options['dequeueStatusCallbackUrl'], + 'CallFrom' => $options['callFrom'], + 'CallRecord' => $options['callRecord'], + 'CallTimeout' => $options['callTimeout'], + 'CallTo' => $options['callTo'], + 'CallUrl' => $options['callUrl'], + 'CallStatusCallbackUrl' => $options['callStatusCallbackUrl'], + 'CallAccept' => Serialize::booleanToString($options['callAccept']), + 'RedirectCallSid' => $options['redirectCallSid'], + 'RedirectAccept' => Serialize::booleanToString($options['redirectAccept']), + 'RedirectUrl' => $options['redirectUrl'], + 'To' => $options['to'], + 'From' => $options['from'], + 'StatusCallback' => $options['statusCallback'], + 'StatusCallbackMethod' => $options['statusCallbackMethod'], + 'StatusCallbackEvent' => Serialize::map($options['statusCallbackEvent'], function($e) { return $e; }), + 'Timeout' => $options['timeout'], + 'Record' => Serialize::booleanToString($options['record']), + 'Muted' => Serialize::booleanToString($options['muted']), + 'Beep' => $options['beep'], + 'StartConferenceOnEnter' => Serialize::booleanToString($options['startConferenceOnEnter']), + 'EndConferenceOnExit' => Serialize::booleanToString($options['endConferenceOnExit']), + 'WaitUrl' => $options['waitUrl'], + 'WaitMethod' => $options['waitMethod'], + 'EarlyMedia' => Serialize::booleanToString($options['earlyMedia']), + 'MaxParticipants' => $options['maxParticipants'], + 'ConferenceStatusCallback' => $options['conferenceStatusCallback'], + 'ConferenceStatusCallbackMethod' => $options['conferenceStatusCallbackMethod'], + 'ConferenceStatusCallbackEvent' => Serialize::map($options['conferenceStatusCallbackEvent'], function($e) { return $e; }), + 'ConferenceRecord' => $options['conferenceRecord'], + 'ConferenceTrim' => $options['conferenceTrim'], + 'RecordingChannels' => $options['recordingChannels'], + 'RecordingStatusCallback' => $options['recordingStatusCallback'], + 'RecordingStatusCallbackMethod' => $options['recordingStatusCallbackMethod'], + 'ConferenceRecordingStatusCallback' => $options['conferenceRecordingStatusCallback'], + 'ConferenceRecordingStatusCallbackMethod' => $options['conferenceRecordingStatusCallbackMethod'], + 'Region' => $options['region'], + 'SipAuthUsername' => $options['sipAuthUsername'], + 'SipAuthPassword' => $options['sipAuthPassword'], + 'DequeueStatusCallbackEvent' => Serialize::map($options['dequeueStatusCallbackEvent'], function($e) { return $e; }), + 'PostWorkActivitySid' => $options['postWorkActivitySid'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new ReservationInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $this->solution['sid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.ReservationContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationInstance.php new file mode 100644 index 0000000..4b70438 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationInstance.php @@ -0,0 +1,140 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'reservationStatus' => Values::array_get($payload, 'reservation_status'), + 'sid' => Values::array_get($payload, 'sid'), + 'taskSid' => Values::array_get($payload, 'task_sid'), + 'workerName' => Values::array_get($payload, 'worker_name'), + 'workerSid' => Values::array_get($payload, 'worker_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array( + 'workspaceSid' => $workspaceSid, + 'workerSid' => $workerSid, + 'sid' => $sid ?: $this->properties['sid'], + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\ReservationContext Context for this ReservationInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new ReservationContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a ReservationInstance + * + * @return ReservationInstance Fetched ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the ReservationInstance + * + * @param array|Options $options Optional Arguments + * @return ReservationInstance Updated ReservationInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.ReservationInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationList.php new file mode 100644 index 0000000..a4e5fd7 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationList.php @@ -0,0 +1,149 @@ +solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/' . rawurlencode($workerSid) . '/Reservations'; + } + + /** + * Streams ReservationInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads ReservationInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return ReservationInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of ReservationInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of ReservationInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'ReservationStatus' => $options['reservationStatus'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new ReservationPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of ReservationInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of ReservationInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new ReservationPage($this->version, $response, $this->solution); + } + + /** + * Constructs a ReservationContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\ReservationContext + */ + public function getContext($sid) { + return new ReservationContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $sid + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.ReservationList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationOptions.php new file mode 100644 index 0000000..7aa1dad --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationOptions.php @@ -0,0 +1,788 @@ +options['reservationStatus'] = $reservationStatus; + } + + /** + * Filter by a worker's reservation status (pending, accepted, rejected, timeout, canceled, rescinded) + * + * @param string $reservationStatus Filter by a worker's reservation status + * @return $this Fluent Builder + */ + public function setReservationStatus($reservationStatus) { + $this->options['reservationStatus'] = $reservationStatus; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadReservationOptions ' . implode(' ', $options) . ']'; + } +} + +class UpdateReservationOptions extends Options { + /** + * @param string $reservationStatus Yes + * @param string $workerActivitySid No + * @param string $instruction Yes + * @param string $dequeuePostWorkActivitySid No + * @param string $dequeueFrom Yes + * @param string $dequeueRecord The dequeue_record + * @param integer $dequeueTimeout The dequeue_timeout + * @param string $dequeueTo The dequeue_to + * @param string $dequeueStatusCallbackUrl The dequeue_status_callback_url + * @param string $callFrom Yes + * @param string $callRecord The call_record + * @param integer $callTimeout The call_timeout + * @param string $callTo The call_to + * @param string $callUrl Yes + * @param string $callStatusCallbackUrl No + * @param boolean $callAccept No + * @param string $redirectCallSid The redirect_call_sid + * @param boolean $redirectAccept The redirect_accept + * @param string $redirectUrl The redirect_url + * @param string $to The to + * @param string $from The from + * @param string $statusCallback The status_callback + * @param string $statusCallbackMethod The status_callback_method + * @param string $statusCallbackEvent The status_callback_event + * @param integer $timeout The timeout + * @param boolean $record The record + * @param boolean $muted The muted + * @param string $beep The beep + * @param boolean $startConferenceOnEnter The start_conference_on_enter + * @param boolean $endConferenceOnExit The end_conference_on_exit + * @param string $waitUrl The wait_url + * @param string $waitMethod The wait_method + * @param boolean $earlyMedia The early_media + * @param integer $maxParticipants The max_participants + * @param string $conferenceStatusCallback The conference_status_callback + * @param string $conferenceStatusCallbackMethod The + * conference_status_callback_method + * @param string $conferenceStatusCallbackEvent The + * conference_status_callback_event + * @param string $conferenceRecord The conference_record + * @param string $conferenceTrim The conference_trim + * @param string $recordingChannels The recording_channels + * @param string $recordingStatusCallback The recording_status_callback + * @param string $recordingStatusCallbackMethod The + * recording_status_callback_method + * @param string $conferenceRecordingStatusCallback The + * conference_recording_status_callback + * @param string $conferenceRecordingStatusCallbackMethod The + * conference_recording_status_callback_method + * @param string $region The region + * @param string $sipAuthUsername The sip_auth_username + * @param string $sipAuthPassword The sip_auth_password + * @param string $dequeueStatusCallbackEvent The dequeue_status_callback_event + * @param string $postWorkActivitySid The post_work_activity_sid + */ + public function __construct($reservationStatus = Values::NONE, $workerActivitySid = Values::NONE, $instruction = Values::NONE, $dequeuePostWorkActivitySid = Values::NONE, $dequeueFrom = Values::NONE, $dequeueRecord = Values::NONE, $dequeueTimeout = Values::NONE, $dequeueTo = Values::NONE, $dequeueStatusCallbackUrl = Values::NONE, $callFrom = Values::NONE, $callRecord = Values::NONE, $callTimeout = Values::NONE, $callTo = Values::NONE, $callUrl = Values::NONE, $callStatusCallbackUrl = Values::NONE, $callAccept = Values::NONE, $redirectCallSid = Values::NONE, $redirectAccept = Values::NONE, $redirectUrl = Values::NONE, $to = Values::NONE, $from = Values::NONE, $statusCallback = Values::NONE, $statusCallbackMethod = Values::NONE, $statusCallbackEvent = Values::NONE, $timeout = Values::NONE, $record = Values::NONE, $muted = Values::NONE, $beep = Values::NONE, $startConferenceOnEnter = Values::NONE, $endConferenceOnExit = Values::NONE, $waitUrl = Values::NONE, $waitMethod = Values::NONE, $earlyMedia = Values::NONE, $maxParticipants = Values::NONE, $conferenceStatusCallback = Values::NONE, $conferenceStatusCallbackMethod = Values::NONE, $conferenceStatusCallbackEvent = Values::NONE, $conferenceRecord = Values::NONE, $conferenceTrim = Values::NONE, $recordingChannels = Values::NONE, $recordingStatusCallback = Values::NONE, $recordingStatusCallbackMethod = Values::NONE, $conferenceRecordingStatusCallback = Values::NONE, $conferenceRecordingStatusCallbackMethod = Values::NONE, $region = Values::NONE, $sipAuthUsername = Values::NONE, $sipAuthPassword = Values::NONE, $dequeueStatusCallbackEvent = Values::NONE, $postWorkActivitySid = Values::NONE) { + $this->options['reservationStatus'] = $reservationStatus; + $this->options['workerActivitySid'] = $workerActivitySid; + $this->options['instruction'] = $instruction; + $this->options['dequeuePostWorkActivitySid'] = $dequeuePostWorkActivitySid; + $this->options['dequeueFrom'] = $dequeueFrom; + $this->options['dequeueRecord'] = $dequeueRecord; + $this->options['dequeueTimeout'] = $dequeueTimeout; + $this->options['dequeueTo'] = $dequeueTo; + $this->options['dequeueStatusCallbackUrl'] = $dequeueStatusCallbackUrl; + $this->options['callFrom'] = $callFrom; + $this->options['callRecord'] = $callRecord; + $this->options['callTimeout'] = $callTimeout; + $this->options['callTo'] = $callTo; + $this->options['callUrl'] = $callUrl; + $this->options['callStatusCallbackUrl'] = $callStatusCallbackUrl; + $this->options['callAccept'] = $callAccept; + $this->options['redirectCallSid'] = $redirectCallSid; + $this->options['redirectAccept'] = $redirectAccept; + $this->options['redirectUrl'] = $redirectUrl; + $this->options['to'] = $to; + $this->options['from'] = $from; + $this->options['statusCallback'] = $statusCallback; + $this->options['statusCallbackMethod'] = $statusCallbackMethod; + $this->options['statusCallbackEvent'] = $statusCallbackEvent; + $this->options['timeout'] = $timeout; + $this->options['record'] = $record; + $this->options['muted'] = $muted; + $this->options['beep'] = $beep; + $this->options['startConferenceOnEnter'] = $startConferenceOnEnter; + $this->options['endConferenceOnExit'] = $endConferenceOnExit; + $this->options['waitUrl'] = $waitUrl; + $this->options['waitMethod'] = $waitMethod; + $this->options['earlyMedia'] = $earlyMedia; + $this->options['maxParticipants'] = $maxParticipants; + $this->options['conferenceStatusCallback'] = $conferenceStatusCallback; + $this->options['conferenceStatusCallbackMethod'] = $conferenceStatusCallbackMethod; + $this->options['conferenceStatusCallbackEvent'] = $conferenceStatusCallbackEvent; + $this->options['conferenceRecord'] = $conferenceRecord; + $this->options['conferenceTrim'] = $conferenceTrim; + $this->options['recordingChannels'] = $recordingChannels; + $this->options['recordingStatusCallback'] = $recordingStatusCallback; + $this->options['recordingStatusCallbackMethod'] = $recordingStatusCallbackMethod; + $this->options['conferenceRecordingStatusCallback'] = $conferenceRecordingStatusCallback; + $this->options['conferenceRecordingStatusCallbackMethod'] = $conferenceRecordingStatusCallbackMethod; + $this->options['region'] = $region; + $this->options['sipAuthUsername'] = $sipAuthUsername; + $this->options['sipAuthPassword'] = $sipAuthPassword; + $this->options['dequeueStatusCallbackEvent'] = $dequeueStatusCallbackEvent; + $this->options['postWorkActivitySid'] = $postWorkActivitySid; + } + + /** + * Yes + * + * @param string $reservationStatus Yes + * @return $this Fluent Builder + */ + public function setReservationStatus($reservationStatus) { + $this->options['reservationStatus'] = $reservationStatus; + return $this; + } + + /** + * No + * + * @param string $workerActivitySid No + * @return $this Fluent Builder + */ + public function setWorkerActivitySid($workerActivitySid) { + $this->options['workerActivitySid'] = $workerActivitySid; + return $this; + } + + /** + * Yes + * + * @param string $instruction Yes + * @return $this Fluent Builder + */ + public function setInstruction($instruction) { + $this->options['instruction'] = $instruction; + return $this; + } + + /** + * No + * + * @param string $dequeuePostWorkActivitySid No + * @return $this Fluent Builder + */ + public function setDequeuePostWorkActivitySid($dequeuePostWorkActivitySid) { + $this->options['dequeuePostWorkActivitySid'] = $dequeuePostWorkActivitySid; + return $this; + } + + /** + * Yes + * + * @param string $dequeueFrom Yes + * @return $this Fluent Builder + */ + public function setDequeueFrom($dequeueFrom) { + $this->options['dequeueFrom'] = $dequeueFrom; + return $this; + } + + /** + * The dequeue_record + * + * @param string $dequeueRecord The dequeue_record + * @return $this Fluent Builder + */ + public function setDequeueRecord($dequeueRecord) { + $this->options['dequeueRecord'] = $dequeueRecord; + return $this; + } + + /** + * The dequeue_timeout + * + * @param integer $dequeueTimeout The dequeue_timeout + * @return $this Fluent Builder + */ + public function setDequeueTimeout($dequeueTimeout) { + $this->options['dequeueTimeout'] = $dequeueTimeout; + return $this; + } + + /** + * The dequeue_to + * + * @param string $dequeueTo The dequeue_to + * @return $this Fluent Builder + */ + public function setDequeueTo($dequeueTo) { + $this->options['dequeueTo'] = $dequeueTo; + return $this; + } + + /** + * The dequeue_status_callback_url + * + * @param string $dequeueStatusCallbackUrl The dequeue_status_callback_url + * @return $this Fluent Builder + */ + public function setDequeueStatusCallbackUrl($dequeueStatusCallbackUrl) { + $this->options['dequeueStatusCallbackUrl'] = $dequeueStatusCallbackUrl; + return $this; + } + + /** + * Yes + * + * @param string $callFrom Yes + * @return $this Fluent Builder + */ + public function setCallFrom($callFrom) { + $this->options['callFrom'] = $callFrom; + return $this; + } + + /** + * The call_record + * + * @param string $callRecord The call_record + * @return $this Fluent Builder + */ + public function setCallRecord($callRecord) { + $this->options['callRecord'] = $callRecord; + return $this; + } + + /** + * The call_timeout + * + * @param integer $callTimeout The call_timeout + * @return $this Fluent Builder + */ + public function setCallTimeout($callTimeout) { + $this->options['callTimeout'] = $callTimeout; + return $this; + } + + /** + * The call_to + * + * @param string $callTo The call_to + * @return $this Fluent Builder + */ + public function setCallTo($callTo) { + $this->options['callTo'] = $callTo; + return $this; + } + + /** + * Yes + * + * @param string $callUrl Yes + * @return $this Fluent Builder + */ + public function setCallUrl($callUrl) { + $this->options['callUrl'] = $callUrl; + return $this; + } + + /** + * No + * + * @param string $callStatusCallbackUrl No + * @return $this Fluent Builder + */ + public function setCallStatusCallbackUrl($callStatusCallbackUrl) { + $this->options['callStatusCallbackUrl'] = $callStatusCallbackUrl; + return $this; + } + + /** + * No + * + * @param boolean $callAccept No + * @return $this Fluent Builder + */ + public function setCallAccept($callAccept) { + $this->options['callAccept'] = $callAccept; + return $this; + } + + /** + * The redirect_call_sid + * + * @param string $redirectCallSid The redirect_call_sid + * @return $this Fluent Builder + */ + public function setRedirectCallSid($redirectCallSid) { + $this->options['redirectCallSid'] = $redirectCallSid; + return $this; + } + + /** + * The redirect_accept + * + * @param boolean $redirectAccept The redirect_accept + * @return $this Fluent Builder + */ + public function setRedirectAccept($redirectAccept) { + $this->options['redirectAccept'] = $redirectAccept; + return $this; + } + + /** + * The redirect_url + * + * @param string $redirectUrl The redirect_url + * @return $this Fluent Builder + */ + public function setRedirectUrl($redirectUrl) { + $this->options['redirectUrl'] = $redirectUrl; + return $this; + } + + /** + * The to + * + * @param string $to The to + * @return $this Fluent Builder + */ + public function setTo($to) { + $this->options['to'] = $to; + return $this; + } + + /** + * The from + * + * @param string $from The from + * @return $this Fluent Builder + */ + public function setFrom($from) { + $this->options['from'] = $from; + return $this; + } + + /** + * The status_callback + * + * @param string $statusCallback The status_callback + * @return $this Fluent Builder + */ + public function setStatusCallback($statusCallback) { + $this->options['statusCallback'] = $statusCallback; + return $this; + } + + /** + * The status_callback_method + * + * @param string $statusCallbackMethod The status_callback_method + * @return $this Fluent Builder + */ + public function setStatusCallbackMethod($statusCallbackMethod) { + $this->options['statusCallbackMethod'] = $statusCallbackMethod; + return $this; + } + + /** + * The status_callback_event + * + * @param string $statusCallbackEvent The status_callback_event + * @return $this Fluent Builder + */ + public function setStatusCallbackEvent($statusCallbackEvent) { + $this->options['statusCallbackEvent'] = $statusCallbackEvent; + return $this; + } + + /** + * The timeout + * + * @param integer $timeout The timeout + * @return $this Fluent Builder + */ + public function setTimeout($timeout) { + $this->options['timeout'] = $timeout; + return $this; + } + + /** + * The record + * + * @param boolean $record The record + * @return $this Fluent Builder + */ + public function setRecord($record) { + $this->options['record'] = $record; + return $this; + } + + /** + * The muted + * + * @param boolean $muted The muted + * @return $this Fluent Builder + */ + public function setMuted($muted) { + $this->options['muted'] = $muted; + return $this; + } + + /** + * The beep + * + * @param string $beep The beep + * @return $this Fluent Builder + */ + public function setBeep($beep) { + $this->options['beep'] = $beep; + return $this; + } + + /** + * The start_conference_on_enter + * + * @param boolean $startConferenceOnEnter The start_conference_on_enter + * @return $this Fluent Builder + */ + public function setStartConferenceOnEnter($startConferenceOnEnter) { + $this->options['startConferenceOnEnter'] = $startConferenceOnEnter; + return $this; + } + + /** + * The end_conference_on_exit + * + * @param boolean $endConferenceOnExit The end_conference_on_exit + * @return $this Fluent Builder + */ + public function setEndConferenceOnExit($endConferenceOnExit) { + $this->options['endConferenceOnExit'] = $endConferenceOnExit; + return $this; + } + + /** + * The wait_url + * + * @param string $waitUrl The wait_url + * @return $this Fluent Builder + */ + public function setWaitUrl($waitUrl) { + $this->options['waitUrl'] = $waitUrl; + return $this; + } + + /** + * The wait_method + * + * @param string $waitMethod The wait_method + * @return $this Fluent Builder + */ + public function setWaitMethod($waitMethod) { + $this->options['waitMethod'] = $waitMethod; + return $this; + } + + /** + * The early_media + * + * @param boolean $earlyMedia The early_media + * @return $this Fluent Builder + */ + public function setEarlyMedia($earlyMedia) { + $this->options['earlyMedia'] = $earlyMedia; + return $this; + } + + /** + * The max_participants + * + * @param integer $maxParticipants The max_participants + * @return $this Fluent Builder + */ + public function setMaxParticipants($maxParticipants) { + $this->options['maxParticipants'] = $maxParticipants; + return $this; + } + + /** + * The conference_status_callback + * + * @param string $conferenceStatusCallback The conference_status_callback + * @return $this Fluent Builder + */ + public function setConferenceStatusCallback($conferenceStatusCallback) { + $this->options['conferenceStatusCallback'] = $conferenceStatusCallback; + return $this; + } + + /** + * The conference_status_callback_method + * + * @param string $conferenceStatusCallbackMethod The + * conference_status_callback_method + * @return $this Fluent Builder + */ + public function setConferenceStatusCallbackMethod($conferenceStatusCallbackMethod) { + $this->options['conferenceStatusCallbackMethod'] = $conferenceStatusCallbackMethod; + return $this; + } + + /** + * The conference_status_callback_event + * + * @param string $conferenceStatusCallbackEvent The + * conference_status_callback_event + * @return $this Fluent Builder + */ + public function setConferenceStatusCallbackEvent($conferenceStatusCallbackEvent) { + $this->options['conferenceStatusCallbackEvent'] = $conferenceStatusCallbackEvent; + return $this; + } + + /** + * The conference_record + * + * @param string $conferenceRecord The conference_record + * @return $this Fluent Builder + */ + public function setConferenceRecord($conferenceRecord) { + $this->options['conferenceRecord'] = $conferenceRecord; + return $this; + } + + /** + * The conference_trim + * + * @param string $conferenceTrim The conference_trim + * @return $this Fluent Builder + */ + public function setConferenceTrim($conferenceTrim) { + $this->options['conferenceTrim'] = $conferenceTrim; + return $this; + } + + /** + * The recording_channels + * + * @param string $recordingChannels The recording_channels + * @return $this Fluent Builder + */ + public function setRecordingChannels($recordingChannels) { + $this->options['recordingChannels'] = $recordingChannels; + return $this; + } + + /** + * The recording_status_callback + * + * @param string $recordingStatusCallback The recording_status_callback + * @return $this Fluent Builder + */ + public function setRecordingStatusCallback($recordingStatusCallback) { + $this->options['recordingStatusCallback'] = $recordingStatusCallback; + return $this; + } + + /** + * The recording_status_callback_method + * + * @param string $recordingStatusCallbackMethod The + * recording_status_callback_method + * @return $this Fluent Builder + */ + public function setRecordingStatusCallbackMethod($recordingStatusCallbackMethod) { + $this->options['recordingStatusCallbackMethod'] = $recordingStatusCallbackMethod; + return $this; + } + + /** + * The conference_recording_status_callback + * + * @param string $conferenceRecordingStatusCallback The + * conference_recording_status_callback + * @return $this Fluent Builder + */ + public function setConferenceRecordingStatusCallback($conferenceRecordingStatusCallback) { + $this->options['conferenceRecordingStatusCallback'] = $conferenceRecordingStatusCallback; + return $this; + } + + /** + * The conference_recording_status_callback_method + * + * @param string $conferenceRecordingStatusCallbackMethod The + * conference_recording_status_callback_method + * @return $this Fluent Builder + */ + public function setConferenceRecordingStatusCallbackMethod($conferenceRecordingStatusCallbackMethod) { + $this->options['conferenceRecordingStatusCallbackMethod'] = $conferenceRecordingStatusCallbackMethod; + return $this; + } + + /** + * The region + * + * @param string $region The region + * @return $this Fluent Builder + */ + public function setRegion($region) { + $this->options['region'] = $region; + return $this; + } + + /** + * The sip_auth_username + * + * @param string $sipAuthUsername The sip_auth_username + * @return $this Fluent Builder + */ + public function setSipAuthUsername($sipAuthUsername) { + $this->options['sipAuthUsername'] = $sipAuthUsername; + return $this; + } + + /** + * The sip_auth_password + * + * @param string $sipAuthPassword The sip_auth_password + * @return $this Fluent Builder + */ + public function setSipAuthPassword($sipAuthPassword) { + $this->options['sipAuthPassword'] = $sipAuthPassword; + return $this; + } + + /** + * The dequeue_status_callback_event + * + * @param string $dequeueStatusCallbackEvent The dequeue_status_callback_event + * @return $this Fluent Builder + */ + public function setDequeueStatusCallbackEvent($dequeueStatusCallbackEvent) { + $this->options['dequeueStatusCallbackEvent'] = $dequeueStatusCallbackEvent; + return $this; + } + + /** + * The post_work_activity_sid + * + * @param string $postWorkActivitySid The post_work_activity_sid + * @return $this Fluent Builder + */ + public function setPostWorkActivitySid($postWorkActivitySid) { + $this->options['postWorkActivitySid'] = $postWorkActivitySid; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateReservationOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationPage.php new file mode 100644 index 0000000..5e4d44b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/ReservationPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new ReservationInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.ReservationPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelContext.php new file mode 100644 index 0000000..8cbc67b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelContext.php @@ -0,0 +1,104 @@ +solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/' . rawurlencode($workerSid) . '/Channels/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a WorkerChannelInstance + * + * @return WorkerChannelInstance Fetched WorkerChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkerChannelInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $this->solution['sid'] + ); + } + + /** + * Update the WorkerChannelInstance + * + * @param array|Options $options Optional Arguments + * @return WorkerChannelInstance Updated WorkerChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'Capacity' => $options['capacity'], + 'Available' => Serialize::booleanToString($options['available']), + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkerChannelInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $this->solution['sid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkerChannelContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelInstance.php new file mode 100644 index 0000000..0ea28cd --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelInstance.php @@ -0,0 +1,146 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'assignedTasks' => Values::array_get($payload, 'assigned_tasks'), + 'available' => Values::array_get($payload, 'available'), + 'availableCapacityPercentage' => Values::array_get($payload, 'available_capacity_percentage'), + 'configuredCapacity' => Values::array_get($payload, 'configured_capacity'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'sid' => Values::array_get($payload, 'sid'), + 'taskChannelSid' => Values::array_get($payload, 'task_channel_sid'), + 'taskChannelUniqueName' => Values::array_get($payload, 'task_channel_unique_name'), + 'workerSid' => Values::array_get($payload, 'worker_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array( + 'workspaceSid' => $workspaceSid, + 'workerSid' => $workerSid, + 'sid' => $sid ?: $this->properties['sid'], + ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerChannelContext Context for this WorkerChannelInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkerChannelContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkerChannelInstance + * + * @return WorkerChannelInstance Fetched WorkerChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the WorkerChannelInstance + * + * @param array|Options $options Optional Arguments + * @return WorkerChannelInstance Updated WorkerChannelInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkerChannelInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelList.php new file mode 100644 index 0000000..e10bb38 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelList.php @@ -0,0 +1,145 @@ +solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/' . rawurlencode($workerSid) . '/Channels'; + } + + /** + * Streams WorkerChannelInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads WorkerChannelInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return WorkerChannelInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of WorkerChannelInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of WorkerChannelInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new WorkerChannelPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of WorkerChannelInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of WorkerChannelInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new WorkerChannelPage($this->version, $response, $this->solution); + } + + /** + * Constructs a WorkerChannelContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerChannelContext + */ + public function getContext($sid) { + return new WorkerChannelContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workerSid'], + $sid + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkerChannelList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelOptions.php new file mode 100644 index 0000000..3ed9779 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelOptions.php @@ -0,0 +1,75 @@ +options['capacity'] = $capacity; + $this->options['available'] = $available; + } + + /** + * The total number of Tasks worker should handle for this TaskChannel type. TaskRouter will only create reservations for Tasks of this TaskChannel type up to the capacity configured. If the capacity is 0, no new reservations will be created + * + * @param integer $capacity The total number of Tasks worker should handle for + * this TaskChannel type. + * @return $this Fluent Builder + */ + public function setCapacity($capacity) { + $this->options['capacity'] = $capacity; + return $this; + } + + /** + * Toggle the availability of the WorkerChannel. Set this to 'False' to make worker unavailable to receive any new Tasks of this TaskChannel type. + * + * @param boolean $available Toggle the availability of the WorkerChannel. + * @return $this Fluent Builder + */ + public function setAvailable($available) { + $this->options['available'] = $available; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateWorkerChannelOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelPage.php new file mode 100644 index 0000000..f6a33ca --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerChannelPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkerChannelInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkerChannelPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsContext.php new file mode 100644 index 0000000..1297d9a --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsContext.php @@ -0,0 +1,79 @@ +solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/' . rawurlencode($workerSid) . '/Statistics'; + } + + /** + * Fetch a WorkerStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkerStatisticsInstance Fetched WorkerStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'TaskChannel' => $options['taskChannel'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkerStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkerStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsInstance.php new file mode 100644 index 0000000..c83792f --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsInstance.php @@ -0,0 +1,111 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'cumulative' => Values::array_get($payload, 'cumulative'), + 'workerSid' => Values::array_get($payload, 'worker_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerStatisticsContext Context for this WorkerStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkerStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workerSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkerStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkerStatisticsInstance Fetched WorkerStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkerStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsList.php new file mode 100644 index 0000000..20ec094 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'workerSid' => $workerSid, ); + } + + /** + * Constructs a WorkerStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerStatisticsContext + */ + public function getContext() { + return new WorkerStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workerSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkerStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsOptions.php new file mode 100644 index 0000000..ed40564 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsOptions.php @@ -0,0 +1,103 @@ +options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['endDate'] = $endDate; + $this->options['taskChannel'] = $taskChannel; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a string of the format: yyyy-MM-dd'T'HH:mm:ss'Z'. + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter cumulative statistics by a end date. This is helpful for defining a range of statistics to capture. Input is a string of the format: yyyy-MM-dd'T'HH:mm:ss'Z'. + * + * @param \DateTime $endDate Filter cumulative statistics by a end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter cumulative statistics by TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkerStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsPage.php new file mode 100644 index 0000000..e532956 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkerStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkerStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workerSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkerStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsContext.php new file mode 100644 index 0000000..9b058fc --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsContext.php @@ -0,0 +1,78 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/CumulativeStatistics'; + } + + /** + * Fetch a WorkersCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkersCumulativeStatisticsInstance Fetched + * WorkersCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskChannel' => $options['taskChannel'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkersCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkersCumulativeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsInstance.php new file mode 100644 index 0000000..53b8c28 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsInstance.php @@ -0,0 +1,126 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'startTime' => Deserialize::dateTime(Values::array_get($payload, 'start_time')), + 'endTime' => Deserialize::dateTime(Values::array_get($payload, 'end_time')), + 'activityDurations' => Values::array_get($payload, 'activity_durations'), + 'reservationsCreated' => Values::array_get($payload, 'reservations_created'), + 'reservationsAccepted' => Values::array_get($payload, 'reservations_accepted'), + 'reservationsRejected' => Values::array_get($payload, 'reservations_rejected'), + 'reservationsTimedOut' => Values::array_get($payload, 'reservations_timed_out'), + 'reservationsCanceled' => Values::array_get($payload, 'reservations_canceled'), + 'reservationsRescinded' => Values::array_get($payload, 'reservations_rescinded'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersCumulativeStatisticsContext Context for this + * WorkersCumulativeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkersCumulativeStatisticsContext( + $this->version, + $this->solution['workspaceSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkersCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkersCumulativeStatisticsInstance Fetched + * WorkersCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkersCumulativeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsList.php new file mode 100644 index 0000000..f191177 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsList.php @@ -0,0 +1,47 @@ +solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Constructs a WorkersCumulativeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersCumulativeStatisticsContext + */ + public function getContext() { + return new WorkersCumulativeStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkersCumulativeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsOptions.php new file mode 100644 index 0000000..700794f --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsOptions.php @@ -0,0 +1,103 @@ +options['endDate'] = $endDate; + $this->options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['taskChannel'] = $taskChannel; + } + + /** + * Filter cumulative statistics by a end date. This is helpful for defining a range of statistics to capture. Input is a string of the format: yyyy-MM-dd'T'HH:mm:ss'Z'. + * + * @param \DateTime $endDate Filter cumulative statistics by a end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a string of the format: yyyy-MM-dd'T'HH:mm:ss'Z'. + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter cumulative statistics by TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkersCumulativeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsPage.php new file mode 100644 index 0000000..ae90bfb --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersCumulativeStatisticsPage.php @@ -0,0 +1,38 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkersCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkersCumulativeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsContext.php new file mode 100644 index 0000000..d7e5e59 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsContext.php @@ -0,0 +1,72 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/RealTimeStatistics'; + } + + /** + * Fetch a WorkersRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkersRealTimeStatisticsInstance Fetched + * WorkersRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array('TaskChannel' => $options['taskChannel'], )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkersRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkersRealTimeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsInstance.php new file mode 100644 index 0000000..f004452 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsInstance.php @@ -0,0 +1,111 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'activityStatistics' => Values::array_get($payload, 'activity_statistics'), + 'totalWorkers' => Values::array_get($payload, 'total_workers'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersRealTimeStatisticsContext Context for this + * WorkersRealTimeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkersRealTimeStatisticsContext( + $this->version, + $this->solution['workspaceSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkersRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkersRealTimeStatisticsInstance Fetched + * WorkersRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkersRealTimeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsList.php new file mode 100644 index 0000000..c650bf8 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsList.php @@ -0,0 +1,47 @@ +solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Constructs a WorkersRealTimeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersRealTimeStatisticsContext + */ + public function getContext() { + return new WorkersRealTimeStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkersRealTimeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsOptions.php new file mode 100644 index 0000000..5e19221 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsOptions.php @@ -0,0 +1,58 @@ +options['taskChannel'] = $taskChannel; + } + + /** + * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter cumulative statistics by TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkersRealTimeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsPage.php new file mode 100644 index 0000000..f13baed --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersRealTimeStatisticsPage.php @@ -0,0 +1,38 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkersRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkersRealTimeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsContext.php new file mode 100644 index 0000000..391b7d6 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsContext.php @@ -0,0 +1,76 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/Statistics'; + } + + /** + * Fetch a WorkersStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkersStatisticsInstance Fetched WorkersStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'TaskQueueSid' => $options['taskQueueSid'], + 'TaskQueueName' => $options['taskQueueName'], + 'FriendlyName' => $options['friendlyName'], + 'TaskChannel' => $options['taskChannel'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkersStatisticsInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkersStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsInstance.php new file mode 100644 index 0000000..8f2e44c --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsInstance.php @@ -0,0 +1,107 @@ +properties = array( + 'realtime' => Values::array_get($payload, 'realtime'), + 'cumulative' => Values::array_get($payload, 'cumulative'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersStatisticsContext Context for this WorkersStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkersStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + return $this->context; + } + + /** + * Fetch a WorkersStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkersStatisticsInstance Fetched WorkersStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkersStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsList.php new file mode 100644 index 0000000..6c2b14b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsList.php @@ -0,0 +1,48 @@ +solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Constructs a WorkersStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersStatisticsContext + */ + public function getContext() { + return new WorkersStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkersStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsOptions.php new file mode 100644 index 0000000..629e470 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsOptions.php @@ -0,0 +1,151 @@ +options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['endDate'] = $endDate; + $this->options['taskQueueSid'] = $taskQueueSid; + $this->options['taskQueueName'] = $taskQueueName; + $this->options['friendlyName'] = $friendlyName; + $this->options['taskChannel'] = $taskChannel; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a string of the format: yyyy-MM-dd'T'HH:mm:ss'Z'. + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter cumulative statistics by a end date. This is helpful for defining a range of statistics to capture. Input is a string of the format: yyyy-MM-dd'T'HH:mm:ss'Z'. + * + * @param \DateTime $endDate Filter cumulative statistics by a end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter the real-time and cumulative statistics based on Workers tied to a particular queue + * + * @param string $taskQueueSid Filter the real-time and cumulative statistics + * based on Workers tied to a particular queue + * @return $this Fluent Builder + */ + public function setTaskQueueSid($taskQueueSid) { + $this->options['taskQueueSid'] = $taskQueueSid; + return $this; + } + + /** + * Filter the real-time and cumulative statistics based on Workers tied to a particular queue + * + * @param string $taskQueueName Filter the real-time and cumulative statistics + * based on Workers tied to a particular queue + * @return $this Fluent Builder + */ + public function setTaskQueueName($taskQueueName) { + $this->options['taskQueueName'] = $taskQueueName; + return $this; + } + + /** + * The friendly_name + * + * @param string $friendlyName The friendly_name + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter cumulative statistics by TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkersStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsPage.php new file mode 100644 index 0000000..5356f01 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Worker/WorkersStatisticsPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkersStatisticsInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkersStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkerContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerContext.php new file mode 100644 index 0000000..3e08cb9 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerContext.php @@ -0,0 +1,251 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a WorkerInstance + * + * @return WorkerInstance Fetched WorkerInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkerInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Update the WorkerInstance + * + * @param array|Options $options Optional Arguments + * @return WorkerInstance Updated WorkerInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'ActivitySid' => $options['activitySid'], + 'Attributes' => $options['attributes'], + 'FriendlyName' => $options['friendlyName'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkerInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the WorkerInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + if (!$this->_realTimeStatistics) { + $this->_realTimeStatistics = new WorkersRealTimeStatisticsList( + $this->version, + $this->solution['workspaceSid'] + ); + } + + return $this->_realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + if (!$this->_cumulativeStatistics) { + $this->_cumulativeStatistics = new WorkersCumulativeStatisticsList( + $this->version, + $this->solution['workspaceSid'] + ); + } + + return $this->_cumulativeStatistics; + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerStatisticsList + */ + protected function getStatistics() { + if (!$this->_statistics) { + $this->_statistics = new WorkerStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_statistics; + } + + /** + * Access the reservations + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\ReservationList + */ + protected function getReservations() { + if (!$this->_reservations) { + $this->_reservations = new ReservationList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_reservations; + } + + /** + * Access the workerChannels + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerChannelList + */ + protected function getWorkerChannels() { + if (!$this->_workerChannels) { + $this->_workerChannels = new WorkerChannelList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_workerChannels; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkerContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkerInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerInstance.php new file mode 100644 index 0000000..d2062a8 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerInstance.php @@ -0,0 +1,201 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'activityName' => Values::array_get($payload, 'activity_name'), + 'activitySid' => Values::array_get($payload, 'activity_sid'), + 'attributes' => Values::array_get($payload, 'attributes'), + 'available' => Values::array_get($payload, 'available'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateStatusChanged' => Deserialize::dateTime(Values::array_get($payload, 'date_status_changed')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'sid' => Values::array_get($payload, 'sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkerContext Context for this + * WorkerInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkerContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkerInstance + * + * @return WorkerInstance Fetched WorkerInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the WorkerInstance + * + * @param array|Options $options Optional Arguments + * @return WorkerInstance Updated WorkerInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the WorkerInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + return $this->proxy()->realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkersCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + return $this->proxy()->cumulativeStatistics; + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerStatisticsList + */ + protected function getStatistics() { + return $this->proxy()->statistics; + } + + /** + * Access the reservations + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\ReservationList + */ + protected function getReservations() { + return $this->proxy()->reservations; + } + + /** + * Access the workerChannels + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Worker\WorkerChannelList + */ + protected function getWorkerChannels() { + return $this->proxy()->workerChannels; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkerInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkerList.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerList.php new file mode 100644 index 0000000..0e46da0 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerList.php @@ -0,0 +1,230 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workers'; + } + + /** + * Streams WorkerInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads WorkerInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return WorkerInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of WorkerInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of WorkerInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'ActivityName' => $options['activityName'], + 'ActivitySid' => $options['activitySid'], + 'Available' => $options['available'], + 'FriendlyName' => $options['friendlyName'], + 'TargetWorkersExpression' => $options['targetWorkersExpression'], + 'TaskQueueName' => $options['taskQueueName'], + 'TaskQueueSid' => $options['taskQueueSid'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new WorkerPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of WorkerInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of WorkerInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new WorkerPage($this->version, $response, $this->solution); + } + + /** + * Create a new WorkerInstance + * + * @param string $friendlyName String representing user-friendly name for the + * Worker. + * @param array|Options $options Optional Arguments + * @return WorkerInstance Newly created WorkerInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($friendlyName, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $friendlyName, + 'ActivitySid' => $options['activitySid'], + 'Attributes' => $options['attributes'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkerInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Access the statistics + */ + protected function getStatistics() { + if (!$this->_statistics) { + $this->_statistics = new WorkersStatisticsList($this->version, $this->solution['workspaceSid']); + } + + return $this->_statistics; + } + + /** + * Constructs a WorkerContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkerContext + */ + public function getContext($sid) { + return new WorkerContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkerList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkerOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerOptions.php new file mode 100644 index 0000000..4b572a6 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerOptions.php @@ -0,0 +1,288 @@ +options['activityName'] = $activityName; + $this->options['activitySid'] = $activitySid; + $this->options['available'] = $available; + $this->options['friendlyName'] = $friendlyName; + $this->options['targetWorkersExpression'] = $targetWorkersExpression; + $this->options['taskQueueName'] = $taskQueueName; + $this->options['taskQueueSid'] = $taskQueueSid; + } + + /** + * Filter by workers that are in a particular Activity by Friendly Name + * + * @param string $activityName Filter by workers that are in a particular + * Activity by Friendly Name + * @return $this Fluent Builder + */ + public function setActivityName($activityName) { + $this->options['activityName'] = $activityName; + return $this; + } + + /** + * Filter by workers that are in a particular Activity by SID + * + * @param string $activitySid Filter by workers that are in a particular + * Activity by SID + * @return $this Fluent Builder + */ + public function setActivitySid($activitySid) { + $this->options['activitySid'] = $activitySid; + return $this; + } + + /** + * Filter by workers that are available or unavailable. (Note: This can be 'true', '1' or 'yes' to indicate a true value. All other values will represent false) + * + * @param string $available Filter by workers that are available or unavailable. + * @return $this Fluent Builder + */ + public function setAvailable($available) { + $this->options['available'] = $available; + return $this; + } + + /** + * Filter by a worker's friendly name + * + * @param string $friendlyName Filter by a worker's friendly name + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Filter by workers that would match an expression on a TaskQueue. This is helpful for debugging which workers would match a potential queue. + * + * @param string $targetWorkersExpression Filter by workers that would match an + * expression on a TaskQueue. + * @return $this Fluent Builder + */ + public function setTargetWorkersExpression($targetWorkersExpression) { + $this->options['targetWorkersExpression'] = $targetWorkersExpression; + return $this; + } + + /** + * Filter by workers that are eligible for a TaskQueue by Friendly Name + * + * @param string $taskQueueName Filter by workers that are eligible for a + * TaskQueue by Friendly Name + * @return $this Fluent Builder + */ + public function setTaskQueueName($taskQueueName) { + $this->options['taskQueueName'] = $taskQueueName; + return $this; + } + + /** + * Filter by workers that are eligible for a TaskQueue by SID + * + * @param string $taskQueueSid Filter by workers that are eligible for a + * TaskQueue by SID + * @return $this Fluent Builder + */ + public function setTaskQueueSid($taskQueueSid) { + $this->options['taskQueueSid'] = $taskQueueSid; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadWorkerOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateWorkerOptions extends Options { + /** + * @param string $activitySid A valid Activity describing the worker's initial + * state. + * @param string $attributes JSON object describing this worker. + */ + public function __construct($activitySid = Values::NONE, $attributes = Values::NONE) { + $this->options['activitySid'] = $activitySid; + $this->options['attributes'] = $attributes; + } + + /** + * A valid Activity describing the worker's initial state. See Activities for more information. If not provided, new Workers will be use the DefaultActivitySid configured on the Workspace. + * + * @param string $activitySid A valid Activity describing the worker's initial + * state. + * @return $this Fluent Builder + */ + public function setActivitySid($activitySid) { + $this->options['activitySid'] = $activitySid; + return $this; + } + + /** + * JSON object describing this worker. For example: `{ 'email: 'Bob@foo.com', 'phone': '8675309' }`. This data will be passed to the Assignment Callback URL whenever TaskRouter assigns a Task to this worker. Defaults to {}. + * + * @param string $attributes JSON object describing this worker. + * @return $this Fluent Builder + */ + public function setAttributes($attributes) { + $this->options['attributes'] = $attributes; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.CreateWorkerOptions ' . implode(' ', $options) . ']'; + } +} + +class UpdateWorkerOptions extends Options { + /** + * @param string $activitySid The activity_sid + * @param string $attributes The attributes + * @param string $friendlyName The friendly_name + */ + public function __construct($activitySid = Values::NONE, $attributes = Values::NONE, $friendlyName = Values::NONE) { + $this->options['activitySid'] = $activitySid; + $this->options['attributes'] = $attributes; + $this->options['friendlyName'] = $friendlyName; + } + + /** + * The activity_sid + * + * @param string $activitySid The activity_sid + * @return $this Fluent Builder + */ + public function setActivitySid($activitySid) { + $this->options['activitySid'] = $activitySid; + return $this; + } + + /** + * The attributes + * + * @param string $attributes The attributes + * @return $this Fluent Builder + */ + public function setAttributes($attributes) { + $this->options['attributes'] = $attributes; + return $this; + } + + /** + * The friendly_name + * + * @param string $friendlyName The friendly_name + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateWorkerOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkerPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerPage.php new file mode 100644 index 0000000..282e252 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkerPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkerInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkerPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsContext.php new file mode 100644 index 0000000..85eebf6 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsContext.php @@ -0,0 +1,81 @@ +solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workflows/' . rawurlencode($workflowSid) . '/CumulativeStatistics'; + } + + /** + * Fetch a WorkflowCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowCumulativeStatisticsInstance Fetched + * WorkflowCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkflowCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowCumulativeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsInstance.php new file mode 100644 index 0000000..0f0cc5b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsInstance.php @@ -0,0 +1,148 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'avgTaskAcceptanceTime' => Values::array_get($payload, 'avg_task_acceptance_time'), + 'startTime' => Deserialize::dateTime(Values::array_get($payload, 'start_time')), + 'endTime' => Deserialize::dateTime(Values::array_get($payload, 'end_time')), + 'reservationsCreated' => Values::array_get($payload, 'reservations_created'), + 'reservationsAccepted' => Values::array_get($payload, 'reservations_accepted'), + 'reservationsRejected' => Values::array_get($payload, 'reservations_rejected'), + 'reservationsTimedOut' => Values::array_get($payload, 'reservations_timed_out'), + 'reservationsCanceled' => Values::array_get($payload, 'reservations_canceled'), + 'reservationsRescinded' => Values::array_get($payload, 'reservations_rescinded'), + 'splitByWaitTime' => Values::array_get($payload, 'split_by_wait_time'), + 'waitDurationUntilAccepted' => Values::array_get($payload, 'wait_duration_until_accepted'), + 'waitDurationUntilCanceled' => Values::array_get($payload, 'wait_duration_until_canceled'), + 'tasksCanceled' => Values::array_get($payload, 'tasks_canceled'), + 'tasksCompleted' => Values::array_get($payload, 'tasks_completed'), + 'tasksEntered' => Values::array_get($payload, 'tasks_entered'), + 'tasksDeleted' => Values::array_get($payload, 'tasks_deleted'), + 'tasksMoved' => Values::array_get($payload, 'tasks_moved'), + 'tasksTimedOutInWorkflow' => Values::array_get($payload, 'tasks_timed_out_in_workflow'), + 'workflowSid' => Values::array_get($payload, 'workflow_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowCumulativeStatisticsContext Context for this + * WorkflowCumulativeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkflowCumulativeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkflowCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowCumulativeStatisticsInstance Fetched + * WorkflowCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowCumulativeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsList.php new file mode 100644 index 0000000..c3b6dc5 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + } + + /** + * Constructs a WorkflowCumulativeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowCumulativeStatisticsContext + */ + public function getContext() { + return new WorkflowCumulativeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowCumulativeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsOptions.php new file mode 100644 index 0000000..a077be4 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsOptions.php @@ -0,0 +1,126 @@ +options['endDate'] = $endDate; + $this->options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkflowCumulativeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsPage.php new file mode 100644 index 0000000..aa10add --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowCumulativeStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkflowCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowCumulativeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsContext.php new file mode 100644 index 0000000..47fe0a3 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsContext.php @@ -0,0 +1,74 @@ +solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workflows/' . rawurlencode($workflowSid) . '/RealTimeStatistics'; + } + + /** + * Fetch a WorkflowRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowRealTimeStatisticsInstance Fetched + * WorkflowRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array('TaskChannel' => $options['taskChannel'], )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkflowRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowRealTimeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsInstance.php new file mode 100644 index 0000000..eb6e31c --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsInstance.php @@ -0,0 +1,119 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'longestTaskWaitingAge' => Values::array_get($payload, 'longest_task_waiting_age'), + 'tasksByPriority' => Values::array_get($payload, 'tasks_by_priority'), + 'tasksByStatus' => Values::array_get($payload, 'tasks_by_status'), + 'totalTasks' => Values::array_get($payload, 'total_tasks'), + 'workflowSid' => Values::array_get($payload, 'workflow_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowRealTimeStatisticsContext Context for this + * WorkflowRealTimeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkflowRealTimeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkflowRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowRealTimeStatisticsInstance Fetched + * WorkflowRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowRealTimeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsList.php new file mode 100644 index 0000000..132a9c6 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + } + + /** + * Constructs a WorkflowRealTimeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowRealTimeStatisticsContext + */ + public function getContext() { + return new WorkflowRealTimeStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowRealTimeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsOptions.php new file mode 100644 index 0000000..5438305 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsOptions.php @@ -0,0 +1,61 @@ +options['taskChannel'] = $taskChannel; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkflowRealTimeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsPage.php new file mode 100644 index 0000000..6ebb1fa --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowRealTimeStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkflowRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowRealTimeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsContext.php new file mode 100644 index 0000000..86ded94 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsContext.php @@ -0,0 +1,80 @@ +solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workflows/' . rawurlencode($workflowSid) . '/Statistics'; + } + + /** + * Fetch a WorkflowStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowStatisticsInstance Fetched WorkflowStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkflowStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsInstance.php new file mode 100644 index 0000000..ca4d807 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsInstance.php @@ -0,0 +1,114 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'cumulative' => Values::array_get($payload, 'cumulative'), + 'realtime' => Values::array_get($payload, 'realtime'), + 'workflowSid' => Values::array_get($payload, 'workflow_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowStatisticsContext Context for this + * WorkflowStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkflowStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkflowStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowStatisticsInstance Fetched WorkflowStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsList.php new file mode 100644 index 0000000..0d2f3a0 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsList.php @@ -0,0 +1,52 @@ +solution = array('workspaceSid' => $workspaceSid, 'workflowSid' => $workflowSid, ); + } + + /** + * Constructs a WorkflowStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowStatisticsContext + */ + public function getContext() { + return new WorkflowStatisticsContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsOptions.php new file mode 100644 index 0000000..07cbb47 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsOptions.php @@ -0,0 +1,126 @@ +options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['endDate'] = $endDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkflowStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsPage.php new file mode 100644 index 0000000..ef4ccf7 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/Workflow/WorkflowStatisticsPage.php @@ -0,0 +1,39 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkflowStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['workflowSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowContext.php new file mode 100644 index 0000000..d9cc0ab --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowContext.php @@ -0,0 +1,213 @@ +solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workflows/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a WorkflowInstance + * + * @return WorkflowInstance Fetched WorkflowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkflowInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Update the WorkflowInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowInstance Updated WorkflowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'AssignmentCallbackUrl' => $options['assignmentCallbackUrl'], + 'FallbackAssignmentCallbackUrl' => $options['fallbackAssignmentCallbackUrl'], + 'Configuration' => $options['configuration'], + 'TaskReservationTimeout' => $options['taskReservationTimeout'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkflowInstance( + $this->version, + $payload, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the WorkflowInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowStatisticsList + */ + protected function getStatistics() { + if (!$this->_statistics) { + $this->_statistics = new WorkflowStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_statistics; + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + if (!$this->_realTimeStatistics) { + $this->_realTimeStatistics = new WorkflowRealTimeStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + if (!$this->_cumulativeStatistics) { + $this->_cumulativeStatistics = new WorkflowCumulativeStatisticsList( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->_cumulativeStatistics; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowInstance.php new file mode 100644 index 0000000..0d32e1b --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowInstance.php @@ -0,0 +1,182 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'assignmentCallbackUrl' => Values::array_get($payload, 'assignment_callback_url'), + 'configuration' => Values::array_get($payload, 'configuration'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'documentContentType' => Values::array_get($payload, 'document_content_type'), + 'fallbackAssignmentCallbackUrl' => Values::array_get($payload, 'fallback_assignment_callback_url'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'sid' => Values::array_get($payload, 'sid'), + 'taskReservationTimeout' => Values::array_get($payload, 'task_reservation_timeout'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkflowContext Context for + * this + * WorkflowInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkflowContext( + $this->version, + $this->solution['workspaceSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkflowInstance + * + * @return WorkflowInstance Fetched WorkflowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the WorkflowInstance + * + * @param array|Options $options Optional Arguments + * @return WorkflowInstance Updated WorkflowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the WorkflowInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowStatisticsList + */ + protected function getStatistics() { + return $this->proxy()->statistics; + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + return $this->proxy()->realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\Workflow\WorkflowCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + return $this->proxy()->cumulativeStatistics; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkflowInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowList.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowList.php new file mode 100644 index 0000000..67c6fef --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowList.php @@ -0,0 +1,176 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Workflows'; + } + + /** + * Streams WorkflowInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads WorkflowInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return WorkflowInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of WorkflowInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of WorkflowInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new WorkflowPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of WorkflowInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of WorkflowInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new WorkflowPage($this->version, $response, $this->solution); + } + + /** + * Create a new WorkflowInstance + * + * @param string $friendlyName A string representing a human readable name for + * this Workflow. + * @param string $configuration JSON document configuring the rules for this + * Workflow. + * @param array|Options $options Optional Arguments + * @return WorkflowInstance Newly created WorkflowInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($friendlyName, $configuration, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $friendlyName, + 'Configuration' => $configuration, + 'AssignmentCallbackUrl' => $options['assignmentCallbackUrl'], + 'FallbackAssignmentCallbackUrl' => $options['fallbackAssignmentCallbackUrl'], + 'TaskReservationTimeout' => $options['taskReservationTimeout'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkflowInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Constructs a WorkflowContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkflowContext + */ + public function getContext($sid) { + return new WorkflowContext($this->version, $this->solution['workspaceSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowOptions.php new file mode 100644 index 0000000..5800344 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowOptions.php @@ -0,0 +1,282 @@ +options['friendlyName'] = $friendlyName; + $this->options['assignmentCallbackUrl'] = $assignmentCallbackUrl; + $this->options['fallbackAssignmentCallbackUrl'] = $fallbackAssignmentCallbackUrl; + $this->options['configuration'] = $configuration; + $this->options['taskReservationTimeout'] = $taskReservationTimeout; + } + + /** + * A string representing a human readable name for this Workflow. Examples include 'Customer Support' or 'Sales Team'. + * + * @param string $friendlyName A string representing a human readable name for + * this Workflow. + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * A valid URL for the application that will process task assignment events. See [Handling Task Assignment Callback](https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks) for more details. + * + * @param string $assignmentCallbackUrl A valid URL for the application that + * will process task assignment events. + * @return $this Fluent Builder + */ + public function setAssignmentCallbackUrl($assignmentCallbackUrl) { + $this->options['assignmentCallbackUrl'] = $assignmentCallbackUrl; + return $this; + } + + /** + * If the request to the AssignmentCallbackUrl fails, the assignment callback will be made to this URL. + * + * @param string $fallbackAssignmentCallbackUrl If the request to the + * AssignmentCallbackUrl fails, + * the assignment callback will be + * made to this URL. + * @return $this Fluent Builder + */ + public function setFallbackAssignmentCallbackUrl($fallbackAssignmentCallbackUrl) { + $this->options['fallbackAssignmentCallbackUrl'] = $fallbackAssignmentCallbackUrl; + return $this; + } + + /** + * JSON document configuring the rules for this Workflow. See [Configuring Workflows](https://www.twilio.com/docs/api/taskrouter/workflow-configuration) for more information. + * + * @param string $configuration JSON document configuring the rules for this + * Workflow. + * @return $this Fluent Builder + */ + public function setConfiguration($configuration) { + $this->options['configuration'] = $configuration; + return $this; + } + + /** + * An integer value controlling how long in seconds TaskRouter will wait for a confirmation response from your application after assigning a Task to a worker. Defaults to 120 seconds. Maximum value is 86400 (24 hours) + * + * @param integer $taskReservationTimeout An integer value controlling how long + * in seconds TaskRouter will wait for a + * confirmation response from your + * application after assigning a Task to + * a worker. + * @return $this Fluent Builder + */ + public function setTaskReservationTimeout($taskReservationTimeout) { + $this->options['taskReservationTimeout'] = $taskReservationTimeout; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateWorkflowOptions ' . implode(' ', $options) . ']'; + } +} + +class ReadWorkflowOptions extends Options { + /** + * @param string $friendlyName Human readable description of this Workflow + */ + public function __construct($friendlyName = Values::NONE) { + $this->options['friendlyName'] = $friendlyName; + } + + /** + * Human readable description of this Workflow (for example "Customer Support" or "2014 Election Campaign") + * + * @param string $friendlyName Human readable description of this Workflow + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadWorkflowOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateWorkflowOptions extends Options { + /** + * @param string $assignmentCallbackUrl A valid URL for the application that + * will process task assignment events. + * @param string $fallbackAssignmentCallbackUrl If the request to the + * AssignmentCallbackUrl fails, + * the assignment callback will be + * made to this URL. + * @param integer $taskReservationTimeout An integer value controlling how long + * in seconds TaskRouter will wait for a + * confirmation response from your + * application after assigning a Task to + * a worker. + */ + public function __construct($assignmentCallbackUrl = Values::NONE, $fallbackAssignmentCallbackUrl = Values::NONE, $taskReservationTimeout = Values::NONE) { + $this->options['assignmentCallbackUrl'] = $assignmentCallbackUrl; + $this->options['fallbackAssignmentCallbackUrl'] = $fallbackAssignmentCallbackUrl; + $this->options['taskReservationTimeout'] = $taskReservationTimeout; + } + + /** + * A valid URL for the application that will process task assignment events. See [Handling Task Assignment Callback](https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks) for more details. + * + * @param string $assignmentCallbackUrl A valid URL for the application that + * will process task assignment events. + * @return $this Fluent Builder + */ + public function setAssignmentCallbackUrl($assignmentCallbackUrl) { + $this->options['assignmentCallbackUrl'] = $assignmentCallbackUrl; + return $this; + } + + /** + * If the request to the AssignmentCallbackUrl fails, the assignment callback will be made to this URL. + * + * @param string $fallbackAssignmentCallbackUrl If the request to the + * AssignmentCallbackUrl fails, + * the assignment callback will be + * made to this URL. + * @return $this Fluent Builder + */ + public function setFallbackAssignmentCallbackUrl($fallbackAssignmentCallbackUrl) { + $this->options['fallbackAssignmentCallbackUrl'] = $fallbackAssignmentCallbackUrl; + return $this; + } + + /** + * An integer value controlling how long in seconds TaskRouter will wait for a confirmation response from your application after assigning a Task to a worker. See Task Assignment Callback for more information. Defaults to 120 seconds. Maximum value is 86400 (24 hours) + * + * @param integer $taskReservationTimeout An integer value controlling how long + * in seconds TaskRouter will wait for a + * confirmation response from your + * application after assigning a Task to + * a worker. + * @return $this Fluent Builder + */ + public function setTaskReservationTimeout($taskReservationTimeout) { + $this->options['taskReservationTimeout'] = $taskReservationTimeout; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.CreateWorkflowOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowPage.php new file mode 100644 index 0000000..a42fded --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkflowPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkflowInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkflowPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsContext.php new file mode 100644 index 0000000..0a0ee58 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsContext.php @@ -0,0 +1,79 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/CumulativeStatistics'; + } + + /** + * Fetch a WorkspaceCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceCumulativeStatisticsInstance Fetched + * WorkspaceCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkspaceCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceCumulativeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsInstance.php new file mode 100644 index 0000000..a9518e0 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsInstance.php @@ -0,0 +1,144 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'avgTaskAcceptanceTime' => Values::array_get($payload, 'avg_task_acceptance_time'), + 'startTime' => Deserialize::dateTime(Values::array_get($payload, 'start_time')), + 'endTime' => Deserialize::dateTime(Values::array_get($payload, 'end_time')), + 'reservationsCreated' => Values::array_get($payload, 'reservations_created'), + 'reservationsAccepted' => Values::array_get($payload, 'reservations_accepted'), + 'reservationsRejected' => Values::array_get($payload, 'reservations_rejected'), + 'reservationsTimedOut' => Values::array_get($payload, 'reservations_timed_out'), + 'reservationsCanceled' => Values::array_get($payload, 'reservations_canceled'), + 'reservationsRescinded' => Values::array_get($payload, 'reservations_rescinded'), + 'splitByWaitTime' => Values::array_get($payload, 'split_by_wait_time'), + 'waitDurationUntilAccepted' => Values::array_get($payload, 'wait_duration_until_accepted'), + 'waitDurationUntilCanceled' => Values::array_get($payload, 'wait_duration_until_canceled'), + 'tasksCanceled' => Values::array_get($payload, 'tasks_canceled'), + 'tasksCompleted' => Values::array_get($payload, 'tasks_completed'), + 'tasksCreated' => Values::array_get($payload, 'tasks_created'), + 'tasksDeleted' => Values::array_get($payload, 'tasks_deleted'), + 'tasksMoved' => Values::array_get($payload, 'tasks_moved'), + 'tasksTimedOutInWorkflow' => Values::array_get($payload, 'tasks_timed_out_in_workflow'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceCumulativeStatisticsContext Context for this + * WorkspaceCumulativeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkspaceCumulativeStatisticsContext( + $this->version, + $this->solution['workspaceSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkspaceCumulativeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceCumulativeStatisticsInstance Fetched + * WorkspaceCumulativeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceCumulativeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsList.php new file mode 100644 index 0000000..955c666 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsList.php @@ -0,0 +1,47 @@ +solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Constructs a WorkspaceCumulativeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceCumulativeStatisticsContext + */ + public function getContext() { + return new WorkspaceCumulativeStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceCumulativeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsOptions.php new file mode 100644 index 0000000..85a40e0 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsOptions.php @@ -0,0 +1,126 @@ +options['endDate'] = $endDate; + $this->options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkspaceCumulativeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsPage.php new file mode 100644 index 0000000..08398f1 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceCumulativeStatisticsPage.php @@ -0,0 +1,38 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkspaceCumulativeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceCumulativeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsContext.php new file mode 100644 index 0000000..9148e74 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsContext.php @@ -0,0 +1,72 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/RealTimeStatistics'; + } + + /** + * Fetch a WorkspaceRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceRealTimeStatisticsInstance Fetched + * WorkspaceRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array('TaskChannel' => $options['taskChannel'], )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkspaceRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceRealTimeStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsInstance.php new file mode 100644 index 0000000..42fb5c8 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsInstance.php @@ -0,0 +1,119 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'activityStatistics' => Values::array_get($payload, 'activity_statistics'), + 'longestTaskWaitingAge' => Values::array_get($payload, 'longest_task_waiting_age'), + 'tasksByPriority' => Values::array_get($payload, 'tasks_by_priority'), + 'tasksByStatus' => Values::array_get($payload, 'tasks_by_status'), + 'totalTasks' => Values::array_get($payload, 'total_tasks'), + 'totalWorkers' => Values::array_get($payload, 'total_workers'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceRealTimeStatisticsContext Context for this + * WorkspaceRealTimeStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkspaceRealTimeStatisticsContext( + $this->version, + $this->solution['workspaceSid'] + ); + } + + return $this->context; + } + + /** + * Fetch a WorkspaceRealTimeStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceRealTimeStatisticsInstance Fetched + * WorkspaceRealTimeStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceRealTimeStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsList.php new file mode 100644 index 0000000..d55f5d5 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsList.php @@ -0,0 +1,47 @@ +solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Constructs a WorkspaceRealTimeStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceRealTimeStatisticsContext + */ + public function getContext() { + return new WorkspaceRealTimeStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceRealTimeStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsOptions.php new file mode 100644 index 0000000..db82c35 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsOptions.php @@ -0,0 +1,61 @@ +options['taskChannel'] = $taskChannel; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkspaceRealTimeStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsPage.php new file mode 100644 index 0000000..b823d20 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceRealTimeStatisticsPage.php @@ -0,0 +1,38 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkspaceRealTimeStatisticsInstance( + $this->version, + $payload, + $this->solution['workspaceSid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceRealTimeStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsContext.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsContext.php new file mode 100644 index 0000000..7cfc9ca --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsContext.php @@ -0,0 +1,74 @@ +solution = array('workspaceSid' => $workspaceSid, ); + + $this->uri = '/Workspaces/' . rawurlencode($workspaceSid) . '/Statistics'; + } + + /** + * Fetch a WorkspaceStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceStatisticsInstance Fetched WorkspaceStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + $options = new Values($options); + + $params = Values::of(array( + 'Minutes' => $options['minutes'], + 'StartDate' => Serialize::iso8601DateTime($options['startDate']), + 'EndDate' => Serialize::iso8601DateTime($options['endDate']), + 'TaskChannel' => $options['taskChannel'], + 'SplitByWaitTime' => $options['splitByWaitTime'], + )); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkspaceStatisticsInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceStatisticsContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsInstance.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsInstance.php new file mode 100644 index 0000000..52920c0 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsInstance.php @@ -0,0 +1,106 @@ +properties = array( + 'realtime' => Values::array_get($payload, 'realtime'), + 'cumulative' => Values::array_get($payload, 'cumulative'), + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'workspaceSid' => Values::array_get($payload, 'workspace_sid'), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceStatisticsContext Context for this WorkspaceStatisticsInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkspaceStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + return $this->context; + } + + /** + * Fetch a WorkspaceStatisticsInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceStatisticsInstance Fetched WorkspaceStatisticsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch($options = array()) { + return $this->proxy()->fetch($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceStatisticsInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsList.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsList.php new file mode 100644 index 0000000..cda7899 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsList.php @@ -0,0 +1,47 @@ +solution = array('workspaceSid' => $workspaceSid, ); + } + + /** + * Constructs a WorkspaceStatisticsContext + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceStatisticsContext + */ + public function getContext() { + return new WorkspaceStatisticsContext($this->version, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceStatisticsList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsOptions.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsOptions.php new file mode 100644 index 0000000..0bbbf92 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsOptions.php @@ -0,0 +1,126 @@ +options['minutes'] = $minutes; + $this->options['startDate'] = $startDate; + $this->options['endDate'] = $endDate; + $this->options['taskChannel'] = $taskChannel; + $this->options['splitByWaitTime'] = $splitByWaitTime; + } + + /** + * Filter cumulative statistics by up to 'x' minutes in the past. This is helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends. Defaults to 15 minutes. + * + * @param integer $minutes Filter cumulative statistics by up to 'x' minutes in + * the past. + * @return $this Fluent Builder + */ + public function setMinutes($minutes) { + $this->options['minutes'] = $minutes; + return $this; + } + + /** + * Filter cumulative statistics by a start date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $startDate Filter cumulative statistics by a start date. + * @return $this Fluent Builder + */ + public function setStartDate($startDate) { + $this->options['startDate'] = $startDate; + return $this; + } + + /** + * Filter cumulative statistics by an end date. This is helpful for defining a range of statistics to capture. Input is a GMT ISO 8601 Timestamp + * + * @param \DateTime $endDate Filter cumulative statistics by an end date. + * @return $this Fluent Builder + */ + public function setEndDate($endDate) { + $this->options['endDate'] = $endDate; + return $this; + } + + /** + * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", "sms", "default", etc.) or a TaskChannelSid. + * + * @param string $taskChannel Filter real-time and cumulative statistics by + * TaskChannel. + * @return $this Fluent Builder + */ + public function setTaskChannel($taskChannel) { + $this->options['taskChannel'] = $taskChannel; + return $this; + } + + /** + * A comma separated values for viewing splits of tasks canceled and accepted above the given threshold in seconds. Ex: "5,30" would show splits of tasks that were canceled or accepted before or after 5 seconds and respectively, 30 seconds. This is great for showing short abandoned tasks or tasks that failed to meet your SLA. + * + * @param string $splitByWaitTime A comma separated values for viewing splits + * of tasks canceled and accepted above the + * given threshold in seconds. + * @return $this Fluent Builder + */ + public function setSplitByWaitTime($splitByWaitTime) { + $this->options['splitByWaitTime'] = $splitByWaitTime; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.FetchWorkspaceStatisticsOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsPage.php b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsPage.php new file mode 100644 index 0000000..dbdf462 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/Workspace/WorkspaceStatisticsPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkspaceStatisticsInstance($this->version, $payload, $this->solution['workspaceSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceStatisticsPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/WorkspaceContext.php b/Twilio/Rest/Taskrouter/V1/WorkspaceContext.php new file mode 100644 index 0000000..0239a97 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/WorkspaceContext.php @@ -0,0 +1,318 @@ +solution = array('sid' => $sid, ); + + $this->uri = '/Workspaces/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a WorkspaceInstance + * + * @return WorkspaceInstance Fetched WorkspaceInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new WorkspaceInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Update the WorkspaceInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceInstance Updated WorkspaceInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'DefaultActivitySid' => $options['defaultActivitySid'], + 'EventCallbackUrl' => $options['eventCallbackUrl'], + 'EventsFilter' => $options['eventsFilter'], + 'FriendlyName' => $options['friendlyName'], + 'MultiTaskEnabled' => Serialize::booleanToString($options['multiTaskEnabled']), + 'TimeoutActivitySid' => $options['timeoutActivitySid'], + 'PrioritizeQueueOrder' => $options['prioritizeQueueOrder'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkspaceInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Deletes the WorkspaceInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Access the activities + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\ActivityList + */ + protected function getActivities() { + if (!$this->_activities) { + $this->_activities = new ActivityList($this->version, $this->solution['sid']); + } + + return $this->_activities; + } + + /** + * Access the events + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\EventList + */ + protected function getEvents() { + if (!$this->_events) { + $this->_events = new EventList($this->version, $this->solution['sid']); + } + + return $this->_events; + } + + /** + * Access the tasks + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskList + */ + protected function getTasks() { + if (!$this->_tasks) { + $this->_tasks = new TaskList($this->version, $this->solution['sid']); + } + + return $this->_tasks; + } + + /** + * Access the taskQueues + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueueList + */ + protected function getTaskQueues() { + if (!$this->_taskQueues) { + $this->_taskQueues = new TaskQueueList($this->version, $this->solution['sid']); + } + + return $this->_taskQueues; + } + + /** + * Access the workers + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkerList + */ + protected function getWorkers() { + if (!$this->_workers) { + $this->_workers = new WorkerList($this->version, $this->solution['sid']); + } + + return $this->_workers; + } + + /** + * Access the workflows + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkflowList + */ + protected function getWorkflows() { + if (!$this->_workflows) { + $this->_workflows = new WorkflowList($this->version, $this->solution['sid']); + } + + return $this->_workflows; + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceStatisticsList + */ + protected function getStatistics() { + if (!$this->_statistics) { + $this->_statistics = new WorkspaceStatisticsList($this->version, $this->solution['sid']); + } + + return $this->_statistics; + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + if (!$this->_realTimeStatistics) { + $this->_realTimeStatistics = new WorkspaceRealTimeStatisticsList( + $this->version, + $this->solution['sid'] + ); + } + + return $this->_realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + if (!$this->_cumulativeStatistics) { + $this->_cumulativeStatistics = new WorkspaceCumulativeStatisticsList( + $this->version, + $this->solution['sid'] + ); + } + + return $this->_cumulativeStatistics; + } + + /** + * Access the taskChannels + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskChannelList + */ + protected function getTaskChannels() { + if (!$this->_taskChannels) { + $this->_taskChannels = new TaskChannelList($this->version, $this->solution['sid']); + } + + return $this->_taskChannels; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/WorkspaceInstance.php b/Twilio/Rest/Taskrouter/V1/WorkspaceInstance.php new file mode 100644 index 0000000..09397ae --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/WorkspaceInstance.php @@ -0,0 +1,249 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'defaultActivityName' => Values::array_get($payload, 'default_activity_name'), + 'defaultActivitySid' => Values::array_get($payload, 'default_activity_sid'), + 'eventCallbackUrl' => Values::array_get($payload, 'event_callback_url'), + 'eventsFilter' => Values::array_get($payload, 'events_filter'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'multiTaskEnabled' => Values::array_get($payload, 'multi_task_enabled'), + 'sid' => Values::array_get($payload, 'sid'), + 'timeoutActivityName' => Values::array_get($payload, 'timeout_activity_name'), + 'timeoutActivitySid' => Values::array_get($payload, 'timeout_activity_sid'), + 'prioritizeQueueOrder' => Values::array_get($payload, 'prioritize_queue_order'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Taskrouter\V1\WorkspaceContext Context for this + * WorkspaceInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new WorkspaceContext($this->version, $this->solution['sid']); + } + + return $this->context; + } + + /** + * Fetch a WorkspaceInstance + * + * @return WorkspaceInstance Fetched WorkspaceInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Update the WorkspaceInstance + * + * @param array|Options $options Optional Arguments + * @return WorkspaceInstance Updated WorkspaceInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Deletes the WorkspaceInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Access the activities + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\ActivityList + */ + protected function getActivities() { + return $this->proxy()->activities; + } + + /** + * Access the events + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\EventList + */ + protected function getEvents() { + return $this->proxy()->events; + } + + /** + * Access the tasks + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskList + */ + protected function getTasks() { + return $this->proxy()->tasks; + } + + /** + * Access the taskQueues + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskQueueList + */ + protected function getTaskQueues() { + return $this->proxy()->taskQueues; + } + + /** + * Access the workers + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkerList + */ + protected function getWorkers() { + return $this->proxy()->workers; + } + + /** + * Access the workflows + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkflowList + */ + protected function getWorkflows() { + return $this->proxy()->workflows; + } + + /** + * Access the statistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceStatisticsList + */ + protected function getStatistics() { + return $this->proxy()->statistics; + } + + /** + * Access the realTimeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceRealTimeStatisticsList + */ + protected function getRealTimeStatistics() { + return $this->proxy()->realTimeStatistics; + } + + /** + * Access the cumulativeStatistics + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\WorkspaceCumulativeStatisticsList + */ + protected function getCumulativeStatistics() { + return $this->proxy()->cumulativeStatistics; + } + + /** + * Access the taskChannels + * + * @return \Twilio\Rest\Taskrouter\V1\Workspace\TaskChannelList + */ + protected function getTaskChannels() { + return $this->proxy()->taskChannels; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Taskrouter.V1.WorkspaceInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/WorkspaceList.php b/Twilio/Rest/Taskrouter/V1/WorkspaceList.php new file mode 100644 index 0000000..3030488 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/WorkspaceList.php @@ -0,0 +1,173 @@ +solution = array(); + + $this->uri = '/Workspaces'; + } + + /** + * Streams WorkspaceInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($options = array(), $limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($options, $limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads WorkspaceInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param array|Options $options Optional Arguments + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return WorkspaceInstance[] Array of results + */ + public function read($options = array(), $limit = null, $pageSize = null) { + return iterator_to_array($this->stream($options, $limit, $pageSize), false); + } + + /** + * Retrieve a single page of WorkspaceInstance records from the API. + * Request is executed immediately + * + * @param array|Options $options Optional Arguments + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of WorkspaceInstance + */ + public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $options = new Values($options); + $params = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new WorkspacePage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of WorkspaceInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of WorkspaceInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new WorkspacePage($this->version, $response, $this->solution); + } + + /** + * Create a new WorkspaceInstance + * + * @param string $friendlyName Human readable description of this workspace + * @param array|Options $options Optional Arguments + * @return WorkspaceInstance Newly created WorkspaceInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($friendlyName, $options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $friendlyName, + 'EventCallbackUrl' => $options['eventCallbackUrl'], + 'EventsFilter' => $options['eventsFilter'], + 'MultiTaskEnabled' => Serialize::booleanToString($options['multiTaskEnabled']), + 'Template' => $options['template'], + 'PrioritizeQueueOrder' => $options['prioritizeQueueOrder'], + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new WorkspaceInstance($this->version, $payload); + } + + /** + * Constructs a WorkspaceContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Taskrouter\V1\WorkspaceContext + */ + public function getContext($sid) { + return new WorkspaceContext($this->version, $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspaceList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/WorkspaceOptions.php b/Twilio/Rest/Taskrouter/V1/WorkspaceOptions.php new file mode 100644 index 0000000..cb75f09 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/WorkspaceOptions.php @@ -0,0 +1,338 @@ +options['defaultActivitySid'] = $defaultActivitySid; + $this->options['eventCallbackUrl'] = $eventCallbackUrl; + $this->options['eventsFilter'] = $eventsFilter; + $this->options['friendlyName'] = $friendlyName; + $this->options['multiTaskEnabled'] = $multiTaskEnabled; + $this->options['timeoutActivitySid'] = $timeoutActivitySid; + $this->options['prioritizeQueueOrder'] = $prioritizeQueueOrder; + } + + /** + * The ID of the Activity that will be used when new Workers are created in this Workspace. + * + * @param string $defaultActivitySid The ID of the Activity that will be used + * when new Workers are created in this + * Workspace. + * @return $this Fluent Builder + */ + public function setDefaultActivitySid($defaultActivitySid) { + $this->options['defaultActivitySid'] = $defaultActivitySid; + return $this; + } + + /** + * The Workspace will publish events to this URL. You can use this to gather data for reporting. See [Events][/docs/taskrouter/api/events] for more information. + * + * @param string $eventCallbackUrl The Workspace will publish events to this + * URL. + * @return $this Fluent Builder + */ + public function setEventCallbackUrl($eventCallbackUrl) { + $this->options['eventCallbackUrl'] = $eventCallbackUrl; + return $this; + } + + /** + * Use this parameter to receive webhooks on EventCallbackUrl for specific events on a workspace. For example if 'EventsFilter=task.created,task.canceled,worker.activity.update', then TaskRouter will webhook to EventCallbackUrl only when a task is created, canceled or a worker activity is updated. + * + * @param string $eventsFilter Use this parameter to receive webhooks on + * EventCallbackUrl for specific events on a + * workspace. + * @return $this Fluent Builder + */ + public function setEventsFilter($eventsFilter) { + $this->options['eventsFilter'] = $eventsFilter; + return $this; + } + + /** + * Human readable description of this workspace (for example "Sales Call Center" or "Customer Support Team") + * + * @param string $friendlyName Human readable description of this workspace + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Enable or Disable Multitasking by passing either *true* or *False* with the POST request. Learn more by visiting [Multitasking][/docs/taskrouter/multitasking]. + * + * @param boolean $multiTaskEnabled Enable or Disable Multitasking by passing + * either true or False with the POST request. + * @return $this Fluent Builder + */ + public function setMultiTaskEnabled($multiTaskEnabled) { + $this->options['multiTaskEnabled'] = $multiTaskEnabled; + return $this; + } + + /** + * The ID of the Activity that will be assigned to a Worker when a Task reservation times out without a response. + * + * @param string $timeoutActivitySid The ID of the Activity that will be + * assigned to a Worker when a Task + * reservation times out without a response. + * @return $this Fluent Builder + */ + public function setTimeoutActivitySid($timeoutActivitySid) { + $this->options['timeoutActivitySid'] = $timeoutActivitySid; + return $this; + } + + /** + * Use this parameter to configure whether to prioritize LIFO or FIFO when workers are receiving Tasks from combination of LIFO and FIFO TaskQueues. Default is FIFO. [Click here][/docs/taskrouter/queue-ordering-last-first-out-lifo] to learn more about LIFO and the use of the parameter. + * + * @param string $prioritizeQueueOrder Use this parameter to configure whether + * to prioritize LIFO or FIFO when workers + * are receiving Tasks from combination of + * LIFO and FIFO TaskQueues. + * @return $this Fluent Builder + */ + public function setPrioritizeQueueOrder($prioritizeQueueOrder) { + $this->options['prioritizeQueueOrder'] = $prioritizeQueueOrder; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.UpdateWorkspaceOptions ' . implode(' ', $options) . ']'; + } +} + +class ReadWorkspaceOptions extends Options { + /** + * @param string $friendlyName Filter by a workspace's friendly name. + */ + public function __construct($friendlyName = Values::NONE) { + $this->options['friendlyName'] = $friendlyName; + } + + /** + * Filter by a workspace's friendly name. This is a human readable description of this Workspace (for example "Customer Support" or "2014 Election Campaign") + * + * @param string $friendlyName Filter by a workspace's friendly name. + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.ReadWorkspaceOptions ' . implode(' ', $options) . ']'; + } +} + +class CreateWorkspaceOptions extends Options { + /** + * @param string $eventCallbackUrl If provided, the Workspace will publish + * events to this URL. + * @param string $eventsFilter Use this parameter to receive webhooks on + * EventCallbackUrl for specific events on a + * workspace. + * @param boolean $multiTaskEnabled Multi tasking allows workers to handle + * multiple tasks simultaneously. + * @param string $template One of the available template names. + * @param string $prioritizeQueueOrder Use this parameter to configure whether + * to prioritize LIFO or FIFO when workers + * are receiving Tasks from combination of + * LIFO and FIFO TaskQueues. + */ + public function __construct($eventCallbackUrl = Values::NONE, $eventsFilter = Values::NONE, $multiTaskEnabled = Values::NONE, $template = Values::NONE, $prioritizeQueueOrder = Values::NONE) { + $this->options['eventCallbackUrl'] = $eventCallbackUrl; + $this->options['eventsFilter'] = $eventsFilter; + $this->options['multiTaskEnabled'] = $multiTaskEnabled; + $this->options['template'] = $template; + $this->options['prioritizeQueueOrder'] = $prioritizeQueueOrder; + } + + /** + * If provided, the Workspace will publish events to this URL. You can use this to gather data for reporting. See Workspace Events for more information. + * + * @param string $eventCallbackUrl If provided, the Workspace will publish + * events to this URL. + * @return $this Fluent Builder + */ + public function setEventCallbackUrl($eventCallbackUrl) { + $this->options['eventCallbackUrl'] = $eventCallbackUrl; + return $this; + } + + /** + * Use this parameter to receive webhooks on EventCallbackUrl for specific events on a workspace. For example if 'EventsFilter=task.created,task.canceled,worker.activity.update', then TaskRouter will webhook to EventCallbackUrl only when a task is created, canceled or a worker activity is updated. + * + * @param string $eventsFilter Use this parameter to receive webhooks on + * EventCallbackUrl for specific events on a + * workspace. + * @return $this Fluent Builder + */ + public function setEventsFilter($eventsFilter) { + $this->options['eventsFilter'] = $eventsFilter; + return $this; + } + + /** + * Multi tasking allows workers to handle multiple tasks simultaneously. When enabled (MultiTaskEnabled=true), each worker will be eligible to receive parallel reservations up to the per-channel maximums defined in the Workers section. Default is disabled (MultiTaskEnabled=false), where each worker will only receive a new reservation when the previous task is completed. Learn more by visiting [Multitasking][/docs/taskrouter/multitasking]. + * + * @param boolean $multiTaskEnabled Multi tasking allows workers to handle + * multiple tasks simultaneously. + * @return $this Fluent Builder + */ + public function setMultiTaskEnabled($multiTaskEnabled) { + $this->options['multiTaskEnabled'] = $multiTaskEnabled; + return $this; + } + + /** + * One of the available template names. Will pre-configure this Workspace with the Workflow and Activities specified in the template. "NONE" will create a Workspace with a set of default activities and nothing else. "FIFO" will configure TaskRouter with a set of default activities and a single task queue for first-in, first-out distribution, useful if you want to see a simple TaskRouter configuration when getting started. Defaults to "NONE". + * + * @param string $template One of the available template names. + * @return $this Fluent Builder + */ + public function setTemplate($template) { + $this->options['template'] = $template; + return $this; + } + + /** + * Use this parameter to configure whether to prioritize LIFO or FIFO when workers are receiving Tasks from combination of LIFO and FIFO TaskQueues. Default is FIFO. [Click here][/docs/taskrouter/queue-ordering-last-first-out-lifo] to learn more about LIFO and the use of the parameter. + * + * @param string $prioritizeQueueOrder Use this parameter to configure whether + * to prioritize LIFO or FIFO when workers + * are receiving Tasks from combination of + * LIFO and FIFO TaskQueues. + * @return $this Fluent Builder + */ + public function setPrioritizeQueueOrder($prioritizeQueueOrder) { + $this->options['prioritizeQueueOrder'] = $prioritizeQueueOrder; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Taskrouter.V1.CreateWorkspaceOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Taskrouter/V1/WorkspacePage.php b/Twilio/Rest/Taskrouter/V1/WorkspacePage.php new file mode 100644 index 0000000..78900f4 --- /dev/null +++ b/Twilio/Rest/Taskrouter/V1/WorkspacePage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new WorkspaceInstance($this->version, $payload); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Taskrouter.V1.WorkspacePage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1.php b/Twilio/Rest/Trunking/V1.php new file mode 100644 index 0000000..ffc45ae --- /dev/null +++ b/Twilio/Rest/Trunking/V1.php @@ -0,0 +1,86 @@ +version = 'v1'; + } + + /** + * @return \Twilio\Rest\Trunking\V1\TrunkList + */ + protected function getTrunks() { + if (!$this->_trunks) { + $this->_trunks = new TrunkList($this); + } + return $this->_trunks; + } + + /** + * Magic getter to lazy load root resources + * + * @param string $name Resource to return + * @return \Twilio\ListResource The requested resource + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown resource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/CredentialListContext.php b/Twilio/Rest/Trunking/V1/Trunk/CredentialListContext.php new file mode 100644 index 0000000..832bc66 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/CredentialListContext.php @@ -0,0 +1,79 @@ +solution = array('trunkSid' => $trunkSid, 'sid' => $sid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/CredentialLists/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a CredentialListInstance + * + * @return CredentialListInstance Fetched CredentialListInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new CredentialListInstance( + $this->version, + $payload, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the CredentialListInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.CredentialListContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/CredentialListInstance.php b/Twilio/Rest/Trunking/V1/Trunk/CredentialListInstance.php new file mode 100644 index 0000000..cd2f1ec --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/CredentialListInstance.php @@ -0,0 +1,126 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'sid' => Values::array_get($payload, 'sid'), + 'trunkSid' => Values::array_get($payload, 'trunk_sid'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('trunkSid' => $trunkSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Trunking\V1\Trunk\CredentialListContext Context for + * this + * CredentialListInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new CredentialListContext( + $this->version, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a CredentialListInstance + * + * @return CredentialListInstance Fetched CredentialListInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the CredentialListInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.CredentialListInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/CredentialListList.php b/Twilio/Rest/Trunking/V1/Trunk/CredentialListList.php new file mode 100644 index 0000000..e6d4117 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/CredentialListList.php @@ -0,0 +1,161 @@ +solution = array('trunkSid' => $trunkSid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/CredentialLists'; + } + + /** + * Create a new CredentialListInstance + * + * @param string $credentialListSid The SID of the Credential List that you + * want to associate with this trunk. Once + * associated, Twilio will start + * authenticating access to the trunk against + * this list. + * @return CredentialListInstance Newly created CredentialListInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($credentialListSid) { + $data = Values::of(array('CredentialListSid' => $credentialListSid, )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new CredentialListInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Streams CredentialListInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads CredentialListInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return CredentialListInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of CredentialListInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of CredentialListInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new CredentialListPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of CredentialListInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of CredentialListInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new CredentialListPage($this->version, $response, $this->solution); + } + + /** + * Constructs a CredentialListContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Trunking\V1\Trunk\CredentialListContext + */ + public function getContext($sid) { + return new CredentialListContext($this->version, $this->solution['trunkSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.CredentialListList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/CredentialListPage.php b/Twilio/Rest/Trunking/V1/Trunk/CredentialListPage.php new file mode 100644 index 0000000..d770da1 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/CredentialListPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new CredentialListInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.CredentialListPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListContext.php b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListContext.php new file mode 100644 index 0000000..84b7dfb --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListContext.php @@ -0,0 +1,79 @@ +solution = array('trunkSid' => $trunkSid, 'sid' => $sid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/IpAccessControlLists/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a IpAccessControlListInstance + * + * @return IpAccessControlListInstance Fetched IpAccessControlListInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new IpAccessControlListInstance( + $this->version, + $payload, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the IpAccessControlListInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.IpAccessControlListContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListInstance.php b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListInstance.php new file mode 100644 index 0000000..6aa45e7 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListInstance.php @@ -0,0 +1,126 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'sid' => Values::array_get($payload, 'sid'), + 'trunkSid' => Values::array_get($payload, 'trunk_sid'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('trunkSid' => $trunkSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Trunking\V1\Trunk\IpAccessControlListContext Context + * for this + * IpAccessControlListInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new IpAccessControlListContext( + $this->version, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a IpAccessControlListInstance + * + * @return IpAccessControlListInstance Fetched IpAccessControlListInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the IpAccessControlListInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.IpAccessControlListInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListList.php b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListList.php new file mode 100644 index 0000000..8d9fc3e --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListList.php @@ -0,0 +1,160 @@ +solution = array('trunkSid' => $trunkSid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/IpAccessControlLists'; + } + + /** + * Create a new IpAccessControlListInstance + * + * @param string $ipAccessControlListSid The SID of the IP Access Control List + * that you want to associate with this + * trunk. + * @return IpAccessControlListInstance Newly created IpAccessControlListInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($ipAccessControlListSid) { + $data = Values::of(array('IpAccessControlListSid' => $ipAccessControlListSid, )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new IpAccessControlListInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Streams IpAccessControlListInstance records from the API as a generator + * stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads IpAccessControlListInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return IpAccessControlListInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of IpAccessControlListInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of IpAccessControlListInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new IpAccessControlListPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of IpAccessControlListInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of IpAccessControlListInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new IpAccessControlListPage($this->version, $response, $this->solution); + } + + /** + * Constructs a IpAccessControlListContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Trunking\V1\Trunk\IpAccessControlListContext + */ + public function getContext($sid) { + return new IpAccessControlListContext($this->version, $this->solution['trunkSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.IpAccessControlListList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListPage.php b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListPage.php new file mode 100644 index 0000000..ee2979b --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/IpAccessControlListPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new IpAccessControlListInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.IpAccessControlListPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlContext.php b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlContext.php new file mode 100644 index 0000000..b53db16 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlContext.php @@ -0,0 +1,114 @@ +solution = array('trunkSid' => $trunkSid, 'sid' => $sid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/OriginationUrls/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a OriginationUrlInstance + * + * @return OriginationUrlInstance Fetched OriginationUrlInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new OriginationUrlInstance( + $this->version, + $payload, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the OriginationUrlInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Update the OriginationUrlInstance + * + * @param array|Options $options Optional Arguments + * @return OriginationUrlInstance Updated OriginationUrlInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'Weight' => $options['weight'], + 'Priority' => $options['priority'], + 'Enabled' => Serialize::booleanToString($options['enabled']), + 'FriendlyName' => $options['friendlyName'], + 'SipUrl' => $options['sipUrl'], + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new OriginationUrlInstance( + $this->version, + $payload, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.OriginationUrlContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlInstance.php b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlInstance.php new file mode 100644 index 0000000..c222c75 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlInstance.php @@ -0,0 +1,147 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'sid' => Values::array_get($payload, 'sid'), + 'trunkSid' => Values::array_get($payload, 'trunk_sid'), + 'weight' => Values::array_get($payload, 'weight'), + 'enabled' => Values::array_get($payload, 'enabled'), + 'sipUrl' => Values::array_get($payload, 'sip_url'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'priority' => Values::array_get($payload, 'priority'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'url' => Values::array_get($payload, 'url'), + ); + + $this->solution = array('trunkSid' => $trunkSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Trunking\V1\Trunk\OriginationUrlContext Context for + * this + * OriginationUrlInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new OriginationUrlContext( + $this->version, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a OriginationUrlInstance + * + * @return OriginationUrlInstance Fetched OriginationUrlInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the OriginationUrlInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Update the OriginationUrlInstance + * + * @param array|Options $options Optional Arguments + * @return OriginationUrlInstance Updated OriginationUrlInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.OriginationUrlInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlList.php b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlList.php new file mode 100644 index 0000000..7db6a59 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlList.php @@ -0,0 +1,173 @@ +solution = array('trunkSid' => $trunkSid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/OriginationUrls'; + } + + /** + * Create a new OriginationUrlInstance + * + * @param integer $weight Weight is used to determine the share of load when + * more than one URI has the same priority. + * @param integer $priority Priority ranks the importance of the URI. + * @param boolean $enabled A boolean value indicating whether the URL is + * enabled or disabled. + * @param string $friendlyName A human readable descriptive text, up to 64 + * characters long. + * @param string $sipUrl The SIP address you want Twilio to route your + * Origination calls to. + * @return OriginationUrlInstance Newly created OriginationUrlInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($weight, $priority, $enabled, $friendlyName, $sipUrl) { + $data = Values::of(array( + 'Weight' => $weight, + 'Priority' => $priority, + 'Enabled' => Serialize::booleanToString($enabled), + 'FriendlyName' => $friendlyName, + 'SipUrl' => $sipUrl, + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new OriginationUrlInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Streams OriginationUrlInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads OriginationUrlInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return OriginationUrlInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of OriginationUrlInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of OriginationUrlInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new OriginationUrlPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of OriginationUrlInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of OriginationUrlInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new OriginationUrlPage($this->version, $response, $this->solution); + } + + /** + * Constructs a OriginationUrlContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Trunking\V1\Trunk\OriginationUrlContext + */ + public function getContext($sid) { + return new OriginationUrlContext($this->version, $this->solution['trunkSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.OriginationUrlList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlOptions.php b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlOptions.php new file mode 100644 index 0000000..08ea011 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlOptions.php @@ -0,0 +1,126 @@ +options['weight'] = $weight; + $this->options['priority'] = $priority; + $this->options['enabled'] = $enabled; + $this->options['friendlyName'] = $friendlyName; + $this->options['sipUrl'] = $sipUrl; + } + + /** + * Weight is used to determine the share of load when more than one URI has the same priority. Its values range from 1 to 65535. The higher the value, the more load a URI is given. Defaults to 10. + * + * @param integer $weight Weight is used to determine the share of load when + * more than one URI has the same priority. + * @return $this Fluent Builder + */ + public function setWeight($weight) { + $this->options['weight'] = $weight; + return $this; + } + + /** + * Priority ranks the importance of the URI. Values range from 0 to 65535, where the lowest number represents the highest importance. Defaults to 10. + * + * @param integer $priority Priority ranks the importance of the URI. + * @return $this Fluent Builder + */ + public function setPriority($priority) { + $this->options['priority'] = $priority; + return $this; + } + + /** + * A boolean value indicating whether the URL is enabled or disabled. Defaults to true. + * + * @param boolean $enabled A boolean value indicating whether the URL is + * enabled or disabled. + * @return $this Fluent Builder + */ + public function setEnabled($enabled) { + $this->options['enabled'] = $enabled; + return $this; + } + + /** + * A human readable descriptive text, up to 64 characters long. + * + * @param string $friendlyName A human readable descriptive text, up to 64 + * characters long. + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * The SIP address you want Twilio to route your Origination calls to. This must be a `sip:` schema. `sips` is NOT supported + * + * @param string $sipUrl The SIP address you want Twilio to route your + * Origination calls to. + * @return $this Fluent Builder + */ + public function setSipUrl($sipUrl) { + $this->options['sipUrl'] = $sipUrl; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Trunking.V1.UpdateOriginationUrlOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlPage.php b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlPage.php new file mode 100644 index 0000000..df7a4dc --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/OriginationUrlPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new OriginationUrlInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.OriginationUrlPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberContext.php b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberContext.php new file mode 100644 index 0000000..5fa4dd1 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberContext.php @@ -0,0 +1,79 @@ +solution = array('trunkSid' => $trunkSid, 'sid' => $sid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/PhoneNumbers/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a PhoneNumberInstance + * + * @return PhoneNumberInstance Fetched PhoneNumberInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new PhoneNumberInstance( + $this->version, + $payload, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + /** + * Deletes the PhoneNumberInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.PhoneNumberContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberInstance.php b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberInstance.php new file mode 100644 index 0000000..7715eb3 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberInstance.php @@ -0,0 +1,163 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'addressRequirements' => Values::array_get($payload, 'address_requirements'), + 'apiVersion' => Values::array_get($payload, 'api_version'), + 'beta' => Values::array_get($payload, 'beta'), + 'capabilities' => Values::array_get($payload, 'capabilities'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'links' => Values::array_get($payload, 'links'), + 'phoneNumber' => Values::array_get($payload, 'phone_number'), + 'sid' => Values::array_get($payload, 'sid'), + 'smsApplicationSid' => Values::array_get($payload, 'sms_application_sid'), + 'smsFallbackMethod' => Values::array_get($payload, 'sms_fallback_method'), + 'smsFallbackUrl' => Values::array_get($payload, 'sms_fallback_url'), + 'smsMethod' => Values::array_get($payload, 'sms_method'), + 'smsUrl' => Values::array_get($payload, 'sms_url'), + 'statusCallback' => Values::array_get($payload, 'status_callback'), + 'statusCallbackMethod' => Values::array_get($payload, 'status_callback_method'), + 'trunkSid' => Values::array_get($payload, 'trunk_sid'), + 'url' => Values::array_get($payload, 'url'), + 'voiceApplicationSid' => Values::array_get($payload, 'voice_application_sid'), + 'voiceCallerIdLookup' => Values::array_get($payload, 'voice_caller_id_lookup'), + 'voiceFallbackMethod' => Values::array_get($payload, 'voice_fallback_method'), + 'voiceFallbackUrl' => Values::array_get($payload, 'voice_fallback_url'), + 'voiceMethod' => Values::array_get($payload, 'voice_method'), + 'voiceUrl' => Values::array_get($payload, 'voice_url'), + ); + + $this->solution = array('trunkSid' => $trunkSid, 'sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Trunking\V1\Trunk\PhoneNumberContext Context for this + * PhoneNumberInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new PhoneNumberContext( + $this->version, + $this->solution['trunkSid'], + $this->solution['sid'] + ); + } + + return $this->context; + } + + /** + * Fetch a PhoneNumberInstance + * + * @return PhoneNumberInstance Fetched PhoneNumberInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the PhoneNumberInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.PhoneNumberInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberList.php b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberList.php new file mode 100644 index 0000000..f46df01 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberList.php @@ -0,0 +1,158 @@ +solution = array('trunkSid' => $trunkSid, ); + + $this->uri = '/Trunks/' . rawurlencode($trunkSid) . '/PhoneNumbers'; + } + + /** + * Create a new PhoneNumberInstance + * + * @param string $phoneNumberSid The SID of the Incoming Phone Number that you + * want to associate with this trunk. + * @return PhoneNumberInstance Newly created PhoneNumberInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($phoneNumberSid) { + $data = Values::of(array('PhoneNumberSid' => $phoneNumberSid, )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new PhoneNumberInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Streams PhoneNumberInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads PhoneNumberInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return PhoneNumberInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of PhoneNumberInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of PhoneNumberInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new PhoneNumberPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of PhoneNumberInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of PhoneNumberInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new PhoneNumberPage($this->version, $response, $this->solution); + } + + /** + * Constructs a PhoneNumberContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Trunking\V1\Trunk\PhoneNumberContext + */ + public function getContext($sid) { + return new PhoneNumberContext($this->version, $this->solution['trunkSid'], $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.PhoneNumberList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberPage.php b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberPage.php new file mode 100644 index 0000000..3178cce --- /dev/null +++ b/Twilio/Rest/Trunking/V1/Trunk/PhoneNumberPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new PhoneNumberInstance($this->version, $payload, $this->solution['trunkSid']); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.PhoneNumberPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/TrunkContext.php b/Twilio/Rest/Trunking/V1/TrunkContext.php new file mode 100644 index 0000000..1cc7642 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/TrunkContext.php @@ -0,0 +1,210 @@ +solution = array('sid' => $sid, ); + + $this->uri = '/Trunks/' . rawurlencode($sid) . ''; + } + + /** + * Fetch a TrunkInstance + * + * @return TrunkInstance Fetched TrunkInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + $params = Values::of(array()); + + $payload = $this->version->fetch( + 'GET', + $this->uri, + $params + ); + + return new TrunkInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Deletes the TrunkInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->version->delete('delete', $this->uri); + } + + /** + * Update the TrunkInstance + * + * @param array|Options $options Optional Arguments + * @return TrunkInstance Updated TrunkInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'DomainName' => $options['domainName'], + 'DisasterRecoveryUrl' => $options['disasterRecoveryUrl'], + 'DisasterRecoveryMethod' => $options['disasterRecoveryMethod'], + 'Recording' => $options['recording'], + 'Secure' => Serialize::booleanToString($options['secure']), + 'CnamLookupEnabled' => Serialize::booleanToString($options['cnamLookupEnabled']), + )); + + $payload = $this->version->update( + 'POST', + $this->uri, + array(), + $data + ); + + return new TrunkInstance($this->version, $payload, $this->solution['sid']); + } + + /** + * Access the originationUrls + * + * @return \Twilio\Rest\Trunking\V1\Trunk\OriginationUrlList + */ + protected function getOriginationUrls() { + if (!$this->_originationUrls) { + $this->_originationUrls = new OriginationUrlList($this->version, $this->solution['sid']); + } + + return $this->_originationUrls; + } + + /** + * Access the credentialsLists + * + * @return \Twilio\Rest\Trunking\V1\Trunk\CredentialListList + */ + protected function getCredentialsLists() { + if (!$this->_credentialsLists) { + $this->_credentialsLists = new CredentialListList($this->version, $this->solution['sid']); + } + + return $this->_credentialsLists; + } + + /** + * Access the ipAccessControlLists + * + * @return \Twilio\Rest\Trunking\V1\Trunk\IpAccessControlListList + */ + protected function getIpAccessControlLists() { + if (!$this->_ipAccessControlLists) { + $this->_ipAccessControlLists = new IpAccessControlListList($this->version, $this->solution['sid']); + } + + return $this->_ipAccessControlLists; + } + + /** + * Access the phoneNumbers + * + * @return \Twilio\Rest\Trunking\V1\Trunk\PhoneNumberList + */ + protected function getPhoneNumbers() { + if (!$this->_phoneNumbers) { + $this->_phoneNumbers = new PhoneNumberList($this->version, $this->solution['sid']); + } + + return $this->_phoneNumbers; + } + + /** + * Magic getter to lazy load subresources + * + * @param string $name Subresource to return + * @return \Twilio\ListResource The requested subresource + * @throws \Twilio\Exceptions\TwilioException For unknown subresources + */ + public function __get($name) { + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown subresource ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $property = $this->$name; + if (method_exists($property, 'getContext')) { + return call_user_func_array(array($property, 'getContext'), $arguments); + } + + throw new TwilioException('Resource does not have a context'); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.TrunkContext ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/TrunkInstance.php b/Twilio/Rest/Trunking/V1/TrunkInstance.php new file mode 100644 index 0000000..81d1d6e --- /dev/null +++ b/Twilio/Rest/Trunking/V1/TrunkInstance.php @@ -0,0 +1,188 @@ +properties = array( + 'accountSid' => Values::array_get($payload, 'account_sid'), + 'domainName' => Values::array_get($payload, 'domain_name'), + 'disasterRecoveryMethod' => Values::array_get($payload, 'disaster_recovery_method'), + 'disasterRecoveryUrl' => Values::array_get($payload, 'disaster_recovery_url'), + 'friendlyName' => Values::array_get($payload, 'friendly_name'), + 'secure' => Values::array_get($payload, 'secure'), + 'recording' => Values::array_get($payload, 'recording'), + 'cnamLookupEnabled' => Values::array_get($payload, 'cnam_lookup_enabled'), + 'authType' => Values::array_get($payload, 'auth_type'), + 'authTypeSet' => Values::array_get($payload, 'auth_type_set'), + 'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')), + 'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')), + 'sid' => Values::array_get($payload, 'sid'), + 'url' => Values::array_get($payload, 'url'), + 'links' => Values::array_get($payload, 'links'), + ); + + $this->solution = array('sid' => $sid ?: $this->properties['sid'], ); + } + + /** + * Generate an instance context for the instance, the context is capable of + * performing various actions. All instance actions are proxied to the context + * + * @return \Twilio\Rest\Trunking\V1\TrunkContext Context for this TrunkInstance + */ + protected function proxy() { + if (!$this->context) { + $this->context = new TrunkContext($this->version, $this->solution['sid']); + } + + return $this->context; + } + + /** + * Fetch a TrunkInstance + * + * @return TrunkInstance Fetched TrunkInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function fetch() { + return $this->proxy()->fetch(); + } + + /** + * Deletes the TrunkInstance + * + * @return boolean True if delete succeeds, false otherwise + * @throws TwilioException When an HTTP error occurs. + */ + public function delete() { + return $this->proxy()->delete(); + } + + /** + * Update the TrunkInstance + * + * @param array|Options $options Optional Arguments + * @return TrunkInstance Updated TrunkInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function update($options = array()) { + return $this->proxy()->update($options); + } + + /** + * Access the originationUrls + * + * @return \Twilio\Rest\Trunking\V1\Trunk\OriginationUrlList + */ + protected function getOriginationUrls() { + return $this->proxy()->originationUrls; + } + + /** + * Access the credentialsLists + * + * @return \Twilio\Rest\Trunking\V1\Trunk\CredentialListList + */ + protected function getCredentialsLists() { + return $this->proxy()->credentialsLists; + } + + /** + * Access the ipAccessControlLists + * + * @return \Twilio\Rest\Trunking\V1\Trunk\IpAccessControlListList + */ + protected function getIpAccessControlLists() { + return $this->proxy()->ipAccessControlLists; + } + + /** + * Access the phoneNumbers + * + * @return \Twilio\Rest\Trunking\V1\Trunk\PhoneNumberList + */ + protected function getPhoneNumbers() { + return $this->proxy()->phoneNumbers; + } + + /** + * Magic getter to access properties + * + * @param string $name Property to access + * @return mixed The requested property + * @throws TwilioException For unknown properties + */ + public function __get($name) { + if (array_key_exists($name, $this->properties)) { + return $this->properties[$name]; + } + + if (property_exists($this, '_' . $name)) { + $method = 'get' . ucfirst($name); + return $this->$method(); + } + + throw new TwilioException('Unknown property: ' . $name); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $context = array(); + foreach ($this->solution as $key => $value) { + $context[] = "$key=$value"; + } + return '[Twilio.Trunking.V1.TrunkInstance ' . implode(' ', $context) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/TrunkList.php b/Twilio/Rest/Trunking/V1/TrunkList.php new file mode 100644 index 0000000..42aa692 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/TrunkList.php @@ -0,0 +1,168 @@ +solution = array(); + + $this->uri = '/Trunks'; + } + + /** + * Create a new TrunkInstance + * + * @param array|Options $options Optional Arguments + * @return TrunkInstance Newly created TrunkInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function create($options = array()) { + $options = new Values($options); + + $data = Values::of(array( + 'FriendlyName' => $options['friendlyName'], + 'DomainName' => $options['domainName'], + 'DisasterRecoveryUrl' => $options['disasterRecoveryUrl'], + 'DisasterRecoveryMethod' => $options['disasterRecoveryMethod'], + 'Recording' => $options['recording'], + 'Secure' => Serialize::booleanToString($options['secure']), + 'CnamLookupEnabled' => Serialize::booleanToString($options['cnamLookupEnabled']), + )); + + $payload = $this->version->create( + 'POST', + $this->uri, + array(), + $data + ); + + return new TrunkInstance($this->version, $payload); + } + + /** + * Streams TrunkInstance records from the API as a generator stream. + * This operation lazily loads records as efficiently as possible until the + * limit + * is reached. + * The results are returned as a generator, so this operation is memory + * efficient. + * + * @param int $limit Upper limit for the number of records to return. stream() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, stream() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return \Twilio\Stream stream of results + */ + public function stream($limit = null, $pageSize = null) { + $limits = $this->version->readLimits($limit, $pageSize); + + $page = $this->page($limits['pageSize']); + + return $this->version->stream($page, $limits['limit'], $limits['pageLimit']); + } + + /** + * Reads TrunkInstance records from the API as a list. + * Unlike stream(), this operation is eager and will load `limit` records into + * memory before returning. + * + * @param int $limit Upper limit for the number of records to return. read() + * guarantees to never return more than limit. Default is no + * limit + * @param mixed $pageSize Number of records to fetch per request, when not set + * will use the default value of 50 records. If no + * page_size is defined but a limit is defined, read() + * will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @return TrunkInstance[] Array of results + */ + public function read($limit = null, $pageSize = null) { + return iterator_to_array($this->stream($limit, $pageSize), false); + } + + /** + * Retrieve a single page of TrunkInstance records from the API. + * Request is executed immediately + * + * @param mixed $pageSize Number of records to return, defaults to 50 + * @param string $pageToken PageToken provided by the API + * @param mixed $pageNumber Page Number, this value is simply for client state + * @return \Twilio\Page Page of TrunkInstance + */ + public function page($pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) { + $params = Values::of(array( + 'PageToken' => $pageToken, + 'Page' => $pageNumber, + 'PageSize' => $pageSize, + )); + + $response = $this->version->page( + 'GET', + $this->uri, + $params + ); + + return new TrunkPage($this->version, $response, $this->solution); + } + + /** + * Retrieve a specific page of TrunkInstance records from the API. + * Request is executed immediately + * + * @param string $targetUrl API-generated URL for the requested results page + * @return \Twilio\Page Page of TrunkInstance + */ + public function getPage($targetUrl) { + $response = $this->version->getDomain()->getClient()->request( + 'GET', + $targetUrl + ); + + return new TrunkPage($this->version, $response, $this->solution); + } + + /** + * Constructs a TrunkContext + * + * @param string $sid The sid + * @return \Twilio\Rest\Trunking\V1\TrunkContext + */ + public function getContext($sid) { + return new TrunkContext($this->version, $sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.TrunkList]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/TrunkOptions.php b/Twilio/Rest/Trunking/V1/TrunkOptions.php new file mode 100644 index 0000000..8325a80 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/TrunkOptions.php @@ -0,0 +1,299 @@ +options['friendlyName'] = $friendlyName; + $this->options['domainName'] = $domainName; + $this->options['disasterRecoveryUrl'] = $disasterRecoveryUrl; + $this->options['disasterRecoveryMethod'] = $disasterRecoveryMethod; + $this->options['recording'] = $recording; + $this->options['secure'] = $secure; + $this->options['cnamLookupEnabled'] = $cnamLookupEnabled; + } + + /** + * A human-readable name for the Trunk. + * + * @param string $friendlyName A human-readable name for the Trunk. + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and `-` and must always end with `pstn.twilio.com`. See [Termination Settings](https://www.twilio.com/docs/sip-trunking/getting-started#termination) for more information. + * + * @param string $domainName The unique address you reserve on Twilio to which + * you route your SIP traffic. + * @return $this Fluent Builder + */ + public function setDomainName($domainName) { + $this->options['domainName'] = $domainName; + return $this; + } + + /** + * The HTTP URL that Twilio will request if an error occurs while sending SIP traffic towards your configured Origination URL. Twilio will retrieve TwiML from this URL and execute those instructions like any other normal TwiML call. See [Disaster Recovery](https://www.twilio.com/docs/sip-trunking/getting-started#disaster-recovery) for more information. + * + * @param string $disasterRecoveryUrl The HTTP URL that Twilio will request if + * an error occurs while sending SIP traffic + * towards your configured Origination URL. + * @return $this Fluent Builder + */ + public function setDisasterRecoveryUrl($disasterRecoveryUrl) { + $this->options['disasterRecoveryUrl'] = $disasterRecoveryUrl; + return $this; + } + + /** + * The HTTP method Twilio will use when requesting the `DisasterRecoveryUrl`. Either `GET` or `POST`. + * + * @param string $disasterRecoveryMethod The HTTP method Twilio will use when + * requesting the DisasterRecoveryUrl. + * @return $this Fluent Builder + */ + public function setDisasterRecoveryMethod($disasterRecoveryMethod) { + $this->options['disasterRecoveryMethod'] = $disasterRecoveryMethod; + return $this; + } + + /** + * The recording settings for this trunk. If turned on, all calls going through this trunk will be recorded and the recording can either start when the call is ringing or when the call is answered. See [Recording](https://www.twilio.com/docs/sip-trunking/getting-started#recording) for more information. + * + * @param string $recording The recording settings for this trunk. + * @return $this Fluent Builder + */ + public function setRecording($recording) { + $this->options['recording'] = $recording; + return $this; + } + + /** + * The Secure Trunking settings for this trunk. If turned on, all calls going through this trunk will be secure using SRTP for media and TLS for signalling. If turned off, then RTP will be used for media. See [Secure Trunking](https://www.twilio.com/docs/sip-trunking/getting-started#securetrunking) for more information. + * + * @param boolean $secure The Secure Trunking settings for this trunk. + * @return $this Fluent Builder + */ + public function setSecure($secure) { + $this->options['secure'] = $secure; + return $this; + } + + /** + * The Caller ID Name (CNAM) lookup setting for this trunk. If turned on, all inbound calls to this SIP Trunk from the United States and Canada will automatically perform a CNAM Lookup and display Caller ID data on your phone. See [CNAM](https://www.twilio.com/docs/sip-trunking#CNAM) Lookups for more information. + * + * @param boolean $cnamLookupEnabled The Caller ID Name (CNAM) lookup setting + * for this trunk. + * @return $this Fluent Builder + */ + public function setCnamLookupEnabled($cnamLookupEnabled) { + $this->options['cnamLookupEnabled'] = $cnamLookupEnabled; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Trunking.V1.CreateTrunkOptions ' . implode(' ', $options) . ']'; + } +} + +class UpdateTrunkOptions extends Options { + /** + * @param string $friendlyName A human-readable name for the Trunk. + * @param string $domainName The unique address you reserve on Twilio to which + * you route your SIP traffic. + * @param string $disasterRecoveryUrl The HTTP URL that Twilio will request if + * an error occurs while sending SIP traffic + * towards your configured Origination URL. + * @param string $disasterRecoveryMethod The HTTP method Twilio will use when + * requesting the DisasterRecoveryUrl. + * @param string $recording The recording settings for this trunk. + * @param boolean $secure The Secure Trunking settings for this trunk. + * @param boolean $cnamLookupEnabled The Caller ID Name (CNAM) lookup setting + * for this trunk. + */ + public function __construct($friendlyName = Values::NONE, $domainName = Values::NONE, $disasterRecoveryUrl = Values::NONE, $disasterRecoveryMethod = Values::NONE, $recording = Values::NONE, $secure = Values::NONE, $cnamLookupEnabled = Values::NONE) { + $this->options['friendlyName'] = $friendlyName; + $this->options['domainName'] = $domainName; + $this->options['disasterRecoveryUrl'] = $disasterRecoveryUrl; + $this->options['disasterRecoveryMethod'] = $disasterRecoveryMethod; + $this->options['recording'] = $recording; + $this->options['secure'] = $secure; + $this->options['cnamLookupEnabled'] = $cnamLookupEnabled; + } + + /** + * A human-readable name for the Trunk. + * + * @param string $friendlyName A human-readable name for the Trunk. + * @return $this Fluent Builder + */ + public function setFriendlyName($friendlyName) { + $this->options['friendlyName'] = $friendlyName; + return $this; + } + + /** + * The unique address you reserve on Twilio to which you route your SIP traffic. Domain names can contain letters, digits, and `-` and must always end with `pstn.twilio.com`. See [Termination Settings](https://www.twilio.com/docs/sip-trunking/getting-started#termination) for more information. + * + * @param string $domainName The unique address you reserve on Twilio to which + * you route your SIP traffic. + * @return $this Fluent Builder + */ + public function setDomainName($domainName) { + $this->options['domainName'] = $domainName; + return $this; + } + + /** + * The HTTP URL that Twilio will request if an error occurs while sending SIP traffic towards your configured Origination URL. Twilio will retrieve TwiML from this URL and execute those instructions like any other normal TwiML call. See [Disaster Recovery](https://www.twilio.com/docs/sip-trunking/getting-started#disaster-recovery) for more information. + * + * @param string $disasterRecoveryUrl The HTTP URL that Twilio will request if + * an error occurs while sending SIP traffic + * towards your configured Origination URL. + * @return $this Fluent Builder + */ + public function setDisasterRecoveryUrl($disasterRecoveryUrl) { + $this->options['disasterRecoveryUrl'] = $disasterRecoveryUrl; + return $this; + } + + /** + * The HTTP method Twilio will use when requesting the `DisasterRecoveryUrl`. Either `GET` or `POST`. + * + * @param string $disasterRecoveryMethod The HTTP method Twilio will use when + * requesting the DisasterRecoveryUrl. + * @return $this Fluent Builder + */ + public function setDisasterRecoveryMethod($disasterRecoveryMethod) { + $this->options['disasterRecoveryMethod'] = $disasterRecoveryMethod; + return $this; + } + + /** + * The recording settings for this trunk. If turned on, all calls going through this trunk will be recorded and the recording can either start when the call is ringing or when the call is answered. See [Recording](https://www.twilio.com/docs/sip-trunking/getting-started#recording) for more information. + * + * @param string $recording The recording settings for this trunk. + * @return $this Fluent Builder + */ + public function setRecording($recording) { + $this->options['recording'] = $recording; + return $this; + } + + /** + * The Secure Trunking settings for this trunk. If turned on, all calls going through this trunk will be secure using SRTP for media and TLS for signalling. If turned off, then RTP will be used for media. See [Secure Trunking](https://www.twilio.com/docs/sip-trunking/getting-started#securetrunking) for more information. + * + * @param boolean $secure The Secure Trunking settings for this trunk. + * @return $this Fluent Builder + */ + public function setSecure($secure) { + $this->options['secure'] = $secure; + return $this; + } + + /** + * The Caller ID Name (CNAM) lookup setting for this trunk. If turned on, all inbound calls to this SIP Trunk from the United States and Canada will automatically perform a CNAM Lookup and display Caller ID data on your phone. See [CNAM](https://www.twilio.com/docs/sip-trunking#CNAM) Lookups for more information. + * + * @param boolean $cnamLookupEnabled The Caller ID Name (CNAM) lookup setting + * for this trunk. + * @return $this Fluent Builder + */ + public function setCnamLookupEnabled($cnamLookupEnabled) { + $this->options['cnamLookupEnabled'] = $cnamLookupEnabled; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + $options = array(); + foreach ($this->options as $key => $value) { + if ($value != Values::NONE) { + $options[] = "$key=$value"; + } + } + return '[Twilio.Trunking.V1.UpdateTrunkOptions ' . implode(' ', $options) . ']'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Trunking/V1/TrunkPage.php b/Twilio/Rest/Trunking/V1/TrunkPage.php new file mode 100644 index 0000000..9be3dd0 --- /dev/null +++ b/Twilio/Rest/Trunking/V1/TrunkPage.php @@ -0,0 +1,34 @@ +solution = $solution; + } + + public function buildInstance(array $payload) { + return new TrunkInstance($this->version, $payload); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Trunking.V1.TrunkPage]'; + } +} \ No newline at end of file diff --git a/Twilio/Rest/Verify.php b/Twilio/Rest/Verify.php new file mode 100644 index 0000000..0f9fcd9 --- /dev/null +++ b/Twilio/Rest/Verify.php @@ -0,0 +1,103 @@ +baseUrl = 'https://verify.twilio.com'; + } + + /** + * @return \Twilio\Rest\Verify\V1 Version v1 of verify + */ + protected function getV1() { + if (!$this->_v1) { + $this->_v1 = new V1($this); + } + return $this->_v1; + } + + /** + * Magic getter to lazy load version + * + * @param string $name Version to return + * @return \Twilio\Version The requested version + * @throws \Twilio\Exceptions\TwilioException For unknown versions + */ + public function __get($name) { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->$method(); + } + + throw new TwilioException('Unknown version ' . $name); + } + + /** + * Magic caller to get resource contexts + * + * @param string $name Resource to return + * @param array $arguments Context parameters + * @return \Twilio\InstanceContext The requested resource context + * @throws \Twilio\Exceptions\TwilioException For unknown resource + */ + public function __call($name, $arguments) { + $method = 'context' . ucfirst($name); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + + throw new TwilioException('Unknown context ' . $name); + } + + /** + * @return \Twilio\Rest\Verify\V1\ServiceList + */ + protected function getServices() { + return $this->v1->services; + } + + /** + * @param string $sid Verification Service Instance SID. + * @return \Twilio\Rest\Verify\V1\ServiceContext + */ + protected function contextServices($sid) { + return $this->v1->services($sid); + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString() { + return '[Twilio.Verify]'; + } +} \ No newline at end of file diff --git a/Twilio/TaskRouter/WorkflowConfiguration.php b/Twilio/TaskRouter/WorkflowConfiguration.php new file mode 100644 index 0000000..d12a796 --- /dev/null +++ b/Twilio/TaskRouter/WorkflowConfiguration.php @@ -0,0 +1,50 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class WorkflowConfiguration implements \JsonSerializable { + public $filters; + public $default_filter; + + public function __construct($filters, $default_filter = null) + { + $this->filters = $filters; + $this->default_filter = $default_filter; + } + + public function toJSON() { + return json_encode($this); + } + + public static function parse($json) { + return json_decode($json); + } + + public static function fromJson($json) { + $configJSON = self::parse($json); + $default_filter = $configJSON->task_routing->default_filter; + $filters = array(); + foreach($configJSON->task_routing->filters as $filter) { + // friendly_name and filter_friendly_name should map to same variable + $friendly_name = isset($filter->filter_friendly_name) ? $filter->filter_friendly_name : $filter->friendly_name; + $filter = new WorkflowRule($filter->expression, $filter->targets, $friendly_name); + $filters[] = $filter; + } + return new WorkflowConfiguration($filters, $default_filter); + } + + public function jsonSerialize() { + $json = array(); + $task_routing = array(); + $task_routing["filters"] = $this->filters; + $task_routing["default_filter"] = $this->default_filter; + $json["task_routing"] = $task_routing; + return $json; + } +} \ No newline at end of file diff --git a/Twilio/TaskRouter/WorkflowRule.php b/Twilio/TaskRouter/WorkflowRule.php new file mode 100644 index 0000000..98e95e2 --- /dev/null +++ b/Twilio/TaskRouter/WorkflowRule.php @@ -0,0 +1,32 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class WorkflowRule implements \JsonSerializable { + public $expression; + public $friendly_name; + public $targets; + + public function __construct($expression, $targets, $friendly_name = null) + { + $this->expression = $expression; + $this->targets = $targets; + $this->friendly_name = $friendly_name; + } + + public function jsonSerialize() { + $json = array(); + $json["expression"] = $this->expression; + $json["targets"] = $this->targets; + if($this->friendly_name != null) { + $json["friendly_name"] = $this->friendly_name; + } + return $json; + } +} \ No newline at end of file diff --git a/Twilio/TaskRouter/WorkflowRuleTarget.php b/Twilio/TaskRouter/WorkflowRuleTarget.php new file mode 100644 index 0000000..de8ca05 --- /dev/null +++ b/Twilio/TaskRouter/WorkflowRuleTarget.php @@ -0,0 +1,39 @@ + + * @license http://creativecommons.org/licenses/MIT/ MIT + */ +class WorkflowRuleTarget implements \JsonSerializable { + public $queue; + public $expression; + public $priority; + public $timeout; + + public function __construct($queue, $priority = null, $timeout = null, $expression = null) + { + $this->queue = $queue; + $this->priority = $priority; + $this->timeout = $timeout; + $this->expression = $expression; + } + + public function jsonSerialize() { + $json = array(); + $json["queue"] = $this->queue; + if($this->priority != null) { + $json["priority"] = $this->priority; + } + if($this->timeout != null) { + $json["timeout"] = $this->timeout; + } + if($this->expression != null) { + $json["expression"] = $this->expression; + } + return $json; + } +} \ No newline at end of file diff --git a/Twilio/Twiml.php b/Twilio/Twiml.php new file mode 100644 index 0000000..4d1968b --- /dev/null +++ b/Twilio/Twiml.php @@ -0,0 +1,141 @@ +element = $arg; + break; + case $arg === null: + $this->element = new \SimpleXMLElement(''); + break; + case is_array($arg): + $this->element = new \SimpleXMLElement(''); + foreach ($arg as $name => $value) { + $this->element->addAttribute($name, $value); + } + break; + default: + throw new TwimlException('Invalid argument'); + } + } + + /** + * Converts method calls into Twiml verbs. + * + * A basic example: + * + * .. code-block:: php + * + * php> print $this->say('hello'); + * hello + * + * An example with attributes: + * + * .. code-block:: php + * + * print $this->say('hello', array('voice' => 'woman')); + * hello + * + * You could even just pass in an attributes array, omitting the noun: + * + * .. code-block:: php + * + * print $this->gather(array('timeout' => '20')); + * + * + * @param string $verb The Twiml verb. + * @param mixed[] $args + * @return self + * :param string $verb: The Twiml verb. + * :param array $args: + * - (noun string) + * - (noun string, attributes array) + * - (attributes array) + * + * :return: A SimpleXmlElement + * :rtype: SimpleXmlElement + */ + public function __call($verb, array $args) { + list($noun, $attrs) = $args + array('', array()); + if (is_array($noun)) { + list($attrs, $noun) = array($noun, ''); + } + /* addChild does not escape XML, while addAttribute does. This means if + * you pass unescaped ampersands ("&") to addChild, you will generate + * an error. + * + * Some inexperienced developers will pass in unescaped ampersands, and + * we want to make their code work, by escaping the ampersands for them + * before passing the string to addChild. (with htmlentities) + * + * However other people will know what to do, and their code + * already escapes ampersands before passing them to addChild. We don't + * want to break their existing code by turning their &'s into + * &amp; + * + * We also want to use numeric entities, not named entities so that we + * are fully compatible with XML + * + * The following lines accomplish the desired behavior. + */ + $decoded = html_entity_decode($noun, ENT_COMPAT, 'UTF-8'); + $normalized = htmlspecialchars($decoded, ENT_COMPAT, 'UTF-8', false); + $hasNoun = is_scalar($noun) && strlen($noun); + $child = $hasNoun + ? $this->element->addChild(ucfirst($verb), $normalized) + : $this->element->addChild(ucfirst($verb)); + + if (is_array($attrs)) { + foreach ($attrs as $name => $value) { + /* Note that addAttribute escapes raw ampersands by default, so we + * haven't touched its implementation. So this is the matrix for + * addAttribute: + * + * & turns into & + * & turns into &amp; + */ + if (is_bool($value)) { + $value = ($value === true) ? 'true' : 'false'; + } + $child->addAttribute($name, $value); + } + } + return new static($child); + } + + /** + * Returns the object as XML. + * + * :return: The response as an XML string + * :rtype: string + */ + public function __toString() { + $xml = $this->element->asXML(); + return (string)str_replace( + '', + '', $xml); + } +} diff --git a/Twilio/Version.php b/Twilio/Version.php new file mode 100644 index 0000000..b5b4af7 --- /dev/null +++ b/Twilio/Version.php @@ -0,0 +1,235 @@ +domain = $domain; + $this->version = null; + } + + /** + * Generate an absolute URL from a version relative uri + * @param string $uri Version relative uri + * @return string Absolute URL + */ + public function absoluteUrl($uri) { + return $this->getDomain()->absoluteUrl($this->relativeUri($uri)); + } + + /** + * Generate a domain relative uri from a version relative uri + * @param string $uri Version relative uri + * @return string Domain relative uri + */ + public function relativeUri($uri) { + return trim($this->version, '/') . '/' . trim($uri, '/'); + } + + public function request($method, $uri, $params = array(), $data = array(), + $headers = array(), $username = null, + $password = null, $timeout = null) { + $uri = $this->relativeUri($uri); + return $this->getDomain()->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + } + + /** + * Create the best possible exception for the response. + * + * Attempts to parse the response for Twilio Standard error messages and use + * those to populate the exception, falls back to generic error message and + * HTTP status code. + * + * @param Response $response Error response + * @param string $header Header for exception message + * @return TwilioException + */ + protected function exception($response, $header) { + $message = '[HTTP ' . $response->getStatusCode() . '] ' . $header; + + $content = $response->getContent(); + if (is_array($content)) { + $message .= isset($content['message']) ? ': ' . $content['message'] : ''; + $code = isset($content['code']) ? $content['code'] : $response->getStatusCode(); + return new RestException($message, $code, $response->getStatusCode()); + } else { + return new RestException($message, $response->getStatusCode(), $response->getStatusCode()); + } + } + + /** + * @throws TwilioException + */ + public function fetch($method, $uri, $params = array(), $data = array(), + $headers = array(), $username = null, + $password = null, $timeout = null) { + $response = $this->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + + if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { + throw $this->exception($response, 'Unable to fetch record'); + } + + return $response->getContent(); + } + + /** + * @throws TwilioException + */ + public function update($method, $uri, $params = array(), $data = array(), + $headers = array(), $username = null, + $password = null, $timeout = null) { + $response = $this->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + + if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { + throw $this->exception($response, 'Unable to update record'); + } + + return $response->getContent(); + } + + /** + * @throws TwilioException + */ + public function delete($method, $uri, $params = array(), $data = array(), + $headers = array(), $username = null, + $password = null, $timeout = null) { + $response = $this->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + + if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { + throw $this->exception($response, 'Unable to delete record'); + } + + return $response->getStatusCode() == 204; + } + + public function readLimits($limit = null, $pageSize = null) { + $pageLimit = Values::NONE; + + if ($limit) { + if (is_null($pageSize)) { + $pageSize = min($limit, self::MAX_PAGE_SIZE); + } + $pageLimit = (int)(ceil($limit / (float)$pageSize)); + } + + $pageSize = min($pageSize, self::MAX_PAGE_SIZE); + + return array( + 'limit' => $limit ?: Values::NONE, + 'pageSize' => $pageSize ?: Values::NONE, + 'pageLimit' => $pageLimit, + ); + } + + public function page($method, $uri, $params = array(), $data = array(), + $headers = array(), $username = null, + $password = null, $timeout = null) { + return $this->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + } + + public function stream($page, $limit = null, $pageLimit = null) { + return new Stream($page, $limit, $pageLimit); + } + + /** + * @throws TwilioException + */ + public function create($method, $uri, $params = array(), $data = array(), + $headers = array(), $username = null, + $password = null, $timeout = null) { + $response = $this->request( + $method, + $uri, + $params, + $data, + $headers, + $username, + $password, + $timeout + ); + + if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { + throw $this->exception($response, 'Unable to create record'); + } + + return $response->getContent(); + } + + /** + * @return \Twilio\Domain $domain + */ + public function getDomain() { + return $this->domain; + } + + public function __toString() { + return '[Version]'; + } +} diff --git a/Twilio/VersionInfo.php b/Twilio/VersionInfo.php new file mode 100644 index 0000000..acebaa5 --- /dev/null +++ b/Twilio/VersionInfo.php @@ -0,0 +1,15 @@ +. + */ + +/** + * SplClassLoader implementation that implements the technical interoperability + * standards for PHP 5.3 namespaces and class names. + * + * http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1 + * + * // Example which loads classes for the Doctrine Common package in the + * // Doctrine\Common namespace. + * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); + * $classLoader->register(); + * + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @author Jonathan H. Wage + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader { + private $_fileExtension = '.php'; + private $_namespace; + private $_includePath; + private $_namespaceSeparator = '\\'; + + /** + * Creates a new SplClassLoader that loads classes of the + * specified namespace. + * + * @param string $ns The namespace to use. + * @param string $includePath The include path to search + */ + public function __construct($ns = null, $includePath = null) { + $this->_namespace = $ns; + $this->_includePath = $includePath; + } + + /** + * Sets the namespace separator used by classes in the namespace of this class loader. + * + * @param string $sep The separator to use. + */ + public function setNamespaceSeparator($sep) { + $this->_namespaceSeparator = $sep; + } + + /** + * Gets the namespace separator used by classes in the namespace of this class loader. + * + * @return string The separator to use. + */ + public function getNamespaceSeparator() { + return $this->_namespaceSeparator; + } + + /** + * Sets the base include path for all class files in the namespace of this class loader. + * + * @param string $includePath + */ + public function setIncludePath($includePath) { + $this->_includePath = $includePath; + } + + /** + * Gets the base include path for all class files in the namespace of this class loader. + * + * @return string $includePath + */ + public function getIncludePath() { + return $this->_includePath; + } + + /** + * Sets the file extension of class files in the namespace of this class loader. + * + * @param string $fileExtension + */ + public function setFileExtension($fileExtension) { + $this->_fileExtension = $fileExtension; + } + + /** + * Gets the file extension of class files in the namespace of this class loader. + * + * @return string $fileExtension + */ + public function getFileExtension() { + return $this->_fileExtension; + } + + /** + * Installs this class loader on the SPL autoload stack. + */ + public function register() { + spl_autoload_register(array($this, 'loadClass')); + } + + /** + * Uninstalls this class loader from the SPL autoloader stack. + */ + public function unregister() { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $className The name of the class to load. + * @return void + */ + public function loadClass($className) { + if (null === $this->_namespace || $this->_namespace . $this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace . $this->_namespaceSeparator))) { + $fileName = ''; + $namespace = ''; + if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; + require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; + } + } +} + +$twilioClassLoader = new SplClassLoader('Twilio', realpath(__DIR__ . DIRECTORY_SEPARATOR . '..')); +$twilioClassLoader->register(); \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fc44700 --- /dev/null +++ b/composer.json @@ -0,0 +1,4 @@ +{ + "name": "ilink/backend", + "require": {} +} diff --git a/database.old/DataBaseConnector.php b/database.old/DataBaseConnector.php new file mode 100644 index 0000000..9f169ff --- /dev/null +++ b/database.old/DataBaseConnector.php @@ -0,0 +1,897 @@ +con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD,DB_DATABASE); + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + $this->messenger = new Messenger(); + + } + public function __destruct() + { + mysqli_close($this->con); + } + public function isPhoneExistedSimple($phone) { + // connecting to mysql + + $result = mysqli_query($this->con,"SELECT phone from users WHERE phone = '$phone'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return true; + } else { + // user not existed + return false; + } + } + public function getNetwork(){ + $r=mysqli_query($this->con,"select * from networks"); + + while($row=mysqli_fetch_array($r, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + if(count($rows)){ + return $rows; + } else { + return null; + } + } + public function isPhoneExisted($phone) { + $result = mysqli_query($this->con,"SELECT phone from users WHERE phone = '$phone'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return true; + } else { + // user not existed + return false; + } + } + public function isPhoneExistedInCategory($phone,$category=null,$phoneTransaction=null){ + + $result = mysqli_query($this->con,"SELECT na.phone from networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE na.transactionNumber ='$phoneTransaction'"); + if($result) { + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + return true; + } + }else echo json_encode(mysqli_error($this->con)); + return false; + + } + + public function checknumberValidity($phone){ + try { + return true;//$this->messenger->checkPhoneExist($phone); + } catch(Exception $ex){ + return false; + } + } + public function isMemberCodeExisted($codemembre) + { + $result = mysqli_query($this->con, "SELECT * from codeGenerer WHERE code_membre = '$codemembre' "); + if ($result) { + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) + return true; + } + return false; + + } + + public function getAgentByCodeMembre($code) + { + + $listIdmemberParrain= mysqli_query($this->con, "SELECT ag.id as id,ag.uid as uid,ag.firstname AS firstname, +ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,na.transactionNumber as phoneTransaction, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password as encrypted_password, + ne.name as network,ct.name as country,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + } + public function getAgentWithCodeMembre($code){ + $listIdmemberParrain=mysqli_query($this->con, + "SELECT na.id as agentId,ag.email as email,ag.number_super as nbre_reseau,ag.number_geoBySuper as nbre_sous_reseau,cg.category as category, cg.code_parrain as code_parrain,cg.code_membre as code_membre from agents ag RIGHT JOIN networks_agents na on ag.id=na.agent_id RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + return $membre; + }else return false; + } + public function getAgentNetworkByCode($code){ + $listIdmemberParrain=mysqli_query($this->con, + "SELECT ne.id, ne.name,ne.status from networks ne INNER JOIN networks_agents na ON na.network_id=ne.id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + return $membre; + }else return ['error'=>mysqli_error($this->con)]; + } + public function getAgentById($id){ + $listIdmemberParrain=mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname,ag.lastname AS lastname, + ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, + na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat + ,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,ne.id as network_id, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password asencrypted_password, + ne.name as network,ct.name as country, ct.code_dial as indicatif,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + ag.id='$id'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + if($membre['category']!='geolocated'){ + $membre['nbre_membre']=$this->getNbMemberOf($membre['code_membre']); + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + } + + public function storeUser($fname, $lname, $email, $phone, $password, $network, $member,$latitude, $longitude,$town,$phoneTransaction) + { + //on verifie si y a un agent qui utilise ce code + if(isset($town->id)){ + $membre = $this->getAgentWithCodeMembre($member); + if ($membre) { + if (isset($membre['agentId'])) { + //s'il y a un agent qui a ce code on cree un membre de son reseau + if (($membre['category'] == 'hyper' && $membre['nbre_reseau'] > 0) || + ($membre['category'] == 'super' && $membre['nbre_sous_reseau'] > 0)) { + //si il s'agit d'un hyperviseur ou superviseur et qu'il peut encore créer des membres alors + if ($membre['category'] == 'super') { + $codeGenerer = $this->generateValideCode($membre['code_membre'], 'geolocated'); + if ($codeGenerer != null) + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $codeGenerer, $latitude, + $longitude, $town,$phoneTransaction); + } else { + //on verifie s'il existe des codes superviseur disponible pour cette hyperviseur + $listIdmemberParrain = mysqli_query($this->con, "SELECT na.codeGenerer_id as id,cg.code_membre as code_membre from networks_agents na RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_parrain='$member' AND na.id is null"); + if ($listIdmemberParrain) { + if(mysqli_num_rows($listIdmemberParrain) > 0) { + $me = mysqli_fetch_array($listIdmemberParrain, MYSQLI_ASSOC)['code_membre']; + } + else{ + $me=$this->generateValideCode($member,'super'); + } + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $me, $latitude, $longitude, $town,$phoneTransaction); + } else { + return ["error" => -5, 'error_msg' => 'le code parrain que vous avez entrée n\'a pas de membre disponible','sql'=>mysqli_error($this->con)]; + } + } + } else { + return ["error" => -6, 'error_msg' => 'le code parrain que vous avez entrée n\'a pas de membre disponible']; + } + } else { + //si aucun membre n'a ce code on verifie s'il sagit d'un hyperviseur + if ($membre['category'] == 'hyper') { + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $member, $latitude, + $longitude, $town,$phoneTransaction); + } else { + return ["error" => -1, "error_msg" => "impossible de verifier le membre"]; + } + } + } else { + return ["error" => -2, "error_msg" => "impossible de verifier le membre", 'sql' => mysqli_error($this->con)]; + } + }else{ + return ["error" => -10, "error_msg" => "La ville dans laquelle vous vous trouvez n'est pas encore pris en charge", 'sql' => mysqli_error($this->con)]; + } + } + + public function random_string() + { + $character_set_array = array(); + $character_set_array[] = array('count' => 7, 'characters' => 'abcdefghjkmnpqrstuvwxyz'); + $character_set_array[] = array('count' => 1, 'characters' => '23456789'); + $temp_array = array(); + foreach ($character_set_array as $character_set) { + for ($i = 0; $i < $character_set['count']; $i++) { + $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)]; + } + } + shuffle($temp_array); + return implode('', $temp_array); + } + + public function getAllPointInCountry($country){ + $etat=1; + $si=1; + $category="geolocated"; + if($result= mysqli_prepare($this->con,"SELECT * FROM agent_plus WHERE code_dial=? AND etat=? AND category=? AND longitude!=0 AND latitude!=0")) { + mysqli_stmt_bind_param($result, 'sis', $country, $etat, $category); + mysqli_stmt_execute($result); + $r = mysqli_stmt_get_result($result); + $rows=[]; + while ($row = mysqli_fetch_array($r, MYSQLI_BOTH)) { + $grow = []; + foreach ($row as $key => $value) { + if (!is_integer($key)) { + if (!isset($grow[$key])) $grow[$key] = $value; + } else if ($key == 5) { + $grow["longitude"] = $value; + } else if ($key == 6) { + $grow["latitude"] = $value; + } + } + $rows[]=$grow; + } + + mysqli_stmt_close($result); + return $rows; + if($result) { + $rows=[]; + while ($row = mysqli_fetch_assoc($result)) { + $rows[] = $row; + } + // $rows; + }else{ + return ['error'=>mysqli_error($this->con)]; + + } + }else{ + return ['error'=>mysqli_error($this->con)]; + + } + + return false; + } + + public function getUserCountryPoint($user_id){ + $result = mysqli_query($this->con,"SELECT * FROM agents ag inner JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.category='geolocated' AND na.etat=1") or die(mysqli_error($this->con)); + if($result) { + $rows=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + return $rows; + }else return false; + + } + + public function getCategoryAgent($codeparrain){ + $result=mysqli_query($this->con,"SELECT category,etat FROM codeGenerer where code_membre = '$codeparrain'"); + if($result) { + $rows=[]; + $row = mysqli_fetch_array($result, MYSQLI_ASSOC); + + return $row; + }else return ["erro"=>mysqli_error($this->con)]; + + } + + public function updateWrongPoints() + { + $result=[]; + + return $result; + } + + public function getSuperviseurNetwork($codeparrain,$user_id){ + $self=$this->getAgentByCodeMembre($codeparrain); + $catparrain=$self['category']; + $catchild=($catparrain=='hyper')?'super':($catparrain=='super'?'geolocated':null); + if($catchild) { + $result = mysqli_query($this->con, "select ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat FROM networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id +INNER JOIN networks nt ON na.network_id=nt.id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN countries ct + ON nt.country_id=ct.id WHERE cg.code_parrain='$codeparrain' AND cg.code_membre!='$codeparrain' AND na.etat='1' AND cg.category='$catchild'"); + + $rows = []; + $re = []; + if ($result) { + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + $re['val'] = $rows; + $re['success'] = 1; + $re['catchild']=$catchild; + $re['catparrain']=$catparrain; + } else { + $re['error'] = mysqli_error($this->con); + } + }else{ + $re['error']='cat child not found'; + } + return $re; + } + + public function getPointsNetwork($network,$user_id){ + $result=mysqli_query($this->con,"SELECT ag.firstname,cg.code_membre,cg.code_parrain,ag.adresse, +ag.lastname,na.phone,ag.email,na.solde,cg.category,ne.name as network,ct.id as country,ag.longitude,ag.latitude,ag.id as AgentId,ne.id as network_id,ct.id as country_id +FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN +codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id INNER JOIN countries ct ON ct.id=ne.country_id WHERE cg.category='geolocated' AND na.etat='1' AND na.network_id='$network' AND ag.longitude>0 AND ag.latitude>0 LIMIT 100"); + if($result) { + $rows=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + return $rows; + }else + { + return ["error"=>mysqli_error($this->con)]; + } + } + + private function getUserByPhoneAndPassword($phone, $password,$table) { + $result = mysqli_query($this->con,"SELECT usr.active,usr.salt,usr.encrypted_password,usr.firstname,usr.lastname,usr.id,usr.phone,usr.email,usr.solde,usr.validation_code,usr.active,usr.network_id,ne.name as network,ne.country_id,ct.name as country,ct.code_dial,ct.code_country FROM $table usr INNER JOIN networks ne ON usr.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE phone = '$phone'") or die(mysqli_error($this->con)); + // check for result + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + $result = mysqli_fetch_array($result,MYSQLI_ASSOC); + $salt = $result['salt']; + $encrypted_password = $result['encrypted_password']; + $hash = $this->checkhashSSHA($salt, $password); + // check for password equality + if ($encrypted_password == $hash) { + // user authentication details are correct + return $result; + }else{ + return ['error'=>-3]; + } + } else { + // user not found + return ['error'=>-2]; + } + } + + public function hashSSHA($password) { + + $salt = sha1(rand()); + $salt = substr($salt, 0, 10); + $encrypted = base64_encode(sha1($password . $salt, true) . $salt); + $hash = array("salt" => $salt, "encrypted" => $encrypted); + return $hash; + } + + public function forgotPasswordSimple($phone, $encrypted_password, $salt) + { + $result = mysqli_query($this->con, "UPDATE `users` SET `encrypted_password` = '$encrypted_password',`salt` = '$salt' WHERE `phone` = '$phone'"); + + if ($result) { + + return true; + + } else { + return false; + } + } + + public function getEmailSimple($phone){ + $result = mysqli_query($this->con,"SELECT email FROM users WHERE phone = '$phone'"); + + if ($result) { + return mysqli_fetch_array($result); + //return true; + + } + else + { + return false; + } + + } + + public function listNetwork(){ + echo "request"; + $res=mysqli_query($this->con,"SELECT * FROM network"); + if($res){ + return mysqli_fetch_array($res); + + }else return ['error'=>'unable to make request','error_'=>mysqli_error($this->con)]; + } + + private function checkhashSSHA($salt, $password) { + + $hash = base64_encode(sha1($password . $salt, true) . $salt); + + return $hash; + } + /** + * Verifies user by phone and password + */ + public function getUserByPhoneAndPasswordSimple($phone, $password) { + return $this->getUserByPhoneAndPassword($phone,$password,'users'); + } + /** + * Verifies user by phone and password + */ + public function generateRandomString($length = 10) { + $characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + public function getUserByPhoneAndPasswordGeolocated($phone, $password) { + // connecting to mysql + $result = mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname,ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,na.transactionNumber as phoneTransaction, +ne.id as network_id,ag.date_created as date_created,cg.category as category, + ag.salt as salt,ag.encrypted_password as encrypted_password,ne.name as network,ct.name as country + ,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id + INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE na.phone='$phone' or na.transactionNumber='$phone'"); + if($result){ + if(mysqli_num_rows($result)>0) { + $mr=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $salt = $row['salt']; + $encrypted_password = $row['encrypted_password']; + $hash = $this->checkhashSSHA($salt, $password); + $mr["hash"]=$hash; + $mr["encrypted_password"]=$encrypted_password; + if ($encrypted_password == $hash) { + if ($row['category'] == 'super') { + $phone = $row["phone"]; + $demandere = mysqli_query($this->con, "SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if ($demandere) + $row['etat_demande'] = mysqli_fetch_array($demandere, MYSQLI_ASSOC)['etat']; + else + echo mysqli_error($this->con); + } + if($row['category']!='geolocated'){ + $row['nbre_membre']=$this->getNbMemberOf($row['code_membre']); + + + } + + return $row; + } + + return ['error'=>-3,"error_msg"=>"Mot de passe incorrect","last"=>$row]; + } + }else + return ['error'=>-1,"error_msg"=>"Numéro incorrect",]; + } + + else + return ['error'=>-2,"error_msg"=>mysqli_error($this->con)]; + + } + + public function getAgentNetworkByPhone($phone){ + $listIdmemberParrain=mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname, +ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone, +ne.id as network_id, +na.id as networkAgentId, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password as encrypted_password, + ne.name as network,ct.name as country,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + na.phone='$phone'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + + } + + public function storeDemandeCredit($phone,$montant,$code){ + $agent=$this->getAgentWithCodeMembre($code); + if($agent) { + $idag=$agent['agentId']; + $q = mysqli_query($this->con, "INSERT INTO demandeCredits(network_agent_id,montant,status) VALUES('$idag','$montant','0')"); + if ($q) { + return ['success' => 1, "agent" => $agent]; + } + } + return false; + +} + + private function createAgent($fname, $lname, $email, $phone, $password, $network, $member, $latitude, $longitude, $town,$phoneTransaction) + { + + $resultFreeCode = mysqli_query($this->con, "SELECT id,code_membre,category,code_parrain from codeGenerer cg WHERE code_membre='$member' "); + if($resultFreeCode){ + $freecodenum=mysqli_num_rows($resultFreeCode); + if($freecodenum>0) { + $codes = mysqli_fetch_array($resultFreeCode, MYSQLI_ASSOC); + $freecode = $codes; + $code_id = $freecode['id']; + $category=$freecode["category"]; + $uuid = uniqid('', true); + $balance = 0; + $etat=0; + if($category=="geolocated"){ + $etat=1; + } + + $hash = $this->hashSSHA($password); + $encrypted_password = $hash["encrypted"]; + $salt = $hash["salt"]; + $validation_code = $this->random_string(); + + if(isset($town->id)) { + $townid = $town->id; + + $agentCreateResult = mysqli_query($this->con, "INSERT INTO agents(uid,adresse, +lastname,email,longitude,latitude +,balance,encrypted_password,salt,active,date_created,town_id) VALUES ('$uuid', +'$fname','$lname','$email','$longitude','$latitude','$balance','$encrypted_password','$salt','$etat',NOW(),'$townid')"); + if ($agentCreateResult) { + $agent_id = mysqli_insert_id($this->con); + if ($agent_id) { + + + + $result = mysqli_query($this->con, "INSERT INTO networks_agents(network_id,agent_id, +solde,etat,codeGenerer_id,phone,validation_code,transactionNumber) +VALUES('$network->id','$agent_id','$balance','$etat','$code_id','$phone','$validation_code','$phoneTransaction')"); + if ($result) { + // get user details + + $agent= $this->getAgentById($agent_id); + $resque=mysqli_query($this->con,"UPDATE codeGenerer SET etat='1' WHERE code_membre='$member'"); + if($resque){ + if($agent['category']=='super'){ + $re=$this->adddemandeAdhesionAgent($agent); + if(!isset($re['success']))return $re; + } + }else{ + return [ + 'error' => 'impossible de de mettre à jour', + 'sql_error' => mysqli_error($this->con), + ]; + } + return $agent; + } else { + return [ + 'error' => 'impossible de créer un network_agent', + 'sql_error' => mysqli_error($this->con), + 'code_generer' => $freecode + ]; + } + + } else { + return [ + 'error' => 'impossible recuperer l agent', + 'sql_error' => mysqli_error($this->con), + 'code_generer' => $freecode + ]; + } + + } else { + return [ + 'error' => 'impossible de créer un agent', + 'sql_error' => mysqli_error($this->con) + ]; + } + }else{ + return ['error'=>-4,'error_msg'=>'la ville que vous aviez entrée n\'est pas encore pris en compte ','ville'=>$town]; + } + + }else return ['error'=>"ce parrain à atteint son quota de membre"]; + }else{ + return ["error"=>"impossible de recuperer verifier la disponibilité ","error_msg"=>mysqli_error($this->con)]; + } + } + + public function generateValideCode($membre, $category) + { + $code=null; + $valide=false; + do{ + $code=$this->generateRandomString(); + $q = mysqli_query($this->con, "SELECT * from codeGenerer WHERE code_membre='$code'"); + if ($q) { + $valide = mysqli_num_rows($q) == 0; + $qe=mysqli_query($this->con, "INSERT INTO codeGenerer(code_parrain,code_membre,category,etat) VALUES ('$membre','$code','$category',0)"); + if(!$qe){ + echo mysqli_error($this->con); + return null; + } + }else{ + echo mysqli_error($this->con); + return null; + } + }while(!$valide); + return $code; + } + + private function adddemandeAdhesionAgent($agent) + { + $codeparrain=$agent['code_parrain']; + $resParrain=mysqli_query($this->con,"SELECT na.id as agentId FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$codeparrain'"); + if($resParrain){ + $parrain=mysqli_fetch_array($resParrain,MYSQLI_ASSOC); + $agentId=$parrain['agentId']; + if($agentId){ + $phone=$agent['phone']; + $resDemande=mysqli_query($this->con,"INSERT INTO demandeAdhesion(phone,networks_agent_id) VALUES ('$phone','$agentId')"); + if($resDemande){ + return ['success'=>1]; + }else{ + return ["error"=>1,"sql"=>mysqli_error($this->con),'agent'=>$agent]; + } + } + }else{ + return ['error'=>'error','ssql'=>mysqli_error($this->con),'agent'=>$agent]; + } + } + + public function storeUserSimple($firstname, $lastname, $email, $phone, $password, $network) + { + $uuid = uniqid('', true); + $balance =0; + $hash = $this->hashSSHA($password); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; // salt + //$validation_code = generateRandomString(); + $validation_code = $this->random_string(); + $networkid=$network->id; + $result = mysqli_query($this->con, + "INSERT INTO users(uid, adresse,lastname, phone, email, solde, encrypted_password, +salt,validation_code, active,network_id) VALUES + ('$uuid', '$firstname', '$lastname', '$phone','$email','$balance','$encrypted_password', '$salt', + '$validation_code','0','$networkid')"); + // check for successful store + if ($result) { + // get user details + $uid = mysqli_insert_id($this->con); // last inserted id + $result = mysqli_query($this->con,"SELECT ne.name as reseau,ct.name as country,usr.firstname as firstname +,usr.lastname as lastname,usr.phone as phone,usr.email as email,usr.validation_code as validation_code FROM users usr INNER JOIN networks ne ON ne.id=usr.network_id INNER JOIN countries ct ON ct.id=ne.country_id WHERE usr.id = '$uid'"); + // return user details + if($result){ + return mysqli_fetch_array($result); + + }else return ['error'=>'error geting information','sql'=>mysqli_error($this->con)]; + } else { + return ['error'=>'error saving information','sql'=>mysqli_error($this->con)]; + } + + } + + public function generateNetworkAgent($phone, $code_parrain) + { + $code=$this->generateValideCode($code_parrain,"geolocated"); + $resParrain=mysqli_query($this->con,"SELECT * FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN towns tw ON ag.town_id=tw.id INNER JOIN countries ct ON tw.country_id=ct.id WHERE cg.code_membre='$code_parrain'"); + + if($resParrain) { + $parrain = mysqli_fetch_array($resParrain, MYSQLI_ASSOC); + $networkId = $parrain['network_id']; + + $phone = $parrain['code_dial'] . $phone; + if (true) { + $resgg = mysqli_query($this->con, "SELECT * FROM codeGenerer cg WHERE cg.code_membre='$code'"); + if ($resgg) { + $membre = mysqli_fetch_array($resgg, MYSQLI_ASSOC); + $codeGenererId = $membre['id']; + $validation_code = $this->random_string(); + + $result = mysqli_query($this->con, "INSERT INTO networks_agents(network_id,solde,etat,codeGenerer_id,transactionNumber,validation_code)VALUES('$networkId','0','0','$codeGenererId','$phone','$validation_code')"); + if ($result) { + $geoId=mysqli_insert_id($this->con); + if (mysqli_query($this->con, "UPDATE codeGenerer SET etat='1' WHERE code_membre='$code'")) + return ['success' => 1,'phone'=>$phone,'code_membre' => $membre['code_membre'], 'validation_code' => $validation_code,"id"=>$geoId]; + else { + $da = ['error' => -7, 'error_msg' => 'impossible de mettre à jour les informations du code membre', 'sql' => mysqli_error($this->con)]; + mysqli_query($this->con, "DELETE FROM codeGenerer WHERE code_membre='$code'"); + return $da; + } + } else { + $da = ['error' => -5, 'error_msg' => 'impossible de recuperer les informations du de code generer', 'sql' => mysqli_error($this->con)]; + mysqli_query($this->con, "DELETE FROM codeGenerer WHERE code_membre='$code'"); + + return $da; + + } + + } else { + return ['error' => -4, 'error_msg' => 'impossible de recuperer les informations du de code generer', 'sql' => mysqli_error($this->con)]; + + } + } + else { + return ['error' => -7, 'error_msg' => 'le numéro de téléphone est invalide', 'phone' =>$phone,"parrain"=>$parrain]; + } + } else { + return ['error' => -3, 'error_msg' => 'impossible de recuperer les information du parrain', 'sql' => mysqli_error($this->con)]; + } + } + + public function getGeoLocatedFreeWithValidationCode($validation_code) + { + $qu=mysqli_query($this->con,"SELECT na.id as id,na.validation_code as validation_code,na.etat as etat, na.agent_id as agent_id,cg.code_membre as code_membre,cg.code_parrain as code_parrain, cg.category as category FROM networks_agents na INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE na.validation_code='$validation_code' AND cg.category='geolocated' AND na.agent_id is null"); + if($qu){ + $num_row=mysqli_num_rows($qu); + if($num_row>0) { + $geo = mysqli_fetch_array($qu, MYSQLI_ASSOC); + return $geo; + }else { + return ['error'=>'Ce code n\'est disponible']; + } + }else{ + return false; + } + + + + } + + public function assignNetworkAgent($idAgent, $idNetworkAgent) + { + $re=mysqli_query($this->con,"UPDATE networks_agents SET agent_id='$idAgent',etat='1' WHERE id='$idNetworkAgent'"); + if($re){ + return ['success'=>1]; + }else return ['error'=>mysqli_error($this->con)]; + } + + public function getListNetworkOfGeoPoint($user_id) + { + $q=mysqli_query($this->con,"SELECT na.id as id,na.network_id as network_id,na.solde as solde,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE ag.id='$user_id'"); + if($q){ + + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListFreeNetworkOfGeoPoint($code_parrain) + { + $q=mysqli_query($this->con,"SELECT na.id as id,na.network_id as network_id,na.solde as solde,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name,na.validation_code as validation_code from networks_agents na INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE cg.code_parrain='$code_parrain' AND cg.code_membre!='$code_parrain' AND na.agent_id IS NULL"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListDemandeReceiveAgent($codeparrain) + { + + $q=mysqli_query($this->con,"SELECT dc.id as id,dc.montant as montant,dc.date_creation,dc.date_modification,dc.status as status,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name,ne.name as reseau from demandeCredits dc INNER JOIN networks_agents na ON na.id=dc.network_agent_id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE cg.code_parrain='$codeparrain'"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListDemandeSendAgent($user_id) + { + $q=mysqli_query($this->con,"SELECT ne.name as reseau, dc.id as id,dc.montant as montant,dc.date_creation,dc.date_modification,dc.status as status,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name from demandeCredits dc INNER JOIN networks_agents na ON na.id=dc.network_agent_id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE ag.id='$user_id'"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function treatDemand($user_id) + { + $dat=date ("Y-m-d H:i:s"); + $q=mysqli_query($this->con,"UPDATE demandeCredits SET status='1',date_modification='$dat' WHERE id='$user_id'"); + if($q){ + $qdemande=mysqli_query($this->con,"SELECT * from demandeCredits dc WHERE dc.id='$user_id'"); + if($qdemande) { + $demande = mysqli_fetch_array($qdemande, MYSQLI_ASSOC); + $montant = (int)$demande["montant"]; + $id = $demande['network_agent_id']; + return ['success' => 1,"montant"=>$montant]; + + } + } + return ['error'=>mysqli_error($this->con)]; + + + } + + private function getNbMemberOf($code_membre) + { + $q=mysqli_query($this->con,"SELECT DISTINCT COUNT(*) AS nbr_membre FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_parrain='$code_membre' AND cg.code_membre!='$code_membre' AND na.etat='1'"); + if($q){ + return mysqli_fetch_array($q,MYSQLI_ASSOC)['nbr_membre']; + }else{ + return 0; + } + } + + public function getPointInDistance($reseau,$position, $distance,$page) + { + $mlat=$position->latitude; + $mlong=$position->longitude; + $re=$reseau->id; + $offset=$page*50; + $res= mysqli_query($this->con,"SELECT ag.id as agentId,na.id as id,ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat + FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN networks nt ON na.network_id=nt.id INNER JOIN countries ct ON ct.id=nt.country_id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.category='geolocated' AND na.etat=1 AND getDistanceMetre($mlat,ag.latitude,$mlong,ag.longitude)<=$distance AND nt.id=$re ORDER BY agentId LIMIT 51 OFFSET $offset"); + if($res){ + $li=["page"=>$page,"offset"=>$offset,"total"=>$offset,"count"=>0]; + while ($r=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $li["items"][]=$r; + $li["count"]=$li["count"]+1; + $li["total"]=$li["total"]+1; + } + return $li; + }else return mysqli_error($this->con); + } +} \ No newline at end of file diff --git a/database.old/Requester.php b/database.old/Requester.php new file mode 100644 index 0000000..4fe32ce --- /dev/null +++ b/database.old/Requester.php @@ -0,0 +1,912 @@ +db = new DataBaseConnector(); + $this->user_id = $user_id; + $this->messenger=new Messenger(); + $la=$lang; + if(in_array($lang,$this->enLangs))$la='en'; + if(file_exists("./../static/$la/message.json")) + $this->messageText=file_get_contents("./../static/$la/message.json"); + else + $this->messageText=file_get_contents("./../static/en/message.json"); + + $this->messageText=json_decode($this->messageText,true); + } + + public function loginPhonePassword($phone, $password) + { + // check for user + $user = $this->loginUser($phone, $password); + if (!$user) { + $user = $this->loginAgent($phone, $password); + if (!$user) { + $response["error"] = 1; + $response["error_msg"] =$this->messageText["PHONE_OR_NUMBER_INCORRECT"] ; + return $response; + } + } + return $user; + } + public function getAgentInfoByCode($code){ + $codes=$this->getChildCode($code); + if(isset($codes["child"])){ + $codes['network']=$this->db->getAgentNetworkByCode($code); + } + return json_encode($codes); + } + public function getSuperviseurNetwork($codesuperviseur) + { + $point = $this->db->getSuperviseurNetwork($codesuperviseur, $this->user_id); + if (isset($point['success'])) { + $response['success'] = 1; + $response['datas'] = $point['val']; + $response['catchild']=$point['catchild']; + $response['catparent']=$point['catparrain']; + return $response; + } else { + $response = ['error' => 1, + 'error_msg' => $this->messageText['UNABLE_TO_GET_GEOLOCATED_POINT'], 'sql_error' => $point["error"]]; + return $response; + } + } + + public function getAllCountryPoint($country) + { + $point = $this->db->getAllPointInCountry($country); + if ($point) { + $response['success'] = 1; + $response['datas'] = $point; + return $response; + } else { + $response = ['error' => 1, 'error_msg' => "impossible de recupere les points de cette ville"]; + return $response; + } + } + + public function recoverPasswordAgent($number) + { + if ($this->db->isPhoneExistedSimple($number)) { + $randomcode = $this->db->random_string(); + $hash = $this->db->hashSSHA($randomcode); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; + $user = $this->db->forgotPasswordSimple($number, $encrypted_password, $salt); + if ($user) { + $mail = $this->db->getEmailSimple($number); + if ($mail) { + $subject = "Password Recovery"; + $message = sprintf($this->messageText['TEXT_RECOVERY_PASSWORD'],$randomcode); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + $this->messenger->setMessage($message); + $this->messenger->setContact($number); + $this->messenger->setMail($mail['email']); + $this->messenger->sendMail(); + $this->messenger->sendSms(); + + // Stop Sending SMS + $response["success"] = 1; + + $response["message"] = "Le mot de passe a été modifié et un message vous a été envoyé à " . $mail["email"]; + return $response; + } else { + $response["error"] = -6; + $response["message"] = "impossible d'envoyer le mail"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + } + } else { + $response["error"] = -7; + $response["message"] = "impossible de changer le mots de passe"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + + } + }else + return ['error' => -5, 'message' => "Ce numéro n'existe pas",'phone'=>$number]; + } + + public function recoverUserPassword($number) + { + if ($this->db->isPhoneExistedSimple($number)) { + $randomcode = $this->db->random_string(); + $hash = $this->db->hashSSHA($randomcode); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; + $user = $this->db->forgotPasswordSimple($number, $encrypted_password, $salt); + if ($user) { + $mail = $this->db->getEmailSimple($number); + if ($mail) { + $subject = "Password Recovery"; + $message = sprintf($this->messageText['TEXT_RECOVERY_PASSWORD'],$randomcode); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + $this->messenger->setMessage($message); + $this->messenger->setContact($number); + $this->messenger->setMail( $mail["email"]); + $this->messenger->sendMail(); + //$this->messenger->sendSms(); + + // Stop Sending SMS + $response["success"] = 1; + $response["message"] = "Le mot de passe a été modifié et un message vous a été envoyé à " . $mail["email"]; + return $response; + } else { + $response["error"] = -6; + $response["message"] = "impossible d'envoyer le mail"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + } + } else { + $response["error"] = -7; + $response["message"] = "impossible de changer le mots de passe"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + + } + }else + return ['error' => -5, 'message' => 'Ce numéro n\'existe pas',"phone"=>"$number"]; + + } + + private function sendMail($email, $subject, $message, $headers) + { + mail($email, $subject, $message, $headers); + } + + private function sendMessage($message, $number) + { + $sms = $this->client->account->messages->create( + $number, + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => sender_number, + + + // the sms body + 'body' => $message + ) + ); + } + + public function getPointAroundKm($reseau,$position, $distance,$page) + { + $list=$this->db->getPointInDistance($reseau,$position,$distance,$page); + return json_encode($list); + } + + public function getNetworkPoint($network) + { + $points = $this->db->getPointsNetwork($network, $this->user_id); + if (!isset($points['error'])) { + $pts=['success'=>1,'datas'=>$points]; + return json_encode($pts); + } else + return json_encode(['error' => -4, 'error_msg' => 'error query','mysql'=> mysqli_error($this->db->con),"data"=>$points,"network"=>$network,"user"=>$this->user_id]); + + } + + function distance($lat1, $lon1, $lat2, $lon2) + { + + $theta = $lon1 - $lon2; + + $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); + $dist = acos($dist); + $dist = rad2deg($dist); + $miles = $dist * 60 * 1.1515; + $unit = "K"; + + if ($unit == "K") { + return ($miles * 1.609344); + } else if ($unit == "N") { + return ($miles * 0.8684); + } else { + return $miles; + } + } + + public function registerGeolocated($request) + { + if ($this->db->isPhoneExistedInCategory($request->phone, $request->category,$request->phone_transaction)) { + // user is already existed - error response + $response["error"] = 1; + $response["error_msg"] = $this->messageText['ALREADY_PHONE_NUMBER']; + echo json_encode($response); + } else { + if ($checkValidity = $this->db->checknumberValidity($request->phone)) { + $membercodetest = $this->db->isMemberCodeExisted($request->member); + if ($membercodetest) { + $user = $this->db->storeUser($request->address, $request->lastname, $request->email, $request->phone, + $request->password, $request->network, $request->member, $request->latitude, $request->longitude, $request->town,$request->phone_transaction); + if ($user != null && !isset($user['error'])) { + //if ($user) { + // user stored successfully + $user["success"] = 1; + $validation = $user["validation_code"]; + $username = $user["lastname"]; + $subject = "Bienvenue sur Ilink"; + $phone = $user['phone']; + $ct=($user['category']=='geolocated'?'Agent Géolocalisé':($user['category']=='super'?'Administrateur':'Super Administrateur')); + $message1 =sprintf($this->messageText['MESSAGE_1'],$username,$ct,$phone,$request->password,$validation); + $message2 = sprintf($this->messageText['MESSAGE_2'],$username,$ct,$phone,$request->password); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setMail($user['email']); + $this->messenger->setContact($user['phone']); + $this->messenger->setMessage($user['category']=='super'?$message2:$message1); + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + if (!$this->messenger->sendMail()) { + return json_encode(error_get_last()); + }; + $sms = $this->messenger->sendSms(); + + + } + return json_encode($user); + + /* echo "Réseau : ".strtoupper($user["network"])."
"; + echo "
"; + echo "Nom(s) :".$user["lastname"]."
"; + echo "Email par défaut du réseau : ".$user["email"]."
"; + echo "Telephone :".$user["phone"]."
"; + echo "Code membre pour le réseau : ".$user["code_membre"]."
"; + echo "
";*/ + } else { + return json_encode(['error' => 'unable to get membrre', 'error_msg' => $this->messageText['NO_CODE_MEMBER']]); + + } + }else{ + return json_encode(['error' => 'unable to get membrre',"msg"=>$this->messageText, 'error_msg' => $this->messageText['INVALID_PHONE']]); + + } + } + + + } + + public function getNetwork() + { + return json_encode($this->db->getNetwork()); + } + + public function loginUser($phone, $password) + { + $user = $this->db->getUserByPhoneAndPasswordSimple($phone, $password); + if (!isset($user['error'])) { + // user found + // echo json with success = 1 + $user["success"] = 1; + if(isset($user['active'])) + $user['etat']=$user['active']; + + } else { + switch ($user['error']){ + case -2:$user['error_msg']=$this->messageText['WRONG_PHONE_NUMBER']; + break; + case -3: + $user['error_msg']=$this->messageText['WRONG_PASSWORD'];break; + } + } + return $user; + } + + public function loginAgent($phone, $password) + { + $user = $this->db->getUserByPhoneAndPasswordGeolocated($phone, $password); + if (!isset($user['error'])) { + // user found + // echo json with success = 1 + $user["success"] = 1; + return $user; + + } else + + return $user; + + } + + public function getSupervisorAdhesionList($codeparrain) + { + $resparrain=mysqli_query($this->db->con,"SELECT na.id as id FROM networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_membre='$codeparrain'"); + if($resparrain){ + $parrain=mysqli_fetch_array($resparrain,MYSQLI_ASSOC)['id']; + + $r=mysqli_query($this->db->con,"select ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone ,ne.name as network,cg.code_membre as code_membre,cg.code_parrain as code_parrain,ds.etat as etat + from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id INNER JOIN networks ne ON na.network_id=ne.id INNER JOIN demandeAdhesion ds ON 1=1 WHERE ds.networks_agent_id='$parrain' AND cg.code_membre!='$codeparrain' AND na.etat='0' AND ds.etat='0' AND cg.code_parrain='$codeparrain'"); + $rows=[]; + if($r) { + while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { + + $rows[] = $row; + } + if (count($rows) > 0) { + return $rows; + } else { + echo mysqli_error($this->db->con); + return $rows; + } + }else{ + + return ['error'=>mysqli_error($this->db->con)]; + } + }else{ + return mysqli_error($this->db->con); + + } + } + + public function getChildCode($codeparrain) + { + $r=$this->db->getCategoryAgent($codeparrain); + if($r['etat']==1){ + switch ($r['category']){ + case 'hyper': + $r['child']='super'; + break; + case 'super': + $r["child"]="geolocated"; + break; + } +} + return $r; + } + + public function updateWrongPoint() + { + $result=[]; + try{ + $result = mysqli_query($this->db->con, "UPDATE users_simple SET firstname = REPLACE(firstname, 'é', 'é') WHERE firstname LIKE '%é%'"); + }catch (Exception $e) { + var_dump(mysqli_error($this->db->con)); + } + $da="freud junior"; + + return $result; + } + + public function storeCreditAsk($phone,$montant,$code) + { + $result=$this->db->storeDemandeCredit($phone,$montant,$code); + if ($result) { + $usr=$result['agent']; + $subject = $this->messageText['NEW_DEMAND_TITLE']; + $email = $usr['email']; + $message = $this->messageText['SEND_CREDIT_DEMAND_TEXT_SUCCESS']; + $from = "noreply@ilink.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setHeader($headers); + $this->messenger->setContact($phone); + $this->messenger->setMessage($message); + $this->messenger->setMail($email); + $this->messenger->setSubject($subject); + $this->messenger->sendMail(); + try { + $this->messenger->sendSms(); + }catch (Exception $e){ + + } + } else { + // user failed to store + $response["error"] = 1; + $response["result"]=$result; + $response["error_msg"] = $this->messageText['UNABLE_TO_SEND_DEMAND']; + $response["sql"]=mysqli_error($this->db->con); + $response["last"]=error_get_last(); + $response["montant"]=$montant; + $response["phone"]=$phone; + echo json_encode($response); + + } + return json_encode($result); + + } + + + + public function getCountryNetWork($indicatif) + + { + $res=mysqli_query($this->db->con, + "SELECT nt.id AS id, nt.name AS name,nt.country_id AS countryId FROM networks nt INNER JOIN countries ct + ON nt.country_id=ct.id WHERE ct.code_dial='$indicatif' AND nt.name!=''AND nt.status=1"); + if($res){ + $rows=[]; + while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>'unable to query list networks','error_sql'=>mysqli_error($this->db->con)]; + + } + + public function getTownInfoByName($name) + { + + $res=mysqli_query($this->db->con,"SELECT nt.name as name,nt.id as id ,ct.code_dial as indicatif FROM towns nt INNER JOIN countries ct ON nt.country_id=ct.id WHERE UPPER(nt.name)=UPPER('$name')"); + if($res){ + while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $rows[]=$row; + } + if($rows==null){ + return ['error'=>'unable to query town information','ville'=>$name,'error_sql'=>mysqli_error($this->db->con)]; + + } + return $rows; + }else + return ['error'=>'unable to query town information','ville'=>$name,'error_sql'=>mysqli_error($this->db->con)]; + + } + + public function getListTownsCountry($indicatif) + { + + $res=mysqli_query($this->db->con,"SELECT nt.name as name,nt.id as id ,ct.code_dial as indicatif FROM towns nt INNER JOIN countries ct ON nt.country_id=ct.id WHERE ct.code_dial='$indicatif'"); + if($res){ + $rows=[]; + while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>'unable to query list towns','indicatif'=>$indicatif,'error_sql'=>mysqli_error($this->db->con)]; + + } + + public function validateAgent($phone, $code_validation,$mbre_reseau=null,$mr_sous_reseau=null) + { + if(isset($phone) && isset($code_validation)){ + $res=mysqli_query($this->db->con,"SELECT na.id as agentId,ag.id as agId,cg.category as category,cg.code_membre as code_membre,cg.code_parrain AS code_parrain FROM agents ag INNER JOIN networks_agents na on ag.id=na.agent_id inner JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE na.phone='$phone' OR na.transactionNumber='$phone' AND na.validation_code='$code_validation'"); + if($res){ + if(mysqli_num_rows($res)>0){ + $net=mysqli_fetch_array($res,MYSQLI_ASSOC); + $agentId=$net['agentId']; + $agId=$net['agId']; + $codeparrain = $net['code_parrain']; + $codeMembre=$net['code_membre']; + $re = mysqli_query($this->db->con, "SELECT ag.id as parrainId, ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id inner JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_membre='$codeparrain'"); + if($re) { + $parrain = mysqli_fetch_array($re, MYSQLI_ASSOC); + $nbre_sup = $parrain['nbre_sous_reseau']; + $nbre = $parrain['nbre_reseau']; + $parrainId=$parrain['parrainId']; + switch ($net['category']) { + case 'hyper': + if (isset($mbre_reseau) && isset($mr_sous_reseau)) { + $r = mysqli_query($this->db->con, "UPDATE `networks_agents` SET etat = '1' WHERE `id` = $agentId "); + $var3["message_erreur_1"] = mysqli_error($this->db->con); + $rs = mysqli_query($this->db->con, "UPDATE agents SET number_super='$mbre_reseau',number_geoBysuper='$mr_sous_reseau' WHERE id='$agId'"); + if ($r && $rs) { + + $var3["success"] = 1; + $var3["message"] = "User has been validated successfully !"; + return $var3; + } else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + } else { + + $var3["error"] = -2; + $var3["message"] = "no nbre reseau et sous reseau"; + return $var3; + + } + break; + case 'geolocated': + $r = mysqli_query($this->db->con, "UPDATE networks_agents SET etat = '1' WHERE id = '$agentId' "); + if ($r) { + $nbre -= $nbre > 0 ? 1 : 0; + mysqli_query($this->db->con, "UPDATE agents SET number_geoBysuper = '$nbre' WHERE `id` = '$parrainId' "); + $var3["success"] = 1; + $var3["message"] = "User has been validated successfully !"; + return $var3; + } else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + break; + case 'super': + $rs = mysqli_query($this->db->con, "UPDATE agents SET number_geoBysuper='$nbre_sup',number_super='$nbre_sup' WHERE id='$agId'"); + if ($rs) { + if (mysqli_num_rows($re) > 0) { + $r = mysqli_query($this->db->con, "UPDATE `networks_agents` SET etat = '1' WHERE id ='$agentId'"); + if ($r) { + $nbre -= $nbre > 0 ? 1 : 0; + if(mysqli_query($this->db->con, "UPDATE `agents` SET number_super = '$nbre' WHERE id='$parrainId'")){ + $var3["success"] = 1; + $var3['nbre_sup']=$nbre; + $var3["message"] = "User has been validated successfully !"; + return $var3; + + }else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + + } else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + + } else { + $var3["error"] = -4; + $var3["message"] = "impossible de trouve le parrain"; + return $var3; + + } + } else { + $var3["error"] = -3; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + break; + } + }else{ + return ['error'=>'impossible de recuperer le parrain','error_msg'=>mysqli_error($this->db->con)]; + + } + }else{ + return ['error'=>'invalide code','error_msg'=>"code de validation incorrect"]; + } + }else{ + return ['error'=>'unable to query info network agent','error_msg'=>mysqli_error($this->db->con)]; + } + } + + } + + public function activeSupervisorAdhesion($code,$phone) + { + $idsUser=mysqli_query($this->db->con,"SELECT ag.email as email,ag.firstname as firstname,ag.lastname as lastname,na.validation_code as validation_code,na.phone as phone, +na.id as agent_id,ds.id as demande_id FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN demandeAdhesion ds ON 1=1 INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE ds.phone='$phone' AND cg.code_membre='$code'"); + if($idsUser){ + $idsusr=mysqli_fetch_array($idsUser,MYSQLI_ASSOC); + $idAgent=$idsusr['agent_id']; + $demandeId=$idsusr['demande_id']; + $udateDemande=mysqli_query($this->db->con,"UPDATE demandeAdhesion SET etat='1' WHERE id='$demandeId'"); + if($udateDemande){ + $user=$idsusr; + $validation = $user["validation_code"]; + $username = $user["lastname"]; + $subject = "Bienvenue sur Ilink"; + $phone = $user['phone']; + $ct='Administrateur'; + $message1 =sprintf($this->messageText['MESSAGE_3'],$ct,$phone,$validation); + + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setMail($user['email']); + $this->messenger->setContact($user['phone']); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + if (!$this->messenger->sendMail()) { + return json_encode(error_get_last()); + }; + + $sms = $this->messenger->sendSms(); + + + }else{ + echo mysqli_error($this->db->con); + } + echo json_encode($idsusr); + }else{ + echo mysqli_error($this->db->con); + } + + + } + + public function registerUser($request) + { + if ($this->db->isPhoneExistedSimple($request->phone)) { + // user is already existed - error response + $response["error"] = 1; + $response["error_msg"] = "numero existe deja"; + echo json_encode($response); + } else { + if ($checkValidity = $this->db->checknumberValidity($request->phone)) { + $user = $this->db->storeUserSimple($request->address, $request->lastname, $request->email, + $request->phone, + $request->password, $request->network); + if ($user != null && !isset($user['error'])) { + $user["success"] = 1; + $username = $user["lastname"]; + $subject = "Bienvenue sur Ilink"; + $phone = $user['phone']; + $validation_code=$user['validation_code']; + $ct="Utilisateur"; + $message1 =sprintf($this->messageText['MESSAGE_1'],$username,$ct,$phone,$request->password,$validation_code); + $message2 = sprintf($this->messageText['MESSAGE_2'],$username,$ct,$phone,$request->password,""); + + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setMail($user['email']); + $this->messenger->setContact($user['phone']); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + if (!$this->messenger->sendMail()) { + return json_encode(error_get_last()); + }; + + $sms = $this->messenger->sendSms(); + + } else { + $user = ['error' => 'impossible de créer l\'utilisateur', 'error_sql' => mysqli_error($this->db->con)]; + } + return json_encode($user); + } else { + return json_encode(['error' => 'unable to get membrre', 'error_msg' =>$this->messageText['INVALID_PHONE']]); + + } + + } + } + + public function generateEmptyAgentNetworkForAgent($phone, $code_parrain) + { + if ($this->db->isPhoneExistedInCategory($phone)) { + // user is al5eady existed - error response + $response["error"] = 1; + $response["error_msg"] =$this->messageText['ALREADY_PHONE_NUMBER']; + return json_encode($response); + }else{ + $user=$this->db->generateNetworkAgent($phone,$code_parrain); + if(isset($user['success'])) { + $validation = $user["validation_code"]; + $subject = "Bienvenue sur Ilink"; + $phone1 = $user['phone']; + $ct='Agent Géolocalisé'; + $message1 =sprintf($this->messageText['MESSAGE_3'],$ct,$phone,$validation); + + + $this->messenger->setContact($phone1); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + + if ($sms = $this->messenger->sendSms()) { + + $user['message'] = $sms; + } else { + return json_encode(['error' => 'imossible d\'envoyer le message']); + }; + } + return json_encode($user); + } + + } + + public function assignNetworkToAgent($agentId, $code_parrain,$phone) + { + $agent = $this->db->getAgentById($agentId); + if ($agent) { + $indicatif=$agent["indicatif"]; + if ($this->db->isPhoneExistedInCategory(null,null,$indicatif.$phone)) { + $response["error"] = 1; + $response["error_msg"] =$this->messageText['ALREADY_PHONE_NUMBER']; + return json_encode($response); + } else { + $user = $this->db->generateNetworkAgent($phone, $code_parrain); + if (isset($user['success'])) { + $result = $this->db->assignNetworkAgent($agentId, $user['id']); + if (isset($result['success'])) { + $geoLocated['success'] = 1; + $geoLocated['agent_id'] = $agentId; + $validation = $user["validation_code"]; + $subject = "Bienvenue sur Ilink"; + $phone1 = $user['phone']; + $message1 = sprintf($this->messageText['MESSAGE_ATTRIBUTE'],$phone1,$validation); + + $this->messenger->setContact($phone1); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + $this->messenger->setMail($agent['email']); + if ($sms = $this->messenger->sendSms()) { + + $user['message'] = $sms; + } else { + return json_encode(['error' => 'imossible d\'envoyer le message']); + }; + + return json_encode($geoLocated); + } else { + return json_encode($result); + } + } else { + return json_encode($user); + } + + } + + } else { + return json_encode(['error' => mysqli_error($this->db->con)]); + } +} + + + public function listNetworksGeo() + { + if($this->user_id){ + $result= $this->db->getListNetworkOfGeoPoint($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'networks'=>$result]; + return $networks; + + }else + return $result; + }else{ + return ['error'=>'unable to find user_id']; + } + + } + + public function listFreeNetworksForSuper() + { + if($this->user_id){ + $result= $this->db->getListFreeNetworkOfGeoPoint($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'networks'=>$result]; + return $networks; + + }else + return $result; + }else{ + return ['error'=>'unable to find user_id']; + } + } + + public function getAgentReceiveDemande() + { + if($this->user_id){ + $result= $this->db->getListDemandeReceiveAgent($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'demands'=>$result]; + return json_encode($networks); + + }else + return json_encode($result); + }else{ + return json_encode(['error'=>'unable to find user_id']); + } + + } + + public function getAgentSendDemande() + { + if($this->user_id){ + $result= $this->db->getListDemandeSendAgent($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'demands'=>$result]; + return json_encode($networks); + + }else + return json_encode($result); + }else{ + return json_encode(['error'=>'unable to find user_id']); + } } + + public function treatDemand($phone) + { + if($this->user_id){ + $result= $this->db->treatDemand($this->user_id); + if(isset($result['success'])){ + $this->messenger->setContact($phone); + $this->messenger->setMessage($this->messageText['MESSAGE_TREAT']); + $this->messenger->sendSms(); + } + return json_encode($result); + }else{ + return json_encode(['error'=>'unable to find user_id']); + } + + } + + public function getActiveCountries() + { + $mq=mysqli_query($this->db->con,"SELECT DISTINCT ct.id,ct.code_dial,ct.name,ct.code_country FROM countries ct INNER JOIN networks ne ON ne.country_id=ct.id"); + if($mq){ + while($row=mysqli_fetch_array($mq,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return json_encode($rows); + }else{ + return ['error'=>mysqli_error($this->db->con)]; + } + } + + public function getAgentById() + { + return$this->db->getAgentById($this->user_id); + } + + public function updatePosition($agentId, $longitude, $latitude) + { + $result=[]; + $q = mysqli_query($this->db->con, "UPDATE agents SET longitude='$longitude',latitude='$latitude' WHERE id='$agentId'"); + if($q){ + return json_encode(['success'=>1]); + }else return json_encode(['error'=>0,'sql'=>mysqli_error($this->db->con)]); + + } + + public function validateUser($phone) + { + + if(isset($phone)){ + $res=mysqli_query($this->db->con,"SELECT * from users_simple WHERE phone='$phone'"); + if($res){ + if(mysqli_num_rows($res)>0){ + $user=mysqli_fetch_array($res,MYSQLI_ASSOC); + $userId=$user['id']; + $r = mysqli_query($this->db->con, "UPDATE users SET active = '1' WHERE id = '$userId' "); + if($r) { + $var3["success"] = 1; + $var3["message"] = "User has been validated successfully !"; + $res=mysqli_query($this->db->con,"SELECT * from users_simple WHERE phone='$phone'"); + $user=mysqli_fetch_array($res,MYSQLI_ASSOC); + $var3['user']=$user; + return $var3; + + }else{ + return ['error'=>'impossible de recuperer le parrain','error_msg'=>mysqli_error($this->db->con)]; + + } + }else{ + return ['error'=>'invalide code','error_msg'=>"code de validation incorrect"]; + } + }else{ + return ['error'=>'unable to query info network agent','error_msg'=>mysqli_error($this->db->con)]; + } + } + + } + + +} diff --git a/database.old/font/courier.php b/database.old/font/courier.php new file mode 100644 index 0000000..67dbeda --- /dev/null +++ b/database.old/font/courier.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/courierb.php b/database.old/font/courierb.php new file mode 100644 index 0000000..62550a4 --- /dev/null +++ b/database.old/font/courierb.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/courierbi.php b/database.old/font/courierbi.php new file mode 100644 index 0000000..6a3ecc6 --- /dev/null +++ b/database.old/font/courierbi.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/courieri.php b/database.old/font/courieri.php new file mode 100644 index 0000000..b88e098 --- /dev/null +++ b/database.old/font/courieri.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/helvetica.php b/database.old/font/helvetica.php new file mode 100644 index 0000000..2be3eca --- /dev/null +++ b/database.old/font/helvetica.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, + 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, + chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, + chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/helveticab.php b/database.old/font/helveticab.php new file mode 100644 index 0000000..c88394c --- /dev/null +++ b/database.old/font/helveticab.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, + 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, + 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, + chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, + chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/helveticabi.php b/database.old/font/helveticabi.php new file mode 100644 index 0000000..bcea807 --- /dev/null +++ b/database.old/font/helveticabi.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, + 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, + 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, + chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, + chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/helveticai.php b/database.old/font/helveticai.php new file mode 100644 index 0000000..a328b04 --- /dev/null +++ b/database.old/font/helveticai.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, + 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, + chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, + chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/symbol.php b/database.old/font/symbol.php new file mode 100644 index 0000000..5b9147b --- /dev/null +++ b/database.old/font/symbol.php @@ -0,0 +1,20 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549, + ','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722, + 'B'=>667,'C'=>722,'D'=>612,'E'=>611,'F'=>763,'G'=>603,'H'=>722,'I'=>333,'J'=>631,'K'=>722,'L'=>686,'M'=>889,'N'=>722,'O'=>722,'P'=>768,'Q'=>741,'R'=>556,'S'=>592,'T'=>611,'U'=>690,'V'=>439,'W'=>768, + 'X'=>645,'Y'=>795,'Z'=>611,'['=>333,'\\'=>863,']'=>333,'^'=>658,'_'=>500,'`'=>500,'a'=>631,'b'=>549,'c'=>549,'d'=>494,'e'=>439,'f'=>521,'g'=>411,'h'=>603,'i'=>329,'j'=>603,'k'=>549,'l'=>549,'m'=>576, + 'n'=>521,'o'=>549,'p'=>549,'q'=>521,'r'=>549,'s'=>603,'t'=>439,'u'=>576,'v'=>713,'w'=>686,'x'=>493,'y'=>686,'z'=>494,'{'=>480,'|'=>200,'}'=>480,'~'=>549,chr(127)=>0,chr(128)=>0,chr(129)=>0,chr(130)=>0,chr(131)=>0, + chr(132)=>0,chr(133)=>0,chr(134)=>0,chr(135)=>0,chr(136)=>0,chr(137)=>0,chr(138)=>0,chr(139)=>0,chr(140)=>0,chr(141)=>0,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, + chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>750,chr(161)=>620,chr(162)=>247,chr(163)=>549,chr(164)=>167,chr(165)=>713,chr(166)=>500,chr(167)=>753,chr(168)=>753,chr(169)=>753,chr(170)=>753,chr(171)=>1042,chr(172)=>987,chr(173)=>603,chr(174)=>987,chr(175)=>603, + chr(176)=>400,chr(177)=>549,chr(178)=>411,chr(179)=>549,chr(180)=>549,chr(181)=>713,chr(182)=>494,chr(183)=>460,chr(184)=>549,chr(185)=>549,chr(186)=>549,chr(187)=>549,chr(188)=>1000,chr(189)=>603,chr(190)=>1000,chr(191)=>658,chr(192)=>823,chr(193)=>686,chr(194)=>795,chr(195)=>987,chr(196)=>768,chr(197)=>768, + chr(198)=>823,chr(199)=>768,chr(200)=>768,chr(201)=>713,chr(202)=>713,chr(203)=>713,chr(204)=>713,chr(205)=>713,chr(206)=>713,chr(207)=>713,chr(208)=>768,chr(209)=>713,chr(210)=>790,chr(211)=>790,chr(212)=>890,chr(213)=>823,chr(214)=>549,chr(215)=>250,chr(216)=>713,chr(217)=>603,chr(218)=>603,chr(219)=>1042, + chr(220)=>987,chr(221)=>603,chr(222)=>987,chr(223)=>603,chr(224)=>494,chr(225)=>329,chr(226)=>790,chr(227)=>790,chr(228)=>786,chr(229)=>713,chr(230)=>384,chr(231)=>384,chr(232)=>384,chr(233)=>384,chr(234)=>384,chr(235)=>384,chr(236)=>494,chr(237)=>494,chr(238)=>494,chr(239)=>494,chr(240)=>0,chr(241)=>329, + chr(242)=>274,chr(243)=>686,chr(244)=>686,chr(245)=>686,chr(246)=>384,chr(247)=>384,chr(248)=>384,chr(249)=>384,chr(250)=>384,chr(251)=>384,chr(252)=>494,chr(253)=>494,chr(254)=>494,chr(255)=>0); +$uv = array(32=>160,33=>33,34=>8704,35=>35,36=>8707,37=>array(37,2),39=>8715,40=>array(40,2),42=>8727,43=>array(43,2),45=>8722,46=>array(46,18),64=>8773,65=>array(913,2),67=>935,68=>array(916,2),70=>934,71=>915,72=>919,73=>921,74=>977,75=>array(922,4),79=>array(927,2),81=>920,82=>929,83=>array(931,3),86=>962,87=>937,88=>926,89=>936,90=>918,91=>91,92=>8756,93=>93,94=>8869,95=>95,96=>63717,97=>array(945,2),99=>967,100=>array(948,2),102=>966,103=>947,104=>951,105=>953,106=>981,107=>array(954,4),111=>array(959,2),113=>952,114=>961,115=>array(963,3),118=>982,119=>969,120=>958,121=>968,122=>950,123=>array(123,3),126=>8764,160=>8364,161=>978,162=>8242,163=>8804,164=>8725,165=>8734,166=>402,167=>9827,168=>9830,169=>9829,170=>9824,171=>8596,172=>array(8592,4),176=>array(176,2),178=>8243,179=>8805,180=>215,181=>8733,182=>8706,183=>8226,184=>247,185=>array(8800,2),187=>8776,188=>8230,189=>array(63718,2),191=>8629,192=>8501,193=>8465,194=>8476,195=>8472,196=>8855,197=>8853,198=>8709,199=>array(8745,2),201=>8835,202=>8839,203=>8836,204=>8834,205=>8838,206=>array(8712,2),208=>8736,209=>8711,210=>63194,211=>63193,212=>63195,213=>8719,214=>8730,215=>8901,216=>172,217=>array(8743,2),219=>8660,220=>array(8656,4),224=>9674,225=>9001,226=>array(63720,3),229=>8721,230=>array(63723,10),241=>9002,242=>8747,243=>8992,244=>63733,245=>8993,246=>array(63734,9)); +?> diff --git a/database.old/font/times.php b/database.old/font/times.php new file mode 100644 index 0000000..f78850f --- /dev/null +++ b/database.old/font/times.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>408,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>180,'('=>333,')'=>333,'*'=>500,'+'=>564, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>564,'='=>564,'>'=>564,'?'=>444,'@'=>921,'A'=>722, + 'B'=>667,'C'=>667,'D'=>722,'E'=>611,'F'=>556,'G'=>722,'H'=>722,'I'=>333,'J'=>389,'K'=>722,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>556,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>722,'W'=>944, + 'X'=>722,'Y'=>722,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>469,'_'=>500,'`'=>333,'a'=>444,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, + 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>333,'s'=>389,'t'=>278,'u'=>500,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>480,'|'=>200,'}'=>480,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>444,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>889,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>444,chr(148)=>444,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>980, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>200,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>564,chr(173)=>333,chr(174)=>760,chr(175)=>333, + chr(176)=>400,chr(177)=>564,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>453,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>444,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>564,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>722,chr(222)=>556,chr(223)=>500,chr(224)=>444,chr(225)=>444,chr(226)=>444,chr(227)=>444,chr(228)=>444,chr(229)=>444,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>564,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>500,chr(254)=>500,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/timesb.php b/database.old/font/timesb.php new file mode 100644 index 0000000..0516750 --- /dev/null +++ b/database.old/font/timesb.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>555,'#'=>500,'$'=>500,'%'=>1000,'&'=>833,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>930,'A'=>722, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>778,'I'=>389,'J'=>500,'K'=>778,'L'=>667,'M'=>944,'N'=>722,'O'=>778,'P'=>611,'Q'=>778,'R'=>722,'S'=>556,'T'=>667,'U'=>722,'V'=>722,'W'=>1000, + 'X'=>722,'Y'=>722,'Z'=>667,'['=>333,'\\'=>278,']'=>333,'^'=>581,'_'=>500,'`'=>333,'a'=>500,'b'=>556,'c'=>444,'d'=>556,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>333,'k'=>556,'l'=>278,'m'=>833, + 'n'=>556,'o'=>500,'p'=>556,'q'=>556,'r'=>444,'s'=>389,'t'=>333,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>394,'|'=>220,'}'=>394,'~'=>520,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>667,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>300,chr(171)=>500,chr(172)=>570,chr(173)=>333,chr(174)=>747,chr(175)=>333, + chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>556,chr(182)=>540,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>330,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>570,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>722,chr(222)=>611,chr(223)=>556,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/timesbi.php b/database.old/font/timesbi.php new file mode 100644 index 0000000..32fe25e --- /dev/null +++ b/database.old/font/timesbi.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>389,'"'=>555,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>832,'A'=>667, + 'B'=>667,'C'=>667,'D'=>722,'E'=>667,'F'=>667,'G'=>722,'H'=>778,'I'=>389,'J'=>500,'K'=>667,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>611,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>667,'W'=>889, + 'X'=>667,'Y'=>611,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>570,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, + 'n'=>556,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>556,'v'=>444,'w'=>667,'x'=>500,'y'=>444,'z'=>389,'{'=>348,'|'=>220,'}'=>348,'~'=>570,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>389,chr(159)=>611,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>266,chr(171)=>500,chr(172)=>606,chr(173)=>333,chr(174)=>747,chr(175)=>333, + chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>576,chr(182)=>500,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>300,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>944,chr(199)=>667,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>570,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>611,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>444,chr(254)=>500,chr(255)=>444); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/timesi.php b/database.old/font/timesi.php new file mode 100644 index 0000000..b0e5a62 --- /dev/null +++ b/database.old/font/timesi.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>420,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>214,'('=>333,')'=>333,'*'=>500,'+'=>675, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>675,'='=>675,'>'=>675,'?'=>500,'@'=>920,'A'=>611, + 'B'=>611,'C'=>667,'D'=>722,'E'=>611,'F'=>611,'G'=>722,'H'=>722,'I'=>333,'J'=>444,'K'=>667,'L'=>556,'M'=>833,'N'=>667,'O'=>722,'P'=>611,'Q'=>722,'R'=>611,'S'=>500,'T'=>556,'U'=>722,'V'=>611,'W'=>833, + 'X'=>611,'Y'=>556,'Z'=>556,'['=>389,'\\'=>278,']'=>389,'^'=>422,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>278,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>444,'l'=>278,'m'=>722, + 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>500,'v'=>444,'w'=>667,'x'=>444,'y'=>444,'z'=>389,'{'=>400,'|'=>275,'}'=>400,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>556,chr(133)=>889,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>500,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>556,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>556,chr(148)=>556,chr(149)=>350,chr(150)=>500,chr(151)=>889,chr(152)=>333,chr(153)=>980, + chr(154)=>389,chr(155)=>333,chr(156)=>667,chr(157)=>350,chr(158)=>389,chr(159)=>556,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>275,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>675,chr(173)=>333,chr(174)=>760,chr(175)=>333, + chr(176)=>400,chr(177)=>675,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>523,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>611,chr(193)=>611,chr(194)=>611,chr(195)=>611,chr(196)=>611,chr(197)=>611, + chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>667,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>675,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>556,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>675,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>444,chr(254)=>500,chr(255)=>444); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database.old/font/zapfdingbats.php b/database.old/font/zapfdingbats.php new file mode 100644 index 0000000..b9d0309 --- /dev/null +++ b/database.old/font/zapfdingbats.php @@ -0,0 +1,20 @@ +0,chr(1)=>0,chr(2)=>0,chr(3)=>0,chr(4)=>0,chr(5)=>0,chr(6)=>0,chr(7)=>0,chr(8)=>0,chr(9)=>0,chr(10)=>0,chr(11)=>0,chr(12)=>0,chr(13)=>0,chr(14)=>0,chr(15)=>0,chr(16)=>0,chr(17)=>0,chr(18)=>0,chr(19)=>0,chr(20)=>0,chr(21)=>0, + chr(22)=>0,chr(23)=>0,chr(24)=>0,chr(25)=>0,chr(26)=>0,chr(27)=>0,chr(28)=>0,chr(29)=>0,chr(30)=>0,chr(31)=>0,' '=>278,'!'=>974,'"'=>961,'#'=>974,'$'=>980,'%'=>719,'&'=>789,'\''=>790,'('=>791,')'=>690,'*'=>960,'+'=>939, + ','=>549,'-'=>855,'.'=>911,'/'=>933,'0'=>911,'1'=>945,'2'=>974,'3'=>755,'4'=>846,'5'=>762,'6'=>761,'7'=>571,'8'=>677,'9'=>763,':'=>760,';'=>759,'<'=>754,'='=>494,'>'=>552,'?'=>537,'@'=>577,'A'=>692, + 'B'=>786,'C'=>788,'D'=>788,'E'=>790,'F'=>793,'G'=>794,'H'=>816,'I'=>823,'J'=>789,'K'=>841,'L'=>823,'M'=>833,'N'=>816,'O'=>831,'P'=>923,'Q'=>744,'R'=>723,'S'=>749,'T'=>790,'U'=>792,'V'=>695,'W'=>776, + 'X'=>768,'Y'=>792,'Z'=>759,'['=>707,'\\'=>708,']'=>682,'^'=>701,'_'=>826,'`'=>815,'a'=>789,'b'=>789,'c'=>707,'d'=>687,'e'=>696,'f'=>689,'g'=>786,'h'=>787,'i'=>713,'j'=>791,'k'=>785,'l'=>791,'m'=>873, + 'n'=>761,'o'=>762,'p'=>762,'q'=>759,'r'=>759,'s'=>892,'t'=>892,'u'=>788,'v'=>784,'w'=>438,'x'=>138,'y'=>277,'z'=>415,'{'=>392,'|'=>392,'}'=>668,'~'=>668,chr(127)=>0,chr(128)=>390,chr(129)=>390,chr(130)=>317,chr(131)=>317, + chr(132)=>276,chr(133)=>276,chr(134)=>509,chr(135)=>509,chr(136)=>410,chr(137)=>410,chr(138)=>234,chr(139)=>234,chr(140)=>334,chr(141)=>334,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, + chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>0,chr(161)=>732,chr(162)=>544,chr(163)=>544,chr(164)=>910,chr(165)=>667,chr(166)=>760,chr(167)=>760,chr(168)=>776,chr(169)=>595,chr(170)=>694,chr(171)=>626,chr(172)=>788,chr(173)=>788,chr(174)=>788,chr(175)=>788, + chr(176)=>788,chr(177)=>788,chr(178)=>788,chr(179)=>788,chr(180)=>788,chr(181)=>788,chr(182)=>788,chr(183)=>788,chr(184)=>788,chr(185)=>788,chr(186)=>788,chr(187)=>788,chr(188)=>788,chr(189)=>788,chr(190)=>788,chr(191)=>788,chr(192)=>788,chr(193)=>788,chr(194)=>788,chr(195)=>788,chr(196)=>788,chr(197)=>788, + chr(198)=>788,chr(199)=>788,chr(200)=>788,chr(201)=>788,chr(202)=>788,chr(203)=>788,chr(204)=>788,chr(205)=>788,chr(206)=>788,chr(207)=>788,chr(208)=>788,chr(209)=>788,chr(210)=>788,chr(211)=>788,chr(212)=>894,chr(213)=>838,chr(214)=>1016,chr(215)=>458,chr(216)=>748,chr(217)=>924,chr(218)=>748,chr(219)=>918, + chr(220)=>927,chr(221)=>928,chr(222)=>928,chr(223)=>834,chr(224)=>873,chr(225)=>828,chr(226)=>924,chr(227)=>924,chr(228)=>917,chr(229)=>930,chr(230)=>931,chr(231)=>463,chr(232)=>883,chr(233)=>836,chr(234)=>836,chr(235)=>867,chr(236)=>867,chr(237)=>696,chr(238)=>696,chr(239)=>874,chr(240)=>0,chr(241)=>874, + chr(242)=>760,chr(243)=>946,chr(244)=>771,chr(245)=>865,chr(246)=>771,chr(247)=>888,chr(248)=>967,chr(249)=>888,chr(250)=>831,chr(251)=>873,chr(252)=>927,chr(253)=>970,chr(254)=>918,chr(255)=>0); +$uv = array(32=>32,33=>array(9985,4),37=>9742,38=>array(9990,4),42=>9755,43=>9758,44=>array(9996,28),72=>9733,73=>array(10025,35),108=>9679,109=>10061,110=>9632,111=>array(10063,4),115=>9650,116=>9660,117=>9670,118=>10070,119=>9687,120=>array(10072,7),128=>array(10088,14),161=>array(10081,7),168=>9827,169=>9830,170=>9829,171=>9824,172=>array(9312,10),182=>array(10102,31),213=>8594,214=>array(8596,2),216=>array(10136,24),241=>array(10161,14)); +?> diff --git a/database.old/fpdf.css b/database.old/fpdf.css new file mode 100644 index 0000000..e69de29 diff --git a/database.old/fpdf.php b/database.old/fpdf.php new file mode 100644 index 0000000..c82d68b --- /dev/null +++ b/database.old/fpdf.php @@ -0,0 +1,915 @@ +_dochecks(); + // Initialization of properties + $this->state = 0; + $this->page = 0; + $this->n = 2; + $this->buffer = ''; + $this->pages = array(); + $this->PageInfo = array(); + $this->fonts = array(); + $this->FontFiles = array(); + $this->encodings = array(); + $this->cmaps = array(); + $this->images = array(); + $this->links = array(); + $this->InHeader = false; + $this->InFooter = false; + $this->lasth = 0; + $this->FontFamily = ''; + $this->FontStyle = ''; + $this->FontSizePt = 12; + $this->underline = false; + $this->DrawColor = '0 G'; + $this->FillColor = '0 g'; + $this->TextColor = '0 g'; + $this->ColorFlag = false; + $this->WithAlpha = false; + $this->ws = 0; + // Font path + if(defined('FPDF_FONTPATH')) + { + $this->fontpath = FPDF_FONTPATH; + if(substr($this->fontpath,-1)!='/' && substr($this->fontpath,-1)!='\\') + $this->fontpath .= '/'; + } + elseif(is_dir(dirname(__FILE__).'/font')) + $this->fontpath = dirname(__FILE__).'/font/'; + else + $this->fontpath = ''; + // Core fonts + $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); + // Scale factor + if($unit=='pt') + $this->k = 1; + elseif($unit=='mm') + $this->k = 72/25.4; + elseif($unit=='cm') + $this->k = 72/2.54; + elseif($unit=='in') + $this->k = 72; + else + $this->Error('Incorrect unit: '.$unit); + // Page sizes + $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), + 'letter'=>array(612,792), 'legal'=>array(612,1008)); + $size = $this->_getpagesize($size); + $this->DefPageSize = $size; + $this->CurPageSize = $size; + // Page orientation + $orientation = strtolower($orientation); + if($orientation=='p' || $orientation=='portrait') + { + $this->DefOrientation = 'P'; + $this->w = $size[0]; + $this->h = $size[1]; + } + elseif($orientation=='l' || $orientation=='landscape') + { + $this->DefOrientation = 'L'; + $this->w = $size[1]; + $this->h = $size[0]; + } + else + $this->Error('Incorrect orientation: '.$orientation); + $this->CurOrientation = $this->DefOrientation; + $this->wPt = $this->w*$this->k; + $this->hPt = $this->h*$this->k; + // Page rotation + $this->CurRotation = 0; + // Page margins (1 cm) + $margin = 28.35/$this->k; + $this->SetMargins($margin,$margin); + // Interior cell margin (1 mm) + $this->cMargin = $margin/10; + // Line width (0.2 mm) + $this->LineWidth = .567/$this->k; + // Automatic page break + $this->SetAutoPageBreak(true,2*$margin); + // Default display mode + $this->SetDisplayMode('default'); + // Enable compression + $this->SetCompression(true); + // Set default PDF version number + $this->PDFVersion = '1.3'; +} + +function SetMargins($left, $top, $right=null) +{ + // Set left, top and right margins + $this->lMargin = $left; + $this->tMargin = $top; + if($right===null) + $right = $left; + $this->rMargin = $right; +} + +function SetLeftMargin($margin) +{ + // Set left margin + $this->lMargin = $margin; + if($this->page>0 && $this->x<$margin) + $this->x = $margin; +} + +function SetTopMargin($margin) +{ + // Set top margin + $this->tMargin = $margin; +} + +function SetRightMargin($margin) +{ + // Set right margin + $this->rMargin = $margin; +} + +function SetAutoPageBreak($auto, $margin=0) +{ + // Set auto page break mode and triggering margin + $this->AutoPageBreak = $auto; + $this->bMargin = $margin; + $this->PageBreakTrigger = $this->h-$margin; +} + +function SetDisplayMode($zoom, $layout='default') +{ + // Set display mode in viewer + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) + $this->ZoomMode = $zoom; + else + $this->Error('Incorrect zoom display mode: '.$zoom); + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') + $this->LayoutMode = $layout; + else + $this->Error('Incorrect layout display mode: '.$layout); +} + +function SetCompression($compress) +{ + // Set page compression + if(function_exists('gzcompress')) + $this->compress = $compress; + else + $this->compress = false; +} + +function SetTitle($title, $isUTF8=false) +{ + // Title of document + $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); +} + +function SetAuthor($author, $isUTF8=false) +{ + // Author of document + $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); +} + +function SetSubject($subject, $isUTF8=false) +{ + // Subject of document + $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); +} + +function SetKeywords($keywords, $isUTF8=false) +{ + // Keywords of document + $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); +} + +function SetCreator($creator, $isUTF8=false) +{ + // Creator of document + $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); +} + +function AliasNbPages($alias='{nb}') +{ + // Define an alias for total number of pages + $this->AliasNbPages = $alias; +} + +function Error($msg) +{ + // Fatal error + throw new Exception('FPDF error: '.$msg); +} + +function Close() +{ + // Terminate document + if($this->state==3) + return; + if($this->page==0) + $this->AddPage(); + // Page footer + $this->InFooter = true; + $this->Footer(); + $this->InFooter = false; + // Close page + $this->_endpage(); + // Close document + $this->_enddoc(); +} + +function AddPage($orientation='', $size='', $rotation=0) +{ + // Start a new page + if($this->state==3) + $this->Error('The document is closed'); + $family = $this->FontFamily; + $style = $this->FontStyle.($this->underline ? 'U' : ''); + $fontsize = $this->FontSizePt; + $lw = $this->LineWidth; + $dc = $this->DrawColor; + $fc = $this->FillColor; + $tc = $this->TextColor; + $cf = $this->ColorFlag; + if($this->page>0) + { + // Page footer + $this->InFooter = true; + $this->Footer(); + $this->InFooter = false; + // Close page + $this->_endpage(); + } + // Start new page + $this->_beginpage($orientation,$size,$rotation); + // Set line cap style to square + $this->_out('2 J'); + // Set line width + $this->LineWidth = $lw; + $this->_out(sprintf('%.2F w',$lw*$this->k)); + // Set font + if($family) + $this->SetFont($family,$style,$fontsize); + // Set colors + $this->DrawColor = $dc; + if($dc!='0 G') + $this->_out($dc); + $this->FillColor = $fc; + if($fc!='0 g') + $this->_out($fc); + $this->TextColor = $tc; + $this->ColorFlag = $cf; + // Page header + $this->InHeader = true; + $this->Header(); + $this->InHeader = false; + // Restore line width + if($this->LineWidth!=$lw) + { + $this->LineWidth = $lw; + $this->_out(sprintf('%.2F w',$lw*$this->k)); + } + // Restore font + if($family) + $this->SetFont($family,$style,$fontsize); + // Restore colors + if($this->DrawColor!=$dc) + { + $this->DrawColor = $dc; + $this->_out($dc); + } + if($this->FillColor!=$fc) + { + $this->FillColor = $fc; + $this->_out($fc); + } + $this->TextColor = $tc; + $this->ColorFlag = $cf; +} + +function Header() +{ + // To be implemented in your own inherited class +} + +function Footer() +{ + // To be implemented in your own inherited class +} + +function PageNo() +{ + // Get current page number + return $this->page; +} + +function SetDrawColor($r, $g=null, $b=null) +{ + // Set color for all stroking operations + if(($r==0 && $g==0 && $b==0) || $g===null) + $this->DrawColor = sprintf('%.3F G',$r/255); + else + $this->DrawColor = sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255); + if($this->page>0) + $this->_out($this->DrawColor); +} + +function SetFillColor($r, $g=null, $b=null) +{ + // Set color for all filling operations + if(($r==0 && $g==0 && $b==0) || $g===null) + $this->FillColor = sprintf('%.3F g',$r/255); + else + $this->FillColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); + $this->ColorFlag = ($this->FillColor!=$this->TextColor); + if($this->page>0) + $this->_out($this->FillColor); +} + +function SetTextColor($r, $g=null, $b=null) +{ + // Set color for text + if(($r==0 && $g==0 && $b==0) || $g===null) + $this->TextColor = sprintf('%.3F g',$r/255); + else + $this->TextColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); + $this->ColorFlag = ($this->FillColor!=$this->TextColor); +} + +function GetStringWidth($s) +{ + // Get width of a string in the current font + $s = (string)$s; + $cw = &$this->CurrentFont['cw']; + $w = 0; + $l = strlen($s); + for($i=0;$i<$l;$i++) + $w += $cw[$s[$i]]; + return $w*$this->FontSize/1000; +} + +function SetLineWidth($width) +{ + // Set line width + $this->LineWidth = $width; + if($this->page>0) + $this->_out(sprintf('%.2F w',$width*$this->k)); +} + +function Line($x1, $y1, $x2, $y2) +{ + // Draw a line + $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); +} + +function Rect($x, $y, $w, $h, $style='') +{ + // Draw a rectangle + if($style=='F') + $op = 'f'; + elseif($style=='FD' || $style=='DF') + $op = 'B'; + else + $op = 'S'; + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); +} + +function AddFont($family, $style='', $file='') +{ + // Add a TrueType, OpenType or Type1 font + $family = strtolower($family); + if($file=='') + $file = str_replace(' ','',$family).strtolower($style).'.php'; + $style = strtoupper($style); + if($style=='IB') + $style = 'BI'; + $fontkey = $family.$style; + if(isset($this->fonts[$fontkey])) + return; + $info = $this->_loadfont($file); + $info['i'] = count($this->fonts)+1; + if(!empty($info['file'])) + { + // Embedded font + if($info['type']=='TrueType') + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); + else + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); + } + $this->fonts[$fontkey] = $info; +} + +function SetFont($family, $style='', $size=0) +{ + // Select a font; size given in points + if($family=='') + $family = $this->FontFamily; + else + $family = strtolower($family); + $style = strtoupper($style); + if(strpos($style,'U')!==false) + { + $this->underline = true; + $style = str_replace('U','',$style); + } + else + $this->underline = false; + if($style=='IB') + $style = 'BI'; + if($size==0) + $size = $this->FontSizePt; + // Test if font is already selected + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) + return; + // Test if font is already loaded + $fontkey = $family.$style; + if(!isset($this->fonts[$fontkey])) + { + // Test if one of the core fonts + if($family=='arial') + $family = 'helvetica'; + if(in_array($family,$this->CoreFonts)) + { + if($family=='symbol' || $family=='zapfdingbats') + $style = ''; + $fontkey = $family.$style; + if(!isset($this->fonts[$fontkey])) + $this->AddFont($family,$style); + } + else + $this->Error('Undefined font: '.$family.' '.$style); + } + // Select it + $this->FontFamily = $family; + $this->FontStyle = $style; + $this->FontSizePt = $size; + $this->FontSize = $size/$this->k; + $this->CurrentFont = &$this->fonts[$fontkey]; + if($this->page>0) + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); +} + +function SetFontSize($size) +{ + // Set font size in points + if($this->FontSizePt==$size) + return; + $this->FontSizePt = $size; + $this->FontSize = $size/$this->k; + if($this->page>0) + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); +} + +function AddLink() +{ + // Create a new internal link + $n = count($this->links)+1; + $this->links[$n] = array(0, 0); + return $n; +} + +function SetLink($link, $y=0, $page=-1) +{ + // Set destination of internal link + if($y==-1) + $y = $this->y; + if($page==-1) + $page = $this->page; + $this->links[$link] = array($page, $y); +} + +function Link($x, $y, $w, $h, $link) +{ + // Put a link on the page + $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); +} + +function Text($x, $y, $txt) +{ + // Output a string + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); + if($this->underline && $txt!='') + $s .= ' '.$this->_dounderline($x,$y,$txt); + if($this->ColorFlag) + $s = 'q '.$this->TextColor.' '.$s.' Q'; + $this->_out($s); +} + +function AcceptPageBreak() +{ + // Accept automatic page break or not + return $this->AutoPageBreak; +} + +function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') +{ + // Output a cell + $k = $this->k; + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) + { + // Automatic page break + $x = $this->x; + $ws = $this->ws; + if($ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + $this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); + $this->x = $x; + if($ws>0) + { + $this->ws = $ws; + $this->_out(sprintf('%.3F Tw',$ws*$k)); + } + } + if($w==0) + $w = $this->w-$this->rMargin-$this->x; + $s = ''; + if($fill || $border==1) + { + if($fill) + $op = ($border==1) ? 'B' : 'f'; + else + $op = 'S'; + $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); + } + if(is_string($border)) + { + $x = $this->x; + $y = $this->y; + if(strpos($border,'L')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); + if(strpos($border,'T')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); + if(strpos($border,'R')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); + if(strpos($border,'B')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); + } + if($txt!=='') + { + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + if($align=='R') + $dx = $w-$this->cMargin-$this->GetStringWidth($txt); + elseif($align=='C') + $dx = ($w-$this->GetStringWidth($txt))/2; + else + $dx = $this->cMargin; + if($this->ColorFlag) + $s .= 'q '.$this->TextColor.' '; + $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt)); + if($this->underline) + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); + if($this->ColorFlag) + $s .= ' Q'; + if($link) + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); + } + if($s) + $this->_out($s); + $this->lasth = $h; + if($ln>0) + { + // Go to next line + $this->y += $h; + if($ln==1) + $this->x = $this->lMargin; + } + else + $this->x += $w; +} + +function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false) +{ + // Output text with automatic or explicit line breaks + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + $cw = &$this->CurrentFont['cw']; + if($w==0) + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + $s = str_replace("\r",'',$txt); + $nb = strlen($s); + if($nb>0 && $s[$nb-1]=="\n") + $nb--; + $b = 0; + if($border) + { + if($border==1) + { + $border = 'LTRB'; + $b = 'LRT'; + $b2 = 'LR'; + } + else + { + $b2 = ''; + if(strpos($border,'L')!==false) + $b2 .= 'L'; + if(strpos($border,'R')!==false) + $b2 .= 'R'; + $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; + } + } + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $ns = 0; + $nl = 1; + while($i<$nb) + { + // Get next character + $c = $s[$i]; + if($c=="\n") + { + // Explicit line break + if($this->ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $i++; + $sep = -1; + $j = $i; + $l = 0; + $ns = 0; + $nl++; + if($border && $nl==2) + $b = $b2; + continue; + } + if($c==' ') + { + $sep = $i; + $ls = $l; + $ns++; + } + $l += $cw[$c]; + if($l>$wmax) + { + // Automatic line break + if($sep==-1) + { + if($i==$j) + $i++; + if($this->ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + } + else + { + if($align=='J') + { + $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; + $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); + } + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); + $i = $sep+1; + } + $sep = -1; + $j = $i; + $l = 0; + $ns = 0; + $nl++; + if($border && $nl==2) + $b = $b2; + } + else + $i++; + } + // Last chunk + if($this->ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + if($border && strpos($border,'B')!==false) + $b .= 'B'; + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $this->x = $this->lMargin; +} + +function Write($h, $txt, $link='') +{ + // Output text in flowing mode + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + $cw = &$this->CurrentFont['cw']; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + $s = str_replace("\r",'',$txt); + $nb = strlen($s); + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $nl = 1; + while($i<$nb) + { + // Get next character + $c = $s[$i]; + if($c=="\n") + { + // Explicit line break + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); + $i++; + $sep = -1; + $j = $i; + $l = 0; + if($nl==1) + { + $this->x = $this->lMargin; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + } + $nl++; + continue; + } + if($c==' ') + $sep = $i; + $l += $cw[$c]; + if($l>$wmax) + { + // Automatic line break + if($sep==-1) + { + if($this->x>$this->lMargin) + { + // Move to next line + $this->x = $this->lMargin; + $this->y += $h; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + $i++; + $nl++; + continue; + } + if($i==$j) + $i++; + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); + } + else + { + $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); + $i = $sep+1; + } + $sep = -1; + $j = $i; + $l = 0; + if($nl==1) + { + $this->x = $this->lMargin; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + } + $nl++; + } + else + $i++; + } + // Last chunk + if($i!=$j) + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); +} + +function Ln($h=null) +{ + // Line feed; default value is the last cell height + $this->x = $this->lMargin; + if($h===null) + $this->y += $this->lasth; + else + $this->y += $h; +} + +function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') +{ + // Put an image on the page + if($file=='') + $this->Error('Image file name is empty'); + if(!isset($this->images[$file])) + { + // First use of this image, get info + if($type=='') + { + $pos = strrpos($file,'.'); + if(!$pos) + $this->Error('Image file has no extension and no type was specified: '.$file); + $type = substr($file,$pos+1); + } + $type = strtolower($type); + if($type=='jpeg') + $type = 'jpg'; + $mtd = '_parse'.$type; + if(!method_exists($this,$mtd)) + $this->Error('Unsupported image type: '.$type); + $info = $this->$mtd($file); + $info['i'] = count($this->images)+1; + $this->images[$file] = $info; + } + else + $info = $this->images[$file]; + + // Automatic width and height calculation if needed + if($w==0 && $h==0) + { + // Put image at 96 dpi + $w = -96; + $h = -96; + } + if($w<0) + $w = -$info['w']*72/$w/$this->k; + if($h<0) + $h = -$info['h']*72/$h/$this->k; + if($w==0) + $w = $h*$info['w']/$info['h']; + if($h==0) + $h = $w*$info['h']/$info['w']; + + // Flowing mode + if($y===null) + { + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) + { + // Automatic page break + $x2 = $this->x; + $this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation) \ No newline at end of file diff --git a/database.old/init.php b/database.old/init.php new file mode 100644 index 0000000..f3c9d60 --- /dev/null +++ b/database.old/init.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/database/DataBaseConnector.php b/database/DataBaseConnector.php new file mode 100644 index 0000000..6bc18f5 --- /dev/null +++ b/database/DataBaseConnector.php @@ -0,0 +1,916 @@ +con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD,DB_DATABASE); + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + $this->messenger = new Messenger(); + + } + public function __destruct() + { + mysqli_close($this->con); + } + public function getPubValue($id_country){ + $result = mysqli_query($this->con,"SELECT * from publiciteConfig WHERE id_config = '2' AND id_country='$id_country'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return mysqli_fetch_array($result,MYSQLI_ASSOC); + } else { + // user not existed + return false; + } + } + public function getPasValue(){ + $result = mysqli_query($this->con,"SELECT * from adminConfig WHERE cle = 'pas_chargement'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return mysqli_fetch_array($result,MYSQLI_ASSOC); + } else { + // user not existed + return false; + } + } + public function isPhoneExistedSimple($phone) { + // connecting to mysql + + $result = mysqli_query($this->con,"SELECT phone from users WHERE phone = '$phone'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return true; + } else { + // user not existed + return false; + } + } + public function getNetwork(){ + $r=mysqli_query($this->con,"select * from networks"); + + while($row=mysqli_fetch_array($r, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + if(count($rows)){ + return $rows; + } else { + return null; + } + } + public function isPhoneExisted($phone) { + $result = mysqli_query($this->con,"SELECT phone from users WHERE phone = '$phone'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return true; + } else { + // user not existed + return false; + } + } + public function isPhoneExistedInCategory($phone,$category=null,$phoneTransaction=null){ + + $result = mysqli_query($this->con,"SELECT na.phone from networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE na.transactionNumber ='$phoneTransaction'"); + if($result) { + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + return true; + } + }else echo json_encode(mysqli_error($this->con)); + return false; + + } + + public function checknumberValidity($phone){ + try { + return true;//$this->messenger->checkPhoneExist($phone); + } catch(Exception $ex){ + return false; + } + } + public function isMemberCodeExisted($codemembre) + { + $result = mysqli_query($this->con, "SELECT * from codeGenerer WHERE code_membre = '$codemembre' "); + if ($result) { + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) + return true; + } + return false; + + } + + public function getAgentByCodeMembre($code) + { + + $listIdmemberParrain= mysqli_query($this->con, "SELECT ag.id as id,ag.uid as uid,ag.firstname AS firstname, +ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,na.transactionNumber as phoneTransaction, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password as encrypted_password, + ne.name as network,ct.name as country,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + } + public function getAgentWithCodeMembre($code){ + $listIdmemberParrain=mysqli_query($this->con, + "SELECT na.id as agentId,na.transactionNumber as transactionNumber,ag.email as email,ag.number_super as nbre_reseau,ag.number_geoBySuper as nbre_sous_reseau,cg.category as category, cg.code_parrain as code_parrain,cg.code_membre as code_membre,cg.id as idCode from agents ag RIGHT JOIN networks_agents na on ag.id=na.agent_id RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + return $membre; + }else return false; + } + public function getAgentNetworkByCode($code){ + $listIdmemberParrain=mysqli_query($this->con, + "SELECT ne.id, ne.name,ne.status from networks ne INNER JOIN networks_agents na ON na.network_id=ne.id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + return $membre; + }else return ['error'=>mysqli_error($this->con)]; + } + public function getAgentById($id){ + $listIdmemberParrain=mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname,ag.lastname AS lastname, + ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, + na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat + ,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,ne.id as network_id, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password asencrypted_password, + ne.name as network,ct.name as country, ct.code_dial as indicatif,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + ag.id='$id'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + if($membre['category']!='geolocated'){ + $membre['nbre_membre']=$this->getNbMemberOf($membre['code_membre']); + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + } + + public function storeUser($fname, $lname, $email, $phone, $password, $network, $member,$latitude, $longitude,$town,$phoneTransaction) + { + //on verifie si y a un agent qui utilise ce code + if(isset($town->id)){ + $membre = $this->getAgentWithCodeMembre($member); + if ($membre) { + if (isset($membre['agentId'])) { + //s'il y a un agent qui a ce code on cree un membre de son reseau + if (($membre['category'] == 'hyper' && $membre['nbre_reseau'] > 0) || + ($membre['category'] == 'super' && $membre['nbre_sous_reseau'] > 0)) { + //si il s'agit d'un hyperviseur ou superviseur et qu'il peut encore créer des membres alors + if ($membre['category'] == 'super') { + $codeGenerer = $this->generateValideCode($membre['code_membre'], 'geolocated'); + if ($codeGenerer != null) + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $codeGenerer, $latitude, + $longitude, $town,$phoneTransaction); + } else { + //on verifie s'il existe des codes superviseur disponible pour cette hyperviseur + $listIdmemberParrain = mysqli_query($this->con, "SELECT na.codeGenerer_id as id,cg.code_membre as code_membre from networks_agents na RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_parrain='$member' AND na.id is null"); + if ($listIdmemberParrain) { + if(mysqli_num_rows($listIdmemberParrain) > 0) { + $me = mysqli_fetch_array($listIdmemberParrain, MYSQLI_ASSOC)['code_membre']; + } + else{ + $me=$this->generateValideCode($member,'super'); + } + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $me, $latitude, $longitude, $town,$phoneTransaction); + } else { + return ["error" => -5, 'error_msg' => 'le code parrain que vous avez entrée n\'a pas de membre disponible','sql'=>mysqli_error($this->con)]; + } + } + } else { + return ["error" => -6, 'error_msg' => 'le code parrain que vous avez entrée n\'a pas de membre disponible']; + } + } else { + //si aucun membre n'a ce code on verifie s'il sagit d'un hyperviseur + if ($membre['category'] == 'hyper') { + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $member, $latitude, + $longitude, $town,$phoneTransaction); + } else { + return ["error" => -1, "error_msg" => "impossible de verifier le membre"]; + } + } + } else { + return ["error" => -2, "error_msg" => "impossible de verifier le membre", 'sql' => mysqli_error($this->con)]; + } + }else{ + return ["error" => -10, "error_msg" => "La ville dans laquelle vous vous trouvez n'est pas encore pris en charge", 'sql' => mysqli_error($this->con)]; + } + } + + public function random_string() + { + $character_set_array = array(); + $character_set_array[] = array('count' => 7, 'characters' => 'abcdefghjkmnpqrstuvwxyz'); + $character_set_array[] = array('count' => 1, 'characters' => '23456789'); + $temp_array = array(); + foreach ($character_set_array as $character_set) { + for ($i = 0; $i < $character_set['count']; $i++) { + $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)]; + } + } + shuffle($temp_array); + return implode('', $temp_array); + } + + public function getAllPointInCountry($country){ + $etat=1; + $si=1; + $category="geolocated"; + if($result= mysqli_prepare($this->con,"SELECT * FROM agent_plus WHERE code_dial=? AND etat=? AND category=? AND (longitude!=0 AND latitude!=0)")) { + mysqli_stmt_bind_param($result, 'sis', $country, $etat, $category); + mysqli_stmt_execute($result); + $r = mysqli_stmt_get_result($result); + $rows=[]; + while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC )) { + $rows[]=$row; + } + + mysqli_stmt_close($result); + return $rows; + if($result) { + $rows=[]; + while ($row = mysqli_fetch_assoc($result)) { + $rows[] = $row; + } + // $rows; + }else{ + return ['error'=>mysqli_error($this->con)]; + + } + }else{ + return ['error'=>mysqli_error($this->con)]; + + } + + return false; + } + + public function getUserCountryPoint($user_id){ + $result = mysqli_query($this->con,"SELECT * FROM agents ag inner JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.category='geolocated' AND na.etat=1") or die(mysqli_error($this->con)); + if($result) { + $rows=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + return $rows; + }else return false; + + } + + public function getCategoryAgent($codeparrain){ + $result=mysqli_query($this->con,"SELECT category,etat FROM codeGenerer where code_membre = '$codeparrain'"); + if($result) { + $rows=[]; + $row = mysqli_fetch_array($result, MYSQLI_ASSOC); + + return $row; + }else return ["erro"=>mysqli_error($this->con)]; + + } + + public function updateWrongPoints() + { + $result=[]; + + return $result; + } + + public function getSuperviseurNetwork($codeparrain,$user_id){ + $self=$this->getAgentByCodeMembre($codeparrain); + $catparrain=$self['category']; + $catchild=($catparrain=='hyper')?'super':($catparrain=='super'?'geolocated':null); + if($catchild) { + $result = mysqli_query($this->con, "select ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat FROM networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id +INNER JOIN networks nt ON na.network_id=nt.id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN countries ct + ON nt.country_id=ct.id WHERE cg.code_parrain='$codeparrain' AND cg.code_membre!='$codeparrain' AND na.etat='1' AND cg.category='$catchild'"); + + $rows = []; + $re = []; + if ($result) { + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + $re['val'] = $rows; + $re['success'] = 1; + $re['catchild']=$catchild; + $re['catparrain']=$catparrain; + } else { + $re['error'] = mysqli_error($this->con); + } + }else{ + $re['error']='cat child not found'; + } + return $re; + } + + public function getPointsNetwork($network,$user_id){ + $result=mysqli_query($this->con,"SELECT ag.firstname,cg.code_membre,cg.code_parrain,ag.adresse, +ag.lastname,na.phone,ag.email,na.solde,cg.category,ne.name as network,ct.id as country,ag.longitude,ag.latitude,ag.id as AgentId,ne.id as network_id,ct.id as country_id +FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN +codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id INNER JOIN countries ct ON ct.id=ne.country_id WHERE cg.category='geolocated' AND na.etat='1' AND na.network_id='$network' AND ag.longitude>0 AND ag.latitude>0 LIMIT 100"); + if($result) { + $rows=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + return $rows; + }else + { + return ["error"=>mysqli_error($this->con)]; + } + } + + private function getUserByPhoneAndPassword($phone, $password,$table) { + $result = mysqli_query($this->con,"SELECT usr.active,usr.salt,usr.encrypted_password,usr.firstname,usr.lastname,usr.id,usr.phone,usr.email,usr.solde,usr.validation_code,usr.active,usr.network_id,ne.name as network,ne.country_id,ct.name as country,ct.code_dial,ct.code_country FROM $table usr INNER JOIN networks ne ON usr.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE phone = '$phone'") or die(mysqli_error($this->con)); + // check for result + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + $result = mysqli_fetch_array($result,MYSQLI_ASSOC); + $salt = $result['salt']; + $encrypted_password = $result['encrypted_password']; + $hash = $this->checkhashSSHA($salt, $password); + // check for password equality + if ($encrypted_password == $hash) { + // user authentication details are correct + return $result; + }else{ + return ['error'=>-3]; + } + } else { + // user not found + return ['error'=>-2,"use"=>$no_of_rows]; + } + } + + public function hashSSHA($password) { + + $salt = sha1(rand()); + $salt = substr($salt, 0, 10); + $encrypted = base64_encode(sha1($password . $salt, true) . $salt); + $hash = array("salt" => $salt, "encrypted" => $encrypted); + return $hash; + } + + public function forgotPasswordSimple($phone, $encrypted_password, $salt) + { + $result = mysqli_query($this->con, "UPDATE `users` SET `encrypted_password` = '$encrypted_password',`salt` = '$salt' WHERE `phone` = '$phone'"); + + if ($result) { + + return true; + + } else { + return false; + } + } + + public function getEmailSimple($phone){ + $result = mysqli_query($this->con,"SELECT email FROM users WHERE phone = '$phone'"); + + if ($result) { + return mysqli_fetch_array($result); + //return true; + + } + else + { + return false; + } + + } + + public function listNetwork(){ + echo "request"; + $res=mysqli_query($this->con,"SELECT * FROM network"); + if($res){ + return mysqli_fetch_array($res); + + }else return ['error'=>'unable to make request','error_'=>mysqli_error($this->con)]; + } + + private function checkhashSSHA($salt, $password) { + + $hash = base64_encode(sha1($password . $salt, true) . $salt); + + return $hash; + } + /** + * Verifies user by phone and password + */ + public function getUserByPhoneAndPasswordSimple($phone, $password) { + return $this->getUserByPhoneAndPassword($phone,$password,'users'); + } + /** + * Verifies user by phone and password + */ + public function generateRandomString($length = 10) { + $characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + public function getUserByPhoneAndPasswordGeolocated($phone, $password) { + // connecting to mysql + $result = mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname,ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,na.transactionNumber as phoneTransaction, +ne.id as network_id,ag.date_created as date_created,cg.category as category, + ag.salt as salt,ag.encrypted_password as encrypted_password,ne.name as network,ct.name as country + ,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id + INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE na.phone='$phone' or na.transactionNumber='$phone'"); + if($result){ + if(mysqli_num_rows($result)>0) { + $mr=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $salt = $row['salt']; + $encrypted_password = $row['encrypted_password']; + $hash = $this->checkhashSSHA($salt, $password); + $mr["hash"]=$hash; + $mr["encrypted_password"]=$encrypted_password; + if ($encrypted_password == $hash) { + if ($row['category'] == 'super') { + $phone = $row["phone"]; + $demandere = mysqli_query($this->con, "SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if ($demandere) + $row['etat_demande'] = mysqli_fetch_array($demandere, MYSQLI_ASSOC)['etat']; + else + echo mysqli_error($this->con); + } + if($row['category']!='geolocated'){ + $row['nbre_membre']=$this->getNbMemberOf($row['code_membre']); + + + } + + return $row; + } + + return ['error'=>-3,"error_msg"=>"Mot de passe incorrect","last"=>$row]; + } + }else + return ['error'=>-1,"error_msg2"=>"Numéro incorrect",]; + } + + else + return ['error'=>-2,"error_msg2"=>mysqli_error($this->con)]; + + } + + public function getAgentNetworkByPhone($phone){ + $listIdmemberParrain=mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname, +ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone, +ne.id as network_id, +na.id as networkAgentId, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password as encrypted_password, + ne.name as network,ct.name as country,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + na.phone='$phone'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + + } + + public function storeDemandeCredit($phone,$montant,$code){ + $agent=$this->getAgentWithCodeMembre($code); + if($agent) { + $idag=$agent['agentId']; + $q = mysqli_query($this->con, "INSERT INTO demandeCredits(network_agent_id,montant,status) VALUES('$idag','$montant','0')"); + if ($q) { + return ['success' => 1, "agent" => $agent]; + } + } + return false; + +} + + private function createAgent($fname, $lname, $email, $phone, $password, $network, $member, $latitude, $longitude, $town,$phoneTransaction) + { + + $resultFreeCode = mysqli_query($this->con, "SELECT id,code_membre,category,code_parrain from codeGenerer cg WHERE code_membre='$member' "); + if($resultFreeCode){ + $freecodenum=mysqli_num_rows($resultFreeCode); + if($freecodenum>0) { + $codes = mysqli_fetch_array($resultFreeCode, MYSQLI_ASSOC); + $freecode = $codes; + $code_id = $freecode['id']; + $category=$freecode["category"]; + $uuid = uniqid('', true); + $balance = 0; + $etat=0; + if($category=="geolocated"){ + $etat=GEOLOCATED_AGENT_ETAT; + } + + $hash = $this->hashSSHA($password); + $encrypted_password = $hash["encrypted"]; + $salt = $hash["salt"]; + $validation_code = $this->random_string(); + + if(isset($town->id)) { + $townid = $town->id; + + $agentCreateResult = mysqli_query($this->con, "INSERT INTO agents(uid,adresse, +lastname,email,longitude,latitude +,balance,encrypted_password,salt,active,date_created,town_id) VALUES ('$uuid', +'$fname','$lname','$email','$longitude','$latitude','$balance','$encrypted_password','$salt','$etat',NOW(),'$townid')"); + if ($agentCreateResult) { + $agent_id = mysqli_insert_id($this->con); + if ($agent_id) { + + + + $result = mysqli_query($this->con, "INSERT INTO networks_agents(network_id,agent_id, +solde,etat,codeGenerer_id,phone,validation_code,transactionNumber) +VALUES('$network->id','$agent_id','$balance','$etat','$code_id','$phone','$validation_code','$phoneTransaction')"); + if ($result) { + // get user details + + $agent= $this->getAgentById($agent_id); + $resque=mysqli_query($this->con,"UPDATE codeGenerer SET etat='1' WHERE code_membre='$member'"); + if($resque){ + if($agent['category']=='super'){ + $re=$this->adddemandeAdhesionAgent($agent); + if(!isset($re['success']))return $re; + } + }else{ + return [ + 'error' => 'impossible de de mettre à jour', + 'sql_error' => mysqli_error($this->con), + ]; + } + return $agent; + } else { + return [ + 'error' => 'impossible de créer un network_agent', + 'sql_error' => mysqli_error($this->con), + 'code_generer' => $freecode + ]; + } + + } else { + return [ + 'error' => 'impossible recuperer l agent', + 'sql_error' => mysqli_error($this->con), + 'code_generer' => $freecode + ]; + } + + } else { + return [ + 'error' => 'impossible de créer un agent', + 'sql_error' => mysqli_error($this->con) + ]; + } + }else{ + return ['error'=>-4,'error_msg'=>'la ville que vous aviez entrée n\'est pas encore pris en compte ','ville'=>$town]; + } + + }else return ['error'=>"ce parrain à atteint son quota de membre"]; + }else{ + return ["error"=>"impossible de recuperer verifier la disponibilité ","error_msg"=>mysqli_error($this->con)]; + } + } + + public function generateValideCode($membre, $category) + { + $code=null; + $valide=false; + do{ + $code=$this->generateRandomString(); + $q = mysqli_query($this->con, "SELECT * from codeGenerer WHERE code_membre='$code'"); + if ($q) { + $valide = mysqli_num_rows($q) == 0; + $qe=mysqli_query($this->con, "INSERT INTO codeGenerer(code_parrain,code_membre,category,etat) VALUES ('$membre','$code','$category',0)"); + if(!$qe){ + echo mysqli_error($this->con); + return null; + } + }else{ + echo mysqli_error($this->con); + return null; + } + }while(!$valide); + return $code; + } + + private function adddemandeAdhesionAgent($agent) + { + $codeparrain=$agent['code_parrain']; + $resParrain=mysqli_query($this->con,"SELECT na.id as agentId FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$codeparrain'"); + if($resParrain){ + $parrain=mysqli_fetch_array($resParrain,MYSQLI_ASSOC); + $agentId=$parrain['agentId']; + if($agentId){ + $phone=$agent['phone']; + $resDemande=mysqli_query($this->con,"INSERT INTO demandeAdhesion(phone,networks_agent_id) VALUES ('$phone','$agentId')"); + if($resDemande){ + return ['success'=>1]; + }else{ + return ["error"=>1,"sql"=>mysqli_error($this->con),'agent'=>$agent]; + } + } + }else{ + return ['error'=>'error','ssql'=>mysqli_error($this->con),'agent'=>$agent]; + } + } + + public function storeUserSimple($firstname, $lastname, $email, $phone, $password, $network) + { + $uuid = uniqid('', true); + $balance =0; + $hash = $this->hashSSHA($password); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; // salt + //$validation_code = generateRandomString(); + $codeCorrect=true; + do{ + $validation_code = $this->random_string(); + $q=mysqli_query($this->con,"SELECT * FROM networks_agents WHERE validation_code='$validation_code'"); + $rowcount=mysqli_num_rows($q); + $codeCorrect=$rowcount<0; + }while($codeCorrect); + $networkid=$network->id; + $result = mysqli_query($this->con, + "INSERT INTO users(uid, adresse,lastname, phone, email, solde, encrypted_password, +salt,validation_code, active,network_id) VALUES + ('$uuid', '$firstname', '$lastname', '$phone','$email','$balance','$encrypted_password', '$salt', + '$validation_code','0','$networkid')"); + // check for successful store + if ($result) { + // get user details + $uid = mysqli_insert_id($this->con); // last inserted id + $result = mysqli_query($this->con,"SELECT ne.name as reseau,ct.name as country,usr.firstname as firstname +,usr.lastname as lastname,usr.phone as phone,usr.email as email,usr.validation_code as validation_code FROM users usr INNER JOIN networks ne ON ne.id=usr.network_id INNER JOIN countries ct ON ct.id=ne.country_id WHERE usr.id = '$uid'"); + // return user details + if($result){ + return mysqli_fetch_array($result); + + }else return ['error'=>'error geting information','sql'=>mysqli_error($this->con)]; + } else { + return ['error'=>'error saving information','sql'=>mysqli_error($this->con)]; + } + + } + + public function generateNetworkAgent($phone, $code_parrain,$agent) + { + $code=$this->generateValideCode($code_parrain,"geolocated"); + $resParrain=mysqli_query($this->con,"SELECT * FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN towns tw ON ag.town_id=tw.id INNER JOIN countries ct ON tw.country_id=ct.id WHERE cg.code_membre='$code_parrain'"); + + if($resParrain) { + $parrain = mysqli_fetch_array($resParrain, MYSQLI_ASSOC); + $networkId = $parrain['network_id']; + + $phone = $parrain['code_dial'] . $phone; + if (true) { + $resgg = mysqli_query($this->con, "SELECT * FROM codeGenerer cg WHERE cg.code_membre='$code'"); + if ($resgg) { + $membre = mysqli_fetch_array($resgg, MYSQLI_ASSOC); + $codeGenererId = $membre['id']; + $codevalide=true; + do{ + $validation_code = $this->random_string(); + $se=mysqli_query($this->con,"SELECT * FROM networks_agents WHERE validation_code='$validation_code'"); + $codevalide=mysqli_num_rows($se)>0; + }while($codevalide); + $agentPhone=$agent['phone']; + $result = mysqli_query($this->con, "INSERT INTO networks_agents(network_id,solde,etat,codeGenerer_id,transactionNumber,phone,validation_code)VALUES('$networkId','0','0','$codeGenererId','$phone','$agentPhone','$validation_code')"); + if ($result) { + $geoId=mysqli_insert_id($this->con); + if (mysqli_query($this->con, "UPDATE codeGenerer SET etat='1' WHERE code_membre='$code'")) + return ['success' => 1,'phone'=>$phone,'code_membre' => $membre['code_membre'], 'validation_code' => $validation_code,"id"=>$geoId]; + else { + $da = ['error' => -7, 'error_msg' => 'impossible de mettre à jour les informations du code membre', 'sql' => mysqli_error($this->con)]; + mysqli_query($this->con, "DELETE FROM codeGenerer WHERE code_membre='$code'"); + return $da; + } + } else { + $da = ['error' => -5, 'error_msg' => 'impossible de recuperer les informations du de code generer', 'sql' => mysqli_error($this->con)]; + mysqli_query($this->con, "DELETE FROM codeGenerer WHERE code_membre='$code'"); + + return $da; + + } + + } else { + return ['error' => -4, 'error_msg' => 'impossible de recuperer les informations du de code generer', 'sql' => mysqli_error($this->con)]; + + } + } + else { + return ['error' => -7, 'error_msg' => 'le numéro de téléphone est invalide', 'phone' =>$phone,"parrain"=>$parrain]; + } + } else { + return ['error' => -3, 'error_msg' => 'impossible de recuperer les information du parrain', 'sql' => mysqli_error($this->con)]; + } + } + + public function getGeoLocatedFreeWithValidationCode($validation_code) + { + $qu=mysqli_query($this->con,"SELECT na.id as id,na.validation_code as validation_code,na.etat as etat, na.agent_id as agent_id,cg.code_membre as code_membre,cg.code_parrain as code_parrain, cg.category as category FROM networks_agents na INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE na.validation_code='$validation_code' AND cg.category='geolocated' AND na.agent_id is null"); + if($qu){ + $num_row=mysqli_num_rows($qu); + if($num_row>0) { + $geo = mysqli_fetch_array($qu, MYSQLI_ASSOC); + return $geo; + }else { + return ['error'=>'Ce code n\'est disponible']; + } + }else{ + return false; + } + + + + } + + public function assignNetworkAgent($idAgent, $idNetworkAgent) + { + $re=mysqli_query($this->con,"UPDATE networks_agents SET agent_id='$idAgent',etat='1' WHERE id='$idNetworkAgent'"); + if($re){ + return ['success'=>1]; + }else return ['error'=>mysqli_error($this->con)]; + } + + public function getListNetworkOfGeoPoint($user_id) + { + $q=mysqli_query($this->con,"SELECT na.id as id,na.network_id as network_id,na.solde as solde,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE ag.id='$user_id'"); + if($q){ + + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListFreeNetworkOfGeoPoint($code_parrain) + { + $q=mysqli_query($this->con,"SELECT na.id as id,na.network_id as network_id,na.solde as solde,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name,na.validation_code as validation_code from networks_agents na INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE cg.code_parrain='$code_parrain' AND cg.code_membre!='$code_parrain' AND na.agent_id IS NULL"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListDemandeReceiveAgent($codeparrain) + { + + $q=mysqli_query($this->con,"SELECT dc.id as id,dc.montant as montant,dc.date_creation,dc.date_modification,dc.status as status,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name,ne.name as reseau from demandeCredits dc INNER JOIN networks_agents na ON na.id=dc.network_agent_id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE cg.code_parrain='$codeparrain'"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListDemandeSendAgent($user_id) + { + $q=mysqli_query($this->con,"SELECT ne.name as reseau, dc.id as id,dc.montant as montant,dc.date_creation,dc.date_modification,dc.status as status,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name from demandeCredits dc INNER JOIN networks_agents na ON na.id=dc.network_agent_id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE ag.id='$user_id'"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function treatDemand($user_id) + { + $dat=date ("Y-m-d H:i:s"); + $q=mysqli_query($this->con,"UPDATE demandeCredits SET status='1',date_modification='$dat' WHERE id='$user_id'"); + if($q){ + $qdemande=mysqli_query($this->con,"SELECT * from demandeCredits dc WHERE dc.id='$user_id'"); + if($qdemande) { + $demande = mysqli_fetch_array($qdemande, MYSQLI_ASSOC); + $montant = (int)$demande["montant"]; + $id = $demande['network_agent_id']; + return ['success' => 1,"montant"=>$montant]; + + } + } + return ['error'=>mysqli_error($this->con)]; + + + } + + private function getNbMemberOf($code_membre) + { + $q=mysqli_query($this->con,"SELECT DISTINCT COUNT(*) AS nbr_membre FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_parrain='$code_membre' AND cg.code_membre!='$code_membre' AND na.etat='1'"); + if($q){ + return mysqli_fetch_array($q,MYSQLI_ASSOC)['nbr_membre']; + }else{ + return 0; + } + } + + public function getPointInDistance($reseau,$position, $distance,$page) + { + $mlat=$position->latitude; + $mlong=$position->longitude; + $re=$reseau->id; + $offset=$page*50; + $res= mysqli_query($this->con,"SELECT ag.id as agentId,na.id as id,ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat + FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN networks nt ON na.network_id=nt.id INNER JOIN countries ct ON ct.id=nt.country_id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.category='geolocated' AND na.etat=1 AND getDistanceMetre($mlat,ag.latitude,$mlong,ag.longitude)<=$distance AND nt.id=$re ORDER BY agentId LIMIT 51 OFFSET $offset"); + if($res){ + $li=["page"=>$page,"offset"=>$offset,"total"=>$offset,"count"=>0]; + while ($r=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $li["items"][]=$r; + $li["count"]=$li["count"]+1; + $li["total"]=$li["total"]+1; + } + return $li; + }else return mysqli_error($this->con); + } +} \ No newline at end of file diff --git a/database/DataBaseConnector_safe_save_172137.php b/database/DataBaseConnector_safe_save_172137.php new file mode 100644 index 0000000..771a447 --- /dev/null +++ b/database/DataBaseConnector_safe_save_172137.php @@ -0,0 +1,920 @@ +con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD,DB_DATABASE_TEST); + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + $this->messenger = new Messenger(); + + } + public function __destruct() + { + mysqli_close($this->con); + } + public function getPubValue($id_country){ + $result = mysqli_query($this->con,"SELECT * from publiciteConfig WHERE id_config = '2' AND id_country='$id_country'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return mysqli_fetch_array($result,MYSQLI_ASSOC); + } else { + // user not existed + return false; + } + } + public function getPasValue(){ + $result = mysqli_query($this->con,"SELECT * from adminConfig WHERE cle = 'pas_chargement'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return mysqli_fetch_array($result,MYSQLI_ASSOC); + } else { + // user not existed + return false; + } + } + public function isPhoneExistedSimple($phone) { + // connecting to mysql + + $result = mysqli_query($this->con,"SELECT phone from users WHERE phone = '$phone'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return true; + } else { + // user not existed + return false; + } + } + public function getNetwork(){ + $r=mysqli_query($this->con,"select * from networks"); + + while($row=mysqli_fetch_array($r, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + if(count($rows)){ + return $rows; + } else { + return null; + } + } + public function isPhoneExisted($phone) { + $result = mysqli_query($this->con,"SELECT phone from users WHERE phone = '$phone'"); + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + // user existed + return true; + } else { + // user not existed + return false; + } + } + public function isPhoneExistedInCategory($phone,$category=null,$phoneTransaction=null){ + + $result = mysqli_query($this->con,"SELECT na.phone from networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE na.transactionNumber ='$phoneTransaction'"); + if($result) { + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + return true; + } + }else echo json_encode(mysqli_error($this->con)); + return false; + + } + + public function checknumberValidity($phone){ + try { + return true;//$this->messenger->checkPhoneExist($phone); + } catch(Exception $ex){ + return false; + } + } + public function isMemberCodeExisted($codemembre) + { + $result = mysqli_query($this->con, "SELECT * from codeGenerer WHERE code_membre = '$codemembre' "); + if ($result) { + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) + return true; + } + return false; + + } + + public function getAgentByCodeMembre($code) + { + + $listIdmemberParrain= mysqli_query($this->con, "SELECT ag.id as id,ag.uid as uid,ag.firstname AS firstname, +ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,na.transactionNumber as phoneTransaction, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password as encrypted_password, + ne.name as network,ct.name as country,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + } + public function getAgentWithCodeMembre($code){ + $listIdmemberParrain=mysqli_query($this->con, + "SELECT na.id as agentId,na.transactionNumber as transactionNumber,ag.email as email,ag.number_super as nbre_reseau,ag.number_geoBySuper as nbre_sous_reseau,cg.category as category, cg.code_parrain as code_parrain,cg.code_membre as code_membre,cg.id as idCode from agents ag RIGHT JOIN networks_agents na on ag.id=na.agent_id RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + return $membre; + }else return false; + } + public function getAgentNetworkByCode($code){ + $listIdmemberParrain=mysqli_query($this->con, + "SELECT ne.id, ne.name,ne.status from networks ne INNER JOIN networks_agents na ON na.network_id=ne.id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + return $membre; + }else return ['error'=>mysqli_error($this->con)]; + } + public function getAgentById($id){ + $listIdmemberParrain=mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname,ag.lastname AS lastname, + ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, + na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat + ,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,ne.id as network_id, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password asencrypted_password, + ne.name as network,ct.name as country, ct.code_dial as indicatif,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + ag.id='$id'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + if($membre['category']!='geolocated'){ + $membre['nbre_membre']=$this->getNbMemberOf($membre['code_membre']); + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + } + + public function storeUser($fname, $lname, $email, $phone, $password, $network, $member,$latitude, $longitude,$town,$phoneTransaction) + { + //on verifie si y a un agent qui utilise ce code + if(isset($town->id)){ + $membre = $this->getAgentWithCodeMembre($member); + if ($membre) { + if (isset($membre['agentId'])) { + //s'il y a un agent qui a ce code on cree un membre de son reseau + if (($membre['category'] == 'hyper' && $membre['nbre_reseau'] > 0) || + ($membre['category'] == 'super' && $membre['nbre_sous_reseau'] > 0)) { + //si il s'agit d'un hyperviseur ou superviseur et qu'il peut encore créer des membres alors + if ($membre['category'] == 'super') { + $codeGenerer = $this->generateValideCode($membre['code_membre'], 'geolocated'); + if ($codeGenerer != null) + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $codeGenerer, $latitude, + $longitude, $town,$phoneTransaction); + } else { + //on verifie s'il existe des codes superviseur disponible pour cette hyperviseur + $listIdmemberParrain = mysqli_query($this->con, "SELECT na.codeGenerer_id as id,cg.code_membre as code_membre from networks_agents na RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_parrain='$member' AND na.id is null"); + if ($listIdmemberParrain) { + if(mysqli_num_rows($listIdmemberParrain) > 0) { + $me = mysqli_fetch_array($listIdmemberParrain, MYSQLI_ASSOC)['code_membre']; + } + else{ + $me=$this->generateValideCode($member,'super'); + } + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $me, $latitude, $longitude, $town,$phoneTransaction); + } else { + return ["error" => -5, 'error_msg' => 'le code parrain que vous avez entrée n\'a pas de membre disponible','sql'=>mysqli_error($this->con)]; + } + } + } else { + return ["error" => -6, 'error_msg' => 'le code parrain que vous avez entrée n\'a pas de membre disponible']; + } + } else { + //si aucun membre n'a ce code on verifie s'il sagit d'un hyperviseur + if ($membre['category'] == 'hyper') { + return $this->createAgent($fname, $lname, $email, $phone, $password, $network, $member, $latitude, + $longitude, $town,$phoneTransaction); + } else { + return ["error" => -1, "error_msg" => "impossible de verifier le membre"]; + } + } + } else { + return ["error" => -2, "error_msg" => "impossible de verifier le membre", 'sql' => mysqli_error($this->con)]; + } + }else{ + return ["error" => -10, "error_msg" => "La ville dans laquelle vous vous trouvez n'est pas encore pris en charge", 'sql' => mysqli_error($this->con)]; + } + } + + public function random_string() + { + $character_set_array = array(); + $character_set_array[] = array('count' => 7, 'characters' => 'abcdefghjkmnpqrstuvwxyz'); + $character_set_array[] = array('count' => 1, 'characters' => '23456789'); + $temp_array = array(); + foreach ($character_set_array as $character_set) { + for ($i = 0; $i < $character_set['count']; $i++) { + $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)]; + } + } + shuffle($temp_array); + return implode('', $temp_array); + } + + public function getAllPointInCountry($country){ + $etat=1; + $si=1; + $category="geolocated"; + if($result= mysqli_prepare($this->con,"SELECT * FROM agent_plus WHERE code_dial=? AND etat=? AND category=? AND (longitude!=0 AND latitude!=0)")) { + mysqli_stmt_bind_param($result, 'sis', $country, $etat, $category); + mysqli_stmt_execute($result); + $r = mysqli_stmt_get_result($result); + $rows=[]; + while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC )) { + $rows[]=$row; + } + + mysqli_stmt_close($result); + return $rows; + if($result) { + $rows=[]; + while ($row = mysqli_fetch_assoc($result)) { + $rows[] = $row; + } + // $rows; + }else{ + return ['error'=>mysqli_error($this->con)]; + + } + }else{ + return ['error'=>mysqli_error($this->con)]; + + } + + return false; + } + + public function getUserCountryPoint($user_id){ + $result = mysqli_query($this->con,"SELECT * FROM agents ag inner JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.category='geolocated' AND na.etat=1") or die(mysqli_error($this->con)); + if($result) { + $rows=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + return $rows; + }else return false; + + } + + public function getCategoryAgent($codeparrain){ + $result=mysqli_query($this->con,"SELECT category,etat FROM codeGenerer where code_membre = '$codeparrain'"); + if($result) { + $rows=[]; + $row = mysqli_fetch_array($result, MYSQLI_ASSOC); + + return $row; + }else return ["erro"=>mysqli_error($this->con)]; + + } + + public function updateWrongPoints() + { + $result=[]; + + return $result; + } + + public function getSuperviseurNetwork($codeparrain,$user_id){ + $self=$this->getAgentByCodeMembre($codeparrain); + $catparrain=$self['category']; + $catchild=($catparrain=='hyper')?'super':($catparrain=='super'?'geolocated':null); + if($catchild) { + $result = mysqli_query($this->con, "select ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat FROM networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id +INNER JOIN networks nt ON na.network_id=nt.id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN countries ct + ON nt.country_id=ct.id WHERE cg.code_parrain='$codeparrain' AND cg.code_membre!='$codeparrain' AND na.etat='1' AND cg.category='$catchild'"); + + $rows = []; + $re = []; + if ($result) { + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + $re['val'] = $rows; + $re['success'] = 1; + $re['catchild']=$catchild; + $re['catparrain']=$catparrain; + } else { + $re['error'] = mysqli_error($this->con); + } + }else{ + $re['error']='cat child not found'; + } + return $re; + } + + public function getPointsNetwork($network,$user_id){ + $result=mysqli_query($this->con,"SELECT ag.firstname,cg.code_membre,cg.code_parrain,ag.adresse, +ag.lastname,na.phone,ag.email,na.solde,cg.category,ne.name as network,ct.id as country,ag.longitude,ag.latitude,ag.id as AgentId,ne.id as network_id,ct.id as country_id +FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN +codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id INNER JOIN countries ct ON ct.id=ne.country_id WHERE cg.category='geolocated' AND na.etat='1' AND na.network_id='$network' AND ag.longitude>0 AND ag.latitude>0 LIMIT 100"); + if($result) { + $rows=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $rows[] = $row; + } + return $rows; + }else + { + return ["error"=>mysqli_error($this->con)]; + } + } + + private function getUserByPhoneAndPassword($phone, $password,$table) { + $result = mysqli_query($this->con,"SELECT usr.active,usr.salt,usr.encrypted_password,usr.firstname,usr.lastname,usr.id,usr.phone,usr.email,usr.solde,usr.validation_code,usr.active,usr.network_id,ne.name as network,ne.country_id,ct.name as country,ct.code_dial,ct.code_country FROM $table usr INNER JOIN networks ne ON usr.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE phone = '$phone'") or die(mysqli_error($this->con)); + // check for result + $no_of_rows = mysqli_num_rows($result); + if ($no_of_rows > 0) { + $result = mysqli_fetch_array($result,MYSQLI_ASSOC); + $salt = $result['salt']; + $encrypted_password = $result['encrypted_password']; + $hash = $this->checkhashSSHA($salt, $password); + // check for password equality + if ($encrypted_password == $hash) { + // user authentication details are correct + return $result; + }else{ + return ['error'=>-3]; + } + } else { + // user not found + return ['error'=>-2,"use"=>$no_of_rows]; + } + } + + public function hashSSHA($password) { + + $salt = sha1(rand()); + $salt = substr($salt, 0, 10); + $encrypted = base64_encode(sha1($password . $salt, true) . $salt); + $hash = array("salt" => $salt, "encrypted" => $encrypted); + return $hash; + } + + public function forgotPasswordSimple($phone, $encrypted_password, $salt) + { + $result = mysqli_query($this->con, "UPDATE `users` SET `encrypted_password` = '$encrypted_password',`salt` = '$salt' WHERE `phone` = '$phone'"); + + if ($result) { + + return true; + + } else { + return false; + } + } + + public function getEmailSimple($phone){ + $result = mysqli_query($this->con,"SELECT email FROM users WHERE phone = '$phone'"); + + if ($result) { + return mysqli_fetch_array($result); + //return true; + + } + else + { + return false; + } + + } + + public function listNetwork(){ + echo "request"; + $res=mysqli_query($this->con,"SELECT * FROM network"); + if($res){ + return mysqli_fetch_array($res); + + }else return ['error'=>'unable to make request','error_'=>mysqli_error($this->con)]; + } + + private function checkhashSSHA($salt, $password) { + + $hash = base64_encode(sha1($password . $salt, true) . $salt); + + return $hash; + } + /** + * Verifies user by phone and password + */ + public function getUserByPhoneAndPasswordSimple($phone, $password) { + return $this->getUserByPhoneAndPassword($phone,$password,'users'); + } + /** + * Verifies user by phone and password + */ + public function generateRandomString($length = 10) { + $characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + public function getUserByPhoneAndPasswordGeolocated($phone, $password) { + // connecting to mysql + $result = mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname,ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone,na.transactionNumber as phoneTransaction, +ne.id as network_id,ag.date_created as date_created,cg.category as category, + ag.salt as salt,ag.encrypted_password as encrypted_password,ne.name as network,ct.name as country + ,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id + INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE na.phone='$phone' or na.transactionNumber='$phone'"); + if($result){ + if(mysqli_num_rows($result)>0) { + $mr=[]; + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $salt = $row['salt']; + $encrypted_password = $row['encrypted_password']; + $hash = $this->checkhashSSHA($salt, $password); + $mr["hash"]=$hash; + $mr["encrypted_password"]=$encrypted_password; + if ($encrypted_password == $hash) { + if ($row['category'] == 'super') { + $phone = $row["phone"]; + $demandere = mysqli_query($this->con, "SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if ($demandere) + $row['etat_demande'] = mysqli_fetch_array($demandere, MYSQLI_ASSOC)['etat']; + else + echo mysqli_error($this->con); + } + if($row['category']!='geolocated'){ + $row['nbre_membre']=$this->getNbMemberOf($row['code_membre']); + + + } + + return $row; + } + + return ['error'=>-3,"error_msg"=>"Mot de passe incorrect","last"=>$row]; + } + }else + return ['error'=>-1,"error_msg2"=>"Numéro incorrect",]; + } + + else + return ['error'=>-2,"error_msg2"=>mysqli_error($this->con)]; + + } + + public function getAgentNetworkByPhone($phone){ + $listIdmemberParrain=mysqli_query($this->con, "SELECT ag.uid as uid,ag.firstname AS firstname, +ag.lastname AS lastname, +ag.email AS email,ag.longitude as longitude,ag.latitude AS latitude,ag.active as active, +na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.etat AS etat +,cg.code_parrain AS code_parrain,cg.code_membre AS code_membre,na.phone as phone, +ne.id as network_id, +na.id as networkAgentId, + ag.date_created as date_created,cg.category as category,ag.salt as salt,ag.encrypted_password as encrypted_password, + ne.name as network,ct.name as country,ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau + FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id + INNER JOIN networks as ne ON na.network_id=ne.id INNER JOIN countries ct ON ct.id=ne.country_id WHERE + na.phone='$phone'"); + if($listIdmemberParrain){ + $membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC); + if($membre['category']=='super'){ + $phone=$membre["phone"]; + $demandere=mysqli_query($this->con,"SELECT etat FROM demandeAdhesion WHERE phone='$phone'"); + if($demandere){ + $membre['etat_demande']=mysqli_fetch_array($demandere,MYSQLI_ASSOC)['etat']; + } + } + return $membre; + }else { + echo mysqli_error($this->con); + return false; + } + + } + + public function storeDemandeCredit($phone,$montant,$code){ + $agent=$this->getAgentWithCodeMembre($code); + if($agent) { + $idag=$agent['agentId']; + $q = mysqli_query($this->con, "INSERT INTO demandeCredits(network_agent_id,montant,status) VALUES('$idag','$montant','0')"); + if ($q) { + return ['success' => 1, "agent" => $agent]; + } + } + return false; + +} + + private function createAgent($fname, $lname, $email, $phone, $password, $network, $member, $latitude, $longitude, $town,$phoneTransaction) + { + + $resultFreeCode = mysqli_query($this->con, "SELECT id,code_membre,category,code_parrain from codeGenerer cg WHERE code_membre='$member' "); + if($resultFreeCode){ + $freecodenum=mysqli_num_rows($resultFreeCode); + if($freecodenum>0) { + $codes = mysqli_fetch_array($resultFreeCode, MYSQLI_ASSOC); + $freecode = $codes; + $code_id = $freecode['id']; + $category=$freecode["category"]; + $uuid = uniqid('', true); + $balance = 0; + $etat=0; + if($category=="geolocated"){ + $etat=0; + } + + $hash = $this->hashSSHA($password); + $encrypted_password = $hash["encrypted"]; + $salt = $hash["salt"]; + $validation_code = $this->random_string(); + + if(isset($town->id)) { + $townid = $town->id; + + $agentCreateResult = mysqli_query($this->con, "INSERT INTO agents(uid,adresse, +lastname,email,longitude,latitude +,balance,encrypted_password,salt,active,date_created,town_id) VALUES ('$uuid', +'$fname','$lname','$email','$longitude','$latitude','$balance','$encrypted_password','$salt','$etat',NOW(),'$townid')"); + if ($agentCreateResult) { + $agent_id = mysqli_insert_id($this->con); + if ($agent_id) { + + + + $result = mysqli_query($this->con, "INSERT INTO networks_agents(network_id,agent_id, +solde,etat,codeGenerer_id,phone,validation_code,transactionNumber) +VALUES('$network->id','$agent_id','$balance','$etat','$code_id','$phone','$validation_code','$phoneTransaction')"); + if ($result) { + // get user details + + $agent= $this->getAgentById($agent_id); + $resque=mysqli_query($this->con,"UPDATE codeGenerer SET etat='1' WHERE code_membre='$member'"); + if($resque){ + if($agent['category']=='super'){ + $re=$this->adddemandeAdhesionAgent($agent); + if(!isset($re['success']))return $re; + } + }else{ + return [ + 'error' => 'impossible de de mettre à jour', + 'sql_error' => mysqli_error($this->con), + ]; + } + return $agent; + } else { + return [ + 'error' => 'impossible de créer un network_agent', + 'sql_error' => mysqli_error($this->con), + 'code_generer' => $freecode + ]; + } + + } else { + return [ + 'error' => 'impossible recuperer l agent', + 'sql_error' => mysqli_error($this->con), + 'code_generer' => $freecode + ]; + } + + } else { + return [ + 'error' => 'impossible de créer un agent', + 'sql_error' => mysqli_error($this->con) + ]; + } + }else{ + return ['error'=>-4,'error_msg'=>'la ville que vous aviez entrée n\'est pas encore pris en compte ','ville'=>$town]; + } + + }else return ['error'=>"ce parrain à atteint son quota de membre"]; + }else{ + return ["error"=>"impossible de recuperer verifier la disponibilité ","error_msg"=>mysqli_error($this->con)]; + } + } + + public function generateValideCode($membre, $category) + { + $code=null; + $valide=false; + do{ + $code=$this->generateRandomString(); + $q = mysqli_query($this->con, "SELECT * from codeGenerer WHERE code_membre='$code'"); + if ($q) { + $valide = mysqli_num_rows($q) == 0; + $qe=mysqli_query($this->con, "INSERT INTO codeGenerer(code_parrain,code_membre,category,etat) VALUES ('$membre','$code','$category',0)"); + if(!$qe){ + echo mysqli_error($this->con); + return null; + } + }else{ + echo mysqli_error($this->con); + return null; + } + }while(!$valide); + return $code; + } + + private function adddemandeAdhesionAgent($agent) + { + $codeparrain=$agent['code_parrain']; + $resParrain=mysqli_query($this->con,"SELECT na.id as agentId FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$codeparrain'"); + if($resParrain){ + $parrain=mysqli_fetch_array($resParrain,MYSQLI_ASSOC); + $agentId=$parrain['agentId']; + if($agentId){ + $phone=$agent['phone']; + $resDemande=mysqli_query($this->con,"INSERT INTO demandeAdhesion(phone,networks_agent_id) VALUES ('$phone','$agentId')"); + if($resDemande){ + return ['success'=>1]; + }else{ + return ["error"=>1,"sql"=>mysqli_error($this->con),'agent'=>$agent]; + } + } + }else{ + return ['error'=>'error','ssql'=>mysqli_error($this->con),'agent'=>$agent]; + } + } + + public function storeUserSimple($firstname, $lastname, $email, $phone, $password, $network) + { + $uuid = uniqid('', true); + $balance =0; + $hash = $this->hashSSHA($password); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; // salt + //$validation_code = generateRandomString(); + $codeCorrect=true; + do{ + $validation_code = $this->random_string(); + $q=mysqli_query($this->con,"SELECT * FROM networks_agents WHERE validation_code='$validation_code'"); + $rowcount=mysqli_num_rows($q); + $codeCorrect=$rowcount<0; + }while($codeCorrect); + $networkid=$network->id; + $result = mysqli_query($this->con, + "INSERT INTO users(uid, adresse,lastname, phone, email, solde, encrypted_password, +salt,validation_code, active,network_id) VALUES + ('$uuid', '$firstname', '$lastname', '$phone','$email','$balance','$encrypted_password', '$salt', + '$validation_code','0','$networkid')"); + // check for successful store + if ($result) { + // get user details + $uid = mysqli_insert_id($this->con); // last inserted id + $result = mysqli_query($this->con,"SELECT ne.name as reseau,ct.name as country,usr.firstname as firstname +,usr.lastname as lastname,usr.phone as phone,usr.email as email,usr.validation_code as validation_code FROM users usr INNER JOIN networks ne ON ne.id=usr.network_id INNER JOIN countries ct ON ct.id=ne.country_id WHERE usr.id = '$uid'"); + // return user details + if($result){ + return mysqli_fetch_array($result); + + }else return ['error'=>'error geting information','sql'=>mysqli_error($this->con)]; + } else { + return ['error'=>'error saving information','sql'=>mysqli_error($this->con)]; + } + + } + + public function generateNetworkAgent($phone, $code_parrain,$agent) + { + $code=$this->generateValideCode($code_parrain,"geolocated"); + $resParrain=mysqli_query($this->con,"SELECT * FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN towns tw ON ag.town_id=tw.id INNER JOIN countries ct ON tw.country_id=ct.id WHERE cg.code_membre='$code_parrain'"); + + if($resParrain) { + $parrain = mysqli_fetch_array($resParrain, MYSQLI_ASSOC); + $networkId = $parrain['network_id']; + + $phone = $parrain['code_dial'] . $phone; + if (true) { + $resgg = mysqli_query($this->con, "SELECT * FROM codeGenerer cg WHERE cg.code_membre='$code'"); + if ($resgg) { + $membre = mysqli_fetch_array($resgg, MYSQLI_ASSOC); + $codeGenererId = $membre['id']; + $codevalide=true; + do{ + $validation_code = $this->random_string(); + $se=mysqli_query($this->con,"SELECT * FROM networks_agents WHERE validation_code='$validation_code'"); + $codevalide=mysqli_num_rows($se)>0; + }while($codevalide); + $agentPhone=$agent['phone']; + $result = mysqli_query($this->con, "INSERT INTO networks_agents(network_id,solde,etat,codeGenerer_id,transactionNumber,phone,validation_code)VALUES('$networkId','0','0','$codeGenererId','$phone','$agentPhone','$validation_code')"); + if ($result) { + $geoId=mysqli_insert_id($this->con); + if (mysqli_query($this->con, "UPDATE codeGenerer SET etat='1' WHERE code_membre='$code'")) + return ['success' => 1,'phone'=>$phone,'code_membre' => $membre['code_membre'], 'validation_code' => $validation_code,"id"=>$geoId]; + else { + $da = ['error' => -7, 'error_msg' => 'impossible de mettre à jour les informations du code membre', 'sql' => mysqli_error($this->con)]; + mysqli_query($this->con, "DELETE FROM codeGenerer WHERE code_membre='$code'"); + return $da; + } + } else { + $da = ['error' => -5, 'error_msg' => 'impossible de recuperer les informations du de code generer', 'sql' => mysqli_error($this->con)]; + mysqli_query($this->con, "DELETE FROM codeGenerer WHERE code_membre='$code'"); + + return $da; + + } + + } else { + return ['error' => -4, 'error_msg' => 'impossible de recuperer les informations du de code generer', 'sql' => mysqli_error($this->con)]; + + } + } + else { + return ['error' => -7, 'error_msg' => 'le numéro de téléphone est invalide', 'phone' =>$phone,"parrain"=>$parrain]; + } + } else { + return ['error' => -3, 'error_msg' => 'impossible de recuperer les information du parrain', 'sql' => mysqli_error($this->con)]; + } + } + + public function getGeoLocatedFreeWithValidationCode($validation_code) + { + $qu=mysqli_query($this->con,"SELECT na.id as id,na.validation_code as validation_code,na.etat as etat, na.agent_id as agent_id,cg.code_membre as code_membre,cg.code_parrain as code_parrain, cg.category as category FROM networks_agents na INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE na.validation_code='$validation_code' AND cg.category='geolocated' AND na.agent_id is null"); + if($qu){ + $num_row=mysqli_num_rows($qu); + if($num_row>0) { + $geo = mysqli_fetch_array($qu, MYSQLI_ASSOC); + return $geo; + }else { + return ['error'=>'Ce code n\'est disponible']; + } + }else{ + return false; + } + + + + } + + public function assignNetworkAgent($idAgent, $idNetworkAgent) + { + $re=mysqli_query($this->con,"UPDATE networks_agents SET agent_id='$idAgent',etat='1' WHERE id='$idNetworkAgent'"); + if($re){ + return ['success'=>1]; + }else return ['error'=>mysqli_error($this->con)]; + } + + public function getListNetworkOfGeoPoint($user_id) + { + $q=mysqli_query($this->con,"SELECT na.id as id,na.network_id as network_id,na.solde as solde,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE ag.id='$user_id'"); + if($q){ + + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListFreeNetworkOfGeoPoint($code_parrain) + { + $q=mysqli_query($this->con,"SELECT na.id as id,na.network_id as network_id,na.solde as solde,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name,na.validation_code as validation_code from networks_agents na INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE cg.code_parrain='$code_parrain' AND cg.code_membre!='$code_parrain' AND na.agent_id IS NULL"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListDemandeReceiveAgent($codeparrain) + { + + $q=mysqli_query($this->con,"SELECT dc.id as id,dc.montant as montant,dc.date_creation,dc.date_modification,dc.status as status,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name,ne.name as reseau from demandeCredits dc INNER JOIN networks_agents na ON na.id=dc.network_agent_id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE cg.code_parrain='$codeparrain'"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function getListDemandeSendAgent($user_id) + { + $q=mysqli_query($this->con,"SELECT ne.name as reseau, dc.id as id,dc.montant as montant,dc.date_creation,dc.date_modification,dc.status as status,na.phone as phone,cg.code_membre as code_membre, cg.code_parrain as code_parrain,cg.category as category,ne.name as name from demandeCredits dc INNER JOIN networks_agents na ON na.id=dc.network_agent_id INNER JOIN agents ag ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id WHERE ag.id='$user_id'"); + if($q){ + $rows=[]; + while($row=mysqli_fetch_array($q,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>mysqli_error($this->con)]; + + } + + public function treatDemand($user_id) + { + $dat=date ("Y-m-d H:i:s"); + $q=mysqli_query($this->con,"UPDATE demandeCredits SET status='1',date_modification='$dat' WHERE id='$user_id'"); + if($q){ + $qdemande=mysqli_query($this->con,"SELECT * from demandeCredits dc WHERE dc.id='$user_id'"); + if($qdemande) { + $demande = mysqli_fetch_array($qdemande, MYSQLI_ASSOC); + $montant = (int)$demande["montant"]; + $id = $demande['network_agent_id']; + return ['success' => 1,"montant"=>$montant]; + + } + } + return ['error'=>mysqli_error($this->con)]; + + + } + + private function getNbMemberOf($code_membre) + { + $q=mysqli_query($this->con,"SELECT DISTINCT COUNT(*) AS nbr_membre FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_parrain='$code_membre' AND cg.code_membre!='$code_membre' AND na.etat='1'"); + if($q){ + return mysqli_fetch_array($q,MYSQLI_ASSOC)['nbr_membre']; + }else{ + return 0; + } + } + + public function getPointInDistance($reseau,$position, $distance,$page) + { + $mlat=$position->latitude; + $mlong=$position->longitude; + $re=$reseau->id; + $offset=$page*50; + $res= mysqli_query($this->con,"SELECT ag.id as agentId,na.id as id,ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat + FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN networks nt ON na.network_id=nt.id INNER JOIN countries ct ON ct.id=nt.country_id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.category='geolocated' AND na.etat=1 AND getDistanceMetre($mlat,ag.latitude,$mlong,ag.longitude)<=$distance AND nt.id=$re ORDER BY agentId LIMIT 51 OFFSET $offset"); + if($res){ + $li=["page"=>$page,"offset"=>$offset,"total"=>$offset,"count"=>0]; + while ($r=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $li["items"][]=$r; + $li["count"]=$li["count"]+1; + $li["total"]=$li["total"]+1; + } + return $li; + }else return mysqli_error($this->con); + } +} \ No newline at end of file diff --git a/database/Requester.php b/database/Requester.php new file mode 100644 index 0000000..7f1b5cc --- /dev/null +++ b/database/Requester.php @@ -0,0 +1,973 @@ +db = new DataBaseConnector(); + $this->user_id = $user_id; + $this->messenger=new Messenger(); + $la=$lang; + $pos=strpos($la,"-"); + if($pos!=false){ + $la=strtolower(explode("-",$la)[0]); + } + if(in_array($la,$this->enLangs))$la='en'; + + try{ + if(!file_exists("./../static/$la/message.json")){ + $la="en"; + } + + $this->messageText=file_get_contents("./../static/$la/message.json"); + $this->messageText=json_decode($this->messageText,true); + }catch(Exception $e){ + $subject = "Password Recovery"; + $message ="erreur : la=".$la; + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + $this->messenger->setMessage($message); + $this->messenger->setContact($number); + $this->messenger->setMail($mail['email']); + $this->messenger->sendMail(); + } + } + public function getPasValue(){ + $pasObject=$this->db->getPasValue(); + if($pasObject)return json_encode(['pas'=>$pasObject]); + else return json_encode(['error'=>mysqli_error($this->db->con)]); + } + public function getPubValue($id_country){ + $pasObject=$this->db->getPubValue($id_country); + if($pasObject)return json_encode(['pub'=>$pasObject]); + else return json_encode(['error'=>mysqli_error($this->db->con)]); + } + public function deleteAgent($code){ + $agent=$this->db->getAgentWithCodeMembre($code); + if($agent){ + $codeId=$agent['idCode']; + $res=mysqli_query($this->db->con,"DELETE FROM networks_agents where codeGenerer_id='$codeId'"); + $re=mysqli_query($this->db->con,"DELETE FROM codeGenerer where id='$codeId'"); + return json_encode(['count_network'=>mysqli_num_rows($res),"count_code"=>mysqli_num_rows($re)]); + } + } + public function loginPhonePassword($phone, $password) + { + // check for user + $user = $this->loginUser($phone, $password); + if (!$user) { + $user = $this->loginAgent($phone, $password); + if (!$user) { + $response["error"] = 1; + $response["error_msg"] =$this->messageText["PHONE_OR_NUMBER_INCORRECT"] ; + return $response; + } + } + return $user; + } + public function getAgentInfoByCode($code){ + $codes=$this->getChildCode($code); + if(isset($codes["child"])){ + $codes['network']=$this->db->getAgentNetworkByCode($code); + } + return json_encode($codes); + } + public function getSuperviseurNetwork($codesuperviseur) + { + $point = $this->db->getSuperviseurNetwork($codesuperviseur, $this->user_id); + if (isset($point['success'])) { + $response['success'] = 1; + $response['datas'] = $point['val']; + $response['catchild']=$point['catchild']; + $response['catparent']=$point['catparrain']; + return $response; + } else { + $response = ['error' => 1, + 'error_msg' => $this->messageText['UNABLE_TO_GET_GEOLOCATED_POINT'], 'sql_error' => $point["error"]]; + return $response; + } + } + public function getAllCountryPoint($country) + { + $point = $this->db->getAllPointInCountry($country); + if ($point) { + $response['success'] = 1; + $response['datas'] = $point; + return $response; + } else { + $response = ['error' => 1, 'error_msg' => "impossible de recupere les points de cette ville"]; + return $response; + } + } + public function recoverPasswordAgent($number) + { + if ($this->db->isPhoneExistedSimple($number)) { + $randomcode = $this->db->random_string(); + $hash = $this->db->hashSSHA($randomcode); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; + $user = $this->db->forgotPasswordSimple($number, $encrypted_password, $salt); + if ($user) { + $mail = $this->db->getEmailSimple($number); + if ($mail) { + $subject = "Password Recovery"; + $message = sprintf($this->messageText['TEXT_RECOVERY_PASSWORD'],$randomcode); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + $this->messenger->setMessage($message); + $this->messenger->setContact($number); + $this->messenger->setMail($mail['email']); + $this->messenger->sendMail(); + $this->messenger->sendSms(); + + // Stop Sending SMS + $response["success"] = 1; + + $response["message"] =sprintf($this->messageText['MESSAGE_SUCCESS_RECOVERY_PASSWORD'],$mail["email"]); + return $response; + } else { + $response["error"] = -6; + $response["message"] = "impossible d'envoyer le mail"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + } + } else { + $response["error"] = -7; + $response["message"] = "impossible de changer le mots de passe"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + + } + }else + return ['error' => -5, 'message' => "Ce numéro n'existe pas",'phone'=>$number]; + } + public function recoverUserPassword($number) + { + if ($this->db->isPhoneExistedSimple($number)) { + $randomcode = $this->db->random_string(); + $hash = $this->db->hashSSHA($randomcode); + $encrypted_password = $hash["encrypted"]; // encrypted password + $salt = $hash["salt"]; + $user = $this->db->forgotPasswordSimple($number, $encrypted_password, $salt); + if ($user) { + $mail = $this->db->getEmailSimple($number); + if ($mail) { + $subject = "Password Recovery"; + $message = sprintf($this->messageText['TEXT_RECOVERY_PASSWORD'],$randomcode); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + $this->messenger->setMessage($message); + $this->messenger->setContact($number); + $this->messenger->setMail( $mail["email"]); + $this->messenger->sendMail(); + //$this->messenger->sendSms(); + + // Stop Sending SMS + $response["success"] = 1; + $response["message"] = sprintf($this->messageText['MESSAGE_SUCCESS_RECOVERY_PASSWORD'],$mail["email"]); + return $response; + } else { + $response["error"] = -6; + $response["message"] = "impossible d'envoyer le mail"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + } + } else { + $response["error"] = -7; + $response["message"] = "impossible de changer le mots de passe"; + $response["last_error"] = mysqli_error($this->db->con); + return $response; + + } + }else + return ['error' => -5, 'message' => 'Ce numéro n\'existe pas',"phone"=>"$number"]; + + } + private function sendMail($email, $subject, $message, $headers) + { + mail($email, $subject, $message, $headers); + } + private function sendMessage($message, $number) + { + $sms = $this->client->account->messages->create( + $number, + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => sender_number, + + + // the sms body + 'body' => $message + ) + ); + } + public function getPointAroundKm($reseau,$position, $distance,$page) + { + $list=$this->db->getPointInDistance($reseau,$position,$distance,$page); + return json_encode($list); + } + public function getNetworkPoint($network) + { + $points = $this->db->getPointsNetwork($network, $this->user_id); + if (!isset($points['error'])) { + $pts=['success'=>1,'datas'=>$points]; + return json_encode($pts); + } else + return json_encode(['error' => -4, 'error_msg' => 'error query','mysql'=> mysqli_error($this->db->con),"data"=>$points,"network"=>$network,"user"=>$this->user_id]); + + } + function distance($lat1, $lon1, $lat2, $lon2) + { + + $theta = $lon1 - $lon2; + + $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); + $dist = acos($dist); + $dist = rad2deg($dist); + $miles = $dist * 60 * 1.1515; + $unit = "K"; + + if ($unit == "K") { + return ($miles * 1.609344); + } else if ($unit == "N") { + return ($miles * 0.8684); + } else { + return $miles; + } + } + public function registerGeolocated($request) + { + if ($this->db->isPhoneExistedInCategory($request->phone, $request->category,$request->phone_transaction)) { + // user is already existed - error response + $response["error"] = 1; + $response["error_msg"] = $this->messageText['ALREADY_PHONE_NUMBER']; + echo json_encode($response); + } else { + if ($checkValidity = $this->db->checknumberValidity($request->phone)) { + $membercodetest = $this->db->isMemberCodeExisted($request->member); + if ($membercodetest) { + $user = $this->db->storeUser($request->address, $request->lastname, $request->email, $request->phone, + $request->password, $request->network, $request->member, $request->latitude, $request->longitude, $request->town,$request->phone_transaction); + if ($user != null && !isset($user['error'])) { + //if ($user) { + // user stored successfully + $user["success"] = 1; + $validation = $user["validation_code"]; + $username = $user["lastname"]; + $subject = "Bienvenue sur Ilink"; + $code=$user["code_membre"]; + $phone = $user['phone']; + $ct=($user['category']=='geolocated'?$this->messageText['AGENT_GEO']:($user['category']=='super'?$this->messageText['ADMIN']:$this->messageText['SUPER_ADMIN'])); + $message1 =sprintf($this->messageText['MESSAGE_1'],$username,$ct,$phone,$request->password,$code,$validation); + $message2 = sprintf($this->messageText['MESSAGE_2'],$username,$ct,$phone,$request->password,$code); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setMail($user['email']); + $this->messenger->setContact($user['phone']); + $this->messenger->setMessage($user['category']=='super'?$message2:$message1); + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + if (!$this->messenger->sendMail()) { + return json_encode(error_get_last()); + }; + $sms = $this->messenger->sendSms(); + + + } + return json_encode($user); + + /* echo "Réseau : ".strtoupper($user["network"])."
"; + echo "
"; + echo "Nom(s) :".$user["lastname"]."
"; + echo "Email par défaut du réseau : ".$user["email"]."
"; + echo "Telephone :".$user["phone"]."
"; + echo "Code membre pour le réseau : ".$user["code_membre"]."
"; + echo "
";*/ + } else { + return json_encode(['error' => 'unable to get membrre', 'error_msg' => $this->messageText['NO_CODE_MEMBER']]); + + } + }else{ + return json_encode(['error' => 'unable to get membrre',"msg"=>$this->messageText, 'error_msg' => $this->messageText['INVALID_PHONE']]); + + } + } + + + } + public function getNetwork() + { + return json_encode($this->db->getNetwork()); + } + public function loginUser($phone, $password) + { + $user = $this->db->getUserByPhoneAndPasswordSimple($phone, $password); + if (!isset($user['error'])) { + // user found + // echo json with success = 1 + $user["success"] = 1; + if(isset($user['active'])) + $user['etat']=$user['active']; + + } else { + switch ($user['error']){ + case -2:$user['error_msg']=$this->messageText['WRONG_PHONE_NUMBER']; + $user['sql']=mysqli_error($this->db->con); + break; + case -3: + $user['error_msg']=$this->messageText['WRONG_PASSWORD'];break; + } + } + return $user; + } + public function loginAgent($phone, $password) + { + $user = $this->db->getUserByPhoneAndPasswordGeolocated($phone, $password); + if (!isset($user['error'])) { + // user found + // echo json with success = 1 + $user["success"] = 1; + return $user; + + } else + + return $user; + + } + public function getSupervisorAdhesionList($codeparrain) + { + $resparrain=mysqli_query($this->db->con,"SELECT na.id as id FROM networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_membre='$codeparrain'"); + if($resparrain){ + $parrain=mysqli_fetch_array($resparrain,MYSQLI_ASSOC)['id']; + + $r=mysqli_query($this->db->con,"select ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone ,ne.name as network,cg.code_membre as code_membre,cg.code_parrain as code_parrain,ds.etat as etat + from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id INNER JOIN networks ne ON na.network_id=ne.id INNER JOIN demandeAdhesion ds ON 1=1 WHERE ds.networks_agent_id='$parrain' AND cg.code_membre!='$codeparrain' AND na.etat='0' AND ds.etat='0' AND cg.code_parrain='$codeparrain'"); + $rows=[]; + if($r) { + while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { + + $rows[] = $row; + } + if (count($rows) > 0) { + return $rows; + } else { + echo mysqli_error($this->db->con); + return $rows; + } + }else{ + + return ['error'=>mysqli_error($this->db->con)]; + } + }else{ + return mysqli_error($this->db->con); + + } + } + public function getChildCode($codeparrain) + { + $r=$this->db->getCategoryAgent($codeparrain); + if($r['etat']==1){ + switch ($r['category']){ + case 'hyper': + $r['child']='super'; + break; + case 'super': + $r["child"]="geolocated"; + break; + } +} + return $r; + } + public function updateWrongPoint() + { + $result=[]; + try{ + $result = mysqli_query($this->db->con, "UPDATE users_simple SET firstname = REPLACE(firstname, 'é', 'é') WHERE firstname LIKE '%é%'"); + }catch (Exception $e) { + var_dump(mysqli_error($this->db->con)); + } + $da="freud junior"; + + return $result; + } + public function storeCreditAsk($phone,$montant,$code) + { + $result=$this->db->storeDemandeCredit($phone,$montant,$code); + if ($result) { + $usr=$result['agent']; + $codeParrain=$usr['code_parrain']; + $parrain=$this->db->getAgentWithCodeMembre($codeParrain); + $num=$parrain['transactionNumber']; + $subject = $this->messageText['NEW_DEMAND_TITLE']; + $email = $usr['email']; + $message = sprintf($this->messageText['SEND_CREDIT_DEMAND_TEXT_SUCCESS'],$phone,$montant,$num); + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setHeader($headers); + $this->messenger->setContact($phone); + $this->messenger->setMessage($message); + $this->messenger->setMail($email); + $this->messenger->setSubject($subject); + $this->messenger->sendMail(); + try { + $this->messenger->sendSms(); + }catch (Exception $e){ + + } + } else { + // user failed to store + $response["error"] = 1; + $response["result"]=$result; + $response["error_msg"] = $this->messageText['UNABLE_TO_SEND_DEMAND']; + $response["sql"]=mysqli_error($this->db->con); + $response["last"]=error_get_last(); + $response["montant"]=$montant; + $response["phone"]=$phone; + echo json_encode($response); + + } + return json_encode($result); + + } + + + + public function getCountryNetWork($indicatif) + + { + $res=mysqli_query($this->db->con, + "SELECT nt.id AS id, nt.name AS name,nt.country_id AS countryId FROM networks nt INNER JOIN countries ct + ON nt.country_id=ct.id WHERE ct.code_dial='$indicatif' AND nt.name!=''AND nt.status=1"); + if($res){ + $rows=[]; + while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>'unable to query list networks','error_sql'=>mysqli_error($this->db->con)]; + + } + + public function getTownInfoByName($name) + { + + $res=mysqli_query($this->db->con,"SELECT nt.name as name,nt.id as id ,ct.code_dial as indicatif FROM towns nt INNER JOIN countries ct ON nt.country_id=ct.id WHERE UPPER(nt.name)=UPPER('$name')"); + if($res){ + while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $rows[]=$row; + } + if($rows==null){ + return ['error'=>'unable to query town information','ville'=>$name,'error_sql'=>mysqli_error($this->db->con)]; + + } + return $rows; + }else + return ['error'=>'unable to query town information','ville'=>$name,'error_sql'=>mysqli_error($this->db->con)]; + + } + + public function getListTownsCountry($indicatif) + { + + $res=mysqli_query($this->db->con,"SELECT nt.name as name,nt.id as id ,ct.code_dial as indicatif FROM towns nt INNER JOIN countries ct ON nt.country_id=ct.id WHERE ct.code_dial='$indicatif'"); + if($res){ + $rows=[]; + while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return $rows; + }else + return ['error'=>'unable to query list towns','indicatif'=>$indicatif,'error_sql'=>mysqli_error($this->db->con)]; + + } + + public function validateAgent($phone, $code_validation,$mbre_reseau=null,$mr_sous_reseau=null) + { + if(isset($phone) && isset($code_validation)){ + $res=mysqli_query($this->db->con,"SELECT na.id as agentId,ag.id as agId,cg.category as category,cg.code_membre as code_membre,cg.code_parrain AS code_parrain FROM agents ag INNER JOIN networks_agents na on ag.id=na.agent_id inner JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE (na.phone='$phone' OR na.transactionNumber='$phone') AND na.validation_code='$code_validation' ORDER BY agId DESC LIMIT 1"); + if($res){ + if(mysqli_num_rows($res)>0){ + $net=mysqli_fetch_array($res,MYSQLI_ASSOC); + $agentId=$net['agentId']; + $agId=$net['agId']; + $codeparrain = $net['code_parrain']; + $codeMembre=$net['code_membre']; + $re = mysqli_query($this->db->con, "SELECT ag.id as parrainId, ag.number_super as nbre_reseau,ag.number_geoBysuper as nbre_sous_reseau FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id inner JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE cg.code_membre='$codeparrain'"); + if($re) { + $parrain = mysqli_fetch_array($re, MYSQLI_ASSOC); + $nbre_sup = $parrain['nbre_sous_reseau']; + $nbre = $parrain['nbre_reseau']; + $parrainId=$parrain['parrainId']; + switch ($net['category']) { + case 'hyper': + if (isset($mbre_reseau) && isset($mr_sous_reseau)) { + $r = mysqli_query($this->db->con, "UPDATE `networks_agents` SET etat = '1' WHERE `id` = $agentId "); + $var3["message_erreur_1"] = mysqli_error($this->db->con); + $rs = mysqli_query($this->db->con, "UPDATE agents SET number_super='$mbre_reseau',number_geoBysuper='$mr_sous_reseau' WHERE id='$agId'"); + if ($r && $rs) { + + $var3["success"] = 1; + $var3["message"] = "User has been validated successfully !"; + return $var3; + } else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + } else { + + $var3["error"] = -2; + $var3["message"] = "no nbre reseau et sous reseau"; + return $var3; + + } + break; + case 'geolocated': + $r = mysqli_query($this->db->con, "UPDATE networks_agents SET etat = '1' WHERE id = '$agentId' "); + if ($r) { + $nbre -= $nbre > 0 ? 1 : 0; + mysqli_query($this->db->con, "UPDATE agents SET number_geoBysuper = '$nbre' WHERE `id` = '$parrainId' "); + $var3["success"] = 1; + $var3["message"] = "User has been validated successfully !"; + return $var3; + } else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + break; + case 'super': + $rs = mysqli_query($this->db->con, "UPDATE agents SET number_geoBysuper='$nbre_sup',number_super='$nbre_sup' WHERE id='$agId'"); + if ($rs) { + if (mysqli_num_rows($re) > 0) { + $r = mysqli_query($this->db->con, "UPDATE `networks_agents` SET etat = '1' WHERE id ='$agentId'"); + if ($r) { + $nbre -= $nbre > 0 ? 1 : 0; + if(mysqli_query($this->db->con, "UPDATE `agents` SET number_super = '$nbre' WHERE id='$parrainId'")){ + $var3["success"] = 1; + $var3['nbre_sup']=$nbre; + $var3["message"] = "User has been validated successfully !"; + return $var3; + + }else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + + } else { + $var3["error"] = 1; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + + } else { + $var3["error"] = -4; + $var3["message"] = "impossible de trouve le parrain"; + $var3["error_sql"]=mysqli_error($this->db->con); + $var3["re"]=$re; + $var3['parrain']=$net; + return $var3; + + } + } else { + $var3["error"] = -3; + $var3["message"] = mysqli_error($this->db->con); + return $var3; + } + break; + } + }else{ + return ['error'=>'impossible de recuperer le parrain','error_msg'=>mysqli_error($this->db->con)]; + + } + }else{ + return ['error'=>'invalide code','error_msg'=>"code de validation incorrect"]; + } + }else{ + return ['error'=>'unable to query info network agent','error_msg'=>mysqli_error($this->db->con)]; + } + } + + } + + public function activeSupervisorAdhesion($code,$phone) + { + $idsUser=mysqli_query($this->db->con,"SELECT ag.email as email,ag.firstname as firstname,ag.lastname as lastname,na.validation_code as validation_code,na.phone as phone, +na.id as agent_id,ds.id,cg.code_membre as code_membre ,ds.id as demande_id FROM agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN demandeAdhesion ds ON 1=1 INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE ds.phone='$phone' AND cg.code_membre='$code'"); + if($idsUser){ + $idsusr=mysqli_fetch_array($idsUser,MYSQLI_ASSOC); + $idAgent=$idsusr['agent_id']; + $demandeId=$idsusr['demande_id']; + $code_membre=$idsusr['code_membre']; + $udateDemande=mysqli_query($this->db->con,"UPDATE demandeAdhesion SET etat='1' WHERE id='$demandeId'"); + if($udateDemande){ + $user=$idsusr; + $validation = $user["validation_code"]; + $username = $user["lastname"]; + $subject = $this->messageText['WELCOME_ILINK']; + $phone = $user['phone']; + $ct=$this->messageText['ADMIN']; + $message1 =sprintf($this->messageText['MESSAGE_3'],$ct,$phone,$code_membre,$validation); + + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setMail($user['email']); + $this->messenger->setContact($user['phone']); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + if (!$this->messenger->sendMail()) { + return json_encode(error_get_last()); + }; + + $sms = $this->messenger->sendSms(); + + + }else{ + echo mysqli_error($this->db->con); + } + echo json_encode($idsusr); + }else{ + echo mysqli_error($this->db->con); + } + + + } + + public function registerUser($request) + { + if ($this->db->isPhoneExistedSimple($request->phone)) { + // user is already existed - error response + $response["error"] = 1; + $response["error_msg"] = "numero existe deja"; + echo json_encode($response); + } else { + if ($checkValidity = $this->db->checknumberValidity($request->phone)) { + $user = $this->db->storeUserSimple($request->address, $request->lastname, $request->email, + $request->phone, + $request->password, $request->network); + if ($user != null && !isset($user['error'])) { + $user["success"] = 1; + $username = $user["lastname"]; + $subject = $this->messageText['WELCOME_ILINK']; + $phone = $user['phone']; + $validation_code=$user['validation_code']; + $ct=$this->messageText['USER_']; + $message1 =sprintf($this->messageText['MESSAGE_1_USER'],$username,$ct,$phone,$request->password,$validation_code); + $message2 = sprintf($this->messageText['MESSAGE_2'],$username,$ct,$phone,$request->password,""); + + $from = "noreply@ilink-app.com"; + $headers = "From:" . $from; + $name = "ilink"; + + $this->messenger->setMail($user['email']); + $this->messenger->setContact($user['phone']); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + $this->messenger->setHeader($headers); + if (!$this->messenger->sendMail()) { + return json_encode(error_get_last()); + }; + + $sms = $this->messenger->sendSms(); + + } else { + $user = ['error' => 'impossible de créer l\'utilisateur', 'error_sql' => mysqli_error($this->db->con)]; + } + return json_encode($user); + } else { + return json_encode(['error' => 'unable to get membrre', 'error_msg' =>$this->messageText['INVALID_PHONE']]); + + } + + } + } + + public function generateEmptyAgentNetworkForAgent($phone, $code_parrain) + { + if ($this->db->isPhoneExistedInCategory($phone)) { + // user is al5eady existed - error response + $response["error"] = 1; + $response["error_msg"] =$this->messageText['ALREADY_PHONE_NUMBER']; + return json_encode($response); + }else{ + $user=$this->db->generateNetworkAgent($phone,$code_parrain); + if(isset($user['success'])) { + $validation = $user["validation_code"]; + $subject = $this->messageText['WELCOME_ILINK'];; + $phone1 = $user['phone']; + $ct=$this->messageText['AGENT_GEO']; + $message1 =sprintf($this->messageText['MESSAGE_3'],$ct,$phone,$validation); + + + $this->messenger->setContact($phone1); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + + if ($sms = $this->messenger->sendSms()) { + + $user['message'] = $sms; + } else { + return json_encode(['error' => 'imossible d\'envoyer le message']); + }; + } + return json_encode($user); + } + + } + + public function assignNetworkToAgent($agentId, $code_parrain,$phone) + { + $agent = $this->db->getAgentById($agentId); + if ($agent) { + $indicatif=$agent["indicatif"]; + if ($this->db->isPhoneExistedInCategory(null,null,$indicatif.$phone)) { + $response["error"] = 1; + $response["error_msg"] =$this->messageText['ALREADY_PHONE_NUMBER']; + return json_encode($response); + } else { + $parrain=$this->getChildCode($code_parrain); + if($parrain['child']==='geolocated'){ + $user = $this->db->generateNetworkAgent($phone, $code_parrain,$agent); + if (isset($user['success'])) { + $result = $this->db->assignNetworkAgent($agentId, $user['id']); + if (isset($result['success'])) { + $geoLocated['success'] = 1; + $geoLocated['agent_id'] = $agentId; + $validation = $user["validation_code"]; + $subject = $this->messageText['WELCOME_ILINK'];; + $phone1 = $user['phone']; + $message1 = sprintf($this->messageText['MESSAGE_ATTRIBUTE'],$phone1,$validation); + + $this->messenger->setContact($phone1); + $this->messenger->setMessage($message1); + $this->messenger->setSubject($subject); + $this->messenger->setMail($agent['email']); + if ($sms = $this->messenger->sendSms()) { + + $user['message'] = $sms; + } else { + return json_encode(['error' => 'imossible d\'envoyer le message']); + }; + + return json_encode($geoLocated); + } else { + return json_encode($result); + } + } else { + return json_encode($user); + } + + + }else{ + return json_encode(['error'=>'impossible']); + } + } + } else { + return json_encode(['error' => mysqli_error($this->db->con)]); + } +} + + + public function listNetworksGeo() + { + if($this->user_id){ + $result= $this->db->getListNetworkOfGeoPoint($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'networks'=>$result]; + return $networks; + + }else + return $result; + }else{ + return ['error'=>'unable to find user_id']; + } + + } + + public function listFreeNetworksForSuper() + { + if($this->user_id){ + $result= $this->db->getListFreeNetworkOfGeoPoint($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'networks'=>$result]; + return $networks; + + }else + return $result; + }else{ + return ['error'=>'unable to find user_id']; + } + } + + public function getAgentReceiveDemande() + { + if($this->user_id){ + $result= $this->db->getListDemandeReceiveAgent($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'demands'=>$result]; + return json_encode($networks); + + }else + return json_encode($result); + }else{ + return json_encode(['error'=>'unable to find user_id']); + } + + } + + public function getAgentSendDemande() + { + if($this->user_id){ + $result= $this->db->getListDemandeSendAgent($this->user_id); + if(!isset($result['error'])){ + $networks=['success'=>1,'demands'=>$result]; + return json_encode($networks); + + }else + return json_encode($result); + }else{ + return json_encode(['error'=>'unable to find user_id']); + } } + + public function treatDemand($phone) + { + if($this->user_id){ + $result= $this->db->treatDemand($this->user_id); + if(isset($result['success'])){ + $this->messenger->setContact($phone); + $this->messenger->setMessage($this->messageText['MESSAGE_TREAT']); + $this->messenger->sendSms(); + } + return json_encode($result); + }else{ + return json_encode(['error'=>'unable to find user_id']); + } + + } + + public function getActiveCountries() + { + $mq=mysqli_query($this->db->con,"SELECT DISTINCT ct.id,ct.code_dial,ct.name,ct.code_country FROM countries ct INNER JOIN networks ne ON ne.country_id=ct.id"); + if($mq){ + while($row=mysqli_fetch_array($mq,MYSQLI_ASSOC)){ + $rows[]=$row; + } + return json_encode($rows); + }else{ + return ['error'=>mysqli_error($this->db->con)]; + } + } + + public function getAgentById() + { + return$this->db->getAgentById($this->user_id); + } + + public function updatePosition($agentId, $longitude, $latitude) + { + $result=[]; + $q = mysqli_query($this->db->con, "UPDATE agents SET longitude='$longitude',latitude='$latitude' WHERE id='$agentId'"); + if($q){ + return json_encode(['success'=>1]); + }else return json_encode(['error'=>0,'sql'=>mysqli_error($this->db->con)]); + + } + + public function validateUser($phone) + { + + if(isset($phone)){ + $res=mysqli_query($this->db->con,"SELECT * from users_simple WHERE phone='$phone'"); + if($res){ + if(mysqli_num_rows($res)>0){ + $user=mysqli_fetch_array($res,MYSQLI_ASSOC); + $userId=$user['id']; + $r = mysqli_query($this->db->con, "UPDATE users SET active = '1' WHERE id = '$userId' "); + if($r) { + $var3["success"] = 1; + $var3["message"] = "User has been validated successfully !"; + $res=mysqli_query($this->db->con,"SELECT * from users_simple WHERE phone='$phone'"); + $user=mysqli_fetch_array($res,MYSQLI_ASSOC); + $var3['user']=$user; + return $var3; + + }else{ + return ['error'=>'impossible de recuperer le parrain','error_msg'=>mysqli_error($this->db->con)]; + + } + }else{ + return ['error'=>'invalide code','error_msg'=>"code de validation incorrect"]; + } + }else{ + return ['error'=>'unable to query info network agent','error_msg'=>mysqli_error($this->db->con)]; + } + } + + } + function getAgentWallet($idAgent){ + $res=mysqli_query($this->db->con,"SELECT * FROM wallets where id_networkAgent=$idAgent"); + if($res){ + $agent=$row=mysqli_fetch_array($res,MYSQLI_ASSOC); + return $agent; + } + return null; + } +function createRequestRetrait($numCarte,$cvv,$montant,$taxe,$idAgent){ + $agent=$this->getAgentWallet($idAgent); + $agentCommission=floatval($taxe*0.8); + $newBalance=floatval($agent['balance_princ'])+floatval($montant); + $commission=floatval($agent['balance_com'])+$agentCommission; + $id=$agent["id"]; + $resCreditPrinc=mysqli_query($this->db->con,"INSERT INTO wallet_transaction(montant,type,statut,result,numCarte,id_wallet) VALUES ($montant,'credit',1,1,$numCarte,$id)"); + if($resCreditPrinc){ + $resCreditCom=mysqli_query($this->db->con,"INSERT INTO wallet_transaction(montant,type,statut,result,numCarte,id_wallet) VALUES ($agentCommission,'credit',1,1,$numCarte,$id)"); + if($resCreditCom){ + $resCredit=mysqli_query($this->db->con,"UPDATE wallets SET balance_princ=$newBalance,balance_com=$commission where id=$id"); + }else{ + echo mysqli_error($this->db->con); + + } + }else{ + echo mysqli_error($this->db->con); + } + return ["result"=>"success","agent"=>$this->getAgentWallet($idAgent)]; +} + +} diff --git a/database/font/courier.php b/database/font/courier.php new file mode 100644 index 0000000..67dbeda --- /dev/null +++ b/database/font/courier.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/courierb.php b/database/font/courierb.php new file mode 100644 index 0000000..62550a4 --- /dev/null +++ b/database/font/courierb.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/courierbi.php b/database/font/courierbi.php new file mode 100644 index 0000000..6a3ecc6 --- /dev/null +++ b/database/font/courierbi.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/courieri.php b/database/font/courieri.php new file mode 100644 index 0000000..b88e098 --- /dev/null +++ b/database/font/courieri.php @@ -0,0 +1,10 @@ +array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/helvetica.php b/database/font/helvetica.php new file mode 100644 index 0000000..2be3eca --- /dev/null +++ b/database/font/helvetica.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, + 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, + chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, + chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/helveticab.php b/database/font/helveticab.php new file mode 100644 index 0000000..c88394c --- /dev/null +++ b/database/font/helveticab.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, + 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, + 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, + chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, + chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/helveticabi.php b/database/font/helveticabi.php new file mode 100644 index 0000000..bcea807 --- /dev/null +++ b/database/font/helveticabi.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, + 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, + 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, + chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, + chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/helveticai.php b/database/font/helveticai.php new file mode 100644 index 0000000..a328b04 --- /dev/null +++ b/database/font/helveticai.php @@ -0,0 +1,21 @@ +278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, + 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, + chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, + chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/symbol.php b/database/font/symbol.php new file mode 100644 index 0000000..5b9147b --- /dev/null +++ b/database/font/symbol.php @@ -0,0 +1,20 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549, + ','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722, + 'B'=>667,'C'=>722,'D'=>612,'E'=>611,'F'=>763,'G'=>603,'H'=>722,'I'=>333,'J'=>631,'K'=>722,'L'=>686,'M'=>889,'N'=>722,'O'=>722,'P'=>768,'Q'=>741,'R'=>556,'S'=>592,'T'=>611,'U'=>690,'V'=>439,'W'=>768, + 'X'=>645,'Y'=>795,'Z'=>611,'['=>333,'\\'=>863,']'=>333,'^'=>658,'_'=>500,'`'=>500,'a'=>631,'b'=>549,'c'=>549,'d'=>494,'e'=>439,'f'=>521,'g'=>411,'h'=>603,'i'=>329,'j'=>603,'k'=>549,'l'=>549,'m'=>576, + 'n'=>521,'o'=>549,'p'=>549,'q'=>521,'r'=>549,'s'=>603,'t'=>439,'u'=>576,'v'=>713,'w'=>686,'x'=>493,'y'=>686,'z'=>494,'{'=>480,'|'=>200,'}'=>480,'~'=>549,chr(127)=>0,chr(128)=>0,chr(129)=>0,chr(130)=>0,chr(131)=>0, + chr(132)=>0,chr(133)=>0,chr(134)=>0,chr(135)=>0,chr(136)=>0,chr(137)=>0,chr(138)=>0,chr(139)=>0,chr(140)=>0,chr(141)=>0,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, + chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>750,chr(161)=>620,chr(162)=>247,chr(163)=>549,chr(164)=>167,chr(165)=>713,chr(166)=>500,chr(167)=>753,chr(168)=>753,chr(169)=>753,chr(170)=>753,chr(171)=>1042,chr(172)=>987,chr(173)=>603,chr(174)=>987,chr(175)=>603, + chr(176)=>400,chr(177)=>549,chr(178)=>411,chr(179)=>549,chr(180)=>549,chr(181)=>713,chr(182)=>494,chr(183)=>460,chr(184)=>549,chr(185)=>549,chr(186)=>549,chr(187)=>549,chr(188)=>1000,chr(189)=>603,chr(190)=>1000,chr(191)=>658,chr(192)=>823,chr(193)=>686,chr(194)=>795,chr(195)=>987,chr(196)=>768,chr(197)=>768, + chr(198)=>823,chr(199)=>768,chr(200)=>768,chr(201)=>713,chr(202)=>713,chr(203)=>713,chr(204)=>713,chr(205)=>713,chr(206)=>713,chr(207)=>713,chr(208)=>768,chr(209)=>713,chr(210)=>790,chr(211)=>790,chr(212)=>890,chr(213)=>823,chr(214)=>549,chr(215)=>250,chr(216)=>713,chr(217)=>603,chr(218)=>603,chr(219)=>1042, + chr(220)=>987,chr(221)=>603,chr(222)=>987,chr(223)=>603,chr(224)=>494,chr(225)=>329,chr(226)=>790,chr(227)=>790,chr(228)=>786,chr(229)=>713,chr(230)=>384,chr(231)=>384,chr(232)=>384,chr(233)=>384,chr(234)=>384,chr(235)=>384,chr(236)=>494,chr(237)=>494,chr(238)=>494,chr(239)=>494,chr(240)=>0,chr(241)=>329, + chr(242)=>274,chr(243)=>686,chr(244)=>686,chr(245)=>686,chr(246)=>384,chr(247)=>384,chr(248)=>384,chr(249)=>384,chr(250)=>384,chr(251)=>384,chr(252)=>494,chr(253)=>494,chr(254)=>494,chr(255)=>0); +$uv = array(32=>160,33=>33,34=>8704,35=>35,36=>8707,37=>array(37,2),39=>8715,40=>array(40,2),42=>8727,43=>array(43,2),45=>8722,46=>array(46,18),64=>8773,65=>array(913,2),67=>935,68=>array(916,2),70=>934,71=>915,72=>919,73=>921,74=>977,75=>array(922,4),79=>array(927,2),81=>920,82=>929,83=>array(931,3),86=>962,87=>937,88=>926,89=>936,90=>918,91=>91,92=>8756,93=>93,94=>8869,95=>95,96=>63717,97=>array(945,2),99=>967,100=>array(948,2),102=>966,103=>947,104=>951,105=>953,106=>981,107=>array(954,4),111=>array(959,2),113=>952,114=>961,115=>array(963,3),118=>982,119=>969,120=>958,121=>968,122=>950,123=>array(123,3),126=>8764,160=>8364,161=>978,162=>8242,163=>8804,164=>8725,165=>8734,166=>402,167=>9827,168=>9830,169=>9829,170=>9824,171=>8596,172=>array(8592,4),176=>array(176,2),178=>8243,179=>8805,180=>215,181=>8733,182=>8706,183=>8226,184=>247,185=>array(8800,2),187=>8776,188=>8230,189=>array(63718,2),191=>8629,192=>8501,193=>8465,194=>8476,195=>8472,196=>8855,197=>8853,198=>8709,199=>array(8745,2),201=>8835,202=>8839,203=>8836,204=>8834,205=>8838,206=>array(8712,2),208=>8736,209=>8711,210=>63194,211=>63193,212=>63195,213=>8719,214=>8730,215=>8901,216=>172,217=>array(8743,2),219=>8660,220=>array(8656,4),224=>9674,225=>9001,226=>array(63720,3),229=>8721,230=>array(63723,10),241=>9002,242=>8747,243=>8992,244=>63733,245=>8993,246=>array(63734,9)); +?> diff --git a/database/font/times.php b/database/font/times.php new file mode 100644 index 0000000..f78850f --- /dev/null +++ b/database/font/times.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>408,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>180,'('=>333,')'=>333,'*'=>500,'+'=>564, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>564,'='=>564,'>'=>564,'?'=>444,'@'=>921,'A'=>722, + 'B'=>667,'C'=>667,'D'=>722,'E'=>611,'F'=>556,'G'=>722,'H'=>722,'I'=>333,'J'=>389,'K'=>722,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>556,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>722,'W'=>944, + 'X'=>722,'Y'=>722,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>469,'_'=>500,'`'=>333,'a'=>444,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, + 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>333,'s'=>389,'t'=>278,'u'=>500,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>480,'|'=>200,'}'=>480,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>444,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>889,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>444,chr(148)=>444,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>980, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>200,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>564,chr(173)=>333,chr(174)=>760,chr(175)=>333, + chr(176)=>400,chr(177)=>564,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>453,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>444,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>564,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>722,chr(222)=>556,chr(223)=>500,chr(224)=>444,chr(225)=>444,chr(226)=>444,chr(227)=>444,chr(228)=>444,chr(229)=>444,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>564,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>500,chr(254)=>500,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/timesb.php b/database/font/timesb.php new file mode 100644 index 0000000..0516750 --- /dev/null +++ b/database/font/timesb.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>555,'#'=>500,'$'=>500,'%'=>1000,'&'=>833,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>930,'A'=>722, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>778,'I'=>389,'J'=>500,'K'=>778,'L'=>667,'M'=>944,'N'=>722,'O'=>778,'P'=>611,'Q'=>778,'R'=>722,'S'=>556,'T'=>667,'U'=>722,'V'=>722,'W'=>1000, + 'X'=>722,'Y'=>722,'Z'=>667,'['=>333,'\\'=>278,']'=>333,'^'=>581,'_'=>500,'`'=>333,'a'=>500,'b'=>556,'c'=>444,'d'=>556,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>333,'k'=>556,'l'=>278,'m'=>833, + 'n'=>556,'o'=>500,'p'=>556,'q'=>556,'r'=>444,'s'=>389,'t'=>333,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>394,'|'=>220,'}'=>394,'~'=>520,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>667,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>300,chr(171)=>500,chr(172)=>570,chr(173)=>333,chr(174)=>747,chr(175)=>333, + chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>556,chr(182)=>540,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>330,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>570,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>722,chr(222)=>611,chr(223)=>556,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/timesbi.php b/database/font/timesbi.php new file mode 100644 index 0000000..32fe25e --- /dev/null +++ b/database/font/timesbi.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>389,'"'=>555,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>832,'A'=>667, + 'B'=>667,'C'=>667,'D'=>722,'E'=>667,'F'=>667,'G'=>722,'H'=>778,'I'=>389,'J'=>500,'K'=>667,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>611,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>667,'W'=>889, + 'X'=>667,'Y'=>611,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>570,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, + 'n'=>556,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>556,'v'=>444,'w'=>667,'x'=>500,'y'=>444,'z'=>389,'{'=>348,'|'=>220,'}'=>348,'~'=>570,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>389,chr(159)=>611,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>266,chr(171)=>500,chr(172)=>606,chr(173)=>333,chr(174)=>747,chr(175)=>333, + chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>576,chr(182)=>500,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>300,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>944,chr(199)=>667,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>570,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>611,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>444,chr(254)=>500,chr(255)=>444); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/font/timesi.php b/database/font/timesi.php new file mode 100644 index 0000000..b0e5a62 --- /dev/null +++ b/database/font/timesi.php @@ -0,0 +1,21 @@ +250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>420,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>214,'('=>333,')'=>333,'*'=>500,'+'=>675, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>675,'='=>675,'>'=>675,'?'=>500,'@'=>920,'A'=>611, + 'B'=>611,'C'=>667,'D'=>722,'E'=>611,'F'=>611,'G'=>722,'H'=>722,'I'=>333,'J'=>444,'K'=>667,'L'=>556,'M'=>833,'N'=>667,'O'=>722,'P'=>611,'Q'=>722,'R'=>611,'S'=>500,'T'=>556,'U'=>722,'V'=>611,'W'=>833, + 'X'=>611,'Y'=>556,'Z'=>556,'['=>389,'\\'=>278,']'=>389,'^'=>422,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>278,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>444,'l'=>278,'m'=>722, + 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>500,'v'=>444,'w'=>667,'x'=>444,'y'=>444,'z'=>389,'{'=>400,'|'=>275,'}'=>400,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>556,chr(133)=>889,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>500,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>556,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>556,chr(148)=>556,chr(149)=>350,chr(150)=>500,chr(151)=>889,chr(152)=>333,chr(153)=>980, + chr(154)=>389,chr(155)=>333,chr(156)=>667,chr(157)=>350,chr(158)=>389,chr(159)=>556,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>275,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>675,chr(173)=>333,chr(174)=>760,chr(175)=>333, + chr(176)=>400,chr(177)=>675,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>523,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>611,chr(193)=>611,chr(194)=>611,chr(195)=>611,chr(196)=>611,chr(197)=>611, + chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>667,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>675,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>556,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>675,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>444,chr(254)=>500,chr(255)=>444); +$enc = 'cp1252'; +$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96)); +?> diff --git a/database/fpdf.css b/database/fpdf.css new file mode 100644 index 0000000..e69de29 diff --git a/database/fpdf.php b/database/fpdf.php new file mode 100644 index 0000000..c82d68b --- /dev/null +++ b/database/fpdf.php @@ -0,0 +1,915 @@ +_dochecks(); + // Initialization of properties + $this->state = 0; + $this->page = 0; + $this->n = 2; + $this->buffer = ''; + $this->pages = array(); + $this->PageInfo = array(); + $this->fonts = array(); + $this->FontFiles = array(); + $this->encodings = array(); + $this->cmaps = array(); + $this->images = array(); + $this->links = array(); + $this->InHeader = false; + $this->InFooter = false; + $this->lasth = 0; + $this->FontFamily = ''; + $this->FontStyle = ''; + $this->FontSizePt = 12; + $this->underline = false; + $this->DrawColor = '0 G'; + $this->FillColor = '0 g'; + $this->TextColor = '0 g'; + $this->ColorFlag = false; + $this->WithAlpha = false; + $this->ws = 0; + // Font path + if(defined('FPDF_FONTPATH')) + { + $this->fontpath = FPDF_FONTPATH; + if(substr($this->fontpath,-1)!='/' && substr($this->fontpath,-1)!='\\') + $this->fontpath .= '/'; + } + elseif(is_dir(dirname(__FILE__).'/font')) + $this->fontpath = dirname(__FILE__).'/font/'; + else + $this->fontpath = ''; + // Core fonts + $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); + // Scale factor + if($unit=='pt') + $this->k = 1; + elseif($unit=='mm') + $this->k = 72/25.4; + elseif($unit=='cm') + $this->k = 72/2.54; + elseif($unit=='in') + $this->k = 72; + else + $this->Error('Incorrect unit: '.$unit); + // Page sizes + $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), + 'letter'=>array(612,792), 'legal'=>array(612,1008)); + $size = $this->_getpagesize($size); + $this->DefPageSize = $size; + $this->CurPageSize = $size; + // Page orientation + $orientation = strtolower($orientation); + if($orientation=='p' || $orientation=='portrait') + { + $this->DefOrientation = 'P'; + $this->w = $size[0]; + $this->h = $size[1]; + } + elseif($orientation=='l' || $orientation=='landscape') + { + $this->DefOrientation = 'L'; + $this->w = $size[1]; + $this->h = $size[0]; + } + else + $this->Error('Incorrect orientation: '.$orientation); + $this->CurOrientation = $this->DefOrientation; + $this->wPt = $this->w*$this->k; + $this->hPt = $this->h*$this->k; + // Page rotation + $this->CurRotation = 0; + // Page margins (1 cm) + $margin = 28.35/$this->k; + $this->SetMargins($margin,$margin); + // Interior cell margin (1 mm) + $this->cMargin = $margin/10; + // Line width (0.2 mm) + $this->LineWidth = .567/$this->k; + // Automatic page break + $this->SetAutoPageBreak(true,2*$margin); + // Default display mode + $this->SetDisplayMode('default'); + // Enable compression + $this->SetCompression(true); + // Set default PDF version number + $this->PDFVersion = '1.3'; +} + +function SetMargins($left, $top, $right=null) +{ + // Set left, top and right margins + $this->lMargin = $left; + $this->tMargin = $top; + if($right===null) + $right = $left; + $this->rMargin = $right; +} + +function SetLeftMargin($margin) +{ + // Set left margin + $this->lMargin = $margin; + if($this->page>0 && $this->x<$margin) + $this->x = $margin; +} + +function SetTopMargin($margin) +{ + // Set top margin + $this->tMargin = $margin; +} + +function SetRightMargin($margin) +{ + // Set right margin + $this->rMargin = $margin; +} + +function SetAutoPageBreak($auto, $margin=0) +{ + // Set auto page break mode and triggering margin + $this->AutoPageBreak = $auto; + $this->bMargin = $margin; + $this->PageBreakTrigger = $this->h-$margin; +} + +function SetDisplayMode($zoom, $layout='default') +{ + // Set display mode in viewer + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) + $this->ZoomMode = $zoom; + else + $this->Error('Incorrect zoom display mode: '.$zoom); + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') + $this->LayoutMode = $layout; + else + $this->Error('Incorrect layout display mode: '.$layout); +} + +function SetCompression($compress) +{ + // Set page compression + if(function_exists('gzcompress')) + $this->compress = $compress; + else + $this->compress = false; +} + +function SetTitle($title, $isUTF8=false) +{ + // Title of document + $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); +} + +function SetAuthor($author, $isUTF8=false) +{ + // Author of document + $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); +} + +function SetSubject($subject, $isUTF8=false) +{ + // Subject of document + $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); +} + +function SetKeywords($keywords, $isUTF8=false) +{ + // Keywords of document + $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); +} + +function SetCreator($creator, $isUTF8=false) +{ + // Creator of document + $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); +} + +function AliasNbPages($alias='{nb}') +{ + // Define an alias for total number of pages + $this->AliasNbPages = $alias; +} + +function Error($msg) +{ + // Fatal error + throw new Exception('FPDF error: '.$msg); +} + +function Close() +{ + // Terminate document + if($this->state==3) + return; + if($this->page==0) + $this->AddPage(); + // Page footer + $this->InFooter = true; + $this->Footer(); + $this->InFooter = false; + // Close page + $this->_endpage(); + // Close document + $this->_enddoc(); +} + +function AddPage($orientation='', $size='', $rotation=0) +{ + // Start a new page + if($this->state==3) + $this->Error('The document is closed'); + $family = $this->FontFamily; + $style = $this->FontStyle.($this->underline ? 'U' : ''); + $fontsize = $this->FontSizePt; + $lw = $this->LineWidth; + $dc = $this->DrawColor; + $fc = $this->FillColor; + $tc = $this->TextColor; + $cf = $this->ColorFlag; + if($this->page>0) + { + // Page footer + $this->InFooter = true; + $this->Footer(); + $this->InFooter = false; + // Close page + $this->_endpage(); + } + // Start new page + $this->_beginpage($orientation,$size,$rotation); + // Set line cap style to square + $this->_out('2 J'); + // Set line width + $this->LineWidth = $lw; + $this->_out(sprintf('%.2F w',$lw*$this->k)); + // Set font + if($family) + $this->SetFont($family,$style,$fontsize); + // Set colors + $this->DrawColor = $dc; + if($dc!='0 G') + $this->_out($dc); + $this->FillColor = $fc; + if($fc!='0 g') + $this->_out($fc); + $this->TextColor = $tc; + $this->ColorFlag = $cf; + // Page header + $this->InHeader = true; + $this->Header(); + $this->InHeader = false; + // Restore line width + if($this->LineWidth!=$lw) + { + $this->LineWidth = $lw; + $this->_out(sprintf('%.2F w',$lw*$this->k)); + } + // Restore font + if($family) + $this->SetFont($family,$style,$fontsize); + // Restore colors + if($this->DrawColor!=$dc) + { + $this->DrawColor = $dc; + $this->_out($dc); + } + if($this->FillColor!=$fc) + { + $this->FillColor = $fc; + $this->_out($fc); + } + $this->TextColor = $tc; + $this->ColorFlag = $cf; +} + +function Header() +{ + // To be implemented in your own inherited class +} + +function Footer() +{ + // To be implemented in your own inherited class +} + +function PageNo() +{ + // Get current page number + return $this->page; +} + +function SetDrawColor($r, $g=null, $b=null) +{ + // Set color for all stroking operations + if(($r==0 && $g==0 && $b==0) || $g===null) + $this->DrawColor = sprintf('%.3F G',$r/255); + else + $this->DrawColor = sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255); + if($this->page>0) + $this->_out($this->DrawColor); +} + +function SetFillColor($r, $g=null, $b=null) +{ + // Set color for all filling operations + if(($r==0 && $g==0 && $b==0) || $g===null) + $this->FillColor = sprintf('%.3F g',$r/255); + else + $this->FillColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); + $this->ColorFlag = ($this->FillColor!=$this->TextColor); + if($this->page>0) + $this->_out($this->FillColor); +} + +function SetTextColor($r, $g=null, $b=null) +{ + // Set color for text + if(($r==0 && $g==0 && $b==0) || $g===null) + $this->TextColor = sprintf('%.3F g',$r/255); + else + $this->TextColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); + $this->ColorFlag = ($this->FillColor!=$this->TextColor); +} + +function GetStringWidth($s) +{ + // Get width of a string in the current font + $s = (string)$s; + $cw = &$this->CurrentFont['cw']; + $w = 0; + $l = strlen($s); + for($i=0;$i<$l;$i++) + $w += $cw[$s[$i]]; + return $w*$this->FontSize/1000; +} + +function SetLineWidth($width) +{ + // Set line width + $this->LineWidth = $width; + if($this->page>0) + $this->_out(sprintf('%.2F w',$width*$this->k)); +} + +function Line($x1, $y1, $x2, $y2) +{ + // Draw a line + $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); +} + +function Rect($x, $y, $w, $h, $style='') +{ + // Draw a rectangle + if($style=='F') + $op = 'f'; + elseif($style=='FD' || $style=='DF') + $op = 'B'; + else + $op = 'S'; + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); +} + +function AddFont($family, $style='', $file='') +{ + // Add a TrueType, OpenType or Type1 font + $family = strtolower($family); + if($file=='') + $file = str_replace(' ','',$family).strtolower($style).'.php'; + $style = strtoupper($style); + if($style=='IB') + $style = 'BI'; + $fontkey = $family.$style; + if(isset($this->fonts[$fontkey])) + return; + $info = $this->_loadfont($file); + $info['i'] = count($this->fonts)+1; + if(!empty($info['file'])) + { + // Embedded font + if($info['type']=='TrueType') + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); + else + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); + } + $this->fonts[$fontkey] = $info; +} + +function SetFont($family, $style='', $size=0) +{ + // Select a font; size given in points + if($family=='') + $family = $this->FontFamily; + else + $family = strtolower($family); + $style = strtoupper($style); + if(strpos($style,'U')!==false) + { + $this->underline = true; + $style = str_replace('U','',$style); + } + else + $this->underline = false; + if($style=='IB') + $style = 'BI'; + if($size==0) + $size = $this->FontSizePt; + // Test if font is already selected + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) + return; + // Test if font is already loaded + $fontkey = $family.$style; + if(!isset($this->fonts[$fontkey])) + { + // Test if one of the core fonts + if($family=='arial') + $family = 'helvetica'; + if(in_array($family,$this->CoreFonts)) + { + if($family=='symbol' || $family=='zapfdingbats') + $style = ''; + $fontkey = $family.$style; + if(!isset($this->fonts[$fontkey])) + $this->AddFont($family,$style); + } + else + $this->Error('Undefined font: '.$family.' '.$style); + } + // Select it + $this->FontFamily = $family; + $this->FontStyle = $style; + $this->FontSizePt = $size; + $this->FontSize = $size/$this->k; + $this->CurrentFont = &$this->fonts[$fontkey]; + if($this->page>0) + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); +} + +function SetFontSize($size) +{ + // Set font size in points + if($this->FontSizePt==$size) + return; + $this->FontSizePt = $size; + $this->FontSize = $size/$this->k; + if($this->page>0) + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); +} + +function AddLink() +{ + // Create a new internal link + $n = count($this->links)+1; + $this->links[$n] = array(0, 0); + return $n; +} + +function SetLink($link, $y=0, $page=-1) +{ + // Set destination of internal link + if($y==-1) + $y = $this->y; + if($page==-1) + $page = $this->page; + $this->links[$link] = array($page, $y); +} + +function Link($x, $y, $w, $h, $link) +{ + // Put a link on the page + $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); +} + +function Text($x, $y, $txt) +{ + // Output a string + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); + if($this->underline && $txt!='') + $s .= ' '.$this->_dounderline($x,$y,$txt); + if($this->ColorFlag) + $s = 'q '.$this->TextColor.' '.$s.' Q'; + $this->_out($s); +} + +function AcceptPageBreak() +{ + // Accept automatic page break or not + return $this->AutoPageBreak; +} + +function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') +{ + // Output a cell + $k = $this->k; + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) + { + // Automatic page break + $x = $this->x; + $ws = $this->ws; + if($ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + $this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); + $this->x = $x; + if($ws>0) + { + $this->ws = $ws; + $this->_out(sprintf('%.3F Tw',$ws*$k)); + } + } + if($w==0) + $w = $this->w-$this->rMargin-$this->x; + $s = ''; + if($fill || $border==1) + { + if($fill) + $op = ($border==1) ? 'B' : 'f'; + else + $op = 'S'; + $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); + } + if(is_string($border)) + { + $x = $this->x; + $y = $this->y; + if(strpos($border,'L')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); + if(strpos($border,'T')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); + if(strpos($border,'R')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); + if(strpos($border,'B')!==false) + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); + } + if($txt!=='') + { + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + if($align=='R') + $dx = $w-$this->cMargin-$this->GetStringWidth($txt); + elseif($align=='C') + $dx = ($w-$this->GetStringWidth($txt))/2; + else + $dx = $this->cMargin; + if($this->ColorFlag) + $s .= 'q '.$this->TextColor.' '; + $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt)); + if($this->underline) + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); + if($this->ColorFlag) + $s .= ' Q'; + if($link) + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); + } + if($s) + $this->_out($s); + $this->lasth = $h; + if($ln>0) + { + // Go to next line + $this->y += $h; + if($ln==1) + $this->x = $this->lMargin; + } + else + $this->x += $w; +} + +function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false) +{ + // Output text with automatic or explicit line breaks + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + $cw = &$this->CurrentFont['cw']; + if($w==0) + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + $s = str_replace("\r",'',$txt); + $nb = strlen($s); + if($nb>0 && $s[$nb-1]=="\n") + $nb--; + $b = 0; + if($border) + { + if($border==1) + { + $border = 'LTRB'; + $b = 'LRT'; + $b2 = 'LR'; + } + else + { + $b2 = ''; + if(strpos($border,'L')!==false) + $b2 .= 'L'; + if(strpos($border,'R')!==false) + $b2 .= 'R'; + $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; + } + } + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $ns = 0; + $nl = 1; + while($i<$nb) + { + // Get next character + $c = $s[$i]; + if($c=="\n") + { + // Explicit line break + if($this->ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $i++; + $sep = -1; + $j = $i; + $l = 0; + $ns = 0; + $nl++; + if($border && $nl==2) + $b = $b2; + continue; + } + if($c==' ') + { + $sep = $i; + $ls = $l; + $ns++; + } + $l += $cw[$c]; + if($l>$wmax) + { + // Automatic line break + if($sep==-1) + { + if($i==$j) + $i++; + if($this->ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + } + else + { + if($align=='J') + { + $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; + $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); + } + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); + $i = $sep+1; + } + $sep = -1; + $j = $i; + $l = 0; + $ns = 0; + $nl++; + if($border && $nl==2) + $b = $b2; + } + else + $i++; + } + // Last chunk + if($this->ws>0) + { + $this->ws = 0; + $this->_out('0 Tw'); + } + if($border && strpos($border,'B')!==false) + $b .= 'B'; + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $this->x = $this->lMargin; +} + +function Write($h, $txt, $link='') +{ + // Output text in flowing mode + if(!isset($this->CurrentFont)) + $this->Error('No font has been set'); + $cw = &$this->CurrentFont['cw']; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + $s = str_replace("\r",'',$txt); + $nb = strlen($s); + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $nl = 1; + while($i<$nb) + { + // Get next character + $c = $s[$i]; + if($c=="\n") + { + // Explicit line break + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); + $i++; + $sep = -1; + $j = $i; + $l = 0; + if($nl==1) + { + $this->x = $this->lMargin; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + } + $nl++; + continue; + } + if($c==' ') + $sep = $i; + $l += $cw[$c]; + if($l>$wmax) + { + // Automatic line break + if($sep==-1) + { + if($this->x>$this->lMargin) + { + // Move to next line + $this->x = $this->lMargin; + $this->y += $h; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + $i++; + $nl++; + continue; + } + if($i==$j) + $i++; + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); + } + else + { + $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); + $i = $sep+1; + } + $sep = -1; + $j = $i; + $l = 0; + if($nl==1) + { + $this->x = $this->lMargin; + $w = $this->w-$this->rMargin-$this->x; + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; + } + $nl++; + } + else + $i++; + } + // Last chunk + if($i!=$j) + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); +} + +function Ln($h=null) +{ + // Line feed; default value is the last cell height + $this->x = $this->lMargin; + if($h===null) + $this->y += $this->lasth; + else + $this->y += $h; +} + +function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') +{ + // Put an image on the page + if($file=='') + $this->Error('Image file name is empty'); + if(!isset($this->images[$file])) + { + // First use of this image, get info + if($type=='') + { + $pos = strrpos($file,'.'); + if(!$pos) + $this->Error('Image file has no extension and no type was specified: '.$file); + $type = substr($file,$pos+1); + } + $type = strtolower($type); + if($type=='jpeg') + $type = 'jpg'; + $mtd = '_parse'.$type; + if(!method_exists($this,$mtd)) + $this->Error('Unsupported image type: '.$type); + $info = $this->$mtd($file); + $info['i'] = count($this->images)+1; + $this->images[$file] = $info; + } + else + $info = $this->images[$file]; + + // Automatic width and height calculation if needed + if($w==0 && $h==0) + { + // Put image at 96 dpi + $w = -96; + $h = -96; + } + if($w<0) + $w = -$info['w']*72/$w/$this->k; + if($h<0) + $h = -$info['h']*72/$h/$this->k; + if($w==0) + $w = $h*$info['w']/$info['h']; + if($h==0) + $h = $w*$info['h']/$info['w']; + + // Flowing mode + if($y===null) + { + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) + { + // Automatic page break + $x2 = $this->x; + $this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation) \ No newline at end of file diff --git a/init/init.php b/init/init.php new file mode 100644 index 0000000..db2245e --- /dev/null +++ b/init/init.php @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/interacted.old/BalanceAction.php b/interacted.old/BalanceAction.php new file mode 100644 index 0000000..184db01 --- /dev/null +++ b/interacted.old/BalanceAction.php @@ -0,0 +1,69 @@ +storeCreditAsk($codeMembre, $codeParrain,$montant); + $usr= $requester->getUser($phone)[0]; + + if ($demand) { + + + $subject = "Nouvelle demande de crédit"; + + $email = $usr['email']; + $message = "Bonjour,\n\nVotre demande de crédit a été envoyée.\nNumero de telephone : + $phone \n\n\nCordialement,\nL'équipe Ilink."; + $from = "noreply@ilink.com"; + $headers = "From:" . $from; + $name = "ilink"; + mail($email, $subject, $message, $headers); + // Start Sending SMS + $sms = $client->account->messages->create( + + // the number we are sending to - Any phone number + $phone, + + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => $sender_number, + + + // the sms body + 'body' => $message + ) + ); + // Stop Sending SMS + + + //smtpmailer($email,$from,$name,$subject,$message); + $response["success"] = 1; + echo json_encode($response); + } else { + // user failed to store + $response["error"] = 1; + $response["error_msg"] = "La demande n'a pas pu être envoyée!"; + echo json_encode($response); + + } +} diff --git a/interacted.old/DemandeAction.php b/interacted.old/DemandeAction.php new file mode 100644 index 0000000..e48d78c --- /dev/null +++ b/interacted.old/DemandeAction.php @@ -0,0 +1,79 @@ +tag)) { + + switch ($request->tag){ + case "credit_demands": + getCreditDemand($request); + break; + case "ask_credit": + askCreditToParrain($request); + break; + case 'credit_demands_of_agent': + getCreditDemandeAgent($request); + break; + case 'update_ask_credit': + treatDemand($request); + break; + default: + echo json_encode($request); + } +} +function treatDemand($request) +{ + if(isset($request->phone)){ + if (isset($request->id)) { + $q = new Requester($request->id,$request->lang); + echo $q->treatDemand($request->phone); + } else { + echo json_encode(['error' => 'id missing']); + } + }else{ + echo json_encode(['error' => 'phone missing']); + } +} +function getCreditDemandeAgent($request){ + if(isset($request->id)){ + $q=new Requester($request->id,$request->lang); + echo $q->getAgentSendDemande(); + }else{ + echo json_encode(['error'=>'id missing']); + } +} + + function saveCreditDemande($request){ + +} +function askCreditToParrain($request){ + $montant = $request->montant; + $phone=$request->phone; + $code=$request->code; + $requester=new Requester($phone,$request->lang); + echo $requester->storeCreditAsk($phone,$montant,$code); + } +function getCreditDemand($request){ + if(isset($request->id)){ + $q=new Requester($request->id); + echo $q->getAgentReceiveDemande(); + }else{ + echo json_encode(['error'=>'id missing']); + } + +} diff --git a/interacted.old/LocationAction.php b/interacted.old/LocationAction.php new file mode 100644 index 0000000..d51548a --- /dev/null +++ b/interacted.old/LocationAction.php @@ -0,0 +1,124 @@ +tag)){ + $tag=$request->tag; + switch ($tag){ + case 'location': + $type=$request->type; + switch ($type){ + case 'all': + getAllpoint($request); + break; + case 'all_network': + getSuperviseurNetwork($request); + break; + case 'around': + getPointAround($request); + break; + case 'all_network_point': + getPointNetwork($request); + break; + default: + echo json_encode(['error'=>3,'error_msg'=>'type manquant']); + break; + } + case 'all_towns_by_indicatif': + getListTownsCountry($request); + break; + case 'town_information_name': + getTownInfoByName($request); + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); + +} +function getTownInfoByName($request){ + if(isset($request->name)){ + $req=new Requester(null); + echo json_encode($req->getTownInfoByName($request->name)); + } +} +function getListTownsCountry($request){ + if(isset($request->indicatif)){ + $req=new Requester(null); + echo json_encode($req->getListTownsCountry($request->indicatif)); + } +} + +function getAllPoint($request){ + $result=[]; + $requester=new Requester(null); + if(isset($request->country)) { + $country = $request->country; + echo json_encode($requester->getAllCountryPoint($country)); + }else{ + echo json_encode(['error'=>2,'error_msg'=>' code pays manquant']); + } +} +function getSuperviseurNetwork($request) +{ + $result = []; + $requester = new Requester(null); + if (isset($request->codeparrain)) { + $codeparrain = $request->codeparrain; + echo json_encode($requester->getSuperviseurNetwork($codeparrain)); + } else { + echo json_encode(['error' => 2, 'error_msg' => ' code parrain manquant']); + } +} +function getPointAround($request){ + if(isset($request->id)){ + $requester=new Requester($request->id); + if(isset($request->distance)) { + $distance =$request->distance; + if(isset($request->network)) { + $reseau=$request->network; + if (isset($request->position)) { + $position = $request->position; + $page=isset($request->page)?$request->page:0; + echo $requester->getPointAroundKm($reseau,$position, $distance,$page); + } else + echo json_encode(['error' => -3, 'error_msg' => 'position user missing', + "position" => isset($request->position)]); + }else echo json_encode(['error' => -7, 'error_msg' => 'reseau user missing', + "position" => isset($request->reseau)]); + }else echo json_encode(['error'=>-2,'error_msg'=>'distance manquante']); + }else echo json_encode(['error'=>-1,'error_msg'=>'user id manquant']); + + } + + + function getPointNetwork($request) + { + if (isset($request->id)) { + $requester = new Requester($request->id); + $network=$request->network; + if(isset($network)){ + echo $requester->getNetworkPoint($network); + }else echo json_encode(['error'=>-1,'error_msg'=>'missing network']); + } else echo json_encode(['error' => -1, 'error_msg' => 'user id manquant']); + } + diff --git a/interacted.old/LoginAction.php b/interacted.old/LoginAction.php new file mode 100644 index 0000000..9f6be85 --- /dev/null +++ b/interacted.old/LoginAction.php @@ -0,0 +1,111 @@ +tag)){ + $tag=$request->tag; + switch ($tag){ + case 'login_user': + tryToLogin($request,0); + break; + case 'login_agent': + tryToLogin($request,1); + break; + case 'login': + tryToLogin($request); + break; + case "agent_by_id": + tryGetAgentById($request); + break; + case 'forgot_pass': + recoverPassword($request); + break; + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + $res['resty']=$postdata; + echo json_encode($res); + +} +function tryGetAgentById($request){ + if(isset($request->user_id)) { + $req = new Requester($request->user_id, $request->lang); + echo json_encode($req->getAgentById()); + }else + echo json_encode(['error'=>"no_user_id"]); + } + +function recoverPassword($request){ + + $res=[]; + $res['request']=$request; + if(isset($request->number)){ + $number=$request->number; + + if(isset($request->typeaccount)){ + $type=$request->typeaccount; + $request=new Requester(null,$request->lang); + $res=$type==='agent'?$request->recoverPasswordAgent($number):$request->recoverUserPassword($number); + }else{ + $res['error']=-3; + $res['msg']='aucun type de compte n a été defini'; + $res['data']=$request; + } + }else{ + $res['error']=-2; + $res['msg']='aucun numero n a été defini'; + $res['data']=$request; + } + echo json_encode($res); + +} + +function tryToLogin($request,$type=-1){ + $result=[]; + $requester=new Requester(null,$request->lang); + + if(isset($request->phone)){ + $phone=$request->phone; + if(isset($request->password)){ + + $password=$request->password; + + switch ($type){ + case 0:$user=$requester->loginUser($phone,$password); + break; + case 1:$user=$requester->loginAgent($phone,$password); + break; + default: $user=$requester->loginPhonePassword($phone,$password); + + } + $result=$user; + }else{ + $result['error']=-2; + $result['error_msg']='le mot de passe defini'; + } + }else { + $result['error']=-1; + $result['error_msg']='le numero n est pas defini'; + } + echo json_encode($result); +} +?> diff --git a/interacted.old/MembersAction.php b/interacted.old/MembersAction.php new file mode 100644 index 0000000..de02eb6 --- /dev/null +++ b/interacted.old/MembersAction.php @@ -0,0 +1,304 @@ +tag)){ + $tag=$request->tag; + switch ($tag){ + case 'member': + $type=$request->type; + switch ($type){ + case 'all_geolocated': + getAllMembersGeolocated($request); + break; + case 'all_supervisor': + getSuperviseurNetwork($request); + break; + case 'create_user': + createSimpleUser($request); + break; + case 'get_category_child': + getCagetoryChild($request); + break; + case 'credit_demand': + makeCreditRequest($request); + break; + case 'validate_agent': + validate_agentAccount($request); + break; + case "valider_simple": + validateUserSimple($request); + case 'create_supervisor': + case 'create_geolocated_user': + createAgent($request); + break; + case 'list_demande_adhesion': + listDemandAdhesion($request); + break; + case 'activeSupervisor': + activeSupervisor($request); + break; + case 'generateNetworkAgentForGeo': + generateNetworkForGeo($request); + break; + case 'assignNetworkAgentToGeo': + assignNetworkAgentToGeo($request); + break; + case 'update_position': + updatePosition($request); + break; + case 'agent_info_code': + getAgentInfoByCode($request); + break; + default: + echo json_encode(['error'=>3,'error_msg'=>'type manquant']); + } + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); +} +function getAgentInfoByCode($request){ + if(isset($request->code)){ + $requester=new Requester(null,$request->lang); + $code=$request->code; + echo $requester->getAgentInfoByCode($code); + } + else echo json_encode(['error'=>-3,'data'=>$request]); + +} +function updatePosition($request){ + if(isset($request->agentId)){ + $requester=new Requester(null,"fr"); + $code=$request->agentId; + $long=$request->longitude; + $lat=$request->latitude; + echo $requester->updatePosition($code,$long,$lat); + }else echo json_encode(['error'=>-3,'data'=>$request]); +} +function assignNetworkAgentToGeo($request){ + if(isset($request->agentId)){ + if(isset($request->code_parrain)){ + $requester=new Requester(null,$request->lang); + echo $requester->assignNetworkToAgent($request->agentId,$request->code_parrain,$request->phone); + + }else{ + echo json_encode(['error'=>-2,'error_message'=>'validation code manquant']); + } + + }else{ + echo json_encode(['error'=>-1,'error_message'=>'code_membre manquant']); + } +} +function generateNetworkForGeo($request){ + if(isset($request->phone)){ + if(isset($request->code_parrain)){ + $requester=new Requester(null,$request->lang); + echo $requester->generateEmptyAgentNetworkForAgent($request->phone,$request->code_parrain); + + }else{ + echo json_encode(['error'=>-1,'error_message'=>'parrain manquant']); + } + }else{ + echo json_encode(['error'=>-1,'error_message'=>'phone manquant']); + } +} +function activeSupervisor($request){ + $requester=new Requester(0,$request->lang); + if(isset($request->code)){ + echo $requester->activeSupervisorAdhesion($request->code,$request->phone); + }else{ + echo json_encode(['error'=>'code membre manquant']); + } +} +function validateUserSimple($request){ + $requester=new Requester(0,$request->lang); + if(isset($request->phone)){ + echo json_encode($requester->validateUser($request->phone)); + } +} + +function validate_agentAccount($request){ + $requester=new Requester(0,$request->lang); + if(isset($request->code_validation)){ + if(isset($request->phone)){ + echo json_encode($requester->validateAgent($request->phone,$request->code_validation,$request->nbre_code,$request->nbre_code_superviseur)); + } + } + +} +function getCagetoryChild($request){ + $codeparrain=$request->codeparrain; + $requester=new Requester(0); + if(isset($request->codeparrain)){ + echo json_encode($requester->getChildCode($codeparrain)); + } + else{ + echo json_encode(['error'=>2,'error_msg'=>' code parrain manquant']); + } +} +function listDemandAdhesion($request){ + $result=[]; + $requester=new Requester(null); + if(isset($request->codeparrain)) { + $codeparrain = $request->codeparrain; + echo json_encode($requester->getSupervisorAdhesionList($codeparrain)); + } + else{ + echo json_encode(['error'=>2,'error_msg'=>' code parrain manquant']); + } + } + +function getAllMembersGeolocated($request){ + $result=[]; + $requester=new Requester(null); + if(isset($request->codeparrain)) { + $codeparrain = $request->codeparrain; + echo json_encode($requester->getSuperviseurNetwork($codeparrain)); + }else{ + echo json_encode(['error'=>2,'error_msg'=>' code parrain manquant']); + } + +} +function network(){ + $r=new Requester(null); + echo $r->getNetwork(); +} +function makeCreditRequest($request){ + +} + +function createAgent($request){ + // Register Geolocated + // Request type is Register new user + $requester=new Requester(null,$request->lang); + $req=[]; + if(isset($request->address)) { + if(isset( $request->lastname)){ + if(isset( $request->email)){ + if(isset($request->phone)){ + if(isset($request->password)){ + if(isset( $request->town)){ + if(isset($request->network)){ + if(isset($request->latitude) && isset($request->longitude)){ + if(isset($request->member)){ + if(isset($request->category)){ + echo $requester->registerGeolocated($request); + }else{ + $req['error']=-10; + $req['msg']='missing categorie'; + } + }else { + $req['error']=-9; + $req['msg']='missing member'; + } + } else{ + $req['error']=-8; + $req['msg']='missing position'; + } + }else{ + $req['error']=-7; + $req['msg']='missing network'; + + } + }else{ + $req['error']=-6; + $req['msg']='missing country'; + + } + } else{ + $req['error']=-5; + $req['msg']='missing password'; + } + } else{ + + $req['error']=-4; + $req['msg']='missing phone'; + + } + }else { + + $req['error']=-3; + $req['msg']='missing email'; + + } + }else { + $req['error']=-2; + $req['msg']='missing last name'; + + } + }else { + $req['error']=-1; + $req['msg']='missing first name'; + } +} +function createSimpleUser($request) +{ + $requester=new Requester(null); + $req=[]; + if(isset($request->address)) { + if(isset( $request->lastname)){ + if(isset( $request->email)){ + if(isset($request->phone)){ + if(isset($request->password)){ + if(isset( $request->town)) { + if (isset($request->network)) { + $usr=$requester->registerUser($request); + echo $usr; + } else { + $req['error'] = -7; + $req['msg'] = 'missing network'; + + } + }else{ + $req['error']=-6; + $req['msg']='missing country'; + + } + } else{ + $req['error']=-5; + $req['msg']='missing password'; + } + } else{ + + $req['error']=-4; + $req['msg']='missing phone'; + + } + }else { + + $req['error']=-3; + $req['msg']='missing email'; + + } + }else { + $req['error']=-2; + $req['msg']='missing last name'; + + } + }else { + $req['error']=-1; + $req['msg']='missing first name'; + } + +} diff --git a/interacted.old/Messenger.php b/interacted.old/Messenger.php new file mode 100644 index 0000000..e5f6396 --- /dev/null +++ b/interacted.old/Messenger.php @@ -0,0 +1,166 @@ +contact = $contact; + $this->message = $message; + $this->mail = $mail; + $this->subject = $subject; + try { + $this->client = new Client(Messenger::AccountSid,Messenger::AuthToken); + }catch (Exception $e){ + echo $e->getMessage(); + } + } + public function sendSms() + { + + try { + /* $sms = $this->client->account->messages->create( +// the number we are sending to - Any phone number + $this->getContact(), + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => Messenger::sender_number, + + 'body' => $this->getMessage() + ) + );*/ + return true; + }catch(Exception $e){ + // echo json_encode(["message"=>$e->getMessage(),"line"=>$e->getLine(),"trace"=>$e->getTrace()]); + return false; + } + } + public function sendMail(){ + return mail($this->getMail(),$this->getSubject(),$this->getMessage(),$this->getHeader()); + } + + /** + * @return mixed + */ + public function getHeader() + { + return $this->header; + } + + /** + * @param mixed $header + */ + public function setHeader($header) + { + $this->header = $header; + } + + + /** + * @return null + */ + public function getContact() + { + return $this->contact; + } + + /** + * @param null $contact + */ + public function setContact($contact) + { + $this->contact = $contact; + } + + /** + * @return null + */ + public function getMessage() + { + return $this->message; + } + + /** + * @param null $message + */ + public function setMessage($message) + { + $this->message = $message; + } + + /** + * @return null + */ + public function getMail() + { + return $this->mail; + } + + /** + * @param null $mail + */ + public function setMail($mail) + { + $this->mail = $mail; + } + + /** + * @return null + */ + public function getSubject() + { + return $this->subject; + } + + /** + * @param null $subject + */ + public function setSubject($subject) + { + $this->subject = $subject; + } + + public function checkPhoneExist($phone) + { + try { + $phone_number = $this->client->lookups->v1->phoneNumbers($phone) + ->fetch(); + + return isset($phone_number); + } catch(Exception $ex){ + return false; + } + } + + +} \ No newline at end of file diff --git a/interacted.old/NetworkAction.php b/interacted.old/NetworkAction.php new file mode 100644 index 0000000..48f4d20 --- /dev/null +++ b/interacted.old/NetworkAction.php @@ -0,0 +1,90 @@ +tag)){ + $tag=$request->tag; + switch ($tag) { + case 'avail_countries': + getAvailCountries(); + break; + case 'listnetworkscountryindicatif': + getAllCountryNetwork($request); + break; + case 'geolocated': + + if(isset($request->type)) { + $type = $request->type; + switch ($type) { + case 'listNetwork': + getAllNetworkGeo($request); + break; + } + } + break; + case 'supervisor': + if(isset($request->type)) { + $type = $request->type; + switch ($type) { + case 'listFreeNetwork': + getAllFreeNetworkForSupervisor($request); + break; + } + } + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); +} +function getAvailCountries(){ + $req=new Requester(null); + + echo $req->getActiveCountries(); +} + +function getAllFreeNetworkForSupervisor($request){ + if(isset($request->code_parrain)){ + $req=new Requester($request->code_parrain); + echo json_encode($req->listFreeNetworksForSuper()); + }else + echo json_encode(['error'=>'code parrain est absent']); + +} +function getAllNetworkGeo($request){ + if(isset($request->id)){ + $req=new Requester($request->id ); + echo json_encode($req->listNetworksGeo()); + + }else + echo json_encode(['error'=>'l\'id est absent']); + + +} +function getAllCountryNetwork($request){ + if(isset($request->indicatif)){ + $req=new Requester(null); + echo json_encode($req->getCountryNetWork($request->indicatif)); + } +} \ No newline at end of file diff --git a/interacted.old/testSMS.php b/interacted.old/testSMS.php new file mode 100644 index 0000000..c0d8d94 --- /dev/null +++ b/interacted.old/testSMS.php @@ -0,0 +1,66 @@ +account->messages->create( +// the number we are sending to - Any phone number + "+24107300823", + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => $sender_number, + + + // the sms body + 'body' => $message + ) +); diff --git a/interacted/BalanceAction.php b/interacted/BalanceAction.php new file mode 100644 index 0000000..184db01 --- /dev/null +++ b/interacted/BalanceAction.php @@ -0,0 +1,69 @@ +storeCreditAsk($codeMembre, $codeParrain,$montant); + $usr= $requester->getUser($phone)[0]; + + if ($demand) { + + + $subject = "Nouvelle demande de crédit"; + + $email = $usr['email']; + $message = "Bonjour,\n\nVotre demande de crédit a été envoyée.\nNumero de telephone : + $phone \n\n\nCordialement,\nL'équipe Ilink."; + $from = "noreply@ilink.com"; + $headers = "From:" . $from; + $name = "ilink"; + mail($email, $subject, $message, $headers); + // Start Sending SMS + $sms = $client->account->messages->create( + + // the number we are sending to - Any phone number + $phone, + + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => $sender_number, + + + // the sms body + 'body' => $message + ) + ); + // Stop Sending SMS + + + //smtpmailer($email,$from,$name,$subject,$message); + $response["success"] = 1; + echo json_encode($response); + } else { + // user failed to store + $response["error"] = 1; + $response["error_msg"] = "La demande n'a pas pu être envoyée!"; + echo json_encode($response); + + } +} diff --git a/interacted/ConfigAction.php b/interacted/ConfigAction.php new file mode 100644 index 0000000..46b0302 --- /dev/null +++ b/interacted/ConfigAction.php @@ -0,0 +1,50 @@ +tag)){ + $tag=$request->tag; + switch ($tag) { + case 'get_pas': + getPasValue(); + break; + case 'get_pub': + getPubValue($request); + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); +} + function getPubValue($request){ + $req=new Requester(null); + + echo $req->getPubValue($request->id_country); +} +function getPasValue(){ + $req=new Requester(null); + + echo $req->getPasValue(); +} + diff --git a/interacted/DemandeAction.php b/interacted/DemandeAction.php new file mode 100644 index 0000000..e48d78c --- /dev/null +++ b/interacted/DemandeAction.php @@ -0,0 +1,79 @@ +tag)) { + + switch ($request->tag){ + case "credit_demands": + getCreditDemand($request); + break; + case "ask_credit": + askCreditToParrain($request); + break; + case 'credit_demands_of_agent': + getCreditDemandeAgent($request); + break; + case 'update_ask_credit': + treatDemand($request); + break; + default: + echo json_encode($request); + } +} +function treatDemand($request) +{ + if(isset($request->phone)){ + if (isset($request->id)) { + $q = new Requester($request->id,$request->lang); + echo $q->treatDemand($request->phone); + } else { + echo json_encode(['error' => 'id missing']); + } + }else{ + echo json_encode(['error' => 'phone missing']); + } +} +function getCreditDemandeAgent($request){ + if(isset($request->id)){ + $q=new Requester($request->id,$request->lang); + echo $q->getAgentSendDemande(); + }else{ + echo json_encode(['error'=>'id missing']); + } +} + + function saveCreditDemande($request){ + +} +function askCreditToParrain($request){ + $montant = $request->montant; + $phone=$request->phone; + $code=$request->code; + $requester=new Requester($phone,$request->lang); + echo $requester->storeCreditAsk($phone,$montant,$code); + } +function getCreditDemand($request){ + if(isset($request->id)){ + $q=new Requester($request->id); + echo $q->getAgentReceiveDemande(); + }else{ + echo json_encode(['error'=>'id missing']); + } + +} diff --git a/interacted/LocationAction.php b/interacted/LocationAction.php new file mode 100644 index 0000000..d51548a --- /dev/null +++ b/interacted/LocationAction.php @@ -0,0 +1,124 @@ +tag)){ + $tag=$request->tag; + switch ($tag){ + case 'location': + $type=$request->type; + switch ($type){ + case 'all': + getAllpoint($request); + break; + case 'all_network': + getSuperviseurNetwork($request); + break; + case 'around': + getPointAround($request); + break; + case 'all_network_point': + getPointNetwork($request); + break; + default: + echo json_encode(['error'=>3,'error_msg'=>'type manquant']); + break; + } + case 'all_towns_by_indicatif': + getListTownsCountry($request); + break; + case 'town_information_name': + getTownInfoByName($request); + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); + +} +function getTownInfoByName($request){ + if(isset($request->name)){ + $req=new Requester(null); + echo json_encode($req->getTownInfoByName($request->name)); + } +} +function getListTownsCountry($request){ + if(isset($request->indicatif)){ + $req=new Requester(null); + echo json_encode($req->getListTownsCountry($request->indicatif)); + } +} + +function getAllPoint($request){ + $result=[]; + $requester=new Requester(null); + if(isset($request->country)) { + $country = $request->country; + echo json_encode($requester->getAllCountryPoint($country)); + }else{ + echo json_encode(['error'=>2,'error_msg'=>' code pays manquant']); + } +} +function getSuperviseurNetwork($request) +{ + $result = []; + $requester = new Requester(null); + if (isset($request->codeparrain)) { + $codeparrain = $request->codeparrain; + echo json_encode($requester->getSuperviseurNetwork($codeparrain)); + } else { + echo json_encode(['error' => 2, 'error_msg' => ' code parrain manquant']); + } +} +function getPointAround($request){ + if(isset($request->id)){ + $requester=new Requester($request->id); + if(isset($request->distance)) { + $distance =$request->distance; + if(isset($request->network)) { + $reseau=$request->network; + if (isset($request->position)) { + $position = $request->position; + $page=isset($request->page)?$request->page:0; + echo $requester->getPointAroundKm($reseau,$position, $distance,$page); + } else + echo json_encode(['error' => -3, 'error_msg' => 'position user missing', + "position" => isset($request->position)]); + }else echo json_encode(['error' => -7, 'error_msg' => 'reseau user missing', + "position" => isset($request->reseau)]); + }else echo json_encode(['error'=>-2,'error_msg'=>'distance manquante']); + }else echo json_encode(['error'=>-1,'error_msg'=>'user id manquant']); + + } + + + function getPointNetwork($request) + { + if (isset($request->id)) { + $requester = new Requester($request->id); + $network=$request->network; + if(isset($network)){ + echo $requester->getNetworkPoint($network); + }else echo json_encode(['error'=>-1,'error_msg'=>'missing network']); + } else echo json_encode(['error' => -1, 'error_msg' => 'user id manquant']); + } + diff --git a/interacted/LoginAction.php b/interacted/LoginAction.php new file mode 100644 index 0000000..9f6be85 --- /dev/null +++ b/interacted/LoginAction.php @@ -0,0 +1,111 @@ +tag)){ + $tag=$request->tag; + switch ($tag){ + case 'login_user': + tryToLogin($request,0); + break; + case 'login_agent': + tryToLogin($request,1); + break; + case 'login': + tryToLogin($request); + break; + case "agent_by_id": + tryGetAgentById($request); + break; + case 'forgot_pass': + recoverPassword($request); + break; + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + $res['resty']=$postdata; + echo json_encode($res); + +} +function tryGetAgentById($request){ + if(isset($request->user_id)) { + $req = new Requester($request->user_id, $request->lang); + echo json_encode($req->getAgentById()); + }else + echo json_encode(['error'=>"no_user_id"]); + } + +function recoverPassword($request){ + + $res=[]; + $res['request']=$request; + if(isset($request->number)){ + $number=$request->number; + + if(isset($request->typeaccount)){ + $type=$request->typeaccount; + $request=new Requester(null,$request->lang); + $res=$type==='agent'?$request->recoverPasswordAgent($number):$request->recoverUserPassword($number); + }else{ + $res['error']=-3; + $res['msg']='aucun type de compte n a été defini'; + $res['data']=$request; + } + }else{ + $res['error']=-2; + $res['msg']='aucun numero n a été defini'; + $res['data']=$request; + } + echo json_encode($res); + +} + +function tryToLogin($request,$type=-1){ + $result=[]; + $requester=new Requester(null,$request->lang); + + if(isset($request->phone)){ + $phone=$request->phone; + if(isset($request->password)){ + + $password=$request->password; + + switch ($type){ + case 0:$user=$requester->loginUser($phone,$password); + break; + case 1:$user=$requester->loginAgent($phone,$password); + break; + default: $user=$requester->loginPhonePassword($phone,$password); + + } + $result=$user; + }else{ + $result['error']=-2; + $result['error_msg']='le mot de passe defini'; + } + }else { + $result['error']=-1; + $result['error_msg']='le numero n est pas defini'; + } + echo json_encode($result); +} +?> diff --git a/interacted/MembersAction.php b/interacted/MembersAction.php new file mode 100644 index 0000000..6e53c10 --- /dev/null +++ b/interacted/MembersAction.php @@ -0,0 +1,315 @@ +tag)){ + $tag=$request->tag; + switch ($tag){ + case 'member': + $type=$request->type; + switch ($type){ + case 'all_geolocated': + getAllMembersGeolocated($request); + break; + case 'deleteAgent': + deleteAgent($request); + break; + case 'all_supervisor': + getSuperviseurNetwork($request); + break; + case 'create_user': + createSimpleUser($request); + break; + case 'get_category_child': + getCagetoryChild($request); + break; + case 'credit_demand': + makeCreditRequest($request); + break; + case 'validate_agent': + validate_agentAccount($request); + break; + case "valider_simple": + validateUserSimple($request); + case 'create_supervisor': + case 'create_geolocated_user': + createAgent($request); + break; + case 'list_demande_adhesion': + listDemandAdhesion($request); + break; + case 'activeSupervisor': + activeSupervisor($request); + break; + case 'generateNetworkAgentForGeo': + generateNetworkForGeo($request); + break; + case 'assignNetworkAgentToGeo': + assignNetworkAgentToGeo($request); + break; + case 'update_position': + updatePosition($request); + break; + case 'agen_info_code': + getAgentInfoByCode($request); + break; + default: + echo json_encode(['error'=>3,'error_msg'=>'type manquant',"data"=>$request]); + } + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); +} +function deleteAgent($request){ + if(isset($request->code)){ + $requester=new Requester(null,$request->lang); + $code=$request->code; + echo $requester->deleteAgent($code); + } + else echo json_encode(['error'=>-3,'data'=>$request]); +} +function getAgentInfoByCode($request){ + if(isset($request->code)){ + $requester=new Requester(null,$request->lang); + $code=$request->code; + echo $requester->getAgentInfoByCode($code); + } + else echo json_encode(['error'=>-3,'data'=>$request]); + +} +function updatePosition($request){ + if(isset($request->agentId)){ + $requester=new Requester(null,"fr"); + $code=$request->agentId; + $long=$request->longitude; + $lat=$request->latitude; + echo $requester->updatePosition($code,$long,$lat); + }else echo json_encode(['error'=>-3,'data'=>$request]); +} +function assignNetworkAgentToGeo($request){ + if(isset($request->agentId)){ + if(isset($request->code_parrain)){ + $requester=new Requester(null,$request->lang); + echo $requester->assignNetworkToAgent($request->agentId,$request->code_parrain,$request->phone); + + }else{ + echo json_encode(['error'=>-2,'error_message'=>'validation code manquant']); + } + + }else{ + echo json_encode(['error'=>-1,'error_message'=>'code_membre manquant']); + } +} +function generateNetworkForGeo($request){ + if(isset($request->phone)){ + if(isset($request->code_parrain)){ + $requester=new Requester(null,$request->lang); + echo $requester->generateEmptyAgentNetworkForAgent($request->phone,$request->code_parrain); + + }else{ + echo json_encode(['error'=>-1,'error_message'=>'parrain manquant']); + } + }else{ + echo json_encode(['error'=>-1,'error_message'=>'phone manquant']); + } +} +function activeSupervisor($request){ + $requester=new Requester(0,$request->lang); + if(isset($request->code)){ + echo $requester->activeSupervisorAdhesion($request->code,$request->phone); + }else{ + echo json_encode(['error'=>'code membre manquant']); + } +} +function validateUserSimple($request){ + $requester=new Requester(0,$request->lang); + if(isset($request->phone)){ + echo json_encode($requester->validateUser($request->phone)); + } +} + +function validate_agentAccount($request){ + $requester=new Requester(0,$request->lang); + if(isset($request->code_validation)){ + if(isset($request->phone)){ + echo json_encode($requester->validateAgent($request->phone,$request->code_validation,$request->nbre_code,$request->nbre_code_superviseur)); + } + } + +} +function getCagetoryChild($request){ + $codeparrain=$request->codeparrain; + $requester=new Requester(0); + if(isset($request->codeparrain)){ + echo json_encode($requester->getChildCode($codeparrain)); + } + else{ + echo json_encode(['error'=>2,'error_msg'=>' code parrain manquant']); + } +} +function listDemandAdhesion($request){ + $result=[]; + $requester=new Requester(null); + if(isset($request->codeparrain)) { + $codeparrain = $request->codeparrain; + echo json_encode($requester->getSupervisorAdhesionList($codeparrain)); + } + else{ + echo json_encode(['error'=>2,'error_msg'=>' code parrain manquant']); + } + } + +function getAllMembersGeolocated($request){ + $result=[]; + $requester=new Requester(null); + if(isset($request->codeparrain)) { + $codeparrain = $request->codeparrain; + echo json_encode($requester->getSuperviseurNetwork($codeparrain)); + }else{ + echo json_encode(['error'=>2,'error_msg'=>' code parrain manquant']); + } + +} +function network(){ + $r=new Requester(null); + echo $r->getNetwork(); +} +function makeCreditRequest($request){ + +} + +function createAgent($request){ + // Register Geolocated + // Request type is Register new user + $requester=new Requester(null,$request->lang); + $req=[]; + if(isset($request->address)) { + if(isset( $request->lastname)){ + if(isset( $request->email)){ + if(isset($request->phone)){ + if(isset($request->password)){ + if(isset( $request->town)){ + if(isset($request->network)){ + if(isset($request->latitude) && isset($request->longitude)){ + if(isset($request->member)){ + if(isset($request->category)){ + echo $requester->registerGeolocated($request); + }else{ + $req['error']=-10; + $req['msg']='missing categorie'; + } + }else { + $req['error']=-9; + $req['msg']='missing member'; + } + } else{ + $req['error']=-8; + $req['msg']='missing position'; + } + }else{ + $req['error']=-7; + $req['msg']='missing network'; + + } + }else{ + $req['error']=-6; + $req['msg']='missing country'; + + } + } else{ + $req['error']=-5; + $req['msg']='missing password'; + } + } else{ + + $req['error']=-4; + $req['msg']='missing phone'; + + } + }else { + + $req['error']=-3; + $req['msg']='missing email'; + + } + }else { + $req['error']=-2; + $req['msg']='missing last name'; + + } + }else { + $req['error']=-1; + $req['msg']='missing first name'; + } +} +function createSimpleUser($request) +{ + $requester=new Requester(null); + $req=[]; + if(isset($request->address)) { + if(isset( $request->lastname)){ + if(isset( $request->email)){ + if(isset($request->phone)){ + if(isset($request->password)){ + if(isset( $request->town)) { + if (isset($request->network)) { + $usr=$requester->registerUser($request); + echo $usr; + } else { + $req['error'] = -7; + $req['msg'] = 'missing network'; + + } + }else{ + $req['error']=-6; + $req['msg']='missing country'; + + } + } else{ + $req['error']=-5; + $req['msg']='missing password'; + } + } else{ + + $req['error']=-4; + $req['msg']='missing phone'; + + } + }else { + + $req['error']=-3; + $req['msg']='missing email'; + + } + }else { + $req['error']=-2; + $req['msg']='missing last name'; + + } + }else { + $req['error']=-1; + $req['msg']='missing first name'; + } + +} diff --git a/interacted/Messenger.php b/interacted/Messenger.php new file mode 100644 index 0000000..e5f6396 --- /dev/null +++ b/interacted/Messenger.php @@ -0,0 +1,166 @@ +contact = $contact; + $this->message = $message; + $this->mail = $mail; + $this->subject = $subject; + try { + $this->client = new Client(Messenger::AccountSid,Messenger::AuthToken); + }catch (Exception $e){ + echo $e->getMessage(); + } + } + public function sendSms() + { + + try { + /* $sms = $this->client->account->messages->create( +// the number we are sending to - Any phone number + $this->getContact(), + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => Messenger::sender_number, + + 'body' => $this->getMessage() + ) + );*/ + return true; + }catch(Exception $e){ + // echo json_encode(["message"=>$e->getMessage(),"line"=>$e->getLine(),"trace"=>$e->getTrace()]); + return false; + } + } + public function sendMail(){ + return mail($this->getMail(),$this->getSubject(),$this->getMessage(),$this->getHeader()); + } + + /** + * @return mixed + */ + public function getHeader() + { + return $this->header; + } + + /** + * @param mixed $header + */ + public function setHeader($header) + { + $this->header = $header; + } + + + /** + * @return null + */ + public function getContact() + { + return $this->contact; + } + + /** + * @param null $contact + */ + public function setContact($contact) + { + $this->contact = $contact; + } + + /** + * @return null + */ + public function getMessage() + { + return $this->message; + } + + /** + * @param null $message + */ + public function setMessage($message) + { + $this->message = $message; + } + + /** + * @return null + */ + public function getMail() + { + return $this->mail; + } + + /** + * @param null $mail + */ + public function setMail($mail) + { + $this->mail = $mail; + } + + /** + * @return null + */ + public function getSubject() + { + return $this->subject; + } + + /** + * @param null $subject + */ + public function setSubject($subject) + { + $this->subject = $subject; + } + + public function checkPhoneExist($phone) + { + try { + $phone_number = $this->client->lookups->v1->phoneNumbers($phone) + ->fetch(); + + return isset($phone_number); + } catch(Exception $ex){ + return false; + } + } + + +} \ No newline at end of file diff --git a/interacted/NetworkAction.php b/interacted/NetworkAction.php new file mode 100644 index 0000000..48f4d20 --- /dev/null +++ b/interacted/NetworkAction.php @@ -0,0 +1,90 @@ +tag)){ + $tag=$request->tag; + switch ($tag) { + case 'avail_countries': + getAvailCountries(); + break; + case 'listnetworkscountryindicatif': + getAllCountryNetwork($request); + break; + case 'geolocated': + + if(isset($request->type)) { + $type = $request->type; + switch ($type) { + case 'listNetwork': + getAllNetworkGeo($request); + break; + } + } + break; + case 'supervisor': + if(isset($request->type)) { + $type = $request->type; + switch ($type) { + case 'listFreeNetwork': + getAllFreeNetworkForSupervisor($request); + break; + } + } + break; + default: + echo json_encode(['error'=>4,'error_msg'=>'tag manquant']); + + } +}else{ + $res=[]; + $res['error']=-4; + $res['msg']='aucun tag n a ete defini'; + $res['data']=$request; + echo json_encode($res); +} +function getAvailCountries(){ + $req=new Requester(null); + + echo $req->getActiveCountries(); +} + +function getAllFreeNetworkForSupervisor($request){ + if(isset($request->code_parrain)){ + $req=new Requester($request->code_parrain); + echo json_encode($req->listFreeNetworksForSuper()); + }else + echo json_encode(['error'=>'code parrain est absent']); + +} +function getAllNetworkGeo($request){ + if(isset($request->id)){ + $req=new Requester($request->id ); + echo json_encode($req->listNetworksGeo()); + + }else + echo json_encode(['error'=>'l\'id est absent']); + + +} +function getAllCountryNetwork($request){ + if(isset($request->indicatif)){ + $req=new Requester(null); + echo json_encode($req->getCountryNetWork($request->indicatif)); + } +} \ No newline at end of file diff --git a/interacted/WalletAction.php b/interacted/WalletAction.php new file mode 100644 index 0000000..756c4e9 --- /dev/null +++ b/interacted/WalletAction.php @@ -0,0 +1,46 @@ +tag)) { + + switch ($request->tag){ + case "add_retrait_wallet": + addRetraitWallet($request); + break; + case "add_depot_wallet": + addDepotWallet($request); + break; + default: + echo json_encode($request); + } +} +function addRetraitWallet($request){ + if(isset($request->numCarte) && isset($request->cvv) && isset($request->montant) && isset($request->taxe)){ + $lang=$request->lang; + $req=new Requester($lang); + echo json_encode($req->createRequestRetrait($request->numCarte,$request->cvv,$request->montant,$request->taxe,9975)); + }else + echo json_encode(['error'=>'code parrain est absent']); + +} +function addDepotWallet($request){ + +} + + diff --git a/interacted/testSMS.php b/interacted/testSMS.php new file mode 100644 index 0000000..c0d8d94 --- /dev/null +++ b/interacted/testSMS.php @@ -0,0 +1,66 @@ +account->messages->create( +// the number we are sending to - Any phone number + "+24107300823", + array( + // Step 6: Change the 'From' number below to be a valid Twilio number + // that you've purchased + 'from' => $sender_number, + + + // the sms body + 'body' => $message + ) +); diff --git a/migrations 2.php b/migrations 2.php new file mode 100644 index 0000000..9c9e81a --- /dev/null +++ b/migrations 2.php @@ -0,0 +1,300 @@ +client->lookups->v1->phoneNumbers($phone) + ->fetch(); + echo json_encode($phone_number); + } catch(Exception $ex){ + echo json_encode($ex); + } +} +function testQuery(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $page=($_POST['page']-1)*50; + $res= mysqli_query($con,"SELECT ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat + FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN + networks nt ON na.network_id=nt.id INNER JOIN countries ct ON ct.id=nt.country_id + INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE + cg.category='geolocated' AND na.etat=1 LIMIT 51 OFFSET $page"); + if($res){ + $li=["page"=>$_POST["page"],"count"=>0,"total"=>($_POST["page"]-1)*51]; + while ($r=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $li["items"][]=$r; + $li["count"]=$li["count"]+1; + } + $li["total"]=$li["total"]+$li["count"]; + echo json_encode($li); + }else echo mysqli_error($con); +} +function listPhonenum(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks"); + if($net){ + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } +} +function listOldNetwork(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, "ilink"); + if($con){ + $net=mysqli_query($con,"select * from network WHERE reseau='KENYA'"); + if($net){ + $rows=[]; + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + + $filt=[]; + foreach($row as $key => $value) { + if(strlen($value)>0){ + $filt[$key]=$value; + } + } + $rows[]=$filt; + } + $connexion = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($connexion) { + foreach ($rows as $row) { + foreach ($row as $key=>$value) + if(strtoupper($key)!='RESEAU') + mysqli_query($connexion,"INSERT INTO networks(country_id,name) VALUES('114','$value')"); + } + } + listnetwork(); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } +} +function listUsers(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from users"); + if($net){ + $rows=[]; + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } +} +function listagentNetwork(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id"); + if($net){ + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } +} +function insertNetwork(){ + $country=$_POST['country']; + $name=$_POST['network']; + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"INSERT INTO networks(country_id,name) VALUES('$country','$name')"); + if($net){ + echo json_encode('success'); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listcountry(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from countries"); + if($net){ + echo json_encode(mysqli_fetch_all($net)); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listcode(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from codeGenerer"); + if($net){ + while($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listnetwork(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks"); + if($net){ + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + }; +function generateHyperVisor(){ + $random= generateRandomString(); + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $insert=mysqli_query($con,"insert INTO codeGenerer (code_parrain,code_membre,category) VALUES ('$random','$random','hyper')"); + if($insert){ + var_dump($insert); + }else { + echo mysqli_error($con); + } +} +function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; +} \ No newline at end of file diff --git a/migrations copie.php b/migrations copie.php new file mode 100644 index 0000000..ca3b8dd --- /dev/null +++ b/migrations copie.php @@ -0,0 +1,302 @@ +client->lookups->v1->phoneNumbers($phone) + ->fetch(); + echo json_encode($phone_number); + } catch(Exception $ex){ + echo json_encode($ex); + } +} +function testQuery(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $page=($_POST['page']-1)*50; + $res= mysqli_query($con,"SELECT ag.longitude as longitude, +ag.adresse, + ag.latitude as latitude,na.transactionNumber as phoneTransaction, + ag.firstname as firstname,ag.lastname as lastname, ag.email as email,na.phone as phone,cg.code_membre as code_membre, + nt.name as network,ct.name as country, na.etat as etat + FROM agents ag INNER JOIN networks_agents na ON na.agent_id=ag.id INNER JOIN + networks nt ON na.network_id=nt.id INNER JOIN countries ct ON ct.id=nt.country_id + INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id WHERE + cg.category='geolocated' AND na.etat=1 LIMIT 51 OFFSET $page"); + if($res){ + $li=["page"=>$_POST["page"],"count"=>0,"total"=>($_POST["page"]-1)*51]; + while ($r=mysqli_fetch_array($res,MYSQLI_ASSOC)){ + $li["items"][]=$r; + $li["count"]=$li["count"]+1; + } + $li["total"]=$li["total"]+$li["count"]; + echo json_encode($li); + }else echo mysqli_error($con); +} +function listPhonenum(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks"); + if($net){ + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } +} +function listOldNetwork(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, "ilink"); + if($con){ + $net=mysqli_query($con,"select * from network WHERE reseau='KENYA'"); + if($net){ + $rows=[]; + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + + $filt=[]; + foreach($row as $key => $value) { + if(strlen($value)>0){ + $filt[$key]=$value; + } + } + $rows[]=$filt; + } + $connexion = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($connexion) { + foreach ($rows as $row) { + foreach ($row as $key=>$value) + if(strtoupper($key)!='RESEAU') + mysqli_query($connexion,"INSERT INTO networks(country_id,name) VALUES('114','$value')"); + } + } + listnetwork(); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } +} +function listUsers(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from users"); + if($net){ + $rows=[]; + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } +} +function listagentNetwork(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id"); + if($net){ + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } +} +function insertNetwork(){ + $country=$_POST['country']; + $name=$_POST['network']; + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"INSERT INTO networks(country_id,name) VALUES('$country','$name')"); + if($net){ + echo json_encode('success'); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listcountry(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from countries"); + if($net){ + echo json_encode(mysqli_fetch_all($net)); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listcode(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from codeGenerer"); + if($net){ + while($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listnetwork(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks"); + if($net){ + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + }; +function generateHyperVisor(){ + $random= generateRandomString(); + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE_TEST); + $insert=mysqli_query($con,"insert INTO codeGenerer (code_parrain,code_membre,category) VALUES ('$random','$random','hyper')"); + if($insert){ + var_dump($insert); + }else { + echo mysqli_error($con); + } +} +function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; +} \ No newline at end of file diff --git a/migrations.php b/migrations.php new file mode 100644 index 0000000..c1eb6ac --- /dev/null +++ b/migrations.php @@ -0,0 +1,408 @@ +$me,'total'=>count($rows),'geo'=>$rows]); + }else{ + echo mysqli_error($con); + } +} +function readAgent(){ + $phone=$_POST["phone"]; + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $cod=mysqli_query($con,"SELECT * from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codegenerer_id WHERE na.transactionNumber='$phone' || na.phone='$phone'"); + if($cod) { + while ($me = mysqli_fetch_assoc($cod)) { + $rows[] = $me; + } + + echo json_encode($rows); + }else{ + echo mysqli_error($con); + } +} +function superCreator(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $cod=mysqli_query($con,"SELECT * from codeGenerer WHERE etat=0 AND category='hyper'"); + if($cod){ + $codes=[]; + $networks=[]; + $towns=[]; + $net=mysqli_query($con,"select * from networks WHERE country_id=78"); + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + $networks[] = $row; + } + $tow=mysqli_query($con,"select * from towns WHERE country_id=78"); + while($row=mysqli_fetch_array($tow, MYSQLI_ASSOC )) { + $towns[] = $row; + } + $i=0; + while($code=mysqli_fetch_array($cod, MYSQLI_ASSOC )) { + if($i"member", + 'type'=>'create_supervisor', + 'address' => "Libreville", + 'lastname' => $network["name"], + 'email'=>$network["name"].'@ilink-app.com', + 'phone'=>"0100000$i", + 'network'=>$network, + 'phone_transaction'=>"0100000$i", + 'town'=>$town, + 'password'=>'1234', + 'latitude'=>-1, + 'lang'=>'fr', + 'test'=>false, + 'longitude'=>-1, + 'member'=>$code['code_membre'], + 'category'=>"hyper", + ]; +//url-ify the data for the POST + $fields_string = json_encode($fields); +//open connection + $ch = curl_init(); +//set the url, number of POST vars, POST data + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch,CURLOPT_POST, count($fields)); + curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); +//So that curl_exec returns the contents of the cURL; rather than echoing it + curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); +//execute post + $result = curl_exec($ch); + echo $result; + } + + $i++; + } + echo json_encode($codes); + }else { + echo mysqli_error($con); + } +}; +function deleteRedon(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $cod=mysqli_query($con,"SELECT ag.id as agentId,na.id as agentId2,cg.id as cgId from agents ag INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON na.codegenerer_id=cg.id WHERE etat=0 AND ag.id=7984 AND ag.id=7987"); + if($cod){ + while ($row=mysqli_fetch_array($cod,MYSQLI_ASSOC)){ + $ag= $row['agentId']; + $a =$row["agentId2"]; + $c=$row["cgId"]; + mysqli_query($con,"delete from agents WHERE id=$ag"); + mysqli_query($con,"delete from networks_agents WHERE id=$a"); + mysqli_query($con,"delete from codegenerer WHERE id=$c"); + + } + } +} +function listPhonenum(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks"); + if($net){ + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } +} +function listOldNetwork(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, "ilink"); + if($con){ + $net=mysqli_query($con,"select * from network WHERE reseau='KENYA'"); + if($net){ + $rows=[]; + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + + $filt=[]; + foreach($row as $key => $value) { + if(strlen($value)>0){ + $filt[$key]=$value; + } + } + $rows[]=$filt; + } + $connexion = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($connexion) { + foreach ($rows as $row) { + foreach ($row as $key=>$value) + if(strtoupper($key)!='RESEAU') + mysqli_query($connexion,"INSERT INTO networks(country_id,name) VALUES('114','$value')"); + } + } + listnetwork(); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } +} +function listUsers(){ + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from users"); + if($net){ + $rows=[]; + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } +} +function listagentNetwork(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks_agents na INNER JOIN codeGenerer cg ON na.codeGenerer_id=cg.id"); + if($net){ + while ($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } +} +function insertNetwork(){ + $country=$_POST['country']; + $name=$_POST['network']; + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"INSERT INTO networks(country_id,name) VALUES('$country','$name')"); + if($net){ + echo json_encode('success'); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listcountry(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from countries"); + if($net){ + echo json_encode(mysqli_fetch_all($net)); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listcode(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from codeGenerer"); + if($net){ + while($row=mysqli_fetch_array($net,MYSQLI_ASSOC)){ + $rows[]=$row; + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + +} +function listnetwork(){ + try { + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + if($con){ + $net=mysqli_query($con,"select * from networks WHERE country_id=78"); + if($net){ + while($row=mysqli_fetch_array($net, MYSQLI_ASSOC )) { + + $rows[] = $row; + + } + echo json_encode($rows); + }else{ + echo json_encode(mysqli_error($con)); + } + }else{ + var_dump(mysqli_connect_error()); + } + + }catch (Exception $e){ + echo 'error'; + echo $e->getMessage(); + } + }; +function generateHyperVisor(){ + $random= generateRandomString(); + $con = mysqli_connect(DB_HOST, DB_USER + , DB_PASSWORD, DB_DATABASE); + $insert=mysqli_query($con,"insert INTO codeGenerer (code_parrain,code_membre,category) VALUES ('$random','$random','hyper')"); + if($insert){ + var_dump($insert); + }else { + echo mysqli_error($con); + } +} +function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; +} \ No newline at end of file diff --git a/model 2/Balance.php b/model 2/Balance.php new file mode 100644 index 0000000..1a62d05 --- /dev/null +++ b/model 2/Balance.php @@ -0,0 +1,51 @@ +montant=$montant; + $this->phone=$phone; + } + + /** + * @return mixed + */ + public function getMontant() + { + return $this->montant; + } + + /** + * @return mixed + */ + public function getPhone() + { + return $this->phone; + } + + /** + * @param mixed $phone + */ + public function setPhone($phone) + { + $this->phone = $phone; + } + + /** + * @param mixed $montant + */ + public function setMontant($montant) + { + $this->montant = $montant; + } + +} \ No newline at end of file diff --git a/model 2/User.php b/model 2/User.php new file mode 100644 index 0000000..675bf68 --- /dev/null +++ b/model 2/User.php @@ -0,0 +1,12 @@ +montant=$montant; + $this->phone=$phone; + } + + /** + * @return mixed + */ + public function getMontant() + { + return $this->montant; + } + + /** + * @return mixed + */ + public function getPhone() + { + return $this->phone; + } + + /** + * @param mixed $phone + */ + public function setPhone($phone) + { + $this->phone = $phone; + } + + /** + * @param mixed $montant + */ + public function setMontant($montant) + { + $this->montant = $montant; + } + +} \ No newline at end of file diff --git a/model.old/User.php b/model.old/User.php new file mode 100644 index 0000000..675bf68 --- /dev/null +++ b/model.old/User.php @@ -0,0 +1,12 @@ +montant=$montant; + $this->phone=$phone; + } + + /** + * @return mixed + */ + public function getMontant() + { + return $this->montant; + } + + /** + * @return mixed + */ + public function getPhone() + { + return $this->phone; + } + + /** + * @param mixed $phone + */ + public function setPhone($phone) + { + $this->phone = $phone; + } + + /** + * @param mixed $montant + */ + public function setMontant($montant) + { + $this->montant = $montant; + } + +} \ No newline at end of file diff --git a/model/User.php b/model/User.php new file mode 100644 index 0000000..675bf68 --- /dev/null +++ b/model/User.php @@ -0,0 +1,12 @@ +updateWrongPoint(); + if(!$res){ + var_dump(mysqli_error($requester->db->con)); + }else{ + var_dump($res); + } +}catch (Exception $e){ + var_dump($e); +} diff --git a/updater.php b/updater.php new file mode 100644 index 0000000..0943237 --- /dev/null +++ b/updater.php @@ -0,0 +1,19 @@ +updateWrongPoint(); + if(!$res){ + var_dump(mysqli_error($requester->db->con)); + }else{ + var_dump($res); + } +}catch (Exception $e){ + var_dump($e); +}