Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
M
my.typo3.org
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
t3o
my.typo3.org
Commits
d39b86ec
Commit
d39b86ec
authored
Feb 11, 2019
by
mabolek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] Fetch sum of user's karma on per-source basis
parent
9b1bc16b
Pipeline
#6161
failed with stages
in 17 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
121 additions
and
9 deletions
+121
-9
extensions/karma/Classes/Controller/UserDisplayController.php
...nsions/karma/Classes/Controller/UserDisplayController.php
+4
-2
extensions/karma/Classes/Domain/Model/FrontendUser.php
extensions/karma/Classes/Domain/Model/FrontendUser.php
+59
-0
extensions/karma/Classes/Domain/Repository/LedgerEntryRepository.php
...karma/Classes/Domain/Repository/LedgerEntryRepository.php
+1
-1
extensions/karma/Classes/Service/KarmaService.php
extensions/karma/Classes/Service/KarmaService.php
+34
-2
extensions/karma/Configuration/TCA/Overrides/fe_users.php
extensions/karma/Configuration/TCA/Overrides/fe_users.php
+9
-0
extensions/karma/Resources/Private/Language/locallang_db.xlf
extensions/karma/Resources/Private/Language/locallang_db.xlf
+7
-4
extensions/karma/Resources/Private/Templates/UserDisplay/StatusWidget.html
...Resources/Private/Templates/UserDisplay/StatusWidget.html
+6
-0
extensions/karma/ext_tables.sql
extensions/karma/ext_tables.sql
+1
-0
No files found.
extensions/karma/Classes/Controller/UserDisplayController.php
View file @
d39b86ec
...
...
@@ -48,14 +48,16 @@ class UserDisplayController extends AbstractController
$immutableValue
=
$this
->
karmaService
->
getImmutableKarmaForUser
(
$frontendUser
);
$mutableValue
=
$this
->
karmaService
->
getMutableKarmaForUser
(
$frontendUser
);
$sourceTotals
=
[];
foreach
(
$this
->
getKarmaSourceCodes
()
as
$sourceCode
)
{
$value
=
$this
->
karmaService
->
getImmutableKarmaSourceTotalForUser
(
$sourceCode
,
$frontendUser
);
$sourceTotals
[
$sourceCode
]
=
$value
;
}
$this
->
view
->
assign
(
'immutableValue'
,
$immutableValue
);
$this
->
view
->
assign
(
'mutableValue'
,
$mutableValue
);
$this
->
view
->
assign
(
'hasKarma'
,
(
$immutableValue
>
0
||
$mutableValue
>
0
));
$this
->
view
->
assign
(
'sourceTotals'
,
$sourceTotals
);
}
}
}
extensions/karma/Classes/Domain/Model/FrontendUser.php
View file @
d39b86ec
...
...
@@ -48,6 +48,18 @@ class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected
$karmaCacheTimestamp
=
0
;
/**
* JSON encoded associative array containing totals for the karma source
*
* @var string
*/
protected
$karmaSourceTotalCache
=
''
;
/**
* @var array|null
*/
private
$karmaSourceTotalCacheDecoded
;
/**
* Get the cached immutable karma total
*
...
...
@@ -107,4 +119,51 @@ class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
$this
->
karmaCacheTimestamp
=
$karmaCacheTimestamp
;
}
/**
* Get the JSON string containing the karma source total cache array
*
* @return string
*/
public
function
getKarmaSourceTotalCache
():
string
{
return
$this
->
karmaSourceTotalCache
;
}
/**
* Set the JSON string containing the karma source total cache array
*
* @param string $karmaSourceTotalCache
*/
public
function
setKarmaSourceTotalCache
(
string
$karmaSourceTotalCache
)
{
$this
->
karmaSourceTotalCache
=
$karmaSourceTotalCache
;
}
/**
* @return array|null
*/
public
function
getKarmaSourceTotalCacheDecoded
():
?array
{
if
(
$this
->
karmaSourceTotalCacheDecoded
===
null
)
{
$this
->
karmaSourceTotalCacheDecoded
=
json_decode
(
$this
->
getKarmaSourceTotalCache
());
if
(
!
is_array
(
$this
->
karmaSourceTotalCacheDecoded
))
{
$this
->
karmaSourceTotalCacheDecoded
=
[];
$this
->
setKarmaSourceTotalCache
(
json_encode
(
$this
->
karmaSourceTotalCacheDecoded
));
}
}
return
$this
->
karmaSourceTotalCacheDecoded
;
}
/**
* @param array|null $karmaSourceTotalCacheDecoded
*/
public
function
setKarmaSourceTotalCacheDecoded
(
array
$karmaSouceTotalDecoded
)
{
$this
->
karmaSourceTotalCacheDecoded
=
$karmaSouceTotalDecoded
;
$this
->
setKarmaSourceTotalCache
(
json_encode
(
$this
->
karmaSourceTotalCacheDecoded
));
}
}
extensions/karma/Classes/Domain/Repository/LedgerEntryRepository.php
View file @
d39b86ec
...
...
@@ -116,7 +116,7 @@ class LedgerEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
->
where
(
$queryBuilder
->
expr
()
->
eq
(
'user'
,
$frontendUser
->
getUid
()),
$queryBuilder
->
expr
()
->
eq
(
'expired'
,
0
),
$queryBuilder
->
expr
()
->
eq
(
'karma_source'
,
$
source
)
$queryBuilder
->
expr
()
->
eq
(
'karma_source'
,
$
queryBuilder
->
quote
(
$source
)
)
)
->
execute
();
$sum
=
$result
->
fetchColumn
(
0
);
...
...
extensions/karma/Classes/Service/KarmaService.php
View file @
d39b86ec
...
...
@@ -2,11 +2,9 @@
namespace
T3o\Karma\Service
;
use
T3o\Karma\Domain\Model\Campaign
;
use
T3o\Karma\Domain\Model\FrontendUser
;
use
T3o\Karma\Domain\Model\LedgerEntry
;
use
T3o\Karma\Domain\Repository\FrontendUserRepository
;
use
T3o\Karma\Domain\Repository\KarmaSourceRepository
;
use
T3o\Karma\Domain\Repository\LedgerEntryRepository
;
use
TYPO3\CMS\Extbase\Domain\Model\FrontendUser
as
ExtbaseFrontendUser
;
...
...
@@ -85,6 +83,7 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
$frontendUser
->
setKarmaImmutableValueCache
(
$immutableKarma
);
$frontendUser
->
setKarmaMutableValueCache
(
$mutableKarma
);
$frontendUser
->
setKarmaCacheTimestamp
(
time
());
$frontendUser
->
setKarmaSourceTotalCacheDecoded
([]);
$this
->
frontendUserRepository
->
update
(
$frontendUser
);
}
...
...
@@ -116,6 +115,7 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
$frontendUser
->
setKarmaMutableValueCache
(
$mutableKarma
);
$frontendUser
->
setKarmaImmutableValueCache
(
$immutableKarma
);
$frontendUser
->
setKarmaCacheTimestamp
(
time
());
$frontendUser
->
setKarmaSourceTotalCacheDecoded
([]);
$this
->
frontendUserRepository
->
update
(
$frontendUser
);
}
...
...
@@ -123,6 +123,38 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
return
$mutableKarma
;
}
/**
* Get the immutable karma total for a specific karma source code from the user
*
* @param string $karmaSourceCode The source code to fetch the total for
* @param ExtbaseFrontendUser $frontendUser
* @param bool $ignoreCache Fetch value directly from ledger
* @param bool $updateCacheEntry Update the user's cache entry if we're ignoring cache. Will also update mutable cache.
* @return int Mutable Karma Total
*/
public
function
getImmutableKarmaSourceTotalForUser
(
$karmaSourceCode
,
ExtbaseFrontendUser
$frontendUser
,
$ignoreCache
=
false
,
$updateCacheEntry
=
true
)
{
$frontendUser
=
$this
->
ensureCorrectFrontendUserSubclass
(
$frontendUser
);
$totals
=
$frontendUser
->
getKarmaSourceTotalCacheDecoded
();
if
(
!
$ignoreCache
)
{
if
(
isset
(
$totals
[
$karmaSourceCode
]))
{
return
$totals
[
$karmaSourceCode
];
}
}
$sourceTotal
=
$this
->
ledgerEntryRepository
->
calculateImmutableKarmaSourceTotalForUser
(
$karmaSourceCode
,
$frontendUser
);
if
(
$updateCacheEntry
)
{
$totals
[
$karmaSourceCode
]
=
$sourceTotal
;
$frontendUser
->
setKarmaSourceTotalCacheDecoded
(
$totals
);
$this
->
frontendUserRepository
->
update
(
$frontendUser
);
}
return
$sourceTotal
;
}
/**
* Add karma to a user
*
...
...
extensions/karma/Configuration/TCA/Overrides/fe_users.php
View file @
d39b86ec
...
...
@@ -34,6 +34,15 @@ $feUsersColumns = [
'readOnly'
=>
true
,
],
],
'karma_source_total_cache'
=>
[
'exclude'
=>
0
,
'config'
=>
[
'label'
=>
$ll
.
'fe_users.karma_source_total_cache'
,
'type'
=>
'text'
,
'eval'
=>
''
,
'readOnly'
=>
true
,
],
],
];
$fields
=
'tx_karma_immutable_value_cache,tx_karma_mutable_value_cache,tx_karma_cache_timestamp,'
;
...
...
extensions/karma/Resources/Private/Language/locallang_db.xlf
View file @
d39b86ec
...
...
@@ -31,7 +31,7 @@
<source>
Karma Source Code
</source>
</trans-unit>
<trans-unit
id=
"tx_karma_domain_model_ledgerentry.issuer"
>
<source>
Issuer Code/source>
<source>
Issuer Code
<
/source>
</trans-unit>
<trans-unit
id=
"tx_karma_domain_model_ledgerentry.issuer_action"
>
<source>
Issuer Action Code
</source>
...
...
@@ -51,15 +51,18 @@
<trans-unit
id=
"tx_karma_domain_model_karmasource.code"
>
<source>
Unique Alphanumeric Code
</source>
</trans-unit>
<trans-unit
id=
"fe_users.
tx_
karma_immutable_value_cache"
>
<trans-unit
id=
"fe_users.karma_immutable_value_cache"
>
<source>
Immutable Karma Value Cache
</source>
</trans-unit>
<trans-unit
id=
"fe_users.
tx_
karma_mutable_value_cache"
>
<trans-unit
id=
"fe_users.karma_mutable_value_cache"
>
<source>
Mutable Karma Value Cache
</source>
</trans-unit>
<trans-unit
id=
"fe_users.
tx_
karma_cache_timestamp"
>
<trans-unit
id=
"fe_users.karma_cache_timestamp"
>
<source>
Karma Cache Timestamp
</source>
</trans-unit>
<trans-unit
id=
"fe_users.karma_source_total_cache"
>
<source>
Karma Source Total Cache
</source>
</trans-unit>
</body>
</file>
</xliff>
extensions/karma/Resources/Private/Templates/UserDisplay/StatusWidget.html
View file @
d39b86ec
...
...
@@ -6,6 +6,12 @@
<strong>
{immutableValue}
</strong>
karma points
<br>
<strong>
{mutableValue}
</strong>
karma cash
</p>
<ul>
<f:for
each=
"{sourceTotals}"
as=
"sourceTotal"
key=
"sourceCode"
>
<li>
{settings.sourceCodes.{sourceCode}.label}: {sourceTotal}
</li>
</f:for>
</ul>
</f:then>
<f:else>
<p>
You do not have any karma yet. Participate in the community to earn some.
</p>
...
...
extensions/karma/ext_tables.sql
View file @
d39b86ec
...
...
@@ -50,4 +50,5 @@ CREATE TABLE fe_users (
karma_immutable_value_cache
int
(
11
)
DEFAULT
'0'
,
karma_mutable_value_cache
int
(
11
)
DEFAULT
'0'
,
karma_cache_timestamp
int
(
11
)
DEFAULT
'0'
NOT
NULL
,
karma_source_total_cache
text
DEFAULT
''
NOT
NULL
,
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment