OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxgbentry.php
Go to the documentation of this file.
1 <?php
2 
8 class oxGbEntry extends oxBase
9 {
15  //to skip oxcreate we must change this field to 'CURRENT_TIMESTAMP'
16  //protected $_aSkipSaveFields = array( 'oxcreate' );
17 
23  protected $_sClassName = 'oxgbentry';
24 
29  public function __construct()
30  {
32  $this->init( 'oxgbentries' );
33  }
34 
42  public function assign( $dbRecord )
43  {
44 
45  $blRet = parent::assign( $dbRecord );
46 
47  if ( isset( $this->oxgbentries__oxuserid ) && $this->oxgbentries__oxuserid->value ) {
48  $oDb = oxDb::getDb();
49  $this->oxuser__oxfname = new oxField( $oDb->getOne( "select oxfname from oxuser where oxid=".$oDb->quote( $this->oxgbentries__oxuserid->value ) ));
50  }
51 
52  return $blRet;
53  }
54 
60  protected function _insert()
61  {
62  // set oxcreate
63  $this->oxgbentries__oxcreate = new oxField( date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() ));
64  return parent::_insert();
65  }
66 
76  public function getAllEntries( $iStart, $iNrofCatArticles, $sSortBy)
77  {
78  $myConfig = $this->getConfig();
79 
80  // loading entries
81  $sSelect = 'select oxgbentries.*, oxuser.oxfname,
82  `oxuser`.`oxusername` AS `author`, `oxgbentries`.`oxcreate` AS `date`
83  from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
84  $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
85 
86  // setting GB entry view restirction rules
87  if ( $myConfig->getConfigParam( 'blGBModerate') ) {
88  $oUser = $this->getUser();
89  $sSelect .= " and ( oxgbentries.oxactive = '1' ";
90  $sSelect .= $oUser?" or oxgbentries.oxuserid = " . oxDb::getDb()->quote( $oUser->getId() ) : '';
91  $sSelect .= " ) ";
92  }
93 
94  // setting sort
95  if ( $sSortBy ) {
96  $sSelect .= "order by $sSortBy ";
97  }
98 
99 
100  $oEntries = oxNew( 'oxlist' );
101  $oEntries->init( 'oxgbentry' );
102 
103  $oEntries->setSqlLimit( $iStart, $iNrofCatArticles );
104  $oEntries->selectString( $sSelect );
105 
106  return $oEntries;
107  }
108 
114  public function getEntryCount()
115  {
116  $myConfig = $this->getConfig();
117  $oDb = oxDb::getDb();
118 
119  // loading entries
120  $sSelect = 'select count(*) from oxgbentries left join oxuser on oxgbentries.oxuserid = oxuser.oxid ';
121  $sSelect .= 'where oxuser.oxid is not null and oxgbentries.oxshopid = "'.$myConfig->getShopId().'" ';
122 
123  // setting GB entry view restirction rules
124  if ( $myConfig->getConfigParam( 'blGBModerate') ) {
125  $oUser = $this->getUser();
126  $sSelect .= " and ( oxgbentries.oxactive = '1' ";
127  $sSelect .= $oUser?" or oxgbentries.oxuserid = ".$oDb->quote( $oUser->getId() ):'';
128  $sSelect .= " ) ";
129  }
130 
131  // loading only if there is some data
132  $iRecCnt = (int) $oDb->getOne( $sSelect );
133  return $iRecCnt;
134  }
135 
146  public function floodProtection( $sShopid = 0, $sUserId = null )
147  {
148  $result = true;
149  if ( $sUserId && $sShopid) {
150  $oDb = oxDb::getDb();
151  $sToday = date( 'Y-m-d' );
152  $sSelect = "select count(*) from oxgbentries ";
153  $sSelect .= "where oxgbentries.oxuserid = " . $oDb->quote( $sUserId ) . " and oxgbentries.oxshopid = " . $oDb->quote( $sShopid ) . " ";
154  $sSelect .= "and oxgbentries.oxcreate >= '$sToday 00:00:00' and oxgbentries.oxcreate <= '$sToday 23:59:59' ";
155  $iCnt = $oDb->getOne( $sSelect );
156 
157  $myConfig = $this->getConfig();
158  if ( ( !$myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) || ( $iCnt < $myConfig->getConfigParam( 'iMaxGBEntriesPerDay' ) ) ) {
159  $result = false;
160  }
161  }
162  return $result;
163  }
164 
165 }