Cheetah
ChStoreDb.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbTwigModuleDb');
9 
10 /*
11  * Store module Data
12  */
13 
15 {
16  /*
17  * Constructor.
18  */
19  function __construct(&$oConfig)
20  {
21  parent::__construct($oConfig);
22 
23  $this->_sTableMain = 'products';
24  $this->_sTableMediaPrefix = 'product_';
25  $this->_sFieldId = 'id';
26  $this->_sFieldAuthorId = 'author_id';
27  $this->_sFieldUri = 'uri';
28  $this->_sFieldTitle = 'title';
29  $this->_sFieldDescription = 'desc';
30  $this->_sFieldTags = 'tags';
31  $this->_sFieldThumb = 'thumb';
32  $this->_sFieldStatus = 'status';
33  $this->_sFieldFeatured = 'featured';
34  $this->_sFieldCreated = 'created';
35  $this->_sTableFans = '';
36  $this->_sTableAdmins = '';
37  $this->_sFieldAllowViewTo = 'allow_view_product_to';
38  }
39 
40  function deleteEntryByIdAndOwner($iId, $iOwner, $isAdmin)
41  {
42  if ($iRet = parent::deleteEntryByIdAndOwner($iId, $iOwner, $isAdmin)) {
43  $this->deleteEntryMediaAll($iId, 'images');
44  $this->deleteEntryMediaAll($iId, 'videos');
45  $this->deleteEntryMediaFileAll($iId, 'files');
46  }
47 
48  return $iRet;
49  }
50 
51  // media files
52 
54  {
55  $a = $this->getRow("SELECT `hidden`, `entry_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` WHERE `id` = ?",
56  [$iFileId]);
57  $iHiddenNew = $a['hidden'] ? 0 : 1;
58  if (!$this->query("UPDATE `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` SET `hidden` = $iHiddenNew WHERE `id` = ?",
59  [$iFileId])
60  ) {
61  return false;
62  }
63  $this->updatePriceRange($a['entry_id']);
64 
65  return $iHiddenNew;
66  }
67 
68  function updatePriceRange($iEntryId)
69  {
70  $aRange = $this->getRow("SELECT MIN(`price`) AS `min`, MAX(`price`) AS `max` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` WHERE `entry_id` = ? AND `hidden` = 0",
71  [$iEntryId]);
72  if (!$aRange || ('' == $aRange['min'] && '' == $aRange['max'])) {
73  $sPriceRange = '';
74  } elseif (0 == $aRange['min'] && 0 == $aRange['max']) {
75  $sPriceRange = 'Free';
76  } elseif ($aRange['min'] == $aRange['max']) {
77  $sPriceRange = '%s' . $aRange['min'];
78  } else {
79  $sPriceRange = '%s' . $aRange['min'] . '-' . '%s' . $aRange['max'];
80  }
81  $this->query("UPDATE `" . $this->_sPrefix . $this->_sTableMain . "` SET `price_range` = '$sPriceRange' WHERE `id` = '$iEntryId'");
82 
83  return $aRange;
84  }
85 
86  function insertMediaFiles($iEntryId, $aMedia, $iProfileId)
87  {
88  $i = 0;
89  foreach ($aMedia as $r) {
90  $i += $this->query("INSERT INTO `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` VALUES (NULL, '$iProfileId', '$iEntryId', '{$r['id']}', '{$r['price']}', '{$r['privacy']}', 0)") ? 1 : 0;
91  }
92  if ($i) {
93  $this->updatePriceRange($iEntryId);
94  }
95 
96  return $i;
97  }
98 
99  function deleteMediaFile($iMediaId, $sMediaType)
100  {
101  $aEntries = $this->getAll("SELECT `entry_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "{$sMediaType}` WHERE `media_id` = '$iMediaId'");
102  if (parent::deleteMediaFile($iMediaId, $sMediaType)) {
103  $this->query("DELETE FROM `" . $this->_sPrefix . "customers` WHERE `file_id` = $iMediaId");
104  if ($aEntries) {
105  foreach ($aEntries as $r) {
106  $this->updatePriceRange($r['entry_id']);
107  }
108  }
109 
110  return true;
111  }
112 
113  return false;
114  }
115 
116  function deleteEntryMediaFileAll($iEntryId, $sMediaType)
117  {
118  $aMedia = $this->getAll("SELECT `media_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "{$sMediaType}` WHERE `entry_id` = '$iEntryId'");
119  foreach ($aMedia as $r) {
120  $this->deleteMediaFile($r['media_id'], $sMediaType);
121  }
122  }
123 
124  function getFileInfo($iEntryId, $iMediaId)
125  {
126  return $this->getRow("SELECT `ti`.* FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` AS `ti` WHERE `media_id` = ? AND `entry_id` = ? LIMIT 1",
127  [$iMediaId, $iEntryId]);
128  }
129 
131  {
132  return $this->getRow("SELECT `ti`.*, `tp`.`{$this->_sFieldTitle}`, `tp`.`{$this->_sFieldUri}`
133  FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` AS `ti` LEFT JOIN `" . $this->_sPrefix . $this->_sTableMain . "`
134  AS `tp` ON (`ti`.`entry_id` = `tp`.`{$this->_sFieldId}`) WHERE `ti`.`id` = ? LIMIT 1", [$iId]);
135  }
136 
137  function getFiles($iEntryId, $isFilterHidden = false)
138  {
139  $sWhere = '';
140  if ($isFilterHidden) {
141  $sWhere = ' AND `hidden` = 0';
142  }
143 
144  return $this->getAll("SELECT * FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` WHERE `entry_id` = ? $sWhere", [$iEntryId]);
145  }
146 
147  function getFilesByAuthor($iAuthorId)
148  {
149  return $this->getAll("SELECT `ti`.*, `tp`.`{$this->_sFieldTitle}`, `tp`.`{$this->_sFieldUri}`
150  FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` AS `ti` LEFT JOIN `" . $this->_sPrefix . $this->_sTableMain . "`
151  AS `tp` ON (`ti`.`entry_id` = `tp`.`id`) WHERE `ti`.`{$this->_sFieldAuthorId}` = ?", [$iAuthorId]);
152  }
153 
154  function registerCustomer($iClientId, $iItemId, $sOrderId, $iCount, $iDate)
155  {
156  return $this->query("INSERT INTO `" . $this->_sPrefix . "customers` SET `file_id` = '$iItemId', `client_id` = '$iClientId', `order_id` = '$sOrderId', `count` = '$iCount', `date` = '$iDate'");
157  }
158 
159  function unregisterCustomer($iClientId, $iItemId, $sOrderId)
160  {
161  return $this->query("DELETE FROM `" . $this->_sPrefix . "customers` WHERE `file_id` = '$iItemId' AND `client_id` = '$iClientId' AND `order_id` = '$sOrderId'");
162  }
163 
164  function isCustomer($iClientId, $iProductId)
165  {
166  return $this->query("SELECT 1 FROM `" . $this->_sPrefix . "customers` AS `tc` INNER JOIN `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` AS `tf` ON (`tf`.`id` = `tc`.`file_id` AND `tf`.`entry_id` = '$iProductId') WHERE `tc`.`client_id` = '$iClientId' LIMIT 1");
167  }
168 
169  function isPurchasedItem($iClientId, $iFileId)
170  {
171  return $this->getOne("SELECT 1 FROM `" . $this->_sPrefix . "customers` WHERE `file_id` = '$iFileId' AND `client_id` = '$iClientId' LIMIT 1") ? true : false;
172  }
173 
175  {
176  $iProfileId = (int)$iProfileId;
177  if (!$iProfileId) {
178  return false;
179  }
180 
181  return $this->query("DELETE FROM `" . $this->_sPrefix . "customers` WHERE `client_id` = " . $iProfileId);
182  }
183 
184  function getBroadcastRecipients($iProductId)
185  {
186  return $this->getAll("SELECT DISTINCT `p`.`ID`, `p`.`Email` FROM `" . $this->_sPrefix . "customers` AS `tc` INNER JOIN `" . $this->_sPrefix . $this->_sTableMediaPrefix . "files` AS `tf` ON (`tf`.`id` = `tc`.`file_id` AND `tf`.`entry_id` = '$iProductId') INNER JOIN `Profiles` as `p` ON (`p`.`ID` = `tc`.`client_id` AND `p`.`Status` = 'Active')");
187  }
188 }
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
ChStoreDb\deleteEntryByIdAndOwner
deleteEntryByIdAndOwner($iId, $iOwner, $isAdmin)
Definition: ChStoreDb.php:40
ChWsbTwigModuleDb\deleteEntryMediaAll
deleteEntryMediaAll($iEntryId, $sMediaType)
Definition: ChWsbTwigModuleDb.php:150
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
php
ChStoreDb\getFileInfoByFileId
getFileInfoByFileId($iId)
Definition: ChStoreDb.php:130
$iId
$iId
Definition: license.php:15
ChWsbDb\getAll
getAll($sQuery, $aBindings=[], $iFetchType=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:206
ChStoreDb\unregisterCustomer
unregisterCustomer($iClientId, $iItemId, $sOrderId)
Definition: ChStoreDb.php:159
ChStoreDb\registerCustomer
registerCustomer($iClientId, $iItemId, $sOrderId, $iCount, $iDate)
Definition: ChStoreDb.php:154
ChStoreDb\isPurchasedItem
isPurchasedItem($iClientId, $iFileId)
Definition: ChStoreDb.php:169
ChStoreDb\getFilesByAuthor
getFilesByAuthor($iAuthorId)
Definition: ChStoreDb.php:147
ChWsbDb\getRow
getRow($sQuery, $aBindings=[], $iFetchStyle=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:225
ChWsbDb\query
query($sQuery, $aBindings=[])
Definition: ChWsbDb.php:386
ChWsbTwigModuleDb
Definition: ChWsbTwigModuleDb.php:14
$iDate
$iDate
Definition: cron.php:130
ChStoreDb\deleteMediaFile
deleteMediaFile($iMediaId, $sMediaType)
Definition: ChStoreDb.php:99
ChWsbDb\getOne
getOne($sQuery, $aBindings=[], $iIndex=0)
Definition: ChWsbDb.php:263
ChStoreDb\deleteEntryMediaFileAll
deleteEntryMediaFileAll($iEntryId, $sMediaType)
Definition: ChStoreDb.php:116
ChStoreDb\insertMediaFiles
insertMediaFiles($iEntryId, $aMedia, $iProfileId)
Definition: ChStoreDb.php:86
ChStoreDb\getBroadcastRecipients
getBroadcastRecipients($iProductId)
Definition: ChStoreDb.php:184
$iFileId
$iFileId
Definition: embed.php:12
ChStoreDb\isCustomer
isCustomer($iClientId, $iProductId)
Definition: ChStoreDb.php:164
ChStoreDb\getFileInfo
getFileInfo($iEntryId, $iMediaId)
Definition: ChStoreDb.php:124
ChStoreDb\getFiles
getFiles($iEntryId, $isFilterHidden=false)
Definition: ChStoreDb.php:137
ChStoreDb\updatePriceRange
updatePriceRange($iEntryId)
Definition: ChStoreDb.php:68
ChStoreDb\toggleProductFileVisibility
toggleProductFileVisibility($iFileId)
Definition: ChStoreDb.php:53
ChStoreDb
Definition: ChStoreDb.php:15
ChStoreDb\__construct
__construct(&$oConfig)
Definition: ChStoreDb.php:19
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChStoreDb\removeCustomersFromAllEntries
removeCustomersFromAllEntries($iProfileId)
Definition: ChStoreDb.php:174
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29