-
Notifications
You must be signed in to change notification settings - Fork 0
/
datamodel.itop-gravatar.xml
88 lines (85 loc) · 2.69 KB
/
datamodel.itop-gravatar.xml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?xml version="1.0" encoding="UTF-8"?>
<itop_design version="1.3">
<classes>
<class id="Person" _delta="must_exist">
<methods>
<method id="Get" _delta="define">
<comment>/**
* Override for portal rendering which is based on \ormDocument::GetDownloadURL
* @uses ormGravatarImage
*/
</comment>
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[public function Get($sAttCode)
{
$value = parent::Get($sAttCode);
if (is_null($value))
{
return $value;
}
if (!$this->IsGravatarPictureAtt($sAttCode))
{
return $value;
}
if ($value === '')
{
// on object creation
return $value;
}
if (!$value->IsEmpty())
{
return $value;
}
$sEmailValue = $this->GetGravatarEmailValue();
if (empty($sEmailValue))
{
return $value;
}
$oImageAtt = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
$sDefaultImageUrl = $oImageAtt->Get('default_image');
$iMaxWidth = $oImageAtt->Get('display_max_width');
$iMaxHeight = $oImageAtt->Get('display_max_height');
$iMaxSize = max($iMaxWidth, $iMaxHeight);
$iDefaultMaxSize = $this->GetGravatarDefaultMaxSize();
$iMaxSize = min($iDefaultMaxSize, $iMaxSize);
$oOrmGravatar = new ormGravatarImage($value, $sEmailValue, $sDefaultImageUrl, $iMaxSize);
return $oOrmGravatar;
}
]]></code>
</method>
<method id="IsGravatarPictureAtt" _delta="define">
<static>false</static>
<access>public</access>
<type>Custom</type>
<code><![CDATA[public function IsGravatarPictureAtt($sAttCode)
{
return ($sAttCode === 'picture');
}
]]></code>
</method>
<method id="GetGravatarEmailValue" _delta="define">
<static>false</static>
<access>public</access>
<type>Custom</type>
<code><![CDATA[public function GetGravatarEmailValue()
{
return $this->Get('email');
}
]]></code>
</method>
<method id="GetGravatarDefaultMaxSize" _delta="define">
<static>false</static>
<access>public</access>
<type>Custom</type>
<code><![CDATA[public function GetGravatarDefaultMaxSize()
{
return 512;
}
]]></code>
</method>
</methods>
</class>
</classes>
</itop_design>