public function addVote($intItemId, $fltValue, $blnLock = false)
    {
        if ($this->getSessionBag()->get($this->getLockId($intItemId))) {
            return;
        }

        $arrData = $this->getDataFor([$intItemId]);

        if (!$arrData || !$arrData[$intItemId]['votecount']) {
            $voteCount   = 0;
            $prevPercent = 0;
        } else {
            $voteCount   = $arrData[$intItemId]['votecount'];
            $prevPercent = (float) $arrData[$intItemId]['meanvalue'];
        }

        $grandTotal = ($voteCount * $this->get('rating_max') * $prevPercent);
        $hundred    = ($this->get('rating_max') * (++$voteCount));

        // Calculate the percentage.
        $value = (1 / $hundred * ($grandTotal + $fltValue));

        $arrSet = [
            'mid' => $this->getMetaModel()->get('id'),
            'aid' => $this->get('id'),
            'iid' => $intItemId,
            'votecount' => $voteCount,
            'meanvalue' => $value,
        ];

        $queryBuilder = $this->connection->createQueryBuilder();

        if (!$arrData || !$arrData[$intItemId]['votecount']) {
            $queryBuilder
                ->insert('tl_metamodel_rating')
                ->values($arrSet);
        } else {
            foreach ($arrSet as $key => $value) {
                $queryBuilder
                    ->set($key, ':' . $key)
                    ->setParameter($key, $value);
            }

            $queryBuilder
                ->update('tl_metamodel_rating')
                ->andWhere('mid=:mid AND aid=:aid AND iid=:iid')
                ->setParameter('mid', $this->getMetaModel()->get('id'))
                ->setParameter('aid', $this->get('id'))
                ->setParameter('iid', $intItemId);
        }

        $queryBuilder->execute();

        if ($blnLock) {
            $this->getSessionBag()->set($this->getLockId($intItemId), true);
        }
    }
public function addVote($intItemId, $fltValue, $blnLock = false)
    {
        if ($this->getSessionBag()->get($this->getLockId($intItemId))) {
            return;
        }

        $arrData = $this->getDataFor([$intItemId]);

        if (!$arrData || !$arrData[$intItemId]['votecount']) {
            $voteCount   = 0;
            $prevPercent = 0;
        } else {
            $voteCount   = $arrData[$intItemId]['votecount'];
            $prevPercent = (float) $arrData[$intItemId]['meanvalue'];
        }

        $grandTotal = ($voteCount * $this->get('rating_max') * $prevPercent);
        $hundred    = ($this->get('rating_max') * (++$voteCount));

        // Calculate the percentage.
        $value = (1 / $hundred * ($grandTotal + $fltValue));

        $arrSet = [
            'mid' => $this->getMetaModel()->get('id'),
            'aid' => $this->get('id'),
            'iid' => $intItemId,
            'votecount' => $voteCount,
            'meanvalue' => $value,
        ];

        $queryBuilder = $this->connection->createQueryBuilder();

        if (!$arrData || !$arrData[$intItemId]['votecount']) {
            $queryBuilder
                ->insert('tl_metamodel_rating')
                ->values($arrSet);
        } else {
            foreach ($arrSet as $key => $value) {
                $queryBuilder
                    ->set($key, ':' . $key)
                    ->setParameter($key, $value);
            }

            $queryBuilder
                ->update('tl_metamodel_rating')
                ->andWhere('mid=:mid AND aid=:aid AND iid=:iid')
                ->setParameter('mid', $this->getMetaModel()->get('id'))
                ->setParameter('aid', $this->get('id'))
                ->setParameter('iid', $intItemId);
        }

        $queryBuilder->execute();

        if ($blnLock) {
            $this->getSessionBag()->set($this->getLockId($intItemId), true);
        }
    }
public function addVote ( $ intItemId , $ fltValue , $ blnLock = false ) { if ( $ this -> getSessionBag ( ) -> get ( $ this -> getLockId ( $ intItemId ) ) ) { return ; } $ arrData = $ this -> getDataFor ( [ $ intItemId ] ) ; if ( ! $ arrData || ! $ arrData [ $ intItemId ] [ 'votecount' ] ) { $ voteCount = 0 ; $ prevPercent = 0 ; } else { $ voteCount = $ arrData [ $ intItemId ] [ 'votecount' ] ; $ prevPercent = ( float ) $ arrData [ $ intItemId ] [ 'meanvalue' ] ; } $ grandTotal = ( $ voteCount * $ this -> get ( 'rating_max' ) * $ prevPercent ) ; $ hundred = ( $ this -> get ( 'rating_max' ) * ( ++ $ voteCount ) ) ; // Calculate the percentage. $ value = ( 1 / $ hundred * ( $ grandTotal + $ fltValue ) ) ; $ arrSet = [ 'mid' => $ this -> getMetaModel ( ) -> get ( 'id' ) , 'aid' => $ this -> get ( 'id' ) , 'iid' => $ intItemId , 'votecount' => $ voteCount , 'meanvalue' => $ value , ] ; $ queryBuilder = $ this -> connection -> createQueryBuilder ( ) ; if ( ! $ arrData || ! $ arrData [ $ intItemId ] [ 'votecount' ] ) { $ queryBuilder -> insert ( 'tl_metamodel_rating' ) -> values ( $ arrSet ) ; } else { foreach ( $ arrSet as $ key => $ value ) { $ queryBuilder -> set ( $ key , ':' . $ key ) -> setParameter ( $ key , $ value ) ; } $ queryBuilder -> update ( 'tl_metamodel_rating' ) -> andWhere ( 'mid=:mid AND aid=:aid AND iid=:iid' ) -> setParameter ( 'mid' , $ this -> getMetaModel ( ) -> get ( 'id' ) ) -> setParameter ( 'aid' , $ this -> get ( 'id' ) ) -> setParameter ( 'iid' , $ intItemId ) ; } $ queryBuilder -> execute ( ) ; if ( $ blnLock ) { $ this -> getSessionBag ( ) -> set ( $ this -> getLockId ( $ intItemId ) , true ) ; } }
Add a vote to the database.

@param int   $intItemId The id of the item to be voted.
@param float $fltValue  The value of the vote.
@param bool  $blnLock   Flag if the user session shall be locked against voting for this item again.

@return void
Add a vote to the database .