array( 'title' => t('Nodes (using inc/dec counter)'), 'description' => t("Nodes are a Drupal site's primary content."), 'handler' => 'flag_node_inccount' ), ); } */ class flag_node_inccount extends flag_node { /** * @see flag_flag::_flag */ function _flag($content_id, $uid, $sid) { $transaction = db_transaction(); $fcid = parent::_flag($content_id, $uid, $sid); if ($fcid) { $this->_increase_count($content_id); } return $fcid; } /** * @see flag_flag::_unflag */ function _unflag($content_id, $uid, $sid) { $transaction = db_transaction(); $fcid = parent::_unflag($content_id, $uid, $sid); if ($fcid) { $this->_decrease_count($content_id); } return $fcid; } /** * @see flag_flag::_update_count */ function _update_count($content_id) { // do nothing } /** * Increases the flag count for this content. * * @param $content_id * For which item should the count be increased. * * @param $number * Increase by this number (default 1). * * @protected */ function _increase_count($content_id, $number = 1) { if (!db_update('flag_counts') ->expression('count', "count + $number") ->condition('fid', $this->fid) ->condition('content_id', $content_id) ->execute() ){ db_insert('flag_counts')->fields(array( 'fid' => $this->fid, 'content_type' => $this->content_type, 'content_id' => $content_id, 'count' => $number)) ->execute(); } } /** * Decreases the flag count for this content. * * @param $content_id * For which item should the count be descreased. * * @param $number * Decrease by this number (default 1). * * @protected */ function _decrease_count($content_id, $number = 1) { if (!db_delete('flag_counts') ->condition('fid', $this->fid) ->condition('content_id', $content_id) ->condition('count',$number,'<=') ->execute() ){ db_update('flag_counts') ->expression('count', "count - $number") ->condition('fid', $this->fid) ->condition('content_id', $content_id) ->execute(); } } } ?>