forked from Antidot-be/sydney-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Links.php
executable file
·63 lines (53 loc) · 1.72 KB
/
Links.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
class Sydney_Search_Files_Links
{
/**
* Links object provides storage for shared objects.
* @var Sydney_Search_Files_Links
*/
private static $_links = null;
private $result = array();
/**
* Retrieves the default Sydney_Search_Files_Links instance.
*
* @return Sydney_Search_Files_Links
*/
public static function getInstance()
{
if (self::$_links === null) {
self::$_links = new Sydney_Search_Files_Links();
}
return self::$_links;
}
/**
* Search if the file has linked to a content/resource of Sydney
* @param $fileid
* @return bool
*/
public function isLinked($fileid)
{
if (!key_exists($fileid, $this->result) || !key_exists('isLinked', $this->result[$fileid])) {
// search on content
$this->result[$fileid]['isLinked'] = false;
if (Sydney_Search_Files_Pages_Links::getInstance()->hasLinked($fileid)) {
$this->result[$fileid]['isLinked'] = true;
} else { // search on Users if file has used as avatar
if (Sydney_Search_Files_Users_Links::getInstance()->hasLinked($fileid)) {
$this->result[$fileid]['isLinked'] = true;
}
}
}
return $this->result[$fileid]['isLinked'];
}
/**
* Buils a list of content/resource where a link to the file are found
* @param $fileid
* @return array
*/
public function getLinks($fileid)
{
Sydney_Search_Files_Pages_Links::getInstance()->buildLinks($fileid);
Sydney_Search_Files_Users_Links::getInstance()->buildLinks($fileid);
return Sydney_Search_Files_Result::get();
}
}