Cheetah
ChProfileCustomizeDb.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbModuleDb.php' );
9 
10 define('CH_PROFILE_CUSTOM_TABLE_PREFIX', 'ch_profile_custom');
11 
13 {
14  var $_oConfig;
15  /*
16  * Constructor.
17  */
18  function __construct(&$oConfig)
19  {
20  parent::__construct();
21 
22  $this->_oConfig = $oConfig;
23  }
24 
25  function getProfileByUserId($iUserId)
26  {
27  return $this->getRow("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_main` WHERE `user_id` = ? LIMIT 1", [$iUserId]);
28  }
29 
30  function getProfileTmpByUserId($iUserId)
31  {
32  $aStyle = $this->getProfileByUserId($iUserId);
33 
34  if (!empty($aStyle))
35  return unserialize($aStyle['tmp']);
36 
37  return array();
38  }
39 
40  function getProfileCssByUserId($iUserId)
41  {
42  $aStyle = $this->getProfileByUserId($iUserId);
43 
44  if (!empty($aStyle))
45  return unserialize($aStyle['css']);
46 
47  return '';
48  }
49 
50  function updateProfileByUserId($iUserId, $sStyle, $sType)
51  {
52  // check exist user
53  $aRow = $this->getProfileByUserId($iUserId);
54  if (empty($aRow))
55  return $this->query("INSERT INTO `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_main` (`user_id`, `$sType`) VALUES($iUserId, '$sStyle')");
56  else
57  return $this->query("UPDATE `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_main` SET `$sType` = '$sStyle' WHERE `user_id` = $iUserId LIMIT 1");
58  }
59 
60  function saveProfileByUserId($iUserId)
61  {
62  return $this->query("UPDATE `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_main` SET `css` = `tmp` WHERE `user_id` = $iUserId LIMIT 1");
63  }
64 
65  function updateProfileTmpByUserId($iUserId, $aTmp)
66  {
67  return $this->updateProfileByUserId($iUserId, serialize($aTmp), 'tmp');
68  }
69 
70  function updateProfileCssByUserId($iUserId, $aCss)
71  {
72  return $this->updateProfileByUserId($iUserId, serialize($aCss), 'css');
73  }
74 
75  function resetProfileStyleByUserId($iUserId)
76  {
77  return $this->query("DELETE FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_main` WHERE `user_id` = $iUserId");
78  }
79 
80  function getUnits()
81  {
82  $aResult = array();
83  $aRows = $this->getAll("SELECT `name`, `caption`, `css_name`, `type` FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_units`");
84 
85  foreach ($aRows as $aValue) {
86  $aResult[$aValue['type']][$aValue['name']] = array(
87  'name' => $aValue['caption'],
88  'css_name' => $aValue['css_name']
89  );
90  }
91 
92  return $aResult;
93  }
94 
95  function getUnitById($iUnitId)
96  {
97  return $this->getRow("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_units` WHERE `id` = ? LIMIT 1", [$iUnitId]);
98  }
99 
100  function deleteUnit($iUnitId)
101  {
102  return $this->query("DELETE FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_units` WHERE `id` = $iUnitId");
103  }
104 
105  function getAllThemesByUserId($iUserId)
106  {
107  return $this->getAll("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_themes` WHERE `ownerid` = $iUserId ORDER BY `id`");
108  }
109 
110  function getSharedThemes()
111  {
112  return $this->getAll("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_themes` WHERE `ownerid` = 0 ORDER BY `id`");
113  }
114 
116  {
117  return $this->getRow("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_themes` WHERE `name` = ? LIMIT 1", [$sName]);
118  }
119 
120  function getThemeById($iThemeId)
121  {
122  return $this->getRow("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_themes` WHERE `id` = ? LIMIT 1", [$iThemeId]);
123  }
124 
125  function getThemeStyle($iThemeId)
126  {
127  if ((int)$iThemeId) {
128  $aTheme = $this->getRow("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_themes` WHERE `id` = ? LIMIT 1", [$iThemeId]);
129 
130  if (!empty($aTheme))
131  return unserialize($aTheme['css']);
132  }
133 
134  return array();
135  }
136 
137  function addTheme($sName, $iOwnerId, $sCss)
138  {
139  if ($this->query("INSERT INTO `" . CH_PROFILE_CUSTOM_TABLE_PREFIX .
140  "_themes` (`name`, `ownerid`, `css`) VALUES('$sName', $iOwnerId, '$sCss')"))
141  return $this->lastId();
142 
143  return -1;
144  }
145 
146  function deleteTheme($iThemeId)
147  {
148  return $this->query("DELETE FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_themes` WHERE `id` = $iThemeId");
149  }
150 
151  function addImage($sExt)
152  {
153  if (strlen($sExt) > 0 && $this->query("INSERT INTO `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_images` (`ext`, `count`) VALUES('$sExt', 1)"))
154  return $this->lastId() . '.' . $sExt;
155 
156  return '';
157  }
158 
159  function copyImage($sFileName)
160  {
161  if (strlen($sFileName) > 0) {
162  $sId = basename($sFileName, '.' . pathinfo($sFileName, PATHINFO_EXTENSION));
163  return strlen($sId) > 0 ? $this->query("UPDATE `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_images` SET `count` = `count` + 1 WHERE `id` = $sId") : 0;
164  }
165 
166  return 0;
167  }
168 
169  function deleteImage($sFileName)
170  {
171  $sResult = true;
172 
173  if (strlen($sFileName) > 0) {
174  $sId = basename($sFileName, '.' . pathinfo($sFileName, PATHINFO_EXTENSION));
175  if (strlen($sId) > 0 && $this->query("UPDATE `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_images` SET `count` = `count` - 1 WHERE `id` = $sId")) {
176  $aRow = $this->getRow("SELECT * FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_images` WHERE `id` = ? LIMIT 1", [$sId]);
177  if ($aRow['count'] < 1)
178  $this->query("DELETE FROM `" . CH_PROFILE_CUSTOM_TABLE_PREFIX . "_images` WHERE `id` = $sId");
179  else
180  $sResult = false;
181  }
182  }
183 
184  return $sResult;
185  }
186 
188  {
189  return $this->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name` = 'Profile Customizer' LIMIT 1");
190  }
191 }
ChProfileCustomizeDb\getUnits
getUnits()
Definition: ChProfileCustomizeDb.php:80
ChProfileCustomizeDb\getProfileByUserId
getProfileByUserId($iUserId)
Definition: ChProfileCustomizeDb.php:25
ChProfileCustomizeDb\copyImage
copyImage($sFileName)
Definition: ChProfileCustomizeDb.php:159
ChProfileCustomizeDb\deleteImage
deleteImage($sFileName)
Definition: ChProfileCustomizeDb.php:169
ChProfileCustomizeDb\getThemeStyle
getThemeStyle($iThemeId)
Definition: ChProfileCustomizeDb.php:125
ChProfileCustomizeDb\getThemeById
getThemeById($iThemeId)
Definition: ChProfileCustomizeDb.php:120
$sResult
$sResult
Definition: advanced_settings.php:26
ChProfileCustomizeDb\updateProfileByUserId
updateProfileByUserId($iUserId, $sStyle, $sType)
Definition: ChProfileCustomizeDb.php:50
$aResult
$aResult
Definition: index.php:19
php
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
ChProfileCustomizeDb\addImage
addImage($sExt)
Definition: ChProfileCustomizeDb.php:151
ChProfileCustomizeDb\deleteTheme
deleteTheme($iThemeId)
Definition: ChProfileCustomizeDb.php:146
ChWsbDb\getAll
getAll($sQuery, $aBindings=[], $iFetchType=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:206
ChProfileCustomizeDb\getSettingsCategory
getSettingsCategory()
Definition: ChProfileCustomizeDb.php:187
CH_PROFILE_CUSTOM_TABLE_PREFIX
const CH_PROFILE_CUSTOM_TABLE_PREFIX
Definition: ChProfileCustomizeDb.php:10
$sExt
$sExt
Definition: get_file.php:14
ChProfileCustomizeDb\$_oConfig
$_oConfig
Definition: ChProfileCustomizeDb.php:14
ChProfileCustomizeDb\updateProfileTmpByUserId
updateProfileTmpByUserId($iUserId, $aTmp)
Definition: ChProfileCustomizeDb.php:65
ChProfileCustomizeDb\getUnitById
getUnitById($iUnitId)
Definition: ChProfileCustomizeDb.php:95
ChProfileCustomizeDb\updateProfileCssByUserId
updateProfileCssByUserId($iUserId, $aCss)
Definition: ChProfileCustomizeDb.php:70
ChWsbDb\getRow
getRow($sQuery, $aBindings=[], $iFetchStyle=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:225
$sType
$sType
Definition: actions.inc.php:11
ChProfileCustomizeDb\saveProfileByUserId
saveProfileByUserId($iUserId)
Definition: ChProfileCustomizeDb.php:60
ChWsbDb\query
query($sQuery, $aBindings=[])
Definition: ChWsbDb.php:386
ChWsbDb\getOne
getOne($sQuery, $aBindings=[], $iIndex=0)
Definition: ChWsbDb.php:263
ChProfileCustomizeDb\getSharedThemes
getSharedThemes()
Definition: ChProfileCustomizeDb.php:110
ChProfileCustomizeDb
Definition: ChProfileCustomizeDb.php:13
ChProfileCustomizeDb\getThemeByName
getThemeByName($sName)
Definition: ChProfileCustomizeDb.php:115
ChProfileCustomizeDb\getProfileCssByUserId
getProfileCssByUserId($iUserId)
Definition: ChProfileCustomizeDb.php:40
$sId
$sId
Definition: actions.inc.php:8
ChProfileCustomizeDb\__construct
__construct(&$oConfig)
Definition: ChProfileCustomizeDb.php:18
ChProfileCustomizeDb\getProfileTmpByUserId
getProfileTmpByUserId($iUserId)
Definition: ChProfileCustomizeDb.php:30
ChProfileCustomizeDb\deleteUnit
deleteUnit($iUnitId)
Definition: ChProfileCustomizeDb.php:100
ChWsbDb\lastId
lastId()
Definition: ChWsbDb.php:449
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChProfileCustomizeDb\addTheme
addTheme($sName, $iOwnerId, $sCss)
Definition: ChProfileCustomizeDb.php:137
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChProfileCustomizeDb\resetProfileStyleByUserId
resetProfileStyleByUserId($iUserId)
Definition: ChProfileCustomizeDb.php:75
ChProfileCustomizeDb\getAllThemesByUserId
getAllThemesByUserId($iUserId)
Definition: ChProfileCustomizeDb.php:105