private function prepareInput($attributes) { $preparedAttributes = array(); foreach ($attributes as $key => $value) { if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError', 'setOnEmpty'))) { $preparedAttributes[$key] = CPropertyValue::ensureString($value); } if ($key === 'except' || $key === 'on') { if (is_array($value)) { $preparedAttributes[$key] = implode(', ', $value); } } if ($key === 'value') { if ($value === true || $value === false) { $preparedAttributes[$key] = CPropertyValue::ensureString($value); } else { if (is_null($value)) { $preparedAttributes[$key] = 'null'; } else { if (is_array($value)) { $preparedAttributes[$key] = trim(str_replace('array', '', var_export($value, true))); } } } } } return $preparedAttributes; }
public function testEnsureString() { $entries = array(array('', ''), array('abc', 'abc'), array(null, ''), array(0, '0'), array(1, '1'), array(-1.1, '-1.1'), array(true, 'true'), array(false, 'false'), array(array(), 'Array'), array(array(0), 'Array')); foreach ($entries as $index => $entry) { $this->assertTrue(CPropertyValue::ensureString($entry[0]) === $entry[1], "Comparison {$index}: {$entry[0]}=={$entry[1]}"); } }
public function testEnsureString() { $entries = array(array('', ''), array('abc', 'abc'), array(null, ''), array(0, '0'), array(1, '1'), array(-1.1, '-1.1'), array(true, 'true'), array(false, 'false')); if (version_compare(PHP_VERSION, '5.4.0', '<')) { $entries = array_merge($entries, array(array(array(), 'Array'), array(array(0), 'Array'))); } foreach ($entries as $index => $entry) { $this->assertTrue(CPropertyValue::ensureString($entry[0]) === $entry[1], "Comparison {$index}: {$this->varToString($entry[0])}=={$this->varToString($entry[1])}"); } }
private function prepareInput($attributes) { $preparedAttributes = array(); foreach ($attributes as $key => $value) { if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError'))) { $preparedAttributes[$key] = CPropertyValue::ensureString($value); } if ($key === 'except' || $key === 'on') { if (is_array($value)) { $preparedAttributes[$key] = implode(', ', $value); } } } return $preparedAttributes; }
/** * dropDownList Taxonomy * * @param string $name * @param string $taxonomy * @param string $module * @param int $objectId * @param array $htmlOptions */ public static function dropDownList($name, $taxonomy, $module, $objectId, $htmlOptions = array()) { $properties = array('name' => $name, 'taxonomy' => $taxonomy, 'module' => $module, 'objectId' => $objectId); if (isset($htmlOptions['type'])) { $properties['type'] = CPropertyValue::ensureString($htmlOptions['type']); unset($htmlOptions['type']); } if (isset($htmlOptions['repeatChar'])) { $properties['repeatChar'] = CPropertyValue::ensureString($htmlOptions['repeatChar']); unset($htmlOptions['repeatChar']); } if (isset($htmlOptions['useRepeatChar'])) { $properties['useRepeatChar'] = CPropertyValue::ensureBoolean($htmlOptions['useRepeatChar']); unset($htmlOptions['useRepeatChar']); } $properties['htmlOptions'] = $htmlOptions; return Yii::app()->controller->widget('ListTaxonomy', $properties, true); }
/** * @param string $term */ public function actionSearchName($term) { // escape $term $term = CPropertyValue::ensureString($term); // create criteria $c = new CDbCriteria(); $c->distinct = true; $c->addSearchCondition('name', $term); $c->limit = 5; // save results $result = array(); foreach (Entry::model()->findAll($c) as $model) { /* @var Entry $model */ $result[] = $model->name; } // output result as JSON echo CJSON::encode($result); }
private function prepareInput($attributes) { $preparedAttributes = array(); foreach ($attributes as $key => $value) { if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError', 'allowEmpty', 'caseSensitive'))) { $preparedAttributes[$key] = CPropertyValue::ensureString($value); } if ($key === 'except' || $key === 'on') { if (is_array($value)) { $preparedAttributes[$key] = implode(', ', $value); } } if ($key === 'criteria') { $criteria = var_export($value, true); $criteria = substr_replace($criteria, '', 0, 5); $preparedAttributes[$key] = trim($criteria); } } return $preparedAttributes; }
public function setId($value) { $this->id = CPropertyValue::ensureString($value); }
public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); $criteria->addSearchCondition('username', $this->username, true, 'AND', 'ILIKE'); $criteria->addSearchCondition('email', $this->email, true, 'AND', 'ILIKE'); // $criteria->compare('user_group_id',$this->user_group_id); //$criteria->addSearchCondition('last_login',$this->last_login,true,'AND','ILIKE'); $criteria->compare('status', $this->status); //$criteria->addSearchCondition('creation_datetime',$this->creation_datetime,true,'AND','ILIKE'); //$criteria->addSearchCondition('last_update',$this->last_update,true,'AND','ILIKE'); $criteria->with = array('auth' => array('joinType' => 'LEFT JOIN')); $criteria->together = true; if (!empty($this->userRole)) { if ($this->userRole == 'no-role') { $criteria->addCondition('auth.userid IS NULL'); } else { $criteria->compare('auth.itemname', CPropertyValue::ensureString($this->userRole)); } } $dataprovider = new CActiveDataProvider(get_class($this), array('criteria' => $criteria, 'sort' => array('defaultOrder' => 't.id DESC'), 'pagination' => array('pageSize' => defined('SETTINGS_BO_PAGE_SIZE') ? SETTINGS_BO_PAGE_SIZE : 50))); return $dataprovider; }
/** * Extract an data from input data * * @param string $name can be an normal name or 'Class[attribute]' to get input of a model attribute * * @param mixed $defaultValue it is recommended to specify default value even when you * are sure that the input has data you want to extract. * * @param string $filter 'xss,notag,newline' filters the data is run through before returned * do not combine xss with notag as it slow down the performance. */ public function getInput($name, $defaultValue = null, $filter = '') { if (is_array($parsedName = $this->parseName($name))) { $name = $parsedName[0]; $key = $parsedName[1]; } if (!array_key_exists($name, $this->data)) { return $defaultValue; } else { $value = $this->data[$name]; if (isset($key) && is_array($value)) { $value = $value[$key]; } if (is_null($value)) { return $defaultValue; } } //Run filters if (is_string($value) || is_array($value)) { foreach ($this->filters as $flt) { $value = call_user_func(array($this, $flt), $value, $filter); } } if (is_array($value)) { return $value; } $value = trim($value); //Convert to expected type if (is_null($defaultValue)) { return trim($value); } if (is_string($defaultValue)) { return CPropertyValue::ensureString($value); } if (is_int($defaultValue)) { return CPropertyValue::ensureInteger($value); } if (is_numeric($defaultValue)) { return CPropertyValue::ensureFloat($value); } if (is_array($defaultValue)) { if (!is_array($value)) { return array($value); } else { return $value; } } return $value; }