This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/application/Espo/ORM/DB/MysqlMapper.php
T
Yuri Kuznetsov 65fdabf83c changes and dev
2013-12-27 13:53:47 +02:00

64 lines
1.3 KiB
PHP

<?php
namespace Espo\ORM\DB;
use Espo\ORM\Entity;
use Espo\ORM\Classes\EntityCollection;
use PDO;
/**
* Abstraction for MySQL DB.
* Mapping of Entity to DB.
* Should be used internally only.
*/
class MysqlMapper extends Mapper
{
protected function composeSelectQuery($table, $select, $joins = '', $where = '', $order = '', $offset = null, $limit = null, $distinct = null)
{
$sql = "SELECT";
if (!empty($distinct)) {
$sql .= " DISTINCT";
}
$sql .= " {$select} FROM `{$table}`";
if (!empty($joins)) {
$sql .= " {$joins}";
}
if (!empty($where)) {
$sql .= " WHERE {$where}";
}
if (!empty($order)) {
$sql .= " {$order}";
}
if (is_null($offset) && !is_null($limit)) {
$offset = 0;
}
if (!is_null($offset) && !is_null($limit)) {
$offset = intval($offset);
$limit = intval($limit);
$sql .= " LIMIT {$offset}, {$limit}";
}
return $sql;
}
protected function toDb($field)
{
if (array_key_exists($field, $this->fieldsMapCache)) {
return $this->fieldsMapCache[$field];
} else {
$dbField = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $field));
$this->fieldsMapCache[$field] = $dbField;
return $dbField;
}
}
}
?>