ElixirVault/www/system-brs-core/cms/cmsBuys/inc/cmsBuysModule.php

133 lines
4.0 KiB
PHP

<?php
namespace BRSystems\Core\Cms\cmsBuys\inc;
use BRSystems\Core\Cms\cmsProductAttr\inc\cmsProductAttrModule;
use BRSystems\Core\Cms\cmsProducts\inc\cmsProductsModule;
use BRSystems\Core\Library\cDb\cDb;
class cmsBuysModule
{
public cDb $db;
public function __construct()
{
$this->db = cDb::getInstance();
}
/**
* Function to get data by filter
*
* @param string $sWhere - additional where for search/filter
* @return bool|array found data
* @author Aivars Žukovskis <keiss.mareks@gmail.com>
* @category cmsBuys Module
* @version 1.1
*/
public function getDataBySearch($sWhere)
{
$sSql = "
SELECT
mp.id,
mp.prod_nr as nr,
mpi.prod_name
-- mc.a_name as cname
FROM
mod_products mp
LEFT JOIN mod_products_info mpi ON
mp.id = mpi.prod_id
AND mpi.lang_id = " . cmsProductAttrModule::LV_LANG_ID . "
-- LEFT JOIN mod_companies mc ON
-- mp.prod_comp_link_id = mc.id
WHERE
mp.prod_deleted = '0'
{$sWhere}
";
$this->db->query($sSql);
return $this->db->getFieldBasedArrayFieldsAdv('id');
}
/**
* Function to get product count division
*
* @param int $id - record id for update
* @return array of data
* @author Aivars Žukovskis <keiss.mareks@gmail.com>
* @category cmsBuys Module
* @version 1.1
*/
public function getProdDivision($id)
{
$id = ($id ?: 0);
$sSql = "
SELECT
cc.id,
cc.prod_id,
COALESCE(tr.t_title, '') as cl1,
COALESCE(tr2.t_title, '') as cl2,
ROUND(cc.prod_incoming_price, 2) as incoming_price,
ROUND(cc.prod_price, 2) as price,
CASE WHEN cc.prod_disabled = '1' THEN 0 ELSE 1 END as d,
COALESCE(tc.count, 0) as c,
cc.prod_cl_id,
cc.prod_cl_id_2
FROM
" . cmsProductsModule::TABLE_COUNT_CLASSIFICATION . " cc
LEFT JOIN " . cmsProductsModule::VIEW_TO_COUNT . " as tc ON
tc.prod_id = cc.prod_id
AND tc.row_id = cc.id
LEFT JOIN mod_items_attr_translations tr ON
cc.prod_cl_id = tr.t_id
AND tr.t_lang_id = 7
LEFT JOIN mod_items_attr_translations tr2 ON
cc.prod_cl_id_2 = tr2.t_id
AND tr2.t_lang_id = 7
WHERE
cc.prod_id = " . $this->db->prepData($id) . "
AND cc.prod_disabled <> '2'
";
$this->db->query($sSql);
$fields = ['cl1', 'cl2', 'c', 'incoming_price', 'price', 'd', 'prod_cl_id', 'prod_cl_id_2'];
return $this->db->getFieldBasedArrayFieldsAdv('id', $fields);
}
/**
* Function to insert multi array into db
*
* @param string $sTable - table name
* @param array $vData - record data array
* @return bool|array of ids of data
* @category cmsProducts Module
* @author Aivars Žukovskis <keiss.mareks@gmail.com>
* @version 1.1
*/
public function insertMultiArray($sTable, $vData)
{
if (strlen($sTable) && !!$vData && is_array($vData)) {
return $this->db->_queryInsertArray($sTable, $vData);
}
return false;
}
/**
* Function to get all partners
*
* @return array|null found data
* @category cmsReports Module
* @author Aivars Žukovskis <keiss.mareks@gmail.com>
* @version 1.1
*/
public function getPartners()
{
$table = 'mod_companies';
$fields = ['id', 'a_name'];
$where = ['a_blocked' => 0];
$order = ['a_name' => 'ASC'];
$this->db->_querySelect($table, $fields, $where, $order, false, false);
return $this->db->getKeyValBasedArray('id', 'a_name');
}
}