* */ /** * Маппер для работы с БД * * @package modules.media * @since 1.0 */ class ModuleMedia_MapperMedia extends Mapper { public function GetMediaByTarget($sTargetType,$iTargetId,$iUserId=null) { $sql = "SELECT m.* FROM ".Config::Get('db.table.media_target')." AS t JOIN ".Config::Get('db.table.media')." as m on ( m.id=t.media_id { and m.user_id = ?d } ) WHERE t.target_id = ?d AND t.target_type = ? ORDER BY m.id desc limit 0,500"; $aResult = array(); if ($aRows = $this->oDb->select($sql,$iUserId ? $iUserId : DBSIMPLE_SKIP,$iTargetId, $sTargetType)) { foreach ($aRows as $aRow) { $aResult[]=Engine::GetEntity('ModuleMedia_EntityMedia',$aRow); } } return $aResult; } public function GetMediaByTargetTmp($sTargetTmp,$iUserId=null) { $sql = "SELECT m.* FROM ".Config::Get('db.table.media_target')." AS t JOIN ".Config::Get('db.table.media')." as m on ( m.id=t.media_id { and m.user_id = ?d } ) WHERE t.target_tmp = ? ORDER BY m.id desc limit 0,500"; $aResult = array(); if ($aRows = $this->oDb->select($sql,$iUserId ? $iUserId : DBSIMPLE_SKIP,$sTargetTmp)) { foreach ($aRows as $aRow) { $aResult[]=Engine::GetEntity('ModuleMedia_EntityMedia',$aRow); } } return $aResult; } public function RemoveTargetByTypeAndId($sTargetType,$iTargetId) { $sql = "DELETE FROM ".Config::Get('db.table.media_target')." WHERE target_id = ?d AND target_type = ? "; if ($this->oDb->query($sql,$iTargetId,$sTargetType)!==false) { return true; } return false; } }