本文整理汇总了PHP中devgroup\tagdependencyhelper\ActiveRecordHelper::getObjectTag方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordHelper::getObjectTag方法的具体用法?PHP ActiveRecordHelper::getObjectTag怎么用?PHP ActiveRecordHelper::getObjectTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devgroup\tagdependencyhelper\ActiveRecordHelper
的用法示例。
在下文中一共展示了ActiveRecordHelper::getObjectTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->model === null) {
throw new InvalidConfigException("Model should be set for WarehousesRemains widget");
}
$state = $this->model->getWarehousesState();
$activeWarehousesIds = Warehouse::activeWarehousesIds();
$remains = [];
foreach ($state as $remain) {
$remains[$remain->warehouse_id] = $remain;
if (($key = array_search($remain->warehouse_id, $activeWarehousesIds)) !== false) {
unset($activeWarehousesIds[$key]);
}
}
// if we have new warehouses that not represented in warehouses state
if (count($activeWarehousesIds) > 0) {
foreach ($activeWarehousesIds as $id) {
// create new record with default values
$remain = new WarehouseProduct();
$remain->warehouse_id = $id;
$remain->product_id = $this->model->id;
$remain->save();
// add to remains
$remains[$remain->warehouse_id] = $remain;
}
TagDependency::invalidate(Yii::$app->cache, ActiveRecordHelper::getObjectTag($this->model->className(), $this->model->id));
}
return $this->render('warehouses-remains', ['model' => $this->model, 'remains' => $remains]);
}
示例2: appendPart
/**
* @inheritdoc
*/
public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
{
/*
В parameters должен храниться last_category_id
Если его нет - используем parameters.category_id
*/
$category_id = null;
if (isset($parameters['last_category_id'])) {
$category_id = $parameters['last_category_id'];
} elseif (isset($parameters['category_id'])) {
$category_id = $parameters['category_id'];
}
$used_params[] = 'last_category_id';
$used_params[] = 'category_id';
if ($category_id === null) {
return false;
}
$category = Category::findById($category_id);
if (is_object($category) === true) {
$parentIds = $category->getParentIds();
foreach ($parentIds as $id) {
$cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
}
$cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category_id);
return $category->getUrlPath($this->include_root_category);
} else {
return false;
}
}
示例3: widgetRun
/**
* Actual run function for all widget classes extending BaseWidget
*
* @return mixed
*/
public function widgetRun()
{
$pages = Page::getDb()->cache(function ($db) {
return Page::find()->where(['parent_id' => $this->parent_id])->orderBy([$this->order_by => $this->order])->limit($this->limit)->all();
}, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Page::className(), $this->parent_id)]]));
return $this->render($this->view_file, ['pages' => $pages, 'parent_id' => $this->parent_id, 'more_pages_label' => $this->more_pages_label, 'display_date' => $this->display_date, 'date_format' => $this->date_format]);
}
示例4: getClassNameAndParamsById
/**
* Returns class name and params of widget for specified wysiwyg record id
* @param integer $id ID of Wysiwyg record
* @return array of 'class_name' and 'params'
*/
public static function getClassNameAndParamsById($id)
{
$cacheKey = 'WysiwygClassName:' . $id;
$data = Yii::$app->cache->get($cacheKey);
if (is_array($data) === false) {
$data = self::getDb()->createCommand('select class_name, params from {{%wysiwyg}} where id = :id', [':id' => $id])->queryOne();
$data['params'] = empty($data['params']) ? [] : Json::decode($data['params']);
Yii::$app->cache->set($cacheKey, $data, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(self::className(), $id)]]));
}
return $data;
}
示例5: findById
/**
* @param integer $id
* @return \yii\db\ActiveRecord
*/
public static function findById($id)
{
$cache_key = static::className() . ':' . $id;
$model = Yii::$app->cache->get($cache_key);
if (is_object($model) === false) {
$model = static::findOne($id);
if (is_object($model)) {
Yii::$app->cache->set(static::className() . ":" . $id, $model, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $model->id)]]));
}
}
return $model;
}
示例6: findById
/**
* Get measure by id.
* @param int $id
* @return Measure
*/
public static function findById($id)
{
$cacheKey = 'Measure: ' . $id;
$measure = Yii::$app->cache->get($cacheKey);
if ($measure === false) {
$measure = self::findOne($id);
if (is_null($measure)) {
return null;
}
Yii::$app->cache->set($cacheKey, $measure, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(self::className()), ActiveRecordHelper::getObjectTag(self::className(), $id)]]));
}
return $measure;
}
示例7: findById
/**
* Returns model instance by ID using IdentityMap
* @param integer $id
* @return Object
*/
public static function findById($id)
{
if (!isset(static::$identity_map[$id])) {
static::$identity_map[$id] = Yii::$app->cache->get(static::tableName() . ': ' . $id);
if (static::$identity_map[$id] === false) {
static::$identity_map[$id] = static::findOne($id);
if (is_object(static::$identity_map[$id])) {
Yii::$app->cache->set(static::tableName() . ': ' . $id, static::$identity_map[$id], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id)]]));
}
}
}
return static::$identity_map[$id];
}
示例8: run
/**
* @return string
*/
public function run()
{
parent::run();
if (!$this->product instanceof Product) {
return '';
}
$cacheKey = 'RelatedProduct:' . implode('_', [$this->viewFile, $this->product, json_encode($this->additional)]);
if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
return $cache;
}
$result = $this->render($this->viewFile, ['model' => $this->product, 'products' => $this->product->relatedProducts, 'additional' => $this->additional]);
\Yii::$app->cache->set($cacheKey, $result, 0, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Product::className(), $this->product->id), ActiveRecordHelper::getCommonTag(\app\modules\shop\models\RelatedProduct::className())]]));
return $result;
}
示例9: findBySliderId
/**
* Returns model using indentity map and cache
* @param string $id
* @return SliderHandler|null
*/
public static function findBySliderId($id)
{
if (!isset(SliderHandler::$identity_map[$id])) {
$cacheKey = SliderHandler::tableName() . ":{$id}";
if (false === ($model = Yii::$app->cache->get($cacheKey))) {
$model = SliderHandler::findById($id);
if (null !== $model) {
Yii::$app->cache->set($cacheKey, $model, 86400, new \yii\caching\TagDependency(['tags' => [ActiveRecordHelper::getObjectTag($model, $model->id)]]));
}
}
static::$identity_map[$id] = $model;
}
return static::$identity_map[$id];
}
示例10: getNextPart
/**
* @inheritdoc
*/
public function getNextPart($full_url, $next_part, &$previous_parts)
{
if (mb_strpos($next_part, $this->static_part) === 0) {
if (count($this->parameters) === 0) {
$this->parameters = ['static_part' => $this->static_part];
}
$cacheTags = [];
if (isset($this->parameters['last_category_id']) && $this->parameters['last_category_id'] !== null) {
$cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $this->parameters['last_category_id']);
}
$part = new self(['gathered_part' => $this->static_part, 'rest_part' => mb_substr($next_part, mb_strlen($this->static_part)), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]);
return $part;
} else {
return false;
}
}
示例11: getPaymentMethodArray
/**
* @return array [[DropDownList]]
*/
public static function getPaymentMethodArray()
{
$cacheKey = 'PaymentMethodItems:' . implode(':', []);
$items = Yii::$app->cache->get($cacheKey);
if ($items !== false) {
return $items;
}
$data = self::find()->select(['payment_method_id', 'name'])->orderBy('name ASC')->asArray()->all();
$cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
foreach ($data as $val) {
$key = $val['payment_method_id'];
$items[$key] = $val['name'];
$cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
}
Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
return $items;
}
示例12: getOrderStatusArray
/**
* @return array [[DropDownList]]
*/
public static function getOrderStatusArray($asHtml = false)
{
$cacheKey = 'OrderStatusItems:' . implode(':', [intval($asHtml)]);
$items = Yii::$app->cache->get($cacheKey);
if ($items !== false) {
return $items;
}
$data = self::find()->select(['order_status_id', 'name', 'color'])->orderBy('name ASC')->asArray()->all();
$cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
foreach ($data as $val) {
$key = $val['order_status_id'];
$items[$key] = $asHtml ? Html::badge($val['name'], ['class' => 'btn btn-xs btn-block ' . $val['color']]) : $val['name'];
$cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
}
Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
return $items;
}
示例13: run
/**
* @inheritdoc
*/
public function run()
{
$n = 0;
switch ($this->action) {
case CategoryMovementsButtons::ADD_ACTION:
$n = $this->add();
break;
case CategoryMovementsButtons::MOVE_ACTION:
$n = $this->move();
break;
}
$tags = [];
foreach ($this->items as $id) {
$tags[] = ActiveRecordHelper::getObjectTag(Product::className(), $id);
}
TagDependency::invalidate(Yii::$app->cache, $tags);
Yii::$app->session->setFlash('info', Yii::t('app', 'Items updated: {n}', ['n' => $n]));
}
示例14: getStoreArray
/**
* @return array [[DropDownList]]
*/
public static function getStoreArray()
{
$cacheKey = 'StoreItems:' . implode(':', []);
$items = Yii::$app->cache->get($cacheKey);
if ($items !== false) {
return $items;
}
$userModel = \Yii::createObject(['class' => Yii::$app->user->identityClass]);
$stores_id = $userModel::find()->where(['id' => Yii::$app->user->id])->with('stores')->one();
$data = self::find()->where(['store_id' => ArrayHelper::getColumn($stores_id->stores, 'store_id')])->orderBy('name ASC')->asArray()->all();
$cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
foreach ($data as $val) {
$key = $val['store_id'];
$items[$key] = $val['name'];
$cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
}
Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
return $items;
}
示例15: getForModel
/**
* Get images by objectId and objectModelId
* @param integer $objectId
* @param integer $objectModelId
* @return Image[]
*/
public static function getForModel($objectId, $objectModelId)
{
if (!isset(self::$identityMap[$objectId][$objectModelId])) {
$cacheName = 'Images:' . $objectId . ':' . $objectModelId;
self::$identityMap[$objectId][$objectModelId] = Yii::$app->cache->get($cacheName);
if (!is_array(self::$identityMap[$objectId][$objectModelId])) {
if (!isset(self::$identityMap[$objectId])) {
self::$identityMap[$objectId] = [];
}
self::$identityMap[$objectId][$objectModelId] = static::find()->where(['object_id' => $objectId, 'object_model_id' => $objectModelId])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all();
$object = Object::findById($objectId);
if (is_null($object)) {
return self::$identityMap[$objectId][$objectModelId];
}
Yii::$app->cache->set($cacheName, self::$identityMap[$objectId][$objectModelId], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object->object_class, $objectModelId)]]));
}
}
return self::$identityMap[$objectId][$objectModelId];
}