本文整理汇总了PHP中devgroup\tagdependencyhelper\ActiveRecordHelper类的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordHelper类的具体用法?PHP ActiveRecordHelper怎么用?PHP ActiveRecordHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActiveRecordHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
开发者ID:heartshare,项目名称:dotplant2,代码行数:12,代码来源:Widget.php
示例2: run
public function run()
{
$query = Category::find();
$query->andWhere([Category::tableName() . '.active' => 1]);
if ($this->root_category_id !== null) {
$query->andWhere([Category::tableName() . '.parent_id' => $this->root_category_id]);
}
if ($this->category_group_id !== null) {
$query->andWhere([Category::tableName() . '.category_group_id' => $this->category_group_id]);
}
$query->groupBy(Category::tableName() . ".id");
$query->orderBy($this->sort);
if ($this->limit !== null) {
$query->limit($this->limit);
}
$object = Object::getForClass(Category::className());
\app\properties\PropertiesHelper::appendPropertiesFilters($object, $query, $this->values_by_property_id, []);
$sql = $query->createCommand()->getRawSql();
$cacheKey = "FilteredCategoriesWidget:" . md5($sql);
$result = Yii::$app->cache->get($cacheKey);
if ($result === false) {
$categories = Category::findBySql($sql)->all();
$result = $this->render($this->viewFile, ['categories' => $categories]);
Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::tableName())]));
}
return $result;
}
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:27,代码来源:FilteredCategoriesWidget.php
示例3: 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;
}
}
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:32,代码来源:PartialCategoryPathPart.php
示例4: decorate
/**
* Handle decoration
* @param \yii\base\Controller $controller
* @param string $viewFile
* @param array $params
* @return void
*/
public function decorate($controller, $viewFile, $params)
{
if (isset($controller->view->blocks['content'])) {
$dependency = new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(app\modules\core\models\ContentBlock::className()), ActiveRecordHelper::getCommonTag(get_class($params['model']))]]);
$controller->view->blocks['content'] = ContentBlockHelper::compileContentString($controller->view->blocks['content'], get_class($params['model']) . ':' . $params['model']->id, $dependency);
}
}
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:14,代码来源:ContentBlock.php
示例5: run
public function run()
{
Yii::beginProfile("NavigationWidget for " . $this->rootId);
$items = null;
$cacheKey = implode(':', ['Navigation', $this->rootId, $this->depth, $this->viewFile]);
if ($this->useCache) {
if (false === ($items = \Yii::$app->cache->get($cacheKey))) {
$items = null;
}
}
if (null === $items) {
$root = Navigation::find()->where(['id' => $this->rootId])->with('children')->orderBy(['sort_order' => SORT_ASC])->one();
$items = [];
if ($this->depth > 0) {
foreach ($root->children as $child) {
$items[] = self::getTree($child, $this->depth - 1);
}
}
if (count($items) > 0) {
\Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(Navigation::className())]]));
}
}
$items = ArrayHelper::merge((array) $this->prependItems, $items, (array) $this->appendItems);
$currentUri = Yii::$app->request->url;
array_walk($items, function (&$item) use($currentUri) {
if ($item['url'] === $currentUri) {
$item['active'] = true;
}
});
$result = $this->render($this->viewFile, ['widget' => $this->widget, 'items' => $items, 'options' => $this->options, 'linkTemplate' => $this->linkTemplate, 'submenuTemplate' => $this->submenuTemplate]);
Yii::endProfile("NavigationWidget for " . $this->rootId);
return $result;
}
开发者ID:Razzwan,项目名称:dotplant2,代码行数:33,代码来源:NavigationWidget.php
示例6: run
/**
* @return string
*/
public function run()
{
parent::run();
if (null === $this->rootCategory) {
return '';
}
$cacheKey = $this->className() . ':' . implode('_', [$this->viewFile, $this->rootCategory, null === $this->depth ? 'null' : intval($this->depth), intval($this->includeRoot), intval($this->fetchModels), intval($this->onlyNonEmpty), implode(',', $this->excludedCategories), \Yii::$app->request->url]) . ':' . json_encode($this->additional);
if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
return $cache;
}
/** @var array|Category[] $tree */
$tree = Category::getMenuItems(intval($this->rootCategory), $this->depth, boolval($this->fetchModels));
if (true === $this->includeRoot) {
if (null !== ($_root = Category::findById(intval($this->rootCategory)))) {
$tree = [['label' => $_root->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $_root->category_group_id, 'last_category_id' => $_root->id]), 'id' => $_root->id, 'model' => $this->fetchModels ? $_root : null, 'items' => $tree]];
}
}
if (true === $this->onlyNonEmpty) {
$_sq1 = (new Query())->select('main_category_id')->distinct()->from(Product::tableName());
$_sq2 = (new Query())->select('category_id')->distinct()->from('{{%product_category}}');
$_query = (new Query())->select('id')->from(Category::tableName())->andWhere(['not in', 'id', $_sq1])->andWhere(['not in', 'id', $_sq2])->all();
$this->excludedCategories = array_merge($this->excludedCategories, array_column($_query, 'id'));
}
$tree = $this->filterTree($tree);
$cache = $this->render($this->viewFile, ['tree' => $tree, 'fetchModels' => $this->fetchModels, 'additional' => $this->additional, 'activeClass' => $this->activeClass, 'activateParents' => $this->activateParents]);
\Yii::$app->cache->set($cacheKey, $cache, 0, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Category::className()), ActiveRecordHelper::getCommonTag(Product::className())]]));
return $cache;
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:31,代码来源:CategoriesList.php
示例7: loadModel
/**
* @param $modelName
* @param $id
* @param bool $createIfEmptyId
* @param bool $useCache
* @param int $cacheLifetime
* @param bool $throwException
* @return ActiveRecord|null
* @throws NotFoundHttpException
*/
public static function loadModel($modelName, $id, $createIfEmptyId = false, $useCache = true, $cacheLifetime = 3600, $throwException = true)
{
$model = null;
if (empty($id)) {
if ($createIfEmptyId === true) {
$model = new $modelName();
} else {
if ($throwException) {
throw new NotFoundHttpException();
} else {
return null;
}
}
}
if ($useCache === true && $model === null) {
$model = Yii::$app->cache->get($modelName::className() . ":" . $id);
}
if (!is_object($model)) {
$model = $modelName::findOne($id);
if (is_object($model) && $useCache === true) {
Yii::$app->cache->set($modelName::className() . ":" . $id, $model, $cacheLifetime, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag($modelName::className())]));
}
}
if (!is_object($model)) {
if ($throwException) {
throw new NotFoundHttpException();
} else {
return null;
}
}
return $model;
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:42,代码来源:LoadModel.php
示例8: 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]);
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:32,代码来源:WarehousesRemains.php
示例9: down
public function down()
{
$tbl = '{{%backend_menu}}';
$this->update($tbl, ['route' => '/shop/backend-order/index'], ['route' => 'shop/backend-order/index']);
$this->update($tbl, ['route' => '/shop/backend-customer/index'], ['route' => 'shop/backend-customer/index']);
$this->update($tbl, ['route' => '/shop/backend-contragent/index'], ['route' => 'shop/backend-contragent/index']);
\yii\caching\TagDependency::invalidate(Yii::$app->cache, [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(\app\backend\models\BackendMenu::className())]);
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:8,代码来源:m150723_095512_backend_menu_fixes.php
示例10: getModelsByKey
/**
* @param string $type
* @return SpecialPriceList[]|array
*/
public static function getModelsByKey($type)
{
$cacheKey = static::className() . '_' . $type;
if (false === ($results = Yii::$app->cache->get($cacheKey))) {
$results = self::find()->where(['type' => $type])->all();
Yii::$app->cache->set($cacheKey, $results, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(static::className())]]));
}
return $results;
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:13,代码来源:SpecialPriceList.php
示例11: getAllDecorators
/**
* Retrieves all decorators from db, using cache and static variable caching
* @return ContentDecorator[]
* @throws \Exception
*/
public static function getAllDecorators()
{
if (static::$allDecorators === null) {
static::$allDecorators = self::getDb()->cache(function ($db) {
return self::find()->orderBy(['sort_order' => SORT_ASC])->all($db);
}, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(self::className())]));
}
return static::$allDecorators;
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:14,代码来源:ContentDecorator.php
示例12: activeWarehousesIds
/**
* Returns array of ID of all active warehouses
* @return integer[]
* @throws \Exception
*/
public static function activeWarehousesIds()
{
if (static::$activeWarehousesIds === null) {
static::$activeWarehousesIds = Warehouse::getDb()->cache(function ($db) {
return Warehouse::find()->where('is_active=1')->select('id')->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->asArray()->column($db);
}, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Warehouse::className())]]));
}
return static::$activeWarehousesIds;
}
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:14,代码来源:Warehouse.php
示例13: down
public function down()
{
$this->dropTable('{{%addon}}');
$this->dropTable('{{%addon_category}}');
$this->dropTable('{{%addon_bindings}}');
$this->delete('{{%object}}', ['name' => 'Addon']);
$this->delete('{{%backend_menu}}', ['name' => 'Addons']);
\yii\caching\TagDependency::invalidate(Yii::$app->cache, [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(\app\backend\models\BackendMenu::className())]);
$this->dropColumn('{{%order_item}}', 'addon_id');
}
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:10,代码来源:m150827_075105_product_addons.php
示例14: availableAddons
public static function availableAddons($id)
{
$cacheKey = 'Addons4' . $id;
$addons = Yii::$app->cache->get($cacheKey);
if ($addons === false) {
$addons = Addon::findAll(['addon_category_id' => $id]);
Yii::$app->cache->set($cacheKey, $addons, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Addon::className()), ActiveRecordHelper::getCommonTag(AddonCategory::className())]]));
}
return $addons;
}
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:10,代码来源:AddonCategory.php
示例15: getManagersList
protected function getManagersList()
{
$managers = Yii::$app->cache->get('ManagersList');
if ($managers === false) {
$managers = User::find()->join('INNER JOIN', '{{%auth_assignment}}', '{{%auth_assignment}}.user_id = ' . User::tableName() . '.id')->where(['{{%auth_assignment}}.item_name' => 'manager'])->all();
$managers = ArrayHelper::map($managers, 'id', 'username');
Yii::$app->cache->set('ManagersList', $managers, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(User::className())]]));
}
return $managers;
}
开发者ID:Razzwan,项目名称:dotplant2,代码行数:10,代码来源:BackendOrderController.php
示例16: run
/**
* @inheritdoc
* @return string
*/
public function run()
{
$cacheKey = "PlainCategoriesWidget:" . $this->root_category_id . ":" . $this->viewFile;
$result = Yii::$app->cache->get($cacheKey);
if ($result === false) {
$categories = Category::getByParentId($this->root_category_id);
$result = $this->render($this->viewFile, ['categories' => $categories]);
Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::className())]));
}
return $result;
}
开发者ID:Razzwan,项目名称:dotplant2,代码行数:15,代码来源:PlainCategoriesWidget.php
示例17: getChildren
/**
* @return ActiveRecord[]
*/
public function getChildren()
{
$cacheKey = 'TreeChildren:' . $this->owner->className() . ':' . $this->owner->{$this->idAttribute};
$children = Yii::$app->cache->get($cacheKey);
if ($children === false) {
/** @var $className ActiveRecord */
$className = $this->owner->className();
$children = $className::find()->where([$this->parentIdAttribute => $this->owner->{$this->idAttribute}])->orderBy($this->sortOrder)->all();
Yii::$app->cache->set($cacheKey, $children, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag($className)]]));
}
return $children;
}
开发者ID:heartshare,项目名称:dotplant2,代码行数:15,代码来源:Tree.php
示例18: getAllVariations
/**
* Returns all db-stored variations in array representation
*
* @param bool $force True if you want to refresh static-variable cache
* @return array
*/
public static function getAllVariations($force = false)
{
if (static::$allVariations === null || $force === true) {
$cacheKey = 'AllThemeVariations';
static::$allVariations = Yii::$app->cache->get($cacheKey);
if (static::$allVariations === false) {
static::$allVariations = ThemeVariation::find()->orderBy(['exclusive' => SORT_DESC])->asArray()->all();
Yii::$app->cache->set($cacheKey, static::$allVariations, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ThemeVariation::className())]]));
}
}
return static::$allVariations;
}
开发者ID:Emericanec,项目名称:dotplant2,代码行数:18,代码来源:ThemeVariation.php
示例19: 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;
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:16,代码来源:FindById.php
示例20: enabledSorts
/**
* Returns all enabled sorts as array of rows
* Caches through cache and static variable
* @return array
*/
public static function enabledSorts()
{
if (static::$_cachedRows === null) {
$cacheKey = "ProductListingSorts:all:arrayOfRows";
static::$_cachedRows = Yii::$app->cache->get($cacheKey);
if (!is_array(static::$_cachedRows)) {
static::$_cachedRows = ProductListingSort::find()->where(['enabled' => 1])->orderBy('sort_order ASC')->indexBy('id')->asArray()->all();
Yii::$app->cache->set($cacheKey, static::$_cachedRows, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(static::className())]]));
}
}
return static::$_cachedRows;
}
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:17,代码来源:ProductListingSort.php
注:本文中的devgroup\tagdependencyhelper\ActiveRecordHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论