Example #1
0
 public function notifyAboutNote(array $userIds, \Espo\Entities\Note $note)
 {
     $data = array('noteId' => $note->id);
     $encodedData = Json::encode($data);
     $now = date('Y-m-d H:i:s');
     $pdo = $this->getEntityManager()->getPDO();
     $sql = "INSERT INTO `notification` (`id`, `data`, `type`, `user_id`, `created_at`) VALUES ";
     $arr = [];
     foreach ($userIds as $userId) {
         if (empty($userId)) {
             continue;
         }
         $user = $this->getEntityManager()->getEntity('User');
         $user->id = $userId;
         $user->setAsFetched();
         if (!$this->checkUserNoteAccess($user, $note)) {
             continue;
         }
         $id = uniqid();
         $arr[] = "(" . $pdo->quote($id) . ", " . $pdo->quote($encodedData) . ", " . $pdo->quote('Note') . ", " . $pdo->quote($userId) . ", " . $pdo->quote($now) . ")";
     }
     if (empty($arr)) {
         return;
     }
     $sql .= implode(", ", $arr);
     $pdo->query($sql);
 }
Example #2
0
 public function testEncode()
 {
     $testVal = array('testOption' => 'Test');
     $this->assertEquals(json_encode($testVal), Json::encode($testVal));
 }
Example #3
0
 /**
  * Merge file content and save it to a file
  *
  * @param string | array $path
  * @param string $content JSON string
  * @param bool $isReturnJson
  * @param string | array $removeOptions - List of unset keys from content
  * @param bool $isPhp - Is merge php files
  *
  * @return bool | array
  */
 public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false)
 {
     if ($isPhp) {
         $fileContent = $this->getPhpContents($path);
     } else {
         $fileContent = $this->getContents($path);
     }
     $fullPath = $this->concatPaths($path);
     if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) {
         throw new Error('FileManager: Failed to read file [' . $fullPath . '].');
     }
     $savedDataArray = Utils\Json::getArrayData($fileContent);
     $newDataArray = Utils\Json::getArrayData($content);
     if (isset($removeOptions)) {
         $savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
         $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
     }
     $data = Utils\Util::merge($savedDataArray, $newDataArray);
     if ($isReturnJson) {
         $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
     }
     if ($isPhp) {
         return $this->putPhpContents($path, $data);
     }
     return $this->putContents($path, $data);
 }
Example #4
0
 /**
  * Get All Metadata context
  *
  * @param $isJSON
  * @param bool $reload
  *
  * @return json | array
  */
 public function getAll($isJSON = false, $reload = false)
 {
     if ($reload) {
         $this->init(true);
     }
     if ($isJSON) {
         return Json::encode($this->meta);
     }
     return $this->meta;
 }
Example #5
0
 public function save(Entity $entity)
 {
     if ($entity->id) {
         $this->data[$entity->id] = $entity->toArray();
         $fields = $fields = $this->getMetadata()->get('entityDefs.Preferences.fields');
         $data = array();
         foreach ($this->data[$entity->id] as $field => $value) {
             if (empty($fields[$field]['notStorable'])) {
                 $data[$field] = $value;
             }
         }
         $fileName = $this->getFilePath($entity->id);
         $this->getFileManager()->putContents($fileName, Json::encode($data, \JSON_PRETTY_PRINT));
         $this->storeAutoFollowEntityTypeList($entity);
         return $entity;
     }
 }
Example #6
0
 public function process($controllerName, $actionName, $params, $data, $request)
 {
     $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\\' . Util::normilizeClassName($controllerName);
         } else {
             $controllerClassName = '\\Espo\\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;
     if (method_exists($controller, $beforeMethodName)) {
         $controller->{$beforeMethodName}($params, $data, $request);
     }
     $actionMethodName = 'action' . $actionNameUcfirst;
     if (!method_exists($controller, $actionMethodName)) {
         throw new NotFound("Action '{$actionMethodName}' does not exist in controller '{$controller}'");
     }
     $result = $controller->{$actionMethodName}($params, $data, $request);
     $afterMethodName = 'after' . $actionNameUcfirst;
     if (method_exists($controller, $afterMethodName)) {
         $controller->{$afterMethodName}($params, $data, $request);
     }
     if (is_array($result) || is_bool($result)) {
         return \Espo\Core\Utils\Json::encode($result);
     }
     return $result;
 }
Example #7
0
 protected function setEntityDefs($name, $fieldDef, $scope)
 {
     $fieldDef = $this->normalizeDefs($name, $fieldDef, $scope);
     $data = Json::encode($fieldDef);
     $res = $this->getMetadata()->set($data, $this->metadataType, $scope);
     return $res;
 }
Example #8
0
 /**
  * Get Metadata only without saving it to the a file and database sync
  *
  * @param $isJSON
  * @param bool $reload
  *
  * @return json | array
  */
 public function getMetadataOnly($isJSON = true, $reload = false)
 {
     $data = false;
     if (!file_exists($this->cacheFile) || $reload) {
         $data = $this->getUnifier()->unify($this->name, $this->paths, true, 5, 'options');
         if ($data === false) {
             $GLOBALS['log']->emergency('Metadata:getMetadata() - metadata unite file cannot be created');
         }
         $data = $this->setLanguageFromConfig($data);
     } else {
         if (file_exists($this->cacheFile)) {
             $data = $this->getFileManager()->getContents($this->cacheFile);
         }
     }
     if ($isJSON) {
         $data = Json::encode($data);
     }
     return $data;
 }
Example #9
0
 /**
  * Merge file content and save it to a file
  *
  * @param string | array $path
  * @param string $content JSON string
  * @param bool $isJSON
  * @param string | array $mergeOptions
  * @param string | array $removeOptions - List of unset keys from content
  * @param bool $isReturn - Is result to be returned or stored
  *
  * @return bool | array
  */
 public function mergeContents($path, $content, $isJSON = false, $mergeOptions = null, $removeOptions = null, $isReturn = false)
 {
     $fileContent = $this->getContents($path);
     $savedDataArray = Utils\Json::getArrayData($fileContent);
     $newDataArray = Utils\Json::getArrayData($content);
     if (isset($removeOptions)) {
         $savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
         $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
     }
     $data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions);
     if ($isJSON) {
         $data = Utils\Json::encode($data, JSON_PRETTY_PRINT);
     }
     if ($isReturn) {
         return $data;
     }
     return $this->putContents($path, $data);
 }
Example #10
0
 /**
  * Save changes
  *
  * @return bool
  */
 public function save()
 {
     $result = true;
     if (!empty($this->changedData)) {
         foreach ($this->changedData as $scope => $rowData) {
             foreach ($rowData as $layoutName => $layoutData) {
                 if (empty($scope) || empty($layoutName)) {
                     continue;
                 }
                 $layoutPath = $this->getLayoutPath($scope, true);
                 $data = Json::encode($layoutData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
                 $result &= $this->getFileManager()->putContents(array($layoutPath, $layoutName . '.json'), $data);
             }
         }
     }
     if ($result == true) {
         $this->clearChanges();
     }
     return (bool) $result;
 }
Example #11
0
 /**
  * Merge file content and save it to a file
  *
  * @param string | array $path
  * @param string $content JSON string
  * @param bool $isJSON
  * @param array $mergeOptions
  *
  * @return bool
  */
 public function mergeContents($path, $content, $isJSON = false, $mergeOptions = null)
 {
     $fileContent = $this->getContents($path);
     $savedDataArray = Utils\Json::getArrayData($fileContent);
     $newDataArray = Utils\Json::getArrayData($content);
     $data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions);
     if ($isJSON) {
         $data = Utils\Json::encode($data, JSON_PRETTY_PRINT);
     }
     return $this->putContents($path, $data);
 }