-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
180 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Tags for Craft CMS | ||
* | ||
* @link https://ethercreative.co.uk | ||
* @copyright Copyright (c) 2019 Ether Creative | ||
*/ | ||
|
||
namespace ether\tagManager\elements\db; | ||
|
||
use ether\tagManager\TagManager; | ||
use yii\db\Expression; | ||
|
||
/** | ||
* Class TagQuery | ||
* | ||
* @author Ether Creative | ||
* @package ether\tagManager\elements\db | ||
*/ | ||
class TagQuery extends \craft\elements\db\TagQuery | ||
{ | ||
|
||
protected function beforePrepare (): bool | ||
{ | ||
if (!TagManager::getInstance()->getSettings()->enableUsage) | ||
return parent::beforePrepare(); | ||
|
||
$getUsage = new Expression( | ||
'(SELECT COUNT(*) FROM (SELECT [[r.sourceId]], [[r.sourceSiteId]] FROM {{%relations}} r WHERE [[r.targetId]] = [[elements.id]] GROUP BY [[r.sourceId]], [[r.sourceSiteId]]) as usage) as [[usage]]' | ||
); | ||
|
||
$this->addSelect($getUsage); | ||
$this->subQuery->addSelect($getUsage); | ||
|
||
return parent::beforePrepare(); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Tags for Craft CMS | ||
* | ||
* @link https://ethercreative.co.uk | ||
* @copyright Copyright (c) 2019 Ether Creative | ||
*/ | ||
|
||
namespace ether\tagManager\models; | ||
|
||
use craft\base\Model; | ||
|
||
/** | ||
* Class Settings | ||
* | ||
* @author Ether Creative | ||
* @package ether\tagManager\models | ||
*/ | ||
class Settings extends Model | ||
{ | ||
|
||
/** | ||
* @var bool Will enable the usage column (may be slow on larger sites) | ||
*/ | ||
public $enableUsage = false; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% import "_includes/forms" as forms %} | ||
|
||
{{ forms.lightswitchField({ | ||
label: 'Enable Usage'|t('tag-manager'), | ||
instructions: 'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).'|t('tag-manager'), | ||
name: 'enableUsage', | ||
on: settings.enableUsage, | ||
first: true, | ||
}) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Tags for Craft CMS | ||
* | ||
* @link https://ethercreative.co.uk | ||
* @copyright Copyright (c) 2019 Ether Creative | ||
*/ | ||
|
||
return [ | ||
'Usage' => 'Usage', | ||
'Enable Usage' => 'Enable Usage', | ||
'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).' => | ||
'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).', | ||
]; |