@param ModelInterface $model
@param string         $jsonRelName

@return string
327215
private function getRelationshipSelfSubUrl(ModelInterface $model, string $jsonRelName): string
    {
        return $this->getSelfSubUrl($model) . '/relationships/' . $jsonRelName;
    }
1271057
public static function init(JSONObject $json)
	{
		$object = NULL;
		
		if(!$json->has("@type"))
			throw new ModelFormatException("Not a valid object");
		try
		{
			switch(strtolower($json->get("@type")))
			{
				case "comment":
					$object = CommentObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "like":
					$object = LikeObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "image":
					$object = ImageObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "profile":
					$object = ProfileObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "conversation":
					$object = ConversationObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "conversation-status":
					$object = ConversationStatusObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "conversation-message":
					$object = ConversationMessageObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "conversation-message-status":
					$object = ConversationMessageStatusObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "accesscontrolgroup":
					$object = AccessControlGroupObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "accesscontrolrule":
					$object = AccessControlRuleObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "link":
					$object = LinkObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "link-request":
					$object = LinkRequesObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "link-response":
					$object = LinkResponseObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "response":
					$object = ResponseObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "search-query":
					$object = SearchQueryObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "search-result":
					$object = SearchResultObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "search-result-collection":
					$object = SearchResultCollectionObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				//case "signature":
					//$object = SignaObjectBuilder::buildFromJSON($json->__toString());
				//break;
				
				// feature
				// migration
				
				case "activity":
					$object = StreamItemObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				case "tag":
					$object = TagObjectBuilder::buildFromJSON($json->__toString());
				break;
				
				default:
					throw new ModelFormatException("Not a valid object type");
				break;
			}
		}
		catch(Exception $e)
		{
			throw new ModelFormatException("Could not init object for " . strtolower($json->get("@type")) . ": " . $e->getMessage());
		}
		
		return $object;
	}
997953
public function jsJsonArray($url, $method="get", $params="{}", $jsCallback=NULL,$parameters=[]){
		$parameters=\array_merge($parameters,["modelSelector"=>"#".$this->_identifier." tr.".$this->_modelClass,"url"=>$url,"method"=>$method,"params"=>$params,"jsCallback"=>$jsCallback]);
		return new AjaxCall("jsonArray", $parameters);
	}
187346
protected function getForeignKeyName(Model $model)
    {
        $table = $model->getTable();

        if (array_key_exists($table, $this->foreignKeyLookup)) {
            return $this->foreignKeyLookup[$table];
        }

        return Str::singular($table).'_id';
    }
708721
public function extractEntityName($model)
    {
        $classNames = (array) explode('\\', $model);

        $entityName = end($classNames);

        if ($this->entityHasTranslation($entityName)) {
            return __('exception::exceptions.models.'.$entityName);
        }

        return $entityName;
    }
1179805
public function apply($model, RepositoryInterface $repository)
    {
        $fieldsSearchable = $repository->getFieldsSearchable();
        $search = $this->request->get(config('repository.criteria.params.search', 'search'), null);
        $searchFields = $this->request->get(config('repository.criteria.params.searchFields', 'searchFields'), null);
        $filter = $this->request->get(config('repository.criteria.params.filter', 'filter'), null);
        $orderBy = $this->request->get(config('repository.criteria.params.orderBy', 'orderBy'), null);
        $sortedBy = $this->request->get(config('repository.criteria.params.sortedBy', 'sortedBy'), 'asc');
        $with = $this->request->get(config('repository.criteria.params.with', 'with'), null);
        $sortedBy = !empty($sortedBy) ? $sortedBy : 'asc';

        if ($search && is_array($fieldsSearchable) && count($fieldsSearchable)) {

            $searchFields = is_array($searchFields) || is_null($searchFields) ? $searchFields : explode(';', $searchFields);
            $fields = $this->parserFieldsSearch($fieldsSearchable, $searchFields);
            $isFirstField = true;
            $searchData = $this->parserSearchData($search);
            $search = $this->parserSearchValue($search);
            $modelForceAndWhere = method_exists($repository, 'getIsSearchableForceAndWhere') ? $repository->getIsSearchableForceAndWhere() : false;

            $model = $model->where(function ($query) use ($fields, $search, $searchData, $isFirstField, $modelForceAndWhere) {
                /** @var Builder $query */

                foreach ($fields as $field => $condition) {

                    if (is_numeric($field)) {
                        $field = $condition;
                        $condition = "=";
                    }

                    $value = null;

                    $condition = trim(strtolower($condition));

                    if (isset($searchData[$field])) {
                        if ($condition == "like_raw") {
                            $condition = "like";
                            $value = $searchData[$field];
                        } else if ($condition == "like_safe") {
                            $condition = "like";
                            if (str_contains_ascii_only($searchData[$field])) {
                                $value = "%{$searchData[$field]}%";
                            } else {
                                $value = null;
                            }
                        } else {
                            $value = ($condition == "like" || $condition == "ilike") ? "%{$searchData[$field]}%" : $searchData[$field];
                        }
                    } else {
                        if (!is_null($search)) {
                            if ($condition == "like_raw") {
                                $condition = "like";
                                $value = $searchData[$field];
                            } else if ($condition == "like_safe") {
                                $condition = "like";
                                if (str_contains_ascii_only($search)) {
                                    $value = "%{$search}%";
                                } else {
                                    $value = null;
                                }
                            } else {
                                $value = ($condition == "like" || $condition == "ilike") ? "%{$search}%" : $search;
                            }
                        }
                    }

                    $relation = null;
                    if (stripos($field, '.')) {
                        $explode = explode('.', $field);
                        $field = array_pop($explode);
                        $relation = implode('.', $explode);
                    }
                    $modelTableName = $query->getModel()->getTable();
                    if ($isFirstField || $modelForceAndWhere) {
                        if (!is_null($value)) {
                            if (!is_null($relation)) {
                                $query->whereHas($relation, function ($query) use ($field, $condition, $value) {
                                    $query->where($field, $condition, $value);
                                });
                            } else {
                                $query->where($modelTableName . '.' . $field, $condition, $value);
                            }
                            $isFirstField = false;
                        }
                    } else {
                        if (!is_null($value)) {
                            if (!is_null($relation)) {
                                $query->orWhereHas($relation, function ($query) use ($field, $condition, $value) {
                                    $query->where($field, $condition, $value);
                                });
                            } else {
                                $query->orWhere($modelTableName . '.' . $field, $condition, $value);
                            }
                        }
                    }
                }
            });
        }

        if (isset($orderBy) && !empty($orderBy)) {
            $orderBys = explode(';', $orderBy); // products:product_id:product_id|products.name;updated_at,desc
            $originSortedBy = $sortedBy;
            foreach ($orderBys as $orderBy) {
                // split sorted by
                $splitSortedBy = explode(',', $orderBy);
                if (count($splitSortedBy) > 1) {
                    $sortedBy = $splitSortedBy[1];
                } else {
                    $sortedBy = $originSortedBy;
                }
                $orderBy = $splitSortedBy[0];

                // split joint
                $split = explode('|', $orderBy);
                if (count($split) > 1) {
                    /*
                     * ex.
                     * products|description -> join products on current_table.product_id = products.id order by description
                     *
                     * products:custom_id|products.description -> join products on current_table.custom_id = products.id order
                     * by products.description (in case both tables have same column name)
                     */
                    $table = $model->getModel()->getTable();
                    $sortTable = $split[0];
                    $sortColumn = $split[1];

                    $sortTableKeyName = 'id';
                    $split = explode(':', $sortTable);
                    if (count($split) > 2) { //    products:custom_id:products_table_custom_id|products.description
                        $sortTable = $split[0];
                        $keyName = $table . '.' . $split[1];
                        $sortTableKeyName = $split[2];
                    } else if (count($split) > 1) {
                        $sortTable = $split[0];
                        $keyName = $table . '.' . $split[1];
                    } else {
                        /*
                         * If you do not define which column to use as a joining column on current table, it will
                         * use a singular of a join table appended with _id
                         *
                         * ex.
                         * products -> product_id
                         */
                        $prefix = rtrim($sortTable, 's');
                        $keyName = $table . '.' . $prefix . '_id';
                    }

                    $model = $model
                        ->leftJoin($sortTable, $keyName, '=', $sortTable . '.' . $sortTableKeyName)
                        ->orderBy($sortColumn, $sortedBy)
                        ->groupBy($keyName) // Prevent SQL Error: SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxx' which is not functionally dependent on columns in GROUP BY clause;
                        ->addSelect($table . '.*');
                } else {
                    $model = $model->orderBy($orderBy, $sortedBy);
                }
            }
        }

        if (isset($filter) && !empty($filter)) {
            if (is_string($filter)) {
                $filter = explode(';', $filter);
            }

            $model = $model->select($filter);
        }

        if ($with) {
            $with = explode(';', $with);
            $model = $model->with($with);
        }

        return $model;
    }
128067
private function withJSON(ResponseInterface $response, $jsonable)
    {
        $jsoned = $this->json->encode($jsonable);

        return $this
            ->withNewBody($response, $jsoned)
            ->withHeader('Content-Type', 'application/json');
    }
283650
protected function _translateFieldname(string $fieldname, string $model): string
    {
        // Try to get the generic model.field translation string
        $localeSlug = strtolower(Inflector::singularize(Inflector::delimit($model))) . '.' . strtolower($fieldname);
        $translatedString = __($localeSlug);

        // Return original value when no translation was made
        if ($localeSlug == $translatedString) {
            return $fieldname;
        }

        return $translatedString;
    }
1082581
protected function jsonKeyToClassname($jsonKey)
    {
        if (isset($this->objectMapper[$jsonKey])) {
            return $this->objectMapper[$jsonKey];
        }
        return null;
    }
851476
protected function resolveResourceKey(Model $model, string $resourceKey = null):string
    {
        if (! is_null($resourceKey)) {
            return $resourceKey;
        }

        if (method_exists($model, 'getResourceKey')) {
            return $model->getResourceKey();
        }

        return $model->getTable();
    }
1061137
public function selectSearch(Request $request, ModelConfigurationInterface $model, $field, $id = null)
    {
        $form = $this->getModelLogic($model, $id);

        if ($form instanceof JsonResponse) {
            return $form;
        }

        /** @var DependentSelect $element */
        $element = $form->getElement($field);

        if (is_null($element)) {
            return new JsonResponse([
                'message' => 'Element not found',
            ], 404);
        }

        $field = $request->field;
        $model = new $request->model;

        if ($request->q && is_object($model)) {
            return new JsonResponse(
                $model::where($request->search, 'like', "%{$request->q}%")
                    ->get()
                    ->map(function (Model $item) use ($field) {
                        return [
                            'tag_name'    => $item->{$field},
                            'id'          => $item->id,
                            'custom_name' => $item->custom_name,
                        ];
                    })
            );
        }
    }
42908
public static function fillFromJSON($model, $json, $isError=false) {
        if(is_array($json)) {
            $array = $json;
        } else {
            if (get_magic_quotes_gpc()) {
                $json = stripslashes($json);
            }
            $array = json_decode($json, true);
        }

        if(!is_array($array))
            $array = array();

        if($isError) {
            $exception = self::createFromJSON('infobip\models\SmsException', $json, false);
            $model->exception = $exception;
            return $model;
        }

        $conversionRules = Models::getConversionRules(get_class($model));

        $className = get_class($model);

        // Keep original JSON values (for simple string values):
        foreach($array as $key => $value) {
            if(property_exists($className, $key) && (is_string($value) || is_numeric($value) || is_bool($value))) {
                $model->$key = $value;
            }
        }

        // Convert the ones that have custom conversion rules:
        foreach($conversionRules as $conversionRule) {
            foreach($array as $key => $value) {
                if($conversionRule instanceof FieldConversionRule) {
                    // field conversion rule:
                    if(property_exists($className, $key) && $conversionRule->field == $key) {
                        $model->$key = $conversionRule->convertFromJSON($value);
                    }
                }
            }
        }
        foreach($conversionRules as $conversionRule) {
            if($conversionRule instanceof ObjectConversionRule) {
                $conversionRule->convertFromJson($model, $array);
            }
        }

        return $model;
    }
1012168
public function jsonToInterface($data)
    {
        $parser = new \PHPFHIRGenerated\PHPFHIRResponseParser();
        $fhirPatient = $parser->parse($data);
        if ($fhirPatient instanceof FHIRPatient) {
            return $this->modelToInterface($fhirPatient);
        } else {
            // Error, the Resource does not match, expecting a Patient,
            // // but got something else.
            abort(403, 'Error, the Resource does not match, expecting a Patient, but got "' . typeOf($fhirPatient). '"');
        }
    }
805973
protected function renderHelp(Model $model)
    {
        $data = $model->getJson();

        // Test if we have anything to display at all.
        if (empty($data) === true) {
            return '';
        }

        // We have at least something to display here.
        $helpRow = $this->getTemplateFileContent(static::FILE_HELPROW);
        $helpContent = '';

        // Add the stuff from the json after the help text, if any.
        foreach ($data as $title => $text) {
            $helpContent .= str_replace(
                array(static::MARKER_HELP_TITLE, static::MARKER_HELP_TEXT),
                array($title, $text),
                $helpRow
            );
        }

        // Add it into the wrapper.
        return str_replace(static::MARKER_HELP, $helpContent, $this->getTemplateFileContent(static::FILE_HELP));
    }
1006916
public function deleteModelAction(WorkspaceModel $model)
    {
        $this->checkAccess($model->getWorkspace());
        $id = $model->getId();
        $this->modelManager->delete($model);

        return new JsonResponse(array('id' => $id));
    }
655059
protected function prepare($model, $remote)
    {
        return !empty($model) ? isset($model->data) ? Collection::count($model->data) == 1 ? $model->data[0] : $this->ManyRelationException($remote, $model) : null : null;
    }
540430
protected function getDatasource(ListenerAccessibleInterface $modelName) {

        /**
         * CP-251 - added multiple datasources to a single function. Need to check
         * for requested modelName before defaulting to datasourceKey which is
         * specified in default routing config.
         */
        if (is_object($modelName) && array_key_exists($modelName->getTablename(), $this->datasources)) {
            $datasource = $this->datasourceFactory->getDatasource($this->datasources[$modelName->getTablename()], $this->logger);
            $datasource->setDatasourceKey($this->datasources[$modelName->getTablename()]);
        } elseif (!is_object($modelName) && array_key_exists($modelName, $this->datasources)) {
            $datasource = $this->datasourceFactory->getDatasource($this->datasources[$modelName], $this->logger);
            $datasource->setDatasourceKey($this->datasources[$modelName]);
        } elseif (!is_null($this->datasourceKey)) {
            $datasource = $this->datasourceFactory->getDatasource($this->datasourceKey, $this->logger);
            $datasource->setDatasourceKey($this->datasourceKey);
        } else {
            throw new \Exception($modelName . ' datasource key missing from listeners configuration');
        }

        return $datasource;
    }