2013-10-01 13:26:39 +03:00
|
|
|
|
<?php
|
2014-10-08 08:20:29 +03:00
|
|
|
|
/*
|
2013-10-01 13:26:39 +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>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Маппер для работы с БД
|
|
|
|
|
*
|
2014-10-08 08:20:29 +03:00
|
|
|
|
* @package application.modules.property
|
|
|
|
|
* @since 2.0
|
2013-10-01 13:26:39 +03:00
|
|
|
|
*/
|
2014-10-08 11:49:34 +03:00
|
|
|
|
class ModuleProperty_MapperProperty extends Mapper
|
|
|
|
|
{
|
2013-10-01 13:26:39 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function GetPropertiesValueByTarget($sTargetType, $iTargetId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "SELECT
|
2013-10-01 13:26:39 +03:00
|
|
|
|
v.*,
|
|
|
|
|
p.id as prop_id,
|
|
|
|
|
p.target_type as prop_target_type,
|
|
|
|
|
p.type as prop_type ,
|
|
|
|
|
p.code as prop_code,
|
|
|
|
|
p.title as prop_title,
|
|
|
|
|
p.date_create as prop_date_create,
|
2014-02-11 08:44:52 +02:00
|
|
|
|
p.sort as prop_sort,
|
|
|
|
|
p.params as prop_params
|
2014-10-08 11:49:34 +03:00
|
|
|
|
FROM " . Config::Get('db.table.property') . " AS p
|
|
|
|
|
LEFT JOIN " . Config::Get('db.table.property_value') . " as v on ( v.property_id=p.id and v.target_id = ?d )
|
2013-10-01 13:26:39 +03:00
|
|
|
|
WHERE
|
|
|
|
|
p.target_type = ?
|
|
|
|
|
ORDER BY
|
|
|
|
|
p.sort desc
|
|
|
|
|
limit 0,100";
|
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$aResult = array();
|
|
|
|
|
if ($aRows = $this->oDb->select($sql, $iTargetId, $sTargetType)) {
|
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
|
$aProperty = array();
|
|
|
|
|
$aValue = array();
|
|
|
|
|
foreach ($aRow as $k => $v) {
|
|
|
|
|
if (strpos($k, 'prop_') === 0) {
|
|
|
|
|
$aProperty[str_replace('prop_', '', $k)] = $v;
|
|
|
|
|
} else {
|
|
|
|
|
$aValue[$k] = $v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$oProperty = Engine::GetEntity('ModuleProperty_EntityProperty', $aProperty);
|
|
|
|
|
/**
|
|
|
|
|
* На случай, если нет еще значения свойства в БД
|
|
|
|
|
*/
|
|
|
|
|
$aValue['property_id'] = $oProperty->getId();
|
|
|
|
|
$aValue['property_type'] = $oProperty->getType();
|
|
|
|
|
$aValue['target_type'] = $sTargetType;
|
|
|
|
|
$aValue['target_id'] = $iTargetId;
|
|
|
|
|
$oProperty->setValue(Engine::GetEntity('ModuleProperty_EntityValue', $aValue));
|
|
|
|
|
$aResult[$oProperty->getId()] = $oProperty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aResult;
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function GetPropertiesValueByTargetArray($sTargetType, $aTargetId)
|
|
|
|
|
{
|
|
|
|
|
if (!is_array($aTargetId)) {
|
|
|
|
|
$aTargetId = array($aTargetId);
|
|
|
|
|
}
|
|
|
|
|
if (!$aTargetId) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
$sql = "SELECT
|
2013-10-01 13:26:39 +03:00
|
|
|
|
v.*,
|
|
|
|
|
p.id as prop_id,
|
|
|
|
|
p.target_type as prop_target_type,
|
|
|
|
|
p.type as prop_type ,
|
|
|
|
|
p.code as prop_code,
|
|
|
|
|
p.title as prop_title,
|
|
|
|
|
p.date_create as prop_date_create,
|
2014-02-11 08:44:52 +02:00
|
|
|
|
p.sort as prop_sort,
|
|
|
|
|
p.params as prop_params
|
2014-10-08 11:49:34 +03:00
|
|
|
|
FROM " . Config::Get('db.table.property') . " AS p
|
|
|
|
|
LEFT JOIN " . Config::Get('db.table.property_value') . " as v on ( v.property_id=p.id and v.target_id IN ( ?a ) )
|
2013-10-01 13:26:39 +03:00
|
|
|
|
WHERE
|
|
|
|
|
p.target_type = ?
|
|
|
|
|
ORDER BY
|
|
|
|
|
p.sort desc ";
|
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$aResult = array();
|
|
|
|
|
if ($aRows = $this->oDb->select($sql, $aTargetId, $sTargetType)) {
|
|
|
|
|
return $aRows;
|
|
|
|
|
}
|
|
|
|
|
return $aResult;
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function RemoveValueTagsByTarget($sTargetType, $iTargetId, $iPropertyId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE
|
|
|
|
|
FROM " . Config::Get('db.table.property_value_tag') . "
|
2013-10-01 13:26:39 +03:00
|
|
|
|
WHERE
|
2013-10-29 09:53:26 +02:00
|
|
|
|
target_id = ?d
|
|
|
|
|
and
|
|
|
|
|
target_type = ?
|
|
|
|
|
and
|
|
|
|
|
property_id = ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $iTargetId, $sTargetType, $iPropertyId) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-29 09:53:26 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function RemoveValueSelectsByTarget($sTargetType, $iTargetId, $iPropertyId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE
|
|
|
|
|
FROM " . Config::Get('db.table.property_value_select') . "
|
2013-10-29 09:53:26 +02:00
|
|
|
|
WHERE
|
2013-10-01 13:26:39 +03:00
|
|
|
|
target_id = ?d
|
|
|
|
|
and
|
|
|
|
|
target_type = ?
|
|
|
|
|
and
|
|
|
|
|
property_id = ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $iTargetId, $sTargetType, $iPropertyId) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function RemoveValueByPropertyId($iPropertyId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE
|
|
|
|
|
FROM " . Config::Get('db.table.property_value') . "
|
2014-02-06 09:32:50 +02:00
|
|
|
|
WHERE
|
|
|
|
|
property_id = ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $iPropertyId) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-06 09:32:50 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function RemoveValueTagByPropertyId($iPropertyId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE
|
|
|
|
|
FROM " . Config::Get('db.table.property_value_tag') . "
|
2014-02-06 09:32:50 +02:00
|
|
|
|
WHERE
|
|
|
|
|
property_id = ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $iPropertyId) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-06 09:32:50 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function RemoveValueSelectByPropertyId($iPropertyId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE
|
|
|
|
|
FROM " . Config::Get('db.table.property_value_select') . "
|
2014-02-06 09:32:50 +02:00
|
|
|
|
WHERE
|
|
|
|
|
property_id = ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $iPropertyId) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-06 09:32:50 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function RemoveSelectByPropertyId($iPropertyId)
|
|
|
|
|
{
|
|
|
|
|
$sql = "DELETE
|
|
|
|
|
FROM " . Config::Get('db.table.property_select') . "
|
2014-02-06 09:32:50 +02:00
|
|
|
|
WHERE
|
|
|
|
|
property_id = ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $iPropertyId) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-06 09:32:50 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function GetPropertyTagsByLike($sTag, $iPropertyId, $iLimit)
|
|
|
|
|
{
|
|
|
|
|
$sTag = mb_strtolower($sTag, "UTF-8");
|
|
|
|
|
$sql = "SELECT
|
2013-10-01 13:26:39 +03:00
|
|
|
|
text
|
|
|
|
|
FROM
|
2014-10-08 11:49:34 +03:00
|
|
|
|
" . Config::Get('db.table.property_value_tag') . "
|
2013-10-01 13:26:39 +03:00
|
|
|
|
WHERE
|
|
|
|
|
property_id = ?d and text LIKE ?
|
|
|
|
|
GROUP BY
|
|
|
|
|
text
|
|
|
|
|
LIMIT 0, ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$aReturn = array();
|
|
|
|
|
if ($aRows = $this->oDb->select($sql, $iPropertyId, $sTag . '%', $iLimit)) {
|
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
|
$aReturn[] = Engine::GetEntity('ModuleProperty_EntityValueTag', $aRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aReturn;
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function GetPropertyTagsGroup($iPropertyId, $iLimit)
|
|
|
|
|
{
|
|
|
|
|
$sql = "SELECT
|
2013-10-01 13:26:39 +03:00
|
|
|
|
text,
|
|
|
|
|
count(text) as count
|
|
|
|
|
FROM
|
2014-10-08 11:49:34 +03:00
|
|
|
|
" . Config::Get('db.table.property_value_tag') . "
|
2013-10-01 13:26:39 +03:00
|
|
|
|
WHERE
|
|
|
|
|
1=1
|
|
|
|
|
property_id = ?d
|
|
|
|
|
GROUP BY
|
|
|
|
|
text
|
|
|
|
|
ORDER BY
|
|
|
|
|
count desc
|
|
|
|
|
LIMIT 0, ?d
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$aReturn = array();
|
|
|
|
|
$aReturnSort = array();
|
|
|
|
|
if ($aRows = $this->oDb->select(
|
|
|
|
|
$sql,
|
|
|
|
|
$iPropertyId,
|
|
|
|
|
$iLimit
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
|
$aReturn[mb_strtolower($aRow['text'], 'UTF-8')] = $aRow;
|
|
|
|
|
}
|
|
|
|
|
ksort($aReturn);
|
|
|
|
|
foreach ($aReturn as $aRow) {
|
|
|
|
|
$aReturnSort[] = Engine::GetEntity('ModuleProperty_EntityValueTag', $aRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aReturnSort;
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function GetTargetsByTag($iPropertyId, $sTag, &$iCount, $iCurrPage, $iPerPage)
|
|
|
|
|
{
|
|
|
|
|
$sql = "
|
2013-10-01 13:26:39 +03:00
|
|
|
|
SELECT
|
|
|
|
|
target_id
|
|
|
|
|
FROM
|
2014-10-08 11:49:34 +03:00
|
|
|
|
" . Config::Get('db.table.property_value_tag') . "
|
2013-10-01 13:26:39 +03:00
|
|
|
|
WHERE
|
|
|
|
|
property_id = ?d
|
|
|
|
|
and
|
|
|
|
|
text = ?
|
|
|
|
|
ORDER BY target_id DESC
|
|
|
|
|
LIMIT ?d, ?d ";
|
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$aReturn = array();
|
|
|
|
|
if ($aRows = $this->oDb->selectPage($iCount, $sql, $iPropertyId, $sTag, ($iCurrPage - 1) * $iPerPage,
|
|
|
|
|
$iPerPage)
|
|
|
|
|
) {
|
|
|
|
|
foreach ($aRows as $aTopic) {
|
|
|
|
|
$aReturn[] = $aTopic['target_id'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $aReturn;
|
|
|
|
|
}
|
2014-01-13 07:25:58 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function UpdatePropertyByTargetType($sTargetType, $sTargetTypeNew)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE
|
|
|
|
|
" . Config::Get('db.table.property') . "
|
2014-01-13 07:25:58 +02:00
|
|
|
|
SET target_type = ?
|
|
|
|
|
WHERE
|
|
|
|
|
target_type = ?
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $sTargetTypeNew, $sTargetType) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-13 07:25:58 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function UpdatePropertyTargetByTargetType($sTargetType, $sTargetTypeNew)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE
|
|
|
|
|
" . Config::Get('db.table.property_target') . "
|
2014-02-11 06:43:48 +02:00
|
|
|
|
SET type = ?
|
|
|
|
|
WHERE
|
|
|
|
|
type = ?
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $sTargetTypeNew, $sTargetType) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-11 06:43:48 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function UpdatePropertySelectByTargetType($sTargetType, $sTargetTypeNew)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE
|
|
|
|
|
" . Config::Get('db.table.property_select') . "
|
2014-01-13 07:25:58 +02:00
|
|
|
|
SET target_type = ?
|
|
|
|
|
WHERE
|
|
|
|
|
target_type = ?
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $sTargetTypeNew, $sTargetType) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-13 07:25:58 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function UpdatePropertyValueByTargetType($sTargetType, $sTargetTypeNew)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE
|
|
|
|
|
" . Config::Get('db.table.property_value') . "
|
2014-01-13 07:25:58 +02:00
|
|
|
|
SET target_type = ?
|
|
|
|
|
WHERE
|
|
|
|
|
target_type = ?
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $sTargetTypeNew, $sTargetType) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-13 07:25:58 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function UpdatePropertyValueSelectByTargetType($sTargetType, $sTargetTypeNew)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE
|
|
|
|
|
" . Config::Get('db.table.property_value_select') . "
|
2014-01-13 07:25:58 +02:00
|
|
|
|
SET target_type = ?
|
|
|
|
|
WHERE
|
|
|
|
|
target_type = ?
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $sTargetTypeNew, $sTargetType) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-13 07:25:58 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function UpdatePropertyValueTagByTargetType($sTargetType, $sTargetTypeNew)
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE
|
|
|
|
|
" . Config::Get('db.table.property_value_tag') . "
|
2014-01-13 07:25:58 +02:00
|
|
|
|
SET target_type = ?
|
|
|
|
|
WHERE
|
|
|
|
|
target_type = ?
|
|
|
|
|
";
|
2014-10-08 11:49:34 +03:00
|
|
|
|
if ($this->oDb->query($sql, $sTargetTypeNew, $sTargetType) !== false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
}
|