CustomSettingsTabPlugin::AjaxGetCustomUserData()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
4
{
5
	/**
6
	 * @return void
7
	 */
8
	public function Init()
9
	{
10
		$this->UseLangs(true); // start use langs folder
11
12
		$this->addJs('js/CustomUserSettings.js'); // add js file
13
14
		$this->addAjaxHook('AjaxGetCustomUserData', 'AjaxGetCustomUserData');
15
		$this->addAjaxHook('AjaxSaveCustomUserData', 'AjaxSaveCustomUserData');
16
17
		$this->addTemplate('templates/PluginCustomSettingsTab.html');
18
	}
19
20
	/**
21
	 * @return array
22
	 */
23
	public function AjaxGetCustomUserData()
24
	{
25
		$aSettings = $this->getUserSettings();
26
27
		$sUserFacebook = isset($aSettings['UserFacebook']) ? $aSettings['UserFacebook'] : '';
28
		$sUserSkype = isset($aSettings['UserSkype']) ? $aSettings['UserSkype'] : '';
29
30
		// or get user's data from your custom storage ( DB / LDAP / ... ).
31
32
		\sleep(1);
33
		return $this->ajaxResponse(__FUNCTION__, array(
34
			'UserFacebook' => $sUserFacebook,
35
			'UserSkype' => $sUserSkype
36
		));
37
	}
38
39
	/**
40
	 * @return array
41
	 */
42
	public function AjaxSaveCustomUserData()
43
	{
44
		$sUserFacebook = $this->ajaxParam('UserFacebook');
45
		$sUserSkype = $this->ajaxParam('UserSkype');
46
47
		// or put user's data to your custom storage ( DB / LDAP / ... ).
48
49
		\sleep(1);
50
		return $this->ajaxResponse(__FUNCTION__, $this->saveUserSettings(array(
51
			'UserFacebook' => $sUserFacebook,
52
			'UserSkype' => $sUserSkype
53
		)));
54
	}
55
56
}
57
58