2012-03-10 15:40:59 +02:00
|
|
|
|
<?php
|
2014-10-08 08:20:29 +03:00
|
|
|
|
/*
|
|
|
|
|
* LiveStreet CMS
|
|
|
|
|
* Copyright © 2013 OOO "ЛС-СОФТ"
|
|
|
|
|
*
|
|
|
|
|
* ------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* Official site: www.livestreetcms.com
|
|
|
|
|
* Contact e-mail: office@livestreetcms.com
|
|
|
|
|
*
|
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
|
*
|
|
|
|
|
* ------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* @link http://www.livestreetcms.com
|
|
|
|
|
* @copyright 2013 OOO "ЛС-СОФТ"
|
|
|
|
|
* @author Maxim Mzhelskiy <rus.engine@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-03-10 15:40:59 +02:00
|
|
|
|
|
2012-06-24 13:47:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Объект маппера для работы с БД
|
|
|
|
|
*
|
2014-10-08 08:20:29 +03:00
|
|
|
|
* @package application.modules.subscribe
|
2012-06-24 13:47:34 +03:00
|
|
|
|
* @since 1.0
|
|
|
|
|
*/
|
2014-10-08 11:49:34 +03:00
|
|
|
|
class ModuleSubscribe_MapperSubscribe extends Mapper
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Добавляет подписку в БД
|
|
|
|
|
*
|
|
|
|
|
* @param ModuleSubscribe_EntitySubscribe $oSubscribe Объект подписки
|
|
|
|
|
* @return int|bool
|
|
|
|
|
*/
|
|
|
|
|
public function AddSubscribe($oSubscribe)
|
|
|
|
|
{
|
|
|
|
|
$sql = "INSERT INTO " . Config::Get('db.table.subscribe') . " SET ?a ";
|
|
|
|
|
if ($iId = $this->oDb->query($sql, $oSubscribe->_getData())) {
|
|
|
|
|
return $iId;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение подписки по типы и емайлу
|
|
|
|
|
*
|
|
|
|
|
* @param string $sType Тип
|
|
|
|
|
* @param string $sMail Емайл
|
|
|
|
|
* @return ModuleSubscribe_EntitySubscribe|null
|
|
|
|
|
*/
|
|
|
|
|
public function GetSubscribeByTypeAndMail($sType, $sMail)
|
|
|
|
|
{
|
|
|
|
|
$sql = "SELECT * FROM " . Config::Get('db.table.subscribe') . " WHERE target_type = ? and mail = ?";
|
|
|
|
|
if ($aRow = $this->oDb->selectRow($sql, $sType, $sMail)) {
|
|
|
|
|
return Engine::GetEntity('Subscribe', $aRow);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обновление подписки
|
|
|
|
|
*
|
|
|
|
|
* @param ModuleSubscribe_EntitySubscribe $oSubscribe Объект подписки
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function UpdateSubscribe($oSubscribe)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE " . Config::Get('db.table.subscribe') . "
|
2012-03-10 15:40:59 +02:00
|
|
|
|
SET
|
|
|
|
|
status = ?,
|
|
|
|
|
date_remove = ?
|
|
|
|
|
WHERE id = ?d
|
2012-06-24 13:47:34 +03:00
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$res = $this->oDb->query($sql, $oSubscribe->getStatus(),
|
|
|
|
|
$oSubscribe->getDateRemove(),
|
|
|
|
|
$oSubscribe->getId());
|
|
|
|
|
return $this->IsSuccessful($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Смена емайла в подписках
|
|
|
|
|
*
|
|
|
|
|
* @param string $sMailOld Старый емайл
|
|
|
|
|
* @param string $sMailNew Новый емайл
|
|
|
|
|
* @param int|null $iUserId Id пользователя
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ChangeSubscribeMail($sMailOld, $sMailNew, $iUserId = null)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE " . Config::Get('db.table.subscribe') . "
|
2013-04-01 13:02:46 +03:00
|
|
|
|
SET
|
|
|
|
|
mail = ?
|
|
|
|
|
WHERE mail = ? { and user_id = ?d }
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$res = $this->oDb->query($sql, $sMailNew, $sMailOld, $iUserId ? $iUserId : DBSIMPLE_SKIP);
|
|
|
|
|
return $this->IsSuccessful($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает список подписок по фильтру
|
|
|
|
|
*
|
|
|
|
|
* @param array $aFilter Фильтр
|
|
|
|
|
* @param array $aOrder Сортировка
|
|
|
|
|
* @param int $iCount Возвращает общее количество элементов
|
|
|
|
|
* @param int $iCurrPage Номер страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на страницу
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function GetSubscribes($aFilter, $aOrder, &$iCount, $iCurrPage, $iPerPage)
|
|
|
|
|
{
|
|
|
|
|
$aOrderAllow = array('id', 'date_add', 'status');
|
|
|
|
|
$sOrder = '';
|
|
|
|
|
foreach ($aOrder as $key => $value) {
|
|
|
|
|
if (!in_array($key, $aOrderAllow)) {
|
|
|
|
|
unset($aOrder[$key]);
|
|
|
|
|
} elseif (in_array($value, array('asc', 'desc'))) {
|
|
|
|
|
$sOrder .= " {$key} {$value},";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$sOrder = trim($sOrder, ',');
|
|
|
|
|
if ($sOrder == '') {
|
|
|
|
|
$sOrder = ' id desc ';
|
|
|
|
|
}
|
2012-03-10 15:40:59 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if (isset($aFilter['exclude_mail']) and !is_array($aFilter['exclude_mail'])) {
|
|
|
|
|
$aFilter['exclude_mail'] = array($aFilter['exclude_mail']);
|
|
|
|
|
}
|
2012-03-10 15:40:59 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$sql = "SELECT
|
2012-03-10 15:40:59 +02:00
|
|
|
|
*
|
|
|
|
|
FROM
|
2014-10-08 11:49:34 +03:00
|
|
|
|
" . Config::Get('db.table.subscribe') . "
|
2012-03-10 15:40:59 +02:00
|
|
|
|
WHERE
|
|
|
|
|
1 = 1
|
|
|
|
|
{ AND target_type = ? }
|
|
|
|
|
{ AND target_id = ?d }
|
|
|
|
|
{ AND mail = ? }
|
|
|
|
|
{ AND mail not IN (?a) }
|
|
|
|
|
{ AND `key` = ? }
|
|
|
|
|
{ AND status = ?d }
|
|
|
|
|
ORDER by {$sOrder}
|
|
|
|
|
LIMIT ?d, ?d ;
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$aResult = array();
|
|
|
|
|
if ($aRows = $this->oDb->selectPage($iCount, $sql,
|
|
|
|
|
isset($aFilter['target_type']) ? $aFilter['target_type'] : DBSIMPLE_SKIP,
|
|
|
|
|
isset($aFilter['target_id']) ? $aFilter['target_id'] : DBSIMPLE_SKIP,
|
|
|
|
|
isset($aFilter['mail']) ? $aFilter['mail'] : DBSIMPLE_SKIP,
|
|
|
|
|
(isset($aFilter['exclude_mail']) and count($aFilter['exclude_mail'])) ? $aFilter['exclude_mail'] : DBSIMPLE_SKIP,
|
|
|
|
|
isset($aFilter['key']) ? $aFilter['key'] : DBSIMPLE_SKIP,
|
|
|
|
|
isset($aFilter['status']) ? $aFilter['status'] : DBSIMPLE_SKIP,
|
|
|
|
|
($iCurrPage - 1) * $iPerPage, $iPerPage
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
|
$aResult[] = Engine::GetEntity('Subscribe', $aRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aResult;
|
|
|
|
|
}
|
2014-05-28 08:37:30 +03:00
|
|
|
|
}
|