Example #1
0
 /**
  * Updates table rows with specified data based on a WHERE clause.
  *
  * @param  mixed        $table The table to update.
  * @param  array        $bind  Column-value pairs.
  * @param  mixed        $where UPDATE WHERE clause(s).
  * @return int          The number of affected rows.
  */
 public function update($table = null, array $bind = null, $where = '')
 {
     if (is_null($table) && is_null($bind) && !strlen($where)) {
         return new Harmoni_Db_Update($this);
     } else {
         return parent::update($table, $bind, $where);
     }
 }
Example #2
0
 /**
  * deletes given number from the persistent occurrence property of a given tag
  *
  * @param  Tinbebase_Tags_Model_Tag|string $_tag
  * @param  int                             $_toDel
  * @return void
  */
 protected function _deleteOccurrence($_tag, $_toDel)
 {
     $tagId = $_tag instanceof Tinebase_Model_Tag ? $_tag->getId() : $_tag;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " decreasing tag occurrence of {$tagId} by {$_toDel}");
     }
     $quotedIdentifier = $this->_db->quoteIdentifier('occurrence');
     $data = array('occurrence' => new Zend_Db_Expr('(CASE WHEN ((' . $quotedIdentifier . ' - ' . (int) $_toDel . ') >= 0 THEN ' . $quotedIdentifier . ' - ' . (int) $_toDel . ' ELSE 0 END))'));
     $this->_db->update(SQL_TABLE_PREFIX . 'tags', $data, $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $tagId));
 }
 /**
  * update tag occurrrence
  * 
  * @param Tinebase_Model_Tag|string $tag
  * @param integer $toAddOrRemove
  */
 protected function _updateOccurrence($tag, $toAddOrRemove)
 {
     if ($toAddOrRemove == 0) {
         return;
     }
     $tagId = $tag instanceof Tinebase_Model_Tag ? $tag->getId() : $tag;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " de/increasing tag occurrence of {$tagId} by {$toAddOrRemove}");
     }
     $quotedIdentifier = $this->_db->quoteIdentifier('occurrence');
     if ($toAddOrRemove > 0) {
         $toAdd = (int) $toAddOrRemove;
         $data = array('occurrence' => new Zend_Db_Expr($quotedIdentifier . ' + ' . $toAdd));
     } else {
         $toRemove = abs((int) $toAddOrRemove);
         $data = array('occurrence' => new Zend_Db_Expr('(CASE WHEN (' . $quotedIdentifier . ' - ' . $toRemove . ') > 0 THEN ' . $quotedIdentifier . ' - ' . $toRemove . ' ELSE 0 END)'));
     }
     $this->_db->update(SQL_TABLE_PREFIX . 'tags', $data, $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $tagId));
 }