Go to the documentation of this file.00001 <?php
00002
00007 class oxCounter
00008 {
00009
00017 public function getNext($sIdent)
00018 {
00019 $oDb = oxDb::getDb();
00020 $oDb->startTransaction();
00021
00022 $sQ = "SELECT `oxcount` FROM `oxcounters` WHERE `oxident` = " . $oDb->quote($sIdent) . " FOR UPDATE";
00023
00024 if (($iCnt = $oDb->getOne($sQ, false, false)) === false) {
00025 $sQ = "INSERT INTO `oxcounters` (`oxident`, `oxcount`) VALUES (?, '0')";
00026 $oDb->execute($sQ, array($sIdent));
00027 }
00028
00029 $iCnt = ((int) $iCnt) + 1;
00030 $sQ = "UPDATE `oxcounters` SET `oxcount` = ? WHERE `oxident` = ?";
00031 $oDb->execute($sQ, array($iCnt, $sIdent));
00032
00033 $oDb->commitTransaction();
00034
00035 return $iCnt;
00036 }
00037
00047 public function update($sIdent, $iCount)
00048 {
00049 $oDb = oxDb::getDb();
00050 $oDb->startTransaction();
00051
00052 $sQ = "SELECT `oxcount` FROM `oxcounters` WHERE `oxident` = " . $oDb->quote($sIdent) . " FOR UPDATE";
00053
00054 if (($iCnt = $oDb->getOne($sQ, false, false)) === false) {
00055 $sQ = "INSERT INTO `oxcounters` (`oxident`, `oxcount`) VALUES (?, ?)";
00056 $blResult = $oDb->execute($sQ, array($sIdent, $iCount));
00057 } else {
00058 $sQ = "UPDATE `oxcounters` SET `oxcount` = ? WHERE `oxident` = ? AND `oxcount` < ?";
00059 $blResult = $oDb->execute($sQ, array($iCount, $sIdent, $iCount));
00060 }
00061
00062 $oDb->commitTransaction();
00063
00064 return $blResult;
00065 }
00066 }