ModuleVote_MapperVote

Package modules.vote
Inheritance class ModuleVote_MapperVote » Mapper » LsObject
Since 1.0
Source Code /classes/modules/vote/mapper/Vote.mapper.class.php
Маппер для работы с БД

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
oDb DbSimple_Generic_Database Объект подключения к базе данных Mapper

Public Methods

Hide inherited methods

MethodDescriptionDefined By
AddVote() Добавляет голосование ModuleVote_MapperVote
DeleteVoteByTarget() Удаляет голосование из базы по списку идентификаторов таргета ModuleVote_MapperVote
GetVoteByArray() Получить список голосований по списку айдишников ModuleVote_MapperVote
__construct() Передаем коннект к БД Mapper

Method Details

AddVote() method
public bool AddVote(ModuleVote_EntityVote $oVote)
$oVote ModuleVote_EntityVote Объект голосования
{return} bool
Source Code: /classes/modules/vote/mapper/Vote.mapper.class.php#31 (show)
public function AddVote(ModuleVote_EntityVote $oVote) {
    
$sql "INSERT INTO ".Config::Get('db.table.vote').
        (target_id,
        target_type,
        user_voter_id,
        vote_direction,
        vote_value,            
        vote_date,
        vote_ip
        )
        VALUES(?d, ?, ?d, ?d, ?f, ?, ?)
    "
;
    if (
$this->oDb->query($sql,$oVote->getTargetId(),$oVote->getTargetType(),$oVote->getVoterId(),$oVote->getDirection(),$oVote->getValue(),$oVote->getDate(),$oVote->getIp())===0)
    {
        return 
true;
    }
    return 
false;
}

Добавляет голосование

DeleteVoteByTarget() method
public bool DeleteVoteByTarget(array|int $aTargetId, string $sTargetType)
$aTargetId array|int Список ID владельцев
$sTargetType string Тип владельца
{return} bool
Source Code: /classes/modules/vote/mapper/Vote.mapper.class.php#86 (show)
public function DeleteVoteByTarget($aTargetId,$sTargetType) {
    
$sql "
        DELETE FROM "
.Config::Get('db.table.vote').
        WHERE
            target_id IN(?a)
            AND
            target_type = ?                
    "
;
    if (
$this->oDb->query($sql,$aTargetId,$sTargetType)) {
        return 
true;
    }
    return 
false;
}

Удаляет голосование из базы по списку идентификаторов таргета

GetVoteByArray() method
public array GetVoteByArray(array $aArrayId, string $sTargetType, int $sUserId)
$aArrayId array Список ID владельцев
$sTargetType string Тип владельца
$sUserId int ID пользователя
{return} array
Source Code: /classes/modules/vote/mapper/Vote.mapper.class.php#57 (show)
public function GetVoteByArray($aArrayId,$sTargetType,$sUserId) {
    if (!
is_array($aArrayId) or count($aArrayId)==0) {
        return array();
    }
    
$sql "SELECT 
                *                             
            FROM 
                "
.Config::Get('db.table.vote')."
            WHERE                     
                target_id IN(?a)     
                AND
                target_type = ? 
                AND
                user_voter_id = ?d "
;
    
$aVotes=array();
    if (
$aRows=$this->oDb->select($sql,$aArrayId,$sTargetType,$sUserId)) {
        foreach (
$aRows as $aRow) {
            
$aVotes[]=Engine::GetEntity('Vote',$aRow);
        }
    }
    return 
$aVotes;
}

Получить список голосований по списку айдишников