entity manager improvements

This commit is contained in:
yuri
2016-10-11 12:32:28 +03:00
parent 83aa07b918
commit 1a95e14ee8
11 changed files with 202 additions and 10 deletions

View File

@@ -37,6 +37,7 @@ class EntityManagerUtil extends Base
$this->getContainer()->get('metadata'),
$this->getContainer()->get('language'),
$this->getContainer()->get('fileManager'),
$this->getContainer()->get('config'),
$this->getContainer()
);

View File

@@ -4,5 +4,17 @@
"activityDefs": {
"activitiesCreate": true,
"historyCreate": true
}
},
"filterList": [
{
"name":"planned"
},
{
"name":"held",
"style": "success"
},
{
"name":"todays"
}
]
}

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Templates\SelectManagers;
class Event extends \Espo\Core\SelectManagers\Base
{
protected function filterPlanned(&$result)
{
$result['whereClause'][] = array(
'status' => 'Planned'
);
}
protected function filterHeld(&$result)
{
$result['whereClause'][] = array(
'status' => 'Held'
);
}
protected function filterTodays(&$result)
{
$result['whereClause'][] = $this->convertDateTimeWhere(array(
'type' => 'today',
'attribute' => 'dateStart',
'timeZone' => $this->getUserTimeZone()
));
}
}

View File

@@ -0,0 +1,9 @@
{
"fields": {
},
"links": {
},
"labels": {
"Create {entityType}": "Create {entityTypeTranslated}"
}
}

View File

@@ -0,0 +1,12 @@
{
"fields": {
},
"links": {
"meetings": "Meetings",
"calls": "Calls",
"tasks": "Tasks"
},
"labels": {
"Create {entityType}": "Create {entityTypeTranslated}"
}
}

View File

@@ -0,0 +1,15 @@
{
"fields": {
"billingAddress": "Billing Address",
"shippingAddress": "Shipping Address",
"website": "Website"
},
"links": {
"meetings": "Meetings",
"calls": "Calls",
"tasks": "Tasks"
},
"labels": {
"Create {entityType}": "Create {entityTypeTranslated}"
}
}

View File

@@ -0,0 +1,35 @@
{
"fields": {
"parent": "Parent",
"dateStart": "Date Start",
"dateEnd": "Date End",
"duration": "Duration",
"status": "Status"
},
"links": {
"parent": "Parent"
},
"options": {
"status": {
"Planned": "Planned",
"Held": "Held",
"Not Held": "Not Held"
}
},
"labels": {
"Create {entityType}": "Create {entityTypeTranslated}",
"Schedule {entityType}": "Schedule {entityTypeTranslated}",
"Log {entityType}": "Log {entityTypeTranslated}",
"Set Held": "Set Held",
"Set Not Held": "Set Not Held"
},
"massActions": {
"setHeld": "Set Held",
"setNotHeld": "Set Not Held"
},
"presetFilters": {
"planned": "Planned",
"held": "Held",
"todays": "Today's"
}
}

View File

@@ -0,0 +1,13 @@
{
"fields": {
"address": "Address"
},
"links": {
"meetings": "Meetings",
"calls": "Calls",
"tasks": "Tasks"
},
"labels": {
"Create {entityType}": "Create {entityTypeTranslated}"
}
}

View File

@@ -43,15 +43,18 @@ class EntityManager
private $fileManager;
private $config;
private $metadataHelper;
private $container;
public function __construct(Metadata $metadata, Language $language, File\Manager $fileManager, Container $container = null)
public function __construct(Metadata $metadata, Language $language, File\Manager $fileManager, Config $config, Container $container = null)
{
$this->metadata = $metadata;
$this->language = $language;
$this->fileManager = $fileManager;
$this->config = $config;
$this->metadataHelper = new \Espo\Core\Utils\Metadata\Helper($this->metadata);
@@ -73,6 +76,11 @@ class EntityManager
return $this->fileManager;
}
protected function getConfig()
{
return $this->config;
}
protected function getMetadataHelper()
{
return $this->metadataHelper;
@@ -126,6 +134,17 @@ class EntityManager
$filePath = "custom/Espo/Custom/Repositories/{$normalizedName}.php";
$this->getFileManager()->putContents($filePath, $contents);
if (file_exists('application/Espo/Core/Templates/SelectManagers/' . $type . '.php')) {
$contents = "<" . "?" . "php\n\n".
"namespace Espo\Custom\SelectManagers;\n\n".
"class {$normalizedName} extends \Espo\Core\Templates\SelectManagers\\{$type}\n".
"{\n".
"}\n";
$filePath = "custom/Espo/Custom/SelectManagers/{$normalizedName}.php";
$this->getFileManager()->putContents($filePath, $contents);
}
$stream = false;
if (!empty($params['stream'])) {
$stream = $params['stream'];
@@ -142,14 +161,17 @@ class EntityManager
if (!empty($params['labelPlural'])) {
$labelPlural = $params['labelPlural'];
}
$labelCreate = $this->getLanguage()->translate('Create') . ' ' . $labelSingular;
if ($type == 'Event') {
$labelSchedule = $this->getLanguage()->translate('Schedule', 'labels', 'EntityManager') . ' ' . $labelSingular;
$this->getLanguage()->set($name, 'labels', 'Schedule ' . $name, $labelSchedule);
$languageList = $this->getConfig()->get('languageList', []);
foreach ($languageList as $language) {
$filePath = 'application/Espo/Core/Templates/i18n/' . $language . '/' . $type . '.json';
if (!file_exists($filePath)) continue;
$languageContents = $this->getFileManager()->getContents($filePath);
$languageContents = str_replace('{entityType}', $name, $languageContents);
$languageContents = str_replace('{entityTypeTranslated}', $labelSingular, $languageContents);
$labelLog = $this->getLanguage()->translate('Log', 'labels', 'EntityManager') . ' ' . $labelSingular;
$this->getLanguage()->set($name, 'labels', 'Log ' . $name, $labelLog);
$destinationFilePath = 'custom/Espo/Custom/Resources/i18n/' . $language . '/' . $name . '.json';
$this->getFileManager()->putContents($destinationFilePath, $languageContents);
}
$filePath = "application/Espo/Core/Templates/Metadata/{$type}/scopes.json";
@@ -180,7 +202,6 @@ class EntityManager
$this->getLanguage()->set('Global', 'scopeNames', $name, $labelSingular);
$this->getLanguage()->set('Global', 'scopeNamesPlural', $name, $labelPlural);
$this->getLanguage()->set($name, 'labels', 'Create ' . $name, $labelCreate);
$this->getMetadata()->save();
$this->getLanguage()->save();
@@ -277,9 +298,20 @@ class EntityManager
$this->getFileManager()->removeFile("custom/Espo/Custom/Controllers/{$normalizedName}.php");
$this->getFileManager()->removeFile("custom/Espo/Custom/Repositories/{$normalizedName}.php");
if (file_exists("custom/Espo/Custom/SelectManagers/{$normalizedName}.php")) {
$this->getFileManager()->removeFile("custom/Espo/Custom/SelectManagers/{$normalizedName}.php");
}
$this->getFileManager()->removeInDir("custom/Espo/Custom/Resources/layouts/{$normalizedName}");
$this->getFileManager()->removeDir("custom/Espo/Custom/Resources/layouts/{$normalizedName}");
$languageList = $this->getConfig()->get('languageList', []);
foreach ($languageList as $language) {
$filePath = 'custom/Espo/Custom/Resources/i18n/' . $language . '/' . $normalizedName . '.json' ;
if (!file_exists($filePath)) continue;
$this->getFileManager()->removeFile($filePath);
}
try {
$this->getLanguage()->delete('Global', 'scopeNames', $name);
$this->getLanguage()->delete('Global', 'scopeNamesPlural', $name);

View File

@@ -92,6 +92,11 @@ function Lang (poPath, espoPath) {
dirs.push(installDir);
dirNames[installDir] = 'install/core/i18n/' + resLang + '/';
var templatesDir = this.espoPath + 'application/Espo/Core/Templates/i18n/' + this.baseLanguage + '/';
dirs.push(templatesDir);
dirNames[templatesDir] = 'application/Espo/Core/Templates/i18n/' + resLang + '/';
this.dirs = dirs;
};

3
po.js
View File

@@ -53,7 +53,8 @@ function PO (espoPath, language) {
var dirs = [
this.path + 'application/Espo/Resources/i18n/',
this.path + 'install/core/i18n/'
this.path + 'install/core/i18n/',
this.path + 'application/Espo/Core/Templates/i18n/'
];
this.moduleList.forEach(function (moduleName) {
dirs.push(this.path + 'application/Espo/Modules/' + moduleName + '/Resources/i18n/');