mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-30 07:56:05 +00:00
Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend
This commit is contained in:
@@ -36,6 +36,8 @@ class EntityManager extends Base
|
||||
'password' => $config->get('database.password'),
|
||||
'metadata' => $this->getContainer()->get('metadata')->getOrmMetadata(),
|
||||
'repositoryFactoryClassName' => '\\Espo\\Core\\ORM\\RepositoryFactory',
|
||||
'driver' => $config->get('database.driver'),
|
||||
'platform' => $config->get('database.platform')
|
||||
);
|
||||
|
||||
$entityManager = new \Espo\Core\ORM\EntityManager($params);
|
||||
|
||||
@@ -32,8 +32,6 @@ use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
{
|
||||
public static $mapperClassName = '\\Espo\\Core\\ORM\\DB\\MysqlMapper';
|
||||
|
||||
protected $dependencies = array(
|
||||
'metadata'
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ abstract class Mapper implements IMapper
|
||||
protected $fieldsMapCache = array();
|
||||
protected $aliasesCache = array();
|
||||
|
||||
protected $returnCollection = true;
|
||||
protected $returnCollection = false;
|
||||
|
||||
protected $collectionClass = "\\Espo\\ORM\\EntityCollection";
|
||||
|
||||
@@ -76,7 +76,7 @@ abstract class Mapper implements IMapper
|
||||
'additionalColumnsConditions'
|
||||
);
|
||||
|
||||
public function __construct(PDO $pdo, \Espo\ORM\EntityFactory $entityFactory, Query $query) {
|
||||
public function __construct(PDO $pdo, \Espo\ORM\EntityFactory $entityFactory, Query\Base $query) {
|
||||
$this->pdo = $pdo;
|
||||
$this->query = $query;
|
||||
$this->entityFactory = $entityFactory;
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\ORM\DB;
|
||||
namespace Espo\ORM\DB\Query;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\IEntity;
|
||||
use Espo\ORM\EntityFactory;
|
||||
use PDO;
|
||||
|
||||
class Query
|
||||
class Base
|
||||
{
|
||||
protected static $selectParamList = array(
|
||||
'select',
|
||||
@@ -20,10 +20,14 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM\DB;
|
||||
namespace Espo\ORM\DB\Query;
|
||||
|
||||
class MysqlMapper extends \Espo\ORM\DB\MysqlMapper
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\IEntity;
|
||||
use Espo\ORM\EntityFactory;
|
||||
use PDO;
|
||||
|
||||
class Mysql extends Base
|
||||
{
|
||||
protected $returnCollection = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,12 +41,28 @@ class EntityManager
|
||||
|
||||
protected $query;
|
||||
|
||||
protected $driverPlatformMap = array(
|
||||
'pdo_mysql' => 'Mysql',
|
||||
'mysqli' => 'Mysql',
|
||||
);
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
|
||||
$this->metadata = new Metadata();
|
||||
|
||||
if (empty($this->params['platform'])) {
|
||||
if (empty($this->params['driver'])) {
|
||||
throw new \Exception('No database driver specified.');
|
||||
}
|
||||
$driver = $this->params['driver'];
|
||||
if (empty($this->driverPlatformMap[$driver])) {
|
||||
throw new \Exception("Database driver '{$driver}' is not supported.");
|
||||
}
|
||||
$this->params['platform'] = $this->driverPlatformMap[$this->params['driver']];
|
||||
}
|
||||
|
||||
if (!empty($params['metadata'])) {
|
||||
$this->setMetadata($params['metadata']);
|
||||
}
|
||||
@@ -69,16 +85,36 @@ class EntityManager
|
||||
public function getQuery()
|
||||
{
|
||||
if (empty($this->query)) {
|
||||
$this->query = new DB\Query($this->getPDO(), $this->entityFactory);
|
||||
$platform = $this->params['platform'];
|
||||
$className = '\\Espo\\ORM\\DB\\Query\\' . ucfirst($platform);
|
||||
$this->query = new $className($this->getPDO(), $this->entityFactory);
|
||||
}
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function getMapper($className)
|
||||
protected function getMapperClassName($name)
|
||||
{
|
||||
if (empty($this->mappers[$className])) {
|
||||
// TODO use factory
|
||||
$className = null;
|
||||
|
||||
switch ($name) {
|
||||
case 'RDB':
|
||||
$platform = $this->params['platform'];
|
||||
$className = '\\Espo\\ORM\\DB\\' . ucfirst($platform) . 'Mapper';
|
||||
break;
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
public function getMapper($name)
|
||||
{
|
||||
if ($name{0} == '\\') {
|
||||
$className = $name;
|
||||
} else {
|
||||
$className = $this->getMapperClassName($name);
|
||||
}
|
||||
|
||||
if (empty($this->mappers[$className])) {
|
||||
$this->mappers[$className] = new $className($this->getPDO(), $this->entityFactory, $this->getQuery());
|
||||
}
|
||||
return $this->mappers[$className];
|
||||
@@ -90,7 +126,9 @@ class EntityManager
|
||||
|
||||
$port = empty($params['port']) ? '' : 'port=' . $params['port'] . ';';
|
||||
|
||||
$this->pdo = new \PDO('mysql:host='.$params['host'].';'.$port.'dbname=' . $params['dbname'] . ';charset=utf8', $params['user'], $params['password']);
|
||||
$platform = strtolower($params['platform']);
|
||||
|
||||
$this->pdo = new \PDO($platform . ':host='.$params['host'].';'.$port.'dbname=' . $params['dbname'] . ';charset=utf8', $params['user'], $params['password']);
|
||||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ use \Espo\ORM\IEntity;
|
||||
|
||||
class RDB extends \Espo\ORM\Repository
|
||||
{
|
||||
|
||||
public static $mapperClassName = '\\Espo\\ORM\\DB\\MysqlMapper';
|
||||
|
||||
/**
|
||||
* @var Object Mapper.
|
||||
*/
|
||||
@@ -66,7 +63,7 @@ class RDB extends \Espo\ORM\Repository
|
||||
protected function getMapper()
|
||||
{
|
||||
if (empty($this->mapper)) {
|
||||
$this->mapper = $this->getEntityManager()->getMapper(self::$mapperClassName);
|
||||
$this->mapper = $this->getEntityManager()->getMapper('RDB');
|
||||
}
|
||||
return $this->mapper;
|
||||
}
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
[{"name":"name","width":30,"link":true},{"name":"userName"},{"name":"emailAddress"}]
|
||||
[
|
||||
{"name":"name", "width":35, "link":true},
|
||||
{"name":"userName"},
|
||||
{"name":"emailAddress"}
|
||||
]
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
"tooltip": true
|
||||
},
|
||||
"name": {
|
||||
"type": "personName"
|
||||
"type": "personName",
|
||||
"view": "User.Fields.Name"
|
||||
},
|
||||
"password": {
|
||||
"type": "password",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{{{avatar}}} <a href="#{{model.name}}/view/{{model.id}}" class="link" data-id="{{model.id}}" title="{{value}}">{{value}}</a>
|
||||
1
frontend/client/res/templates/user/fields/name/list.tpl
Normal file
1
frontend/client/res/templates/user/fields/name/list.tpl
Normal file
@@ -0,0 +1 @@
|
||||
{{{avatar}}} {{value}}
|
||||
@@ -62,9 +62,14 @@ Espo.define('Views.User.Fields.Avatar', 'Views.Fields.Image', function (Dep) {
|
||||
var imgHtml;
|
||||
|
||||
if (this.mode == 'detail') {
|
||||
imgHtml = '<img src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '&attachmentId=' + ( id || 'false') + '">';
|
||||
imgHtml = '<img src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '&attachmentId=' + ( id || 'false') + '">';
|
||||
} else {
|
||||
imgHtml = '<img src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '">';
|
||||
var cache = this.getCache();
|
||||
if (cache) {
|
||||
t = cache.get('app', 'timestamp');
|
||||
}
|
||||
imgHtml = '<img width="16" src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '">';
|
||||
return imgHtml;
|
||||
}
|
||||
|
||||
if (id) {
|
||||
|
||||
51
frontend/client/src/views/user/fields/name.js
Normal file
51
frontend/client/src/views/user/fields/name.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
Espo.define('Views.User.Fields.Name', 'Views.Fields.PersonName', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
listTemplate: 'user.fields.name.list-link',
|
||||
|
||||
listLinkTemplate: 'user.fields.name.list-link',
|
||||
|
||||
data: function () {
|
||||
return _.extend({
|
||||
avatar: this.getAvatarHtml()
|
||||
}, Dep.prototype.data.call(this));
|
||||
},
|
||||
|
||||
getAvatarHtml: function () {
|
||||
if (this.getConfig().get('disableAvatars')) {
|
||||
return '';
|
||||
}
|
||||
var t;
|
||||
var cache = this.getCache();
|
||||
if (cache) {
|
||||
t = cache.get('app', 'timestamp');
|
||||
} else {
|
||||
t = Date.now();
|
||||
}
|
||||
return '<img class="avatar avatar-link" width="16" src="?entryPoint=avatar&size=small&id=' + this.model.id + '&t='+t+'">';
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Espo\ORM\DB\MysqlMapper;
|
||||
use Espo\ORM\DB\Query;
|
||||
use Espo\ORM\DB\Query\Mysql as Query;
|
||||
use Espo\ORM\EntityFactory;
|
||||
|
||||
use Espo\Entities\Post;
|
||||
@@ -46,6 +46,8 @@ class DBMapperTest extends PHPUnit_Framework_TestCase
|
||||
$this->query = new Query($this->pdo, $this->entityFactory);
|
||||
|
||||
$this->db = new MysqlMapper($this->pdo, $this->entityFactory, $this->query);
|
||||
$this->db->setReturnCollection(true);
|
||||
|
||||
$this->post = new \Espo\Entities\Post();
|
||||
$this->comment = new \Espo\Entities\Comment();
|
||||
$this->tag = new \Espo\Entities\Tag();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Espo\ORM\DB\Query;
|
||||
use Espo\ORM\DB\Query\Mysql as Query;
|
||||
use Espo\ORM\EntityFactory;
|
||||
|
||||
use Espo\Entities\Post;
|
||||
|
||||
Reference in New Issue
Block a user