|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains only the PageAssessmentsRepository class. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Xtools; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* An PageAssessmentsRepository is responsible for retrieving page assessment |
|
10
|
|
|
* information from the database, and the XTools configuration via the Container. |
|
11
|
|
|
* @codeCoverageIgnore |
|
12
|
|
|
*/ |
|
13
|
|
|
class PageAssessmentsRepository extends Repository |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Get page assessments configuration for the Project. |
|
17
|
|
|
* @param Project $project |
|
18
|
|
|
* @return string[]|bool As defined in config/assessments.yml, or false if none exists. |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getConfig(Project $project) |
|
21
|
|
|
{ |
|
22
|
|
|
$projectsConfig = $this->container->getParameter('assessments'); |
|
23
|
|
|
|
|
24
|
|
|
if (isset($projectsConfig[$project->getDomain()])) { |
|
25
|
|
|
return $projectsConfig[$project->getDomain()]; |
|
26
|
|
|
} else { |
|
27
|
|
|
return false; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get assessment data for the given pages |
|
33
|
|
|
* @param Page $page |
|
34
|
|
|
* @return string[] Assessment data as retrieved from the database. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getAssessments(Page $page) |
|
37
|
|
|
{ |
|
38
|
|
|
$cacheKey = $this->getCacheKey(func_get_args(), 'page_assessments'); |
|
39
|
|
|
if ($this->cache->hasItem($cacheKey)) { |
|
40
|
|
|
return $this->cache->getItem($cacheKey)->get(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$paTable = $this->getTableName($page->getProject()->getDatabaseName(), 'page_assessments'); |
|
44
|
|
|
$papTable = $this->getTableName($page->getProject()->getDatabaseName(), 'page_assessments_projects'); |
|
45
|
|
|
$pageId = $page->getId(); |
|
46
|
|
|
|
|
47
|
|
|
$sql = "SELECT pap_project_title AS wikiproject, pa_class AS class, pa_importance AS importance |
|
48
|
|
|
FROM $paTable |
|
49
|
|
|
LEFT JOIN $papTable ON pa_project_id = pap_project_id |
|
50
|
|
|
WHERE pa_page_id = $pageId"; |
|
51
|
|
|
|
|
52
|
|
|
$result = $this->executeProjectsQuery($sql)->fetchAll(); |
|
53
|
|
|
|
|
54
|
|
|
// Cache and return. |
|
55
|
|
|
return $this->setCache($cacheKey, $result); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|