本文整理汇总了PHP中AuxLib::coerceToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP AuxLib::coerceToArray方法的具体用法?PHP AuxLib::coerceToArray怎么用?PHP AuxLib::coerceToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuxLib
的用法示例。
在下文中一共展示了AuxLib::coerceToArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: evalComparison
/**
* @param mixed $subject if applicable, the value to compare $subject with (value of model
* attribute)
* @param string $operator the type of comparison to be used
* @param mixed $value the value being analyzed (specified in config menu)
* @return boolean
*/
public static function evalComparison($subject, $operator, $value = null, Fields $field = null)
{
$value = self::parseArray($operator, $value);
// if (!in_array ($operator, $expectsArray, true) && is_array ($value)) {
// if (count ($value) > 1) {
// return false;
// } else {
// $value = array_pop ($value);
// }
// }
switch ($operator) {
case '=':
// check for multiselect dropdown
if ($field && $field->type === 'dropdown') {
$dropdown = $field->getDropdown();
if ($dropdown && $dropdown->multi) {
$subject = StringUtil::jsonDecode($subject, false);
AuxLib::coerceToArray($subject);
AuxLib::coerceToArray($value);
return $subject === $value;
}
// check for muti-assignment field
} else {
if ($field && $field->type === 'assignment' && $field->linkType === 'multiple') {
$subject = explode(Fields::MULTI_ASSIGNMENT_DELIM, $subject);
AuxLib::coerceToArray($subject);
AuxLib::coerceToArray($value);
return $subject === $value;
}
}
// this case occurs when dropdown or assignment fields are changed from multiple
// to single selection, and flow conditions are left over from before the change
// was made
if (is_array($value)) {
AuxLib::coerceToArray($subject);
}
return $subject == $value;
case '>':
return $subject > $value;
case '<':
return $subject < $value;
case '>=':
return $subject >= $value;
case '<=':
return $subject <= $value;
case 'between':
if (count($value) !== 2) {
return false;
}
return $subject >= min($value) && $subject <= max($value);
case '<>':
case '!=':
return $subject != $value;
case 'notEmpty':
return $subject !== null && $subject !== '';
case 'empty':
return $subject === null || trim($subject) === '';
case 'list':
if (count($value) === 0) {
// if the list is empty,
return false;
}
// A isn't in it
foreach ($value as &$val) {
if ($subject == $val) {
return true;
}
}
return false;
case 'notList':
if (count($value) === 0) {
// if the list is empty,
return true;
}
// A isn't *not* in it
foreach ($value as &$val) {
if ($subject == $val) {
return false;
}
}
return true;
case 'noContains':
return stripos($subject, $value) === false;
case 'contains':
default:
return stripos($subject, $value) !== false;
}
}
示例2: getItems2
/**
* Improved version of getItems which enables use of empty search string, pagination, and
* configurable option values/names.
* @param string $prefix name prefix of items to retrieve
* @param int $page page number of results to retrieve
* @param int $limit max number of results to retrieve
* @param string|array $valueAttr attribute(s) used to popuplate the option values. If an
* array is passed, value will composed of values of each of the attributes specified, joined
* by commas
* @param string $nameAttr attribute used to popuplate the option names
* @return array name, value pairs
*/
public function getItems2($prefix = '', $page = 0, $limit = 20, $valueAttr = 'name', $nameAttr = 'name')
{
$modelClass = get_class($this->owner);
$model = CActiveRecord::model($modelClass);
$table = $model->tableName();
$offset = intval($page) * intval($limit);
AuxLib::coerceToArray($valueAttr);
$modelClass::checkThrowAttrError(array_merge($valueAttr, array($nameAttr)));
$params = array();
if ($prefix !== '') {
$params[':prefix'] = $prefix . '%';
}
$offset = abs((int) $offset);
$limit = abs((int) $limit);
$command = Yii::app()->db->createCommand("\n SELECT " . implode(',', $valueAttr) . ", {$nameAttr} as __name\n FROM {$table}\n WHERE " . ($prefix === '' ? '1=1' : $nameAttr . ' LIKE :prefix') . "\n ORDER BY __name\n LIMIT {$offset}, {$limit}\n ");
$rows = $command->queryAll(true, $params);
$items = array();
foreach ($rows as $row) {
$name = $row['__name'];
unset($row['__name']);
$items[] = array($name, $row);
}
return $items;
}
示例3: parseModelType
public static function parseModelType($modelType)
{
//AuxLib::debugLogR ($modelType);
if (isset($_GET['workflowAjax']) && $_GET['workflowAjax']) {
$modelType = CJSON::decode($modelType);
}
if (empty($modelType) || is_array($modelType) && sizeof($modelType) === 1 && empty($modelType[0])) {
return '';
}
AuxLib::coerceToArray($modelType);
return $modelType;
}