From f1a7bd7d12373a2b2d4e8d2fc3cec4ebf31b14c9 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 23 Dec 2013 16:53:37 +0200 Subject: [PATCH] dev --- application/Espo/Core/ControllerManager.php | 9 ++- application/Espo/Core/Controllers/Base.php | 17 +++-- application/Espo/Core/ORM/EntityManager.php | 3 +- application/Espo/Core/Utils/Metadata.php | 8 +-- application/Espo/Core/Utils/Util.php | 70 ++++++++++++------- .../Espo/Modules/Crm/Controllers/Call.php | 8 +++ .../Espo/Modules/Crm/Controllers/CaseObj.php | 9 +++ .../Espo/Modules/Crm/Controllers/Lead.php | 8 +++ .../Espo/Modules/Crm/Controllers/Meeting.php | 8 +++ .../Modules/Crm/Controllers/Opportunity.php | 8 +++ .../Espo/Modules/Crm/Controllers/Prospect.php | 8 +++ .../Espo/Modules/Crm/Controllers/Task.php | 8 +++ .../Espo/Modules/Crm/Entities/Call.php | 8 +++ .../Espo/Modules/Crm/Entities/CaseObj.php | 10 +++ .../Espo/Modules/Crm/Entities/Lead.php | 11 +++ .../Espo/Modules/Crm/Entities/Meeting.php | 8 +++ .../Espo/Modules/Crm/Entities/Opportunity.php | 8 +++ .../Espo/Modules/Crm/Entities/Prospect.php | 11 +++ .../Espo/Modules/Crm/Entities/Task.php | 8 +++ application/Espo/ORM/DB/Mapper.php | 11 ++- 20 files changed, 193 insertions(+), 46 deletions(-) create mode 100644 application/Espo/Modules/Crm/Controllers/Call.php create mode 100644 application/Espo/Modules/Crm/Controllers/CaseObj.php create mode 100644 application/Espo/Modules/Crm/Controllers/Lead.php create mode 100644 application/Espo/Modules/Crm/Controllers/Meeting.php create mode 100644 application/Espo/Modules/Crm/Controllers/Opportunity.php create mode 100644 application/Espo/Modules/Crm/Controllers/Prospect.php create mode 100644 application/Espo/Modules/Crm/Controllers/Task.php create mode 100644 application/Espo/Modules/Crm/Entities/Call.php create mode 100644 application/Espo/Modules/Crm/Entities/CaseObj.php create mode 100644 application/Espo/Modules/Crm/Entities/Lead.php create mode 100644 application/Espo/Modules/Crm/Entities/Meeting.php create mode 100644 application/Espo/Modules/Crm/Entities/Opportunity.php create mode 100644 application/Espo/Modules/Crm/Entities/Prospect.php create mode 100644 application/Espo/Modules/Crm/Entities/Task.php diff --git a/application/Espo/Core/ControllerManager.php b/application/Espo/Core/ControllerManager.php index f7da637399..f368f49716 100644 --- a/application/Espo/Core/ControllerManager.php +++ b/application/Espo/Core/ControllerManager.php @@ -36,26 +36,25 @@ class ControllerManager public function process($controllerName, $actionName, $params, $data) { - $customeClassName = '\\Espo\\Custom\\Controllers\\' . $controllerName; + $customeClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName); if (class_exists($customeClassName)) { $controllerClassName = $customeClassName; } else { $moduleName = $this->metadata->getScopeModuleName($controllerName); if ($moduleName) { - $controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . $controllerName; + $controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName); } else { - $controllerClassName = '\\Espo\\Controllers\\' . $controllerName; + $controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName); } } if ($data) { $data = json_decode($data, true); } - if (!class_exists($controllerClassName)) { throw new NotFound("Controller '$controllerName' is not found"); - } + } $controller = new $controllerClassName($this->container, $this->serviceFactory); diff --git a/application/Espo/Core/Controllers/Base.php b/application/Espo/Core/Controllers/Base.php index 9a141f6b9a..aca1bd1b72 100644 --- a/application/Espo/Core/Controllers/Base.php +++ b/application/Espo/Core/Controllers/Base.php @@ -4,6 +4,7 @@ namespace Espo\Core\Controllers; use \Espo\Core\Container; use \Espo\Core\ServiceFactory; +use \Espo\Core\Utils\Util; abstract class Base { @@ -24,18 +25,20 @@ abstract class Base $this->container = $container; $this->serviceFactory = $serviceFactory; - $name = get_class($this); - if (preg_match('@\\\\([\w]+)$@', $name, $matches)) { - $name = $matches[1]; - } - $this->name = $name; + if (empty($this->name)) { + $name = get_class($this); + if (preg_match('@\\\\([\w]+)$@', $name, $matches)) { + $name = $matches[1]; + } + $this->name = $name; + } if (empty($this->serviceClassName)) { $moduleName = $this->getMetadata()->getScopeModuleName($this->name); if ($moduleName) { - $className = '\\Espo\\Modules\\' . $moduleName . '\\Services\\' . $this->name; + $className = '\\Espo\\Modules\\' . $moduleName . '\\Services\\' . Util::normilizeClassName($this->name); } else { - $className = '\\Espo\\Services\\' . $this->name; + $className = '\\Espo\\Services\\' . Util::normilizeClassName($this->name); } } } diff --git a/application/Espo/Core/ORM/EntityManager.php b/application/Espo/Core/ORM/EntityManager.php index ba47ef5879..0543321bc6 100644 --- a/application/Espo/Core/ORM/EntityManager.php +++ b/application/Espo/Core/ORM/EntityManager.php @@ -1,6 +1,7 @@ espoMetadata->getRepositoryPath($name); } diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index b292500f13..f00a8c3183 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -269,18 +269,18 @@ class Metadata * * @return string */ - public function getEntityPath($entityName, $delim= '\\') + public function getEntityPath($entityName, $delim = '\\') { $path = $this->getScopePath($entityName, $delim); - return implode($delim, array($path, 'Entities', ucfirst($entityName))); + return implode($delim, array($path, 'Entities', Util::normilizeClassName(ucfirst($entityName)))); } - public function getRepositoryPath($entityName, $delim= '\\') + public function getRepositoryPath($entityName, $delim = '\\') { $path = $this->getScopePath($entityName, $delim); - return implode($delim, array($path, 'Repositories', ucfirst($entityName))); + return implode($delim, array($path, 'Repositories', Util::normilizeClassName(ucfirst($entityName)))); } diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index 83c9ab7d66..b064fbebe9 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -6,16 +6,18 @@ namespace Espo\Core\Utils; class Util { /** - * @var string - default directory separator - */ - protected static $separator= DIRECTORY_SEPARATOR; + * @var string - default directory separator + */ + protected static $separator = DIRECTORY_SEPARATOR; + + protected static $reservedWords = array('Case'); /** - * Get a folder separator - * - * @return string - */ + * Get a folder separator + * + * @return string + */ public static function getSeparator() { return static::$separator; @@ -23,15 +25,15 @@ class Util /** - * Convert to format with defined delimeter - * ex. Espo/Utils to Espo\Utils - * - * @param string $name - * @param string $delim - delimiter - * - * @return string - */ - public static function toFormat($name, $delim= '/') + * Convert to format with defined delimeter + * ex. Espo/Utils to Espo\Utils + * + * @param string $name + * @param string $delim - delimiter + * + * @return string + */ + public static function toFormat($name, $delim = '/') { //preg_match_all('/[\/]/', $name, $match); //preg_match_all('/(.*)[\/\\\](.*)/', $name, $match); @@ -169,11 +171,11 @@ class Util /** - * Convert array to object format recursively - * - * @param array $array - * @return object - */ + * Convert array to object format recursively + * + * @param array $array + * @return object + */ public static function arrayToObject($array) { if (is_array($array)) { @@ -185,11 +187,11 @@ class Util /** - * Convert object to array format recursively - * - * @param object $object - * @return array - */ + * Convert object to array format recursively + * + * @param object $object + * @return array + */ public static function objectToArray($object) { if (is_object($object)) { @@ -198,6 +200,20 @@ class Util return is_array($object) ? array_map("static::objectToArray", $object) : $object; } + + /** + * Appends 'Obj' if name is reserved PHP word. + * + * @param string $name + * @return string + */ + public static function normilizeClassName($name) + { + if (in_array($name, self::$reservedWords)) { + $name .= 'Obj'; + } + return $name; + } /** @@ -254,4 +270,4 @@ class Util } -?> \ No newline at end of file +?> diff --git a/application/Espo/Modules/Crm/Controllers/Call.php b/application/Espo/Modules/Crm/Controllers/Call.php new file mode 100644 index 0000000000..53fe31b229 --- /dev/null +++ b/application/Espo/Modules/Crm/Controllers/Call.php @@ -0,0 +1,8 @@ +get('firstName') . ' ' . $this->get('lastName'); + } +} diff --git a/application/Espo/Modules/Crm/Entities/Meeting.php b/application/Espo/Modules/Crm/Entities/Meeting.php new file mode 100644 index 0000000000..1b3eb2006a --- /dev/null +++ b/application/Espo/Modules/Crm/Entities/Meeting.php @@ -0,0 +1,8 @@ +get('firstName') . ' ' . $this->get('lastName'); + } +} diff --git a/application/Espo/Modules/Crm/Entities/Task.php b/application/Espo/Modules/Crm/Entities/Task.php new file mode 100644 index 0000000000..6d7bf07205 --- /dev/null +++ b/application/Espo/Modules/Crm/Entities/Task.php @@ -0,0 +1,8 @@ +toDb($entity->getEntityName())}." . $this->toDb($key) . " = {$relTable}." . $this->toDb($nearKey) . " AND " - . "{$relTable}.deleted = " . $this->pdo->quote(0) . " " - . "JOIN {$distantTable} ON {$distantTable}." . $this->toDb($foreignKey) . " = {$relTable}." . $this->toDb($distantKey) + . "{$relTable}.deleted = " . $this->pdo->quote(0); + + if (!empty($relOpt['conditions']) && is_array($relOpt['conditions'])) { + foreach ($relOpt['conditions'] as $f => $v) { + $join .= " AND {$relTable}." . $this->toDb($f) . " = " . $this->pdo->quote($v); + } + } + + $join .= " JOIN {$distantTable} ON {$distantTable}." . $this->toDb($foreignKey) . " = {$relTable}." . $this->toDb($distantKey) . " AND " . "{$distantTable}.deleted = " . $this->pdo->quote(0) . "";