Exemple #1
0
 protected function getNotificator($entityType)
 {
     if (empty($this->notifatorsHash[$entityType])) {
         $normalizedName = Util::normilizeClassName($entityType);
         $className = '\\Fox\\Custom\\Notificators\\' . $normalizedName;
         if (!class_exists($className)) {
             $moduleName = $this->getMetadata()->getScopeModuleName($entityType);
             if ($moduleName) {
                 $className = '\\Fox\\Modules\\' . $moduleName . '\\Notificators\\' . $normalizedName;
             } else {
                 $className = '\\Fox\\Notificators\\' . $normalizedName;
             }
             if (!class_exists($className)) {
                 $className = '\\Fox\\Core\\Notificators\\Base';
             }
         }
         $notificator = new $className();
         $dependencies = $notificator->getDependencyList();
         foreach ($dependencies as $name) {
             $notificator->inject($name, $this->getContainer()->get($name));
         }
         $this->notifatorsHash[$entityType] = $notificator;
     }
     return $this->notifatorsHash[$entityType];
 }
Exemple #2
0
 protected function load($linkName, $entityName)
 {
     $parentRelation = parent::load($linkName, $entityName);
     $relation = array($entityName => array('fields' => array($linkName . 'Types' => array('type' => 'jsonObject', 'notStorable' => true))));
     $relation = \Fox\Core\Utils\Util::merge($parentRelation, $relation);
     return $relation;
 }
Exemple #3
0
 public function convert($linkName, $linkParams, $entityName, $ormMeta)
 {
     $entityDefs = $this->getMetadata()->get('entityDefs');
     $foreignEntityName = $this->getLinkEntityName($entityName, $linkParams);
     $foreignLink = $this->getForeignLink($linkName, $linkParams, $entityDefs[$foreignEntityName]);
     $currentType = $linkParams['type'];
     $method = $currentType;
     if ($foreignLink !== false) {
         $method .= '_' . $foreignLink['params']['type'];
     }
     $method = Util::toCamelCase($method);
     $relationName = $this->isRelationExists($method) ? $method : $currentType;
     //relationDefs defined in separate file
     if (isset($linkParams['relationName']) && $this->isMethodExists($linkParams['relationName'])) {
         $className = $this->getRelationClass($linkParams['relationName']);
     } else {
         if ($this->isMethodExists($relationName)) {
             $className = $this->getRelationClass($relationName);
         }
     }
     if (isset($className) && $className !== false) {
         $helperClass = new $className($this->metadata, $ormMeta, $entityDefs);
         return $helperClass->process($linkName, $entityName, $foreignLink['name'], $foreignEntityName);
     }
     //END: relationDefs defined in separate file
     return null;
 }
Exemple #4
0
 public function getImplementation($scope)
 {
     if (empty($this->implementationHashMap[$scope])) {
         $normalizedName = Util::normilizeClassName($scope);
         $className = '\\Fox\\Custom\\Acl\\' . $normalizedName;
         if (!class_exists($className)) {
             $moduleName = $this->metadata->getScopeModuleName($scope);
             if ($moduleName) {
                 $className = '\\Fox\\Modules\\' . $moduleName . '\\Acl\\' . $normalizedName;
             } else {
                 $className = '\\Fox\\Acl\\' . $normalizedName;
             }
             if (!class_exists($className)) {
                 $className = '\\Fox\\Core\\Acl\\Base';
             }
         }
         if (class_exists($className)) {
             $acl = new $className();
             $dependencies = $acl->getDependencyList();
             foreach ($dependencies as $name) {
                 $acl->inject($name, $this->container->get($name));
             }
             $this->implementationHashMap[$scope] = $acl;
         } else {
             throw new Error();
         }
     }
     return $this->implementationHashMap[$scope];
 }
Exemple #5
0
 protected function load($fieldName, $entityName)
 {
     $subList = array('first' . ucfirst($fieldName), ' ', 'last' . ucfirst($fieldName));
     $tableName = Util::toUnderScore($entityName);
     $orderByField = 'first' . ucfirst($fieldName);
     // TODO available in settings
     $fullList = array();
     $fullListReverse = array();
     $fieldList = array();
     $like = array();
     $equal = array();
     foreach ($subList as $subFieldName) {
         $fieldNameTrimmed = trim($subFieldName);
         if (!empty($fieldNameTrimmed)) {
             $columnName = $tableName . '.' . Util::toUnderScore($fieldNameTrimmed);
             $fullList[] = $fieldList[] = $columnName;
             $like[] = $columnName . " LIKE {value}";
             $equal[] = $columnName . " = {value}";
         } else {
             $fullList[] = "'" . $subFieldName . "'";
         }
     }
     $fullListReverse = array_reverse($fullList);
     return array($entityName => array('fields' => array($fieldName => array('type' => 'varchar', 'select' => $this->getSelect($fullList), 'where' => array('LIKE' => "(" . implode(" OR ", $like) . " OR CONCAT(" . implode(", ", $fullList) . ") LIKE {value} OR CONCAT(" . implode(", ", $fullListReverse) . ") LIKE {value})", '=' => "(" . implode(" OR ", $equal) . " OR CONCAT(" . implode(", ", $fullList) . ") = {value} OR CONCAT(" . implode(", ", $fullListReverse) . ") = {value})"), 'orderBy' => '' . $tableName . '.' . Util::toUnderScore($orderByField) . ' {direction}'))));
 }
Exemple #6
0
 protected function load($linkName, $entityName)
 {
     $parentRelation = parent::load($linkName, $entityName);
     $foreignEntityName = $this->getForeignEntityName();
     $relation = array($entityName => array('relations' => array($linkName => array('midKeys' => array(lcfirst($entityName) . 'Id', lcfirst($foreignEntityName) . 'Id')))));
     $relation = \Fox\Core\Utils\Util::merge($parentRelation, $relation);
     return $relation;
 }
Exemple #7
0
 public function normalizeEntityName($name)
 {
     if (empty($this->entityClassNameHash[$name])) {
         $className = '\\Fox\\Custom\\Entities\\' . Util::normilizeClassName($name);
         if (!class_exists($className)) {
             $className = $this->espoMetadata->getEntityPath($name);
         }
         $this->entityClassNameHash[$name] = $className;
     }
     return $this->entityClassNameHash[$name];
 }
Exemple #8
0
 protected function getClassName($name)
 {
     $name = Util::normilizeClassName($name);
     if (!isset($this->data)) {
         $this->init();
     }
     $name = ucfirst($name);
     if (isset($this->data[$name])) {
         return $this->data[$name];
     }
     return false;
 }
Exemple #9
0
 public function process($controllerName, $actionName, $params, $data, $request)
 {
     $customeClassName = '\\Fox\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
     if (class_exists($customeClassName)) {
         $controllerClassName = $customeClassName;
     } else {
         $moduleName = $this->metadata->getScopeModuleName($controllerName);
         if ($moduleName) {
             $controllerClassName = '\\Fox\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
         } else {
             $controllerClassName = '\\Fox\\Controllers\\' . Util::normilizeClassName($controllerName);
         }
     }
     if ($data && stristr($request->getContentType(), 'application/json')) {
         $data = json_decode($data);
     }
     if ($data instanceof \stdClass) {
         $data = get_object_vars($data);
     }
     if (!class_exists($controllerClassName)) {
         throw new NotFound("Controller '{$controllerName}' is not found");
     }
     $controller = new $controllerClassName($this->container, $request->getMethod());
     if ($actionName == 'index') {
         $actionName = $controllerClassName::$defaultAction;
     }
     $actionNameUcfirst = ucfirst($actionName);
     $beforeMethodName = 'before' . $actionNameUcfirst;
     $actionMethodName = 'action' . $actionNameUcfirst;
     $afterMethodName = 'after' . $actionNameUcfirst;
     $fullActionMethodName = strtolower($request->getMethod()) . ucfirst($actionMethodName);
     if (method_exists($controller, $fullActionMethodName)) {
         $primaryActionMethodName = $fullActionMethodName;
     } else {
         $primaryActionMethodName = $actionMethodName;
     }
     if (!method_exists($controller, $primaryActionMethodName)) {
         throw new NotFound("Action '{$actionName}' (" . $request->getMethod() . ") does not exist in controller '{$controllerName}'");
     }
     if (method_exists($controller, $beforeMethodName)) {
         $controller->{$beforeMethodName}($params, $data, $request);
     }
     $result = $controller->{$primaryActionMethodName}($params, $data, $request);
     if (method_exists($controller, $afterMethodName)) {
         $controller->{$afterMethodName}($params, $data, $request);
     }
     if (is_array($result) || is_bool($result)) {
         return \Fox\Core\Utils\Json::encode($result);
     }
     return $result;
 }
Exemple #10
0
 protected function load($fieldName, $entityName)
 {
     $converedFieldName = $fieldName . 'Converted';
     $currencyColumnName = Util::toUnderScore($fieldName);
     $alias = Util::toUnderScore($fieldName) . "_currency_alias";
     $d = array($entityName => array('fields' => array($fieldName => array("type" => "float", "orderBy" => $converedFieldName . " {direction}"))));
     $params = $this->getFieldParams($fieldName);
     if (!empty($params['notStorable'])) {
         $d[$entityName]['fields'][$fieldName]['notStorable'] = true;
     } else {
         $d[$entityName]['fields'][$fieldName . 'Converted'] = array('type' => 'float', 'select' => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate", 'where' => array("=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate = {value}", ">" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate > {value}", "<" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate < {value}", ">=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate >= {value}", "<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}", "<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"), 'notStorable' => true, 'orderBy' => $converedFieldName . " {direction}");
     }
     return $d;
 }
Exemple #11
0
 public function __construct()
 {
     parent::__construct();
     if (empty($this->entityType)) {
         $name = get_class($this);
         if (preg_match('@\\\\([\\w]+)$@', $name, $matches)) {
             $name = $matches[1];
         }
         if ($name != 'Record') {
             $this->entityType = Util::normilizeScopeName($name);
         }
     }
     $this->entityName = $this->entityType;
 }
Exemple #12
0
 public function run()
 {
     $uid = $_GET['uid'];
     $action = $_GET['action'];
     if (empty($uid) || empty($action)) {
         throw new BadRequest();
     }
     if (!in_array($action, array('accept', 'decline', 'tentative'))) {
         throw new BadRequest();
     }
     $uniqueId = $this->getEntityManager()->getRepository('UniqueId')->where(array('name' => $uid))->findOne();
     if (!$uniqueId) {
         throw new NotFound();
         return;
     }
     $data = $uniqueId->get('data');
     $eventType = $data->eventType;
     $eventId = $data->eventId;
     $inviteeType = $data->inviteeType;
     $inviteeId = $data->inviteeId;
     $link = $data->link;
     if (!empty($eventType) && !empty($eventId) && !empty($inviteeType) && !empty($inviteeId) && !empty($link)) {
         $event = $this->getEntityManager()->getEntity($eventType, $eventId);
         $invitee = $this->getEntityManager()->getEntity($inviteeType, $inviteeId);
         if ($event && $invitee) {
             $relDefs = $event->getRelations();
             $tableName = Util::toUnderscore($relDefs[$link]['relationName']);
             $status = 'None';
             if ($action == 'accept') {
                 $status = 'Accepted';
             } else {
                 if ($action == 'decline') {
                     $status = 'Declined';
                 } else {
                     if ($action == 'tentative') {
                         $status = 'Tentative';
                     }
                 }
             }
             $pdo = $this->getEntityManager()->getPDO();
             $sql = "\n                    UPDATE `{$tableName}` SET status = '{$status}'\n                    WHERE " . strtolower($eventType) . "_id = '{$eventId}' AND " . strtolower($inviteeType) . "_id = '{$inviteeId}'\n                ";
             $sth = $pdo->prepare($sql);
             $sth->execute();
             $this->getEntityManager()->getRepository('UniqueId')->remove($uniqueId);
             echo $status;
             return;
         }
     }
     throw new Error();
 }
Exemple #13
0
 protected function restoreFiles()
 {
     $GLOBALS['log']->info('Installer: Restore previous files.');
     $backupPath = $this->getPath('backupPath');
     $backupFilePath = Util::concatPath($backupPath, self::FILES);
     $backupFileList = $this->getRestoreFileList();
     $copyFileList = $this->getCopyFileList();
     $deleteFileList = array_diff($copyFileList, $backupFileList);
     $res = $this->copy($backupFilePath, '', true);
     $res &= $this->getFileManager()->remove($deleteFileList, null, true);
     if ($res) {
         $this->getFileManager()->removeInDir($backupPath, true);
     }
     return $res;
 }
 public function create($entityType)
 {
     $normalizedName = Util::normilizeClassName($entityType);
     $className = '\\Fox\\Custom\\SelectManagers\\' . $normalizedName;
     if (!class_exists($className)) {
         $moduleName = $this->metadata->getScopeModuleName($entityType);
         if ($moduleName) {
             $className = '\\Fox\\Modules\\' . $moduleName . '\\SelectManagers\\' . $normalizedName;
         } else {
             $className = '\\Fox\\SelectManagers\\' . $normalizedName;
         }
         if (!class_exists($className)) {
             $className = '\\Fox\\Core\\SelectManagers\\Base';
         }
     }
     $selectManager = new $className($this->entityManager, $this->user, $this->acl, $this->metadata);
     $selectManager->setEntityType($entityType);
     return $selectManager;
 }
Exemple #15
0
 /**
  * Unite files content
  *
  * @param array $paths
  * @param bool $isReturnModuleNames - If need to return data with module names
  *
  * @return array
  */
 public function unify(array $paths, $isReturnModuleNames = false)
 {
     $data = $this->loadData($paths['corePath']);
     if (!empty($paths['modulePath'])) {
         $moduleDir = strstr($paths['modulePath'], '{*}', true);
         $moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($moduleDir, false, '', false);
         foreach ($moduleList as $moduleName) {
             $moduleFilePath = str_replace('{*}', $moduleName, $paths['modulePath']);
             if ($isReturnModuleNames) {
                 if (!isset($data[$moduleName])) {
                     $data[$moduleName] = array();
                 }
                 $data[$moduleName] = Util::merge($data[$moduleName], $this->loadData($moduleFilePath));
                 continue;
             }
             $data = Util::merge($data, $this->loadData($moduleFilePath));
         }
     }
     if (!empty($paths['customPath'])) {
         $data = Util::merge($data, $this->loadData($paths['customPath']));
     }
     return $data;
 }
Exemple #16
0
 protected function initFieldTypes()
 {
     foreach ($this->fieldTypePaths as $path) {
         $typeList = $this->getFileManager()->getFileList($path, false, '\\.php$');
         if ($typeList !== false) {
             foreach ($typeList as $name) {
                 $typeName = preg_replace('/\\.php$/i', '', $name);
                 $dbalTypeName = strtolower($typeName);
                 $filePath = Util::concatPath($path, $typeName);
                 $class = Util::getClassName($filePath);
                 if (!Type::hasType($dbalTypeName)) {
                     Type::addType($dbalTypeName, $class);
                 } else {
                     Type::overrideType($dbalTypeName, $class);
                 }
                 $dbTypeName = method_exists($class, 'getDbTypeName') ? $class::getDbTypeName() : $dbalTypeName;
                 $this->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($dbTypeName, $dbalTypeName);
             }
         }
     }
 }
Exemple #17
0
 public function getSetupMessage()
 {
     $language = $this->getContainer()->get('language');
     $OS = $this->getSystemUtil()->getOS();
     $phpBin = $this->getSystemUtil()->getPhpBin();
     $cronFile = Util::concatPath($this->getSystemUtil()->getRootDir(), $this->cronFile);
     $desc = $language->translate('cronSetup', 'options', 'ScheduledJob');
     $message = isset($desc[$OS]) ? $desc[$OS] : $desc['default'];
     $command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default'];
     $command = str_replace(array('{PHP-BIN-DIR}', '{CRON-FILE}'), array($phpBin, $cronFile), $command);
     return array('message' => $message, 'command' => $command);
 }
Exemple #18
0
 public function delete($name)
 {
     if (!$this->isCustom($name)) {
         throw new Forbidden();
     }
     $normalizedName = Util::normilizeClassName($name);
     $unsets = array('entityDefs', 'clientDefs', 'scopes');
     $res = $this->getMetadata()->delete('entityDefs', $name);
     $res = $this->getMetadata()->delete('clientDefs', $name);
     $res = $this->getMetadata()->delete('scopes', $name);
     $this->getFileManager()->removeFile("custom/Fox/Custom/Resources/metadata/entityDefs/{$name}.json");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Resources/metadata/clientDefs/{$name}.json");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Resources/metadata/scopes/{$name}.json");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Entities/{$normalizedName}.php");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Services/{$normalizedName}.php");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Controllers/{$normalizedName}.php");
     $this->getFileManager()->removeFile("custom/Fox/Custom/Repositories/{$normalizedName}.php");
     try {
         $this->getLanguage()->delete('Global', 'scopeNames', $name);
         $this->getLanguage()->delete('Global', 'scopeNamesPlural', $name);
     } catch (\Exception $e) {
     }
     $this->getMetadata()->save();
     $this->getLanguage()->save();
     return true;
 }
Exemple #19
0
 public function getManifest()
 {
     if (!isset($this->data['manifest'])) {
         $packagePath = $this->getPackagePath();
         $manifestPath = Util::concatPath($packagePath, $this->manifestName);
         if (!file_exists($manifestPath)) {
             $this->throwErrorAndRemovePackage('It\'s not an Installation package.');
         }
         $manifestJson = $this->getFileManager()->getContents($manifestPath);
         $this->data['manifest'] = Json::decode($manifestJson, true);
         if (!$this->data['manifest']) {
             $this->throwErrorAndRemovePackage('Syntax error in manifest.json.');
         }
         if (!$this->checkManifest($this->data['manifest'])) {
             $this->throwErrorAndRemovePackage('Unsupported package.');
         }
     }
     return $this->data['manifest'];
 }
Exemple #20
0
 /**
  * Change group permission recursive
  *
  * @param string $filename
  * @param int $fileOctal - ex. 0644
  * @param int $dirOctal - ex. 0755
  *
  * @return bool
  */
 protected function chgrpRecurse($path, $group)
 {
     if (!file_exists($path)) {
         return false;
     }
     if (!is_dir($path)) {
         return $this->chgrpReal($path, $group);
     }
     $result = $this->chgrpReal($path, $group);
     $allFiles = $this->getFileManager()->getFileList($path);
     foreach ($allFiles as $item) {
         $result &= $this->chgrpRecurse($path . Utils\Util::getSeparator() . $item, $group);
     }
     return (bool) $result;
 }
Exemple #21
0
 protected function init($reload = false)
 {
     if ($reload || !file_exists($this->getLangCacheFile()) || !$this->getConfig()->get('useCache')) {
         $fullData = $this->getUnifier()->unify($this->name, $this->paths, true);
         $result = true;
         foreach ($fullData as $i18nName => $i18nData) {
             if ($i18nName != $this->defaultLanguage) {
                 $i18nData = Util::merge($fullData[$this->defaultLanguage], $i18nData);
             }
             $this->data[$i18nName] = $i18nData;
             if ($this->getConfig()->get('useCache')) {
                 $i18nCacheFile = str_replace('{*}', $i18nName, $this->cacheFile);
                 $result &= $this->getFileManager()->putPhpContents($i18nCacheFile, $i18nData);
             }
         }
         if ($result == false) {
             throw new Error('Language::init() - Cannot save data to a cache');
         }
     }
     $currentLanguage = $this->getLanguage();
     if (empty($this->data[$currentLanguage])) {
         $this->data[$currentLanguage] = $this->getFileManager()->getPhpContents($this->getLangCacheFile());
     }
 }
Exemple #22
0
 /**
  * Generate index name
  *
  * @return string
  */
 protected function generateIndexName($name, $entityName)
 {
     $names = array('IDX');
     $names[] = strtoupper(Util::toUnderScore($entityName));
     $names[] = strtoupper(Util::toUnderScore($name));
     return implode('_', $names);
 }
Exemple #23
0
 protected function getSortEntities($entity1, $entity2)
 {
     $entities = array(Util::toCamelCase(lcfirst($entity1)), Util::toCamelCase(lcfirst($entity2)));
     sort($entities);
     return $entities;
 }
Exemple #24
0
 private function getAllowedAdditionalParams($allowedItemName)
 {
     $linkParams = $this->getLinkParams();
     $foreignLinkParams = $this->getForeignLinkParams();
     $itemLinkParams = isset($linkParams[$allowedItemName]) ? $linkParams[$allowedItemName] : null;
     $itemForeignLinkParams = isset($foreignLinkParams[$allowedItemName]) ? $foreignLinkParams[$allowedItemName] : null;
     $additionalParrams = null;
     if (isset($itemLinkParams) && isset($itemForeignLinkParams)) {
         $additionalParrams = Util::merge($itemLinkParams, $itemForeignLinkParams);
     } else {
         if (isset($itemLinkParams)) {
             $additionalParrams = $itemLinkParams;
         } else {
             if (isset($itemForeignLinkParams)) {
                 $additionalParrams = $itemForeignLinkParams;
             }
         }
     }
     return $additionalParrams;
 }
Exemple #25
0
 protected function getInitValues(array $fieldParams)
 {
     $values = array();
     foreach ($this->fieldAccordances as $espoType => $ormType) {
         if (isset($fieldParams[$espoType])) {
             if (is_array($ormType)) {
                 $conditionRes = false;
                 if (!is_array($fieldParams[$espoType])) {
                     $conditionRes = preg_match('/' . $ormType['condition'] . '/i', $fieldParams[$espoType]);
                 }
                 if (!$conditionRes || $conditionRes && $conditionRes === $ormType['conditionEquals']) {
                     $value = is_array($fieldParams[$espoType]) ? json_encode($fieldParams[$espoType]) : $fieldParams[$espoType];
                     $values = Util::merge($values, Util::replaceInArray('{0}', $value, $ormType['value']));
                 }
             } else {
                 $values[$ormType] = $fieldParams[$espoType];
             }
         }
     }
     return $values;
 }
Exemple #26
0
 public function save(Entity $entity, array $options = array())
 {
     $nowString = date('Y-m-d H:i:s', time());
     $restoreData = array();
     if ($entity->isNew()) {
         if (!$entity->has('id')) {
             $entity->set('id', Util::generateId());
         }
         if ($entity->hasField('createdAt')) {
             $entity->set('createdAt', $nowString);
         }
         if ($entity->hasField('modifiedAt')) {
             $entity->set('modifiedAt', $nowString);
         }
         if ($entity->hasField('createdById')) {
             $entity->set('createdById', $this->entityManager->getUser()->id);
         }
         if ($entity->has('modifiedById')) {
             $restoreData['modifiedById'] = $entity->get('modifiedById');
         }
         if ($entity->has('modifiedAt')) {
             $restoreData['modifiedAt'] = $entity->get('modifiedAt');
         }
         $entity->clear('modifiedById');
     } else {
         if (empty($options['silent'])) {
             if ($entity->hasField('modifiedAt')) {
                 $entity->set('modifiedAt', $nowString);
             }
             if ($entity->hasField('modifiedById')) {
                 $entity->set('modifiedById', $this->entityManager->getUser()->id);
             }
         }
         if ($entity->has('createdById')) {
             $restoreData['createdById'] = $entity->get('createdById');
         }
         if ($entity->has('createdAt')) {
             $restoreData['createdAt'] = $entity->get('createdAt');
         }
         $entity->clear('createdById');
         $entity->clear('createdAt');
     }
     $this->restoreData = $restoreData;
     $result = parent::save($entity, $options);
     return $result;
 }
Exemple #27
0
 protected function load($fieldName, $entityName)
 {
     return array($entityName => array('fields' => array($fieldName => array('select' => 'phoneNumbers.name', 'where' => array('LIKE' => \Fox\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n                                SELECT entity_id\n                                FROM entity_phone_number\n                                JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n                                WHERE\n                                    entity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n                                    phone_number.deleted = 0 AND phone_number.name LIKE {value}\n                            )", '=' => \Fox\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n                                SELECT entity_id\n                                FROM entity_phone_number\n                                JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n                                WHERE\n                                    entity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n                                    phone_number.deleted = 0 AND phone_number.name = {value}\n                            )", '<>' => \Fox\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n                                SELECT entity_id\n                                FROM entity_phone_number\n                                JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n                                WHERE\n                                    entity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n                                    phone_number.deleted = 0 AND phone_number.name <> {value}\n                            )"), 'orderBy' => 'phoneNumbers.name {direction}'), $fieldName . 'Data' => array('type' => 'text', 'notStorable' => true)), 'relations' => array($fieldName . 's' => array('type' => 'manyMany', 'entity' => 'PhoneNumber', 'relationName' => 'entityPhoneNumber', 'midKeys' => array('entity_id', 'phone_number_id'), 'conditions' => array('entityType' => $entityName), 'additionalColumns' => array('entityType' => array('type' => 'varchar', 'len' => 100), 'primary' => array('type' => 'bool', 'default' => false))))));
 }
Exemple #28
0
 /**
  * Check if changed metadata defenition for a field except 'label'
  *
  * @return boolean
  */
 protected function isDefsChanged($name, $fieldDef, $scope)
 {
     $fieldDef = $this->prepareFieldDef($name, $fieldDef, $scope);
     $currentFieldDef = $this->getFieldDef($name, $scope);
     $this->isChanged = Util::isEquals($fieldDef, $currentFieldDef) ? false : true;
     return $this->isChanged;
 }
Exemple #29
0
 /**
  * Get additional field list based on field definition in metadata 'fields'
  *
  * @param  string     $fieldName
  * @param  array     $fieldParams
  * @param  array|null $definitionList
  *
  * @return array
  */
 public function getAdditionalFieldList($fieldName, array $fieldParams, array $definitionList = null)
 {
     if (empty($fieldParams['type'])) {
         return;
     }
     $fieldType = $fieldParams['type'];
     $fieldDefinition = isset($definitionList[$fieldType]) ? $definitionList[$fieldType] : $this->getMetadata()->get('fields.' . $fieldType);
     if (!empty($fieldDefinition['fields']) && is_array($fieldDefinition['fields'])) {
         $copiedParams = array_intersect_key($fieldParams, array_flip($this->copiedDefParams));
         $additionalFields = array();
         //add additional fields
         foreach ($fieldDefinition['fields'] as $subFieldName => $subFieldParams) {
             $namingType = isset($fieldDefinition['naming']) ? $fieldDefinition['naming'] : $this->defaultNaming;
             $subFieldNaming = Util::getNaming($fieldName, $subFieldName, $namingType);
             $additionalFields[$subFieldNaming] = array_merge($copiedParams, $subFieldParams);
         }
         return $additionalFields;
     }
 }
Exemple #30
0
 /**
  * Get and merge hook data by checking the files exist in $hookDirs
  *
  * @param array $hookDirs - it can be an array('Fox/Hooks', 'Fox/Custom/Hooks', 'Fox/Modules/Crm/Hooks')
  *
  * @return array
  */
 protected function getHookData($hookDirs)
 {
     if (is_string($hookDirs)) {
         $hookDirs = (array) $hookDirs;
     }
     $hooks = array();
     foreach ($hookDirs as $hookDir) {
         if (file_exists($hookDir)) {
             $fileList = $this->getFileManager()->getFileList($hookDir, 1, '\\.php$', true);
             foreach ($fileList as $scopeName => $hookFiles) {
                 $hookScopeDirPath = Util::concatPath($hookDir, $scopeName);
                 $scopeHooks = array();
                 foreach ($hookFiles as $hookFile) {
                     $hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);
                     $className = Util::getClassName($hookFilePath);
                     foreach ($this->hookList as $hookName) {
                         if (method_exists($className, $hookName)) {
                             $scopeHooks[$hookName][$className::$order][] = $className;
                         }
                     }
                 }
                 //sort hooks by order
                 foreach ($scopeHooks as $hookName => $hookList) {
                     ksort($hookList);
                     $sortedHookList = array();
                     foreach ($hookList as $hookDetails) {
                         $sortedHookList = array_merge($sortedHookList, $hookDetails);
                     }
                     $normalizedScopeName = Util::normilizeScopeName($scopeName);
                     $hooks[$normalizedScopeName][$hookName] = isset($hooks[$normalizedScopeName][$hookName]) ? array_merge($hooks[$normalizedScopeName][$hookName], $sortedHookList) : $sortedHookList;
                 }
             }
         }
     }
     return $hooks;
 }