Cheetah
ChFilesDb.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbFilesDb.php');
9 
10 class ChFilesDb extends ChWsbFilesDb
11 {
12  /*
13  * Constructor.
14  */
15  function __construct(&$oConfig)
16  {
17  parent::__construct($oConfig);
18 
19  $this->sFileTable = 'ch_files_main';
20  $this->sFavoriteTable = 'ch_files_favorites';
21  $this->sMimeTypeTable = 'ch_files_types';
22 
23  $aAddFields = array(
24  'medExt' => 'Ext',
25  'medDesc' => 'Desc',
26  'medSize' => 'Size',
27  'Type' => 'Type',
28  'DownloadsCount' => 'DownloadsCount',
29  'AllowDownload' => 'AllowDownload'
30  );
31  $this->aFileFields = array_merge($this->aFileFields, $aAddFields);
32 
33  $this->aFavoriteFields = array(
34  'fileId' => 'ID',
35  'ownerId' => 'Profile',
36  'favDate' => 'Date'
37  );
38  }
39 
40  function getTypeIcon ($sType)
41  {
43  $sqlQuery = "SELECT `Icon` FROM `{$this->sMimeTypeTable}` WHERE `{$this->aFileFields['Type']}`='$sType' LIMIT 1";
44  return $this->getOne($sqlQuery);
45  }
46 
47  function getTypeToIconArray()
48  {
49  return $this->getPairs("SELECT `Type`, `Icon` FROM `{$this->sMimeTypeTable}` WHERE 1", "Type", "Icon");
50  }
51 
52  function getDownloadsCount ($iFile)
53  {
54  $iFile = (int)$iFile;
55  return $this->query("SELECT `{$this->aFileFields['DownloadsCount']}` FROM `{$this->sFileTable}` WHERE `{$this->aFileFields['medID']}` = '$iFile'");
56  }
57 
58  function updateDownloadsCount ($sFileUri)
59  {
60  $sFileUri = process_db_input($sFileUri, CH_TAGS_STRIP);
61  $this->query("UPDATE `{$this->sFileTable}` SET `{$this->aFileFields['DownloadsCount']}` = `{$this->aFileFields['DownloadsCount']}` + 1 WHERE `{$this->aFileFields['medUri']}`='$sFileUri'");
62  }
63 
64  function insertMimeType ($sMimeType)
65  {
66  $sMimeType = process_db_input($sMimeType, CH_TAGS_STRIP);
67  $sqlQuery = "INSERT INTO `{$this->sMimeTypeTable}` SET `Type`='$sMimeType'";
68  $this->res($sqlQuery);
69  }
70 
71  function updateMimeTypePic ($mixedMimeTypes, $sPic)
72  {
73  $mixedMimeTypes = process_db_input($mixedMimeTypes, CH_TAGS_STRIP);
74  if (is_array($mixedMimeTypes))
75  $sqlCond = "IN('" . implode("', '", $mixedMimeTypes) . "')";
76  else
77  $sqlCond = "= '$mixedMimeTypes'";
78 
79  $sqlQuery = "UPDATE `{$this->sMimeTypeTable}` SET `Icon` = '$sPic' WHERE `Type` $sqlCond";
80  $this->res($sqlQuery);
81  }
82 
83  function checkMimeTypeExist ($sMimeType)
84  {
85  $sMimeType = process_db_input($sMimeType, CH_TAGS_STRIP);
86  $sqlQuery = "SELECT COUNT(*) FROM `{$this->sMimeTypeTable}` WHERE `Type`='$sMimeType'";
87  return (int)$this->getOne($sqlQuery);
88  }
89 
90  function getSettingsCategory ()
91  {
92  return (int)$this->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name` = 'Files' LIMIT 1");
93  }
94 }
ChFilesDb\__construct
__construct(&$oConfig)
Definition: ChFilesDb.php:15
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
php
ChWsbDb\getPairs
getPairs($sQuery, $sFieldKey, $sFieldValue, $aBindings=[])
Definition: ChWsbDb.php:363
ChFilesDb\getTypeToIconArray
getTypeToIconArray()
Definition: ChFilesDb.php:47
ChFilesDb\getSettingsCategory
getSettingsCategory()
Definition: ChFilesDb.php:90
ChFilesDb\checkMimeTypeExist
checkMimeTypeExist($sMimeType)
Definition: ChFilesDb.php:83
$sType
$sType
Definition: actions.inc.php:11
ChFilesDb\updateMimeTypePic
updateMimeTypePic($mixedMimeTypes, $sPic)
Definition: ChFilesDb.php:71
ChWsbDb\query
query($sQuery, $aBindings=[])
Definition: ChWsbDb.php:386
ChWsbDb\res
res($sQuery, $aBindings=[], $bReplaying=false)
Definition: ChWsbDb.php:150
ChFilesDb\insertMimeType
insertMimeType($sMimeType)
Definition: ChFilesDb.php:64
ChWsbDb\getOne
getOne($sQuery, $aBindings=[], $iIndex=0)
Definition: ChWsbDb.php:263
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
ChFilesDb\updateDownloadsCount
updateDownloadsCount($sFileUri)
Definition: ChFilesDb.php:58
ChFilesDb
Definition: ChFilesDb.php:11
ChFilesDb\getTypeIcon
getTypeIcon($sType)
Definition: ChFilesDb.php:40
ChWsbFilesDb
Definition: ChWsbFilesDb.php:11
ChFilesDb\getDownloadsCount
getDownloadsCount($iFile)
Definition: ChFilesDb.php:52