本文整理汇总了PHP中app\models\Property::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Property::findOne方法的具体用法?PHP Property::findOne怎么用?PHP Property::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Property
的用法示例。
在下文中一共展示了Property::findOne方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSavePropertyUnit
/**
* @return Response
* @throws HttpException
*/
public function actionSavePropertyUnit()
{
if (false === \Yii::$app->request->isAjax) {
throw new HttpException(403);
}
/** @var $property Property | null */
$property = null;
Yii::$app->response->format = Response::FORMAT_JSON;
$post = Yii::$app->request->post();
if (false === isset($post['id']) || null === ($property = Property::findOne(['id' => $post['id']]))) {
return 0;
}
if (false === isset($post['name']) || false === isset($post['val'])) {
return 0;
}
$data = Json::decode($property->handler_additional_params);
$data[$post['name']] = $post['val'];
$property->handler_additional_params = Json::encode($data);
if (true === $property->save(true, ['handler_additional_params'])) {
return 1;
}
return 0;
}
示例2: actionAutocomplete
public function actionAutocomplete($search = null, $id = null, $object_id = null)
{
/**
* @todo Добавить отображение вложенности
*/
$out = ['more' => false];
if (!is_null($search)) {
$query = new Query();
$query->select(Property::tableName() . '.id, ' . Property::tableName() . '.name AS text')->from(Property::tableName())->andWhere(['like', Property::tableName() . '.name', $search])->limit(100);
if (!is_null($object_id)) {
$query->leftJoin(PropertyGroup::tableName(), PropertyGroup::tableName() . '.id = ' . Property::tableName() . '.property_group_id');
$query->andWhere([PropertyGroup::tableName() . '.id' => $object_id]);
}
$command = $query->createCommand();
$data = $command->queryAll();
$out['results'] = array_values($data);
} elseif ($id > 0) {
$out['results'] = ['id' => $id, 'text' => Property::findOne($id)->name];
} else {
$out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
}
echo Json::encode($out);
}
示例3: actionDeleteProperty
public function actionDeleteProperty($id, $property_group_id)
{
/** @var Property $model */
$model = Property::findOne($id);
if (is_null($model)) {
throw new NotFoundHttpException();
}
$model->delete();
Yii::$app->session->setFlash('danger', Yii::t('app', 'Object removed'));
return $this->redirect(Url::to(['/backend/properties/group', 'id' => $property_group_id]));
}
示例4: renderProducts
/**
* renders product item and list.
* possible can render all objects, but need for few logic change
* @param array $chunkData params for select and render
* @param TagDependency $dependency
* @return mixed
*/
private static function renderProducts($chunkData, &$dependency)
{
$params = ['itemView' => Yii::$app->getModule('shop')->itemView, 'type' => 'show', 'object' => 'product', 'where' => [], 'limit' => 0, 'listView' => Yii::$app->getModule('shop')->listView];
switch ($chunkData['key']) {
case 'product':
if (ArrayHelper::keyExists('sku', $chunkData)) {
$params['where'] = ['sku' => $chunkData['sku']];
}
break;
case 'productList':
$params['type'] = 'list';
break;
default:
$expression = '%(?P<objectName>[^#]+?)#(?P<objectId>[\\d]+?)$%';
if (preg_match($expression, $chunkData['key'], $matches)) {
$params['where']['id'] = $matches['objectId'];
}
break;
}
switch ($params['object']) {
case 'product':
$dependency->tags[] = ActiveRecordHelper::getCommonTag(Product::className());
$query = Product::find();
if (!empty($chunkData['categoryId'])) {
$query->leftJoin('{{%product_category}}', Product::tableName() . '.id = {{%product_category}}.object_model_id')->andWhere(['{{%product_category}}.category_id' => $chunkData['categoryId']]);
$dependency->tags[] = ActiveRecordHelper::getCommonTag(Category::className());
$dependency->tags[] = ActiveRecordHelper::getObjectTag(Category::className(), $chunkData['categoryId']);
}
if (!empty($chunkData['property'])) {
$expression = '%(?P<propertyKey>[^:]+?):(?P<propertyValue>.+?)$%';
if (preg_match($expression, $chunkData['property'], $matches)) {
$property = Property::findOne(['key' => $matches['propertyKey']]);
if (!is_null($property)) {
/** @var Property $property */
$dependency->tags[] = ActiveRecordHelper::getCommonTag(Property::className());
$dependency->tags[] = $property->objectTag();
if ($property->is_eav == 1) {
$query->leftJoin('{{%product_eav}}', Product::tableName() . '.id = {{%product_eav}}.object_model_id')->andWhere(['{{%product_eav}}.key' => $matches['propertyKey'], '{{%product_eav}}.value' => $matches['propertyValue']]);
} elseif ($property->has_static_values == 1) {
$psv = PropertyStaticValues::findOne(['property_id' => $property->id, 'value' => $matches['propertyValue']]);
if (!is_null($psv)) {
$dependency->tags[] = ActiveRecordHelper::getCommonTag(PropertyStaticValues::className());
$dependency->tags[] = $psv->objectTag();
$query->leftJoin('{{%object_static_values}}', Product::tableName() . '.id = {{%object_static_values}}.object_model_id')->andWhere(['object_id' => 3, '{{%object_static_values}}.property_static_value_id' => $psv->id]);
} else {
return '';
}
}
/** @todo add column_stored */
} else {
return '';
}
}
}
break;
default:
$query = Product::find();
break;
}
$params = ArrayHelper::merge($params, array_intersect_key($chunkData, $params));
if (!empty($params['where'])) {
$query->andWhere($params['where']);
}
if (!empty($params['limit'])) {
$query->limit($params['limit']);
}
if ($params['type'] === 'list') {
$view = $params['listView'];
$objects = $query->all();
foreach ($objects as $object) {
$dependency->tags[] = $object->objectTag();
}
switch ($params['object']) {
case 'product':
$viewParams = ['products' => $objects];
break;
default:
$viewParams = ['products' => $objects];
break;
}
} else {
$view = $params['itemView'];
$object = $query->one();
if (is_null($object)) {
return '';
}
$dependency->tags[] = $object->objectTag();
switch ($params['object']) {
case 'product':
$viewParams = ['product' => $object, 'url' => Url::to(['@product', 'model' => $object, 'category_group_id' => $object->getMainCategory()->category_group_id])];
break;
default:
$viewParams = ['product' => $object, 'url' => Url::to(['@product', 'model' => $object, 'category_group_id' => $object->getMainCategory()->category_group_id])];
//.........这里部分代码省略.........
示例5: getDefaultLanguage
public static function getDefaultLanguage()
{
$languages = self::getLanguages();
$model = Property::findOne('default_language');
return !is_null($model) && !empty($model->value) && in_array($model->value, $languages) ? $model->value : $languages[0];
}