|
@@ 523-556 (lines=34) @@
|
| 520 |
|
* @param User $user The user. |
| 521 |
|
* @return string[] |
| 522 |
|
*/ |
| 523 |
|
public function getMonthCounts(Project $project, User $user) |
| 524 |
|
{ |
| 525 |
|
$username = $user->getUsername(); |
| 526 |
|
$cacheKey = "monthcounts.$username"; |
| 527 |
|
$this->stopwatch->start($cacheKey, 'XTools'); |
| 528 |
|
if ($this->cache->hasItem($cacheKey)) { |
| 529 |
|
return $this->cache->getItem($cacheKey)->get(); |
| 530 |
|
} |
| 531 |
|
|
| 532 |
|
$revisionTable = $this->getTableName($project->getDatabaseName(), 'revision'); |
| 533 |
|
$pageTable = $this->getTableName($project->getDatabaseName(), 'page'); |
| 534 |
|
$sql = |
| 535 |
|
"SELECT " |
| 536 |
|
. " YEAR(rev_timestamp) AS `year`," |
| 537 |
|
. " MONTH(rev_timestamp) AS `month`," |
| 538 |
|
. " page_namespace," |
| 539 |
|
. " COUNT(rev_id) AS `count` " |
| 540 |
|
. " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)" |
| 541 |
|
. " WHERE rev_user_text = :username" |
| 542 |
|
. " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " |
| 543 |
|
. " ORDER BY rev_timestamp DESC"; |
| 544 |
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
| 545 |
|
$resultQuery->bindParam(":username", $username); |
| 546 |
|
$resultQuery->execute(); |
| 547 |
|
$totals = $resultQuery->fetchAll(); |
| 548 |
|
|
| 549 |
|
$cacheItem = $this->cache->getItem($cacheKey); |
| 550 |
|
$cacheItem->expiresAfter(new DateInterval('PT10M')); |
| 551 |
|
$cacheItem->set($totals); |
| 552 |
|
$this->cache->save($cacheItem); |
| 553 |
|
|
| 554 |
|
$this->stopwatch->stop($cacheKey); |
| 555 |
|
return $totals; |
| 556 |
|
} |
| 557 |
|
|
| 558 |
|
/** |
| 559 |
|
* Get yearly edit totals for this user, grouped by namespace. |
|
@@ 564-595 (lines=32) @@
|
| 561 |
|
* @param User $user The user. |
| 562 |
|
* @return string[] ['<namespace>' => ['<year>' => 'total', ... ], ... ] |
| 563 |
|
*/ |
| 564 |
|
public function getYearCounts(Project $project, User $user) |
| 565 |
|
{ |
| 566 |
|
$username = $user->getUsername(); |
| 567 |
|
$cacheKey = "yearcounts.$username"; |
| 568 |
|
$this->stopwatch->start($cacheKey, 'XTools'); |
| 569 |
|
if ($this->cache->hasItem($cacheKey)) { |
| 570 |
|
return $this->cache->getItem($cacheKey)->get(); |
| 571 |
|
} |
| 572 |
|
|
| 573 |
|
$revisionTable = $this->getTableName($project->getDatabaseName(), 'revision'); |
| 574 |
|
$pageTable = $this->getTableName($project->getDatabaseName(), 'page'); |
| 575 |
|
$sql = "SELECT " |
| 576 |
|
. " YEAR(rev_timestamp) AS `year`," |
| 577 |
|
. " page_namespace," |
| 578 |
|
. " COUNT(rev_id) AS `count` " |
| 579 |
|
. " FROM $revisionTable JOIN $pageTable ON (rev_page = page_id)" |
| 580 |
|
. " WHERE rev_user_text = :username" |
| 581 |
|
. " GROUP BY YEAR(rev_timestamp), page_namespace " |
| 582 |
|
. " ORDER BY rev_timestamp DESC "; |
| 583 |
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
| 584 |
|
$resultQuery->bindParam(":username", $username); |
| 585 |
|
$resultQuery->execute(); |
| 586 |
|
$totals = $resultQuery->fetchAll(); |
| 587 |
|
|
| 588 |
|
$cacheItem = $this->cache->getItem($cacheKey); |
| 589 |
|
$cacheItem->set($totals); |
| 590 |
|
$cacheItem->expiresAfter(new DateInterval('P10M')); |
| 591 |
|
$this->cache->save($cacheItem); |
| 592 |
|
|
| 593 |
|
$this->stopwatch->stop($cacheKey); |
| 594 |
|
return $totals; |
| 595 |
|
} |
| 596 |
|
|
| 597 |
|
/** |
| 598 |
|
* Get data for the timecard chart, with totals grouped by day and to the nearest two-hours. |