public function send($phones, $text) { $request = new DOMDocument("1.0", "UTF-8"); $requestBody = $request->createElement('SMS'); $requestBody->appendChild($this->createOperationsElement(array(self::SEND))); $requestBody->appendChild($this->createAuthElement()); $request->appendChild($requestBody); $sms = $request->createElement('message'); $sms->appendChild($request->createElement('sender', $this->sender)); $textElement = $request->createElement('text'); $textElement->appendChild(new DOMCdataSection($text)); $sms->appendChild($textElement); $requestBody->appendChild($sms); if (is_array($phones) == false) { $phones = array($phones => array()); } $numbers = $request->createElement('numbers'); foreach ($phones as $phone => $value) { $variables = implode(';', CPropertyValue::ensureArray($value)) . ';'; $number = $request->createElement('number', $phone); $number->setAttribute('messageid', md5($phone . date() . $variables)); $number->setAttribute('variables', $variables); $numbers->appendChild($number); } $requestBody->appendChild($numbers); $responseText = $this->doRequest($request->saveXML()); $result = $this->parseResponse($responseText); $status = $result['status']; $ok = (bool) ($status > 0); $needSmsAlert = $ok == false && $status != -4; $credits = $this->balance(); return array('status' => $status, 'ok' => $ok, 'responseText' => $responseText, 'credits' => $credits, 'needSmsAlert' => $needSmsAlert); }
public function testEnsureArray() { $entries = array(array(123, array(123)), array(null, array()), array('', array()), array('abc', array('abc')), array('(1,2)', array(1, 2)), array('("key"=>"value",2=>3)', array("key" => "value", 2 => 3)), array(true, array(true)), array(array(), array()), array(array(0), array(0))); foreach ($entries as $index => $entry) { $this->assertTrue(CPropertyValue::ensureArray($entry[0]) === $entry[1], "Comparison {$index}: {$this->varToString($entry[0])}=={$this->varToString($entry[1])}"); } }
public function convertType($value) { $value = trim($value); if (ctype_digit($value)) { return CPropertyValue::ensureInteger($value); } if (is_numeric($value)) { return CPropertyValue::ensureFloat($value); } if (strcasecmp($value, 'null') == 0) { return null; } else { if (strcasecmp($value, 'true') == 0 || strcasecmp($value, 'false') == 0) { return CPropertyValue::ensureBoolean($value); } else { if (preg_match('/^\\(.+\\)|\\(\\)$/', $value)) { return CPropertyValue::ensureArray($value); } } } return $value; }
public function send($phones, $text) { $sender = $this->sender; $result = array(); foreach ($phones as $phone => $variables) { $variables = CPropertyValue::ensureArray($variables); $textMsg = $text; $i = 1; foreach ($variables as $variable) { $textMsg = str_replace('%' . $i . '%', $variable, $textMsg); $i++; } $args = array('login' => $this->username, 'password' => $this->password, 'messages' => array(array('clientId' => $sender, 'phone' => $phone, 'text' => $text))); $response = $this->doRequest(self::SEND_URL, $args); $responseText = CJSON::encode($response); $resultStatus = false; $credits = 0; $status = isset($response['status']) ? $response['status'] : 'no status'; if ($status == 'ok') { if (isset($response['messages']) == false || count($response['messages']) == 0) { throw new Exception('No messages in response'); } $message = $response['messages'][0]; $status = isset($message['status']) ? $message['status'] : 'no status'; $resultStatus = $status == 'accepted'; $response = $this->doRequest(self::CREDITS_URL, array('login' => $this->username, 'password' => $this->password)); if (isset($response['balance'])) { $credits = $response['balance'][0]['balance']; } else { throw new Exception('No credits in response'); } } $result = array('ok' => $status == 'ok', 'status' => $status, 'responseText' => $responseText, 'credits' => $credits, 'needSmsAlert' => true); } return $result; }
public function setScopes ($scopes) { $this->_scopes = CPropertyValue::ensureArray($scopes); }
/** * Apply flags conditions to given criteria * @param CDbCriteria $criteria the criteria to apply flags condition * @param array $flags the array with flags (as flag name or as flag value). Flag name started with '!' is mean 'not flag' * @param string $operator the operator that connect flags conditions * @return CDbCriteria the CDbCriteria object with applied flags conditions */ public function applyFlags($criteria, $flags, $operator = 'AND') { $flagList = $this->cachedFlags(); $flags = CPropertyValue::ensureArray($flags); $newCriteria = new CDbCriteria(); foreach ($flags as $flag) { if (is_string($flag)) { if ($invert = $flag[0] == '!') { $flag = substr($flag, 1); } $flagValue = $flagList[trim(strtolower($flag))]; } else { $flagValue = $flag; } if (empty($flagValue) === false) { $equality = $invert ? '=' : '<>'; $newCriteria->addCondition($this->flagsField . '&' . $flagValue . $equality . '0', $operator); } } $criteria->mergeWith($newCriteria); return $criteria; }
private function prepareOutput() { $preparedAttributes = array(); foreach ($this->getAttributes() as $key => $value) { if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError', 'allowEmpty', 'caseSensitive'))) { $preparedAttributes[$key] = CPropertyValue::ensureBoolean($value); } if ($key === 'except' || $key === 'on') { if (!is_null($value)) { $preparedAttributes[$key] = array_map('trim', explode(',', $value)); } } if ($key === 'criteria') { if (is_string($value)) { $value = trim($value); } $preparedAttributes[$key] = CPropertyValue::ensureArray($value); } } return $preparedAttributes; }
private function findByAttributeValue($array, $attribute, $value) { $array = CPropertyValue::ensureArray($array); foreach ($array as $key => $entry) { if ($entry[$attribute] == $value) { return $entry; } } return false; }
<?php /** * @var $authItem CAuthItem */ ?> <?php if ($authItem->type == CAuthItem::TYPE_OPERATION) { ?> <label> <?php echo CHtml::checkBox('role[' . $authItem->name . ']', in_array($authItem->name, CPropertyValue::ensureArray($role->data))); ?> <?php echo $authItem->description; ?> </label> <?php } else { ?> <p class="form-control-static"> <?php echo CAuthItem::TYPE_ROLE == $authItem->type ? $authItem->name : $authItem->description; ?> </p> <?php }