本文整理汇总了PHP中CPropertyValue::ensureInteger方法的典型用法代码示例。如果您正苦于以下问题:PHP CPropertyValue::ensureInteger方法的具体用法?PHP CPropertyValue::ensureInteger怎么用?PHP CPropertyValue::ensureInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPropertyValue
的用法示例。
在下文中一共展示了CPropertyValue::ensureInteger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionBulkCreate
public function actionBulkCreate(array $names = array(), $parentId = 0, $vocabularyId = 0)
{
$vocabularyId = CPropertyValue::ensureInteger($vocabularyId);
if (!$vocabularyId) {
return errorHandler()->log('Missing Vocabulary Id');
}
foreach ($names as $catName) {
$catName = trim($catName);
if ($catName == '') {
continue;
}
$model = new Term('single_save');
$model->v_id = $vocabularyId;
$model->name = $catName;
$model->alias = Utility::createAlias($model, $model->name);
$model->state = Term::STATE_ACTIVE;
$model->parentId = $parentId;
if (!$model->save()) {
$this->result->fail(ERROR_HANDLING_DB, 'save category failed');
} else {
if ($model->parentId) {
$relation = TermHierarchy::model()->findByAttributes(array('term_id' => $model->id));
if (!is_object($relation)) {
$relation = new TermHierarchy();
$relation->term_id = $model->id;
}
$relation->parent_id = $model->parentId;
if (!$relation->save()) {
Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR);
}
}
}
}
}
示例2: testEnsureInteger
public function testEnsureInteger()
{
$entries = array(array(123, 123), array(1.23, 1), array(null, 0), array('', 0), array('abc', 0), array('123', 123), array('1.23', 1), array(' 1.23', 1), array(' 1.23abc', 1), array('abc1.23abc', 0), array(true, 1), array(false, 0), array(array(), 0), array(array(0), 1));
foreach ($entries as $index => $entry) {
$this->assertTrue(CPropertyValue::ensureInteger($entry[0]) === $entry[1], "Comparison {$index}: {$this->varToString($entry[0])}=={$this->varToString($entry[1])}");
}
}
示例3: generateProductGrid
/**
* This function generates the products grid
* based on the criteria. It also generates the
* pagination object need for the users to navigate
* through products.
*
* @return void
*/
public function generateProductGrid()
{
$this->_numberOfRecords = Product::model()->count($this->_productGridCriteria);
$this->_pages = new CPagination($this->_numberOfRecords);
$this->_pages->setPageSize(CPropertyValue::ensureInteger(Yii::app()->params['PRODUCTS_PER_PAGE']));
$this->_pages->applyLimit($this->_productGridCriteria);
$this->_productsGrid = self::createBookends(Product::model()->findAll($this->_productGridCriteria));
}
示例4: getIsGuest
public function getIsGuest()
{
$customer = Customer::model()->findByPk($this->id);
if ($customer !== null) {
return CPropertyValue::ensureInteger($customer->record_type) === Customer::GUEST;
}
return parent::getIsGuest();
}
示例5: render
public function render($params = array())
{
$height = CPropertyValue::ensureInteger($params['height']);
$height -= $height > 40 ? 20 : 0;
parent::appendOption($this->_htmlOptions, 'class', $this->_cssClass);
parent::appendOption($this->_htmlOptions, 'style', 'height: ' . $height . 'px;');
echo CHtml::tag('li', $this->_htmlOptions, $this->_data);
}
示例6: init
public function init()
{
parent::init();
//find workflow by id
$workflowId = app()->request->getParam('workflow_id', null);
if ($workflowId !== null) {
$this->setWorkflow(CPropertyValue::ensureInteger($workflowId));
}
}
示例7: parseTree
public static function parseTree($objRet, $root = 0)
{
$return = array();
# Traverse the tree and search for direct children of the root
foreach ($objRet as $objItem) {
if (CPropertyValue::ensureInteger($objItem->child_count) > 0 || CPropertyValue::ensureBoolean(Yii::app()->params['DISPLAY_EMPTY_CATEGORY'])) {
$return[] = array('text' => CHtml::link($objItem->family, $objItem->Link), 'label' => $objItem->family, 'link' => $objItem->Link, 'request_url' => $objItem->request_url, 'url' => $objItem->Link, 'id' => $objItem->id, 'child_count' => $objItem->child_count, 'children' => null, 'items' => null);
}
}
return empty($return) ? null : $return;
}
示例8: afterSave
/**
* Responds to {@link CActiveRecord::onAfterSave} event.
* Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
* @param CModelEvent $event event parameter
*/
public function afterSave($event)
{
$data = array();
$objectId = $this->getOwner()->{$this->objectAttribute};
if ($this->useActiveField) {
$data = $this->getOwner()->{$this->name};
if (!is_array($data) && !is_object($data)) {
$data = array((int) $data);
}
} else {
if (isset($_POST[$this->name])) {
$data = $_POST[$this->name];
if (!is_array($data) && !is_object($data)) {
$data = array((int) $data);
}
}
}
//delete old
$sql = "DELETE FROM " . SITE_ID . '_' . "taxonomy_index t" . "\n USING " . SITE_ID . '_' . "taxonomy_term tt, " . SITE_ID . '_' . "taxonomy_vocabulary tv" . "\n WHERE tt.id = t.term_id AND tv.id = tt.v_id" . (is_numeric($this->taxonomy) ? "\n AND (tv.id = :id)" : "\n AND (tv.alias = :alias)") . "\n AND tv.module = :module AND t.object_id = :object_id";
if (count($data)) {
foreach ($data as $index => $val) {
$data[$index] = CPropertyValue::ensureInteger($val);
}
$dataString = implode(',', $data);
$sql .= "\n AND t.term_id NOT IN ({$dataString})";
}
$command = TermRelation::model()->getDbConnection()->createCommand($sql);
if (is_numeric($this->taxonomy)) {
$command->bindParam(":id", $this->taxonomy, PDO::PARAM_INT);
} else {
$command->bindParam(":alias", $this->taxonomy, PDO::PARAM_STR);
}
$command->bindParam(":module", $this->module, PDO::PARAM_STR);
$command->bindParam(":object_id", $objectId, PDO::PARAM_INT);
$command->execute();
//update/create
if (count($data)) {
foreach ($data as $val) {
$relation = TermRelation::model()->findByAttributes(array('object_id' => $objectId, 'term_id' => $val));
if (!is_object($relation)) {
$relation = new TermRelation();
}
$relation->object_id = $objectId;
$relation->term_id = $val;
if (!$relation->save()) {
Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR);
}
}
}
}
示例9: actionIndex
/**
* @return void
*/
public function actionIndex()
{
$model = new Tag('search');
$model->userId = Yii::app()->user->id;
/* @var CHttpRequest $request */
$request = Yii::app()->request;
if ($request->getQuery('pagesize') != null) {
/* @var Setting $setting */
$setting = Setting::model()->name(Setting::PAGINATION_PAGE_SIZE_TAGS)->find();
$pageSize = CPropertyValue::ensureInteger($request->getQuery('pagesize'));
if ($pageSize > 0) {
$setting->value = $pageSize;
$setting->save();
}
}
if (isset($_GET['Tag'])) {
$model->attributes = $_GET['Tag'];
}
$this->render('index', array('model' => $model));
}
示例10: actionIndex
/**
* Default action.
*
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*
* @return void
*/
public function actionIndex()
{
$homePage = _xls_get_conf('HOME_PAGE', '*products');
switch ($homePage) {
case "*index":
if (Yii::app()->params['LIGHTSPEED_MT'] == '1') {
if (Yii::app()->theme->info->showCustomIndexOption) {
$this->render("/site/index");
} else {
$this->forward("search/browse");
}
} else {
$this->render("/site/index");
}
break;
case "*products":
$this->forward("search/browse");
break;
default:
//Custom Page
$objCustomPage = CustomPage::LoadByKey($homePage);
$productsGrid = null;
$dataProvider = null;
if (!$objCustomPage instanceof CustomPage) {
_xls_404();
}
$this->pageTitle = $objCustomPage->PageTitle;
$this->pageDescription = $objCustomPage->meta_description;
$this->pageImageUrl = '';
$this->breadcrumbs = array($objCustomPage->title => $objCustomPage->RequestUrl);
if (CPropertyValue::ensureInteger($objCustomPage->product_display) === 2) {
$productsGrid = new ProductGrid($objCustomPage->getProductGridCriteria());
} else {
$dataProvider = $objCustomPage->taggedProducts();
}
$this->canonicalUrl = $objCustomPage->canonicalUrl;
$this->render('/custompage/index', array('model' => $objCustomPage, 'dataProvider' => $dataProvider, 'productsGrid' => $productsGrid));
break;
}
}
示例11: activeDropDownList
/**
* activeDropDownList Taxonomy
*
* @param string $name
* @param string $taxonomy
* @param string $module
* @param int $objectId
* @param array $htmlOptions
*/
public static function activeDropDownList($model, $attribute, $taxonomy, $module, $htmlOptions = array())
{
$properties = array('model' => $model, 'attribute' => $attribute, 'taxonomy' => $taxonomy, 'module' => $module, 'objectId' => $model->getPrimaryKey());
if (isset($htmlOptions['type'])) {
$properties['type'] = CPropertyValue::ensureString($htmlOptions['type']);
unset($htmlOptions['type']);
}
if (isset($htmlOptions['objectId'])) {
$properties['objectId'] = CPropertyValue::ensureInteger($htmlOptions['objectId']);
unset($htmlOptions['objectId']);
}
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);
}
示例12: convertType
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;
}
示例13: prepareOutput
private function prepareOutput()
{
$preparedAttributes = array();
foreach ($this->getAttributes() as $key => $value) {
if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError', 'allowEmpty'))) {
$preparedAttributes[$key] = CPropertyValue::ensureBoolean($value);
}
if ($key === 'except' || $key === 'on') {
if (!is_null($value)) {
$preparedAttributes[$key] = array_map('trim', explode(',', $value));
}
}
if ($key === 'is' || $key === 'max' || $key === 'min') {
if (!is_null($value)) {
$preparedAttributes[$key] = CPropertyValue::ensureInteger($value);
} else {
$preparedAttributes[$key] = null;
}
}
}
return $preparedAttributes;
}
示例14: actionSetSidebarPositions
/**
* @throws CHttpException
* @return void
*/
public function actionSetSidebarPositions()
{
// only ajax-request are allowed
if (!Yii::app()->request->isAjaxRequest) {
throw new CHttpException(400);
}
$neededParams = array(Setting::MOST_VIEWED_ENTRIES_WIDGET_POSITION, Setting::RECENT_ENTRIES_WIDGET_POSITION, Setting::TAG_CLOUD_WIDGET_POSITION);
// check if all needed params exist
foreach ($neededParams as $paramName) {
if (!isset($_POST[$paramName])) {
throw new CHttpException(401);
}
}
// save settings
foreach ($neededParams as $paramName) {
/* @var Setting $model */
$param = CPropertyValue::ensureInteger($_POST[$paramName]);
$model = Setting::model()->findByAttributes(array('name' => $paramName));
$model->value = $param;
$model->save();
}
echo '1';
}
示例15: getMenuTree
/**
* Build array combining product categories, families and Custom Pages.
*
* @return array
*/
public function getMenuTree()
{
$categoryTree = Category::GetTree();
$extraTopLevelItems = CustomPage::GetTree();
// Whether the families (aka. manufacturers) are displayed the product menu.
// ENABLE_FAMILIES:
// 0 => No families in the product menu.
// 1 => Separate menu item at bottom of product menu.
// 2 => Separate menu item at top of product menu.
// 3 => Blended into the top level of the menu.
//
if (CPropertyValue::ensureInteger(Yii::app()->params['ENABLE_FAMILIES']) > 0) {
$familyTree = Family::GetTree();
if (CPropertyValue::ensureInteger(Yii::app()->params['ENABLE_FAMILIES']) === 3) {
$extraTopLevelItems += $familyTree;
}
}
// The behaviour varies here because OnSite customers are able to
// configure the menu_position of their categories. A more thorough
// solution might modify the menu code to return the menu_position for
// each menu item for sorting, however Categories should already be
// sorted by menu_position.
if (CPropertyValue::ensureInteger(Yii::app()->params['LIGHTSPEED_CLOUD']) !== 0) {
// Retail: Sort the entire menu alphabetically.
$objTree = $categoryTree + $extraTopLevelItems;
ksort($objTree);
} else {
// OnSite: Only sort the extras alphabetically (categories are
// already sorted by menu_position).
ksort($extraTopLevelItems);
$objTree = $categoryTree + $extraTopLevelItems;
}
if (CPropertyValue::ensureInteger(Yii::app()->params['ENABLE_FAMILIES']) === 1 || CPropertyValue::ensureInteger(Yii::app()->params['ENABLE_FAMILIES']) === 2) {
$familyMenu['families_brands_menu'] = array('text' => CHtml::link(Yii::t('category', Yii::app()->params['ENABLE_FAMILIES_MENU_LABEL']), $this->createUrl("search/browse", array('brand' => '*'))), 'label' => Yii::t('category', Yii::app()->params['ENABLE_FAMILIES_MENU_LABEL']), 'link' => $this->createUrl("search/browse", array('brand' => '*')), 'url' => $this->createUrl("search/browse", array('brand' => '*')), 'id' => 0, 'child_count' => count($familyTree), 'hasChildren' => 1, 'children' => $familyTree, 'items' => $familyTree);
if (CPropertyValue::ensureInteger(Yii::app()->params['ENABLE_FAMILIES']) === 1) {
// The manufacturers menu is at the bottom.
$objTree = $objTree + $familyMenu;
} elseif (CPropertyValue::ensureInteger(Yii::app()->params['ENABLE_FAMILIES']) === 2) {
// The manufacturers menu is at the top.
$objTree = $familyMenu + $objTree;
}
}
$this->_objFullTree = $objTree;
return $this->_objFullTree;
}