I have a result object in my view and want do put this in JSON format.
The Object looks like
TYPO3\CMS\Extbase\Persistence\Generic\QueryResultprototypeobject (32 items)
0 => KN\Operations\Domain\Model\Operationprototypepersistent entity (uid=853,
pid=90)
1 => KN\Operations\Domain\Model\Operationprototypepersistent entity (uid=852,
pid=90)
....
I tried to use format
{myObject-> f:format.json()}
but this doesn't work. Result is
{}
I want to give that informations to my JS. For me it is not possible to change the Controller because I don't want to change an existing extension.
the format.json viewhelper expects an array as the value. To get the right result you need to convert your result into an array.
If you set the first param of the execute function in your repository to true you will get an array instead of an Queryresult Object.
return $query->execute(true);
You can find additional information on the documentation page of the viewhelper: https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Format/Json.html
Happy Coding!
Related
As debugDescription returns the XCUIElement UI Tree and this if of type String.
Want to fetch specific information based upon parameters like label :[String] will return all the label values, find_Application - will return the bundleID etc
You can use element.snapshot().dictionaryRepresentation which gives a parsed version of output of element.debugDescription or element.snapshotDescription.
You can use element.snapshot().children to get the child element's snapshots iteratively if you want to create your own parser.
I have a TTL with something like
ex:isDataProperty rdf:type owl:DatatypeProperty .
ex:Article a owl:Class ;
owl:hasKey ( ex:isDataProperty ) .
And when I load the model with RDF4J (as a TreeModel) then try to filter to extract the properties annotated with haskey fails (just returns empty list result)
Some samples that return data:
val dataProperties = model.filter(null, RDF.TYPE, OWL.DATATYPEPROPERTY).subjects().asScala
val classes = model.filter(null, RDF.TYPE, OWL.CLASS).subjects().asScala
The sample I want, that doesn't return data:
val propertiesWithKeys = model.filter(null, RDF.PROPERTY, OWL.HASKEY).subjects().asScala
I have tried a few variations of the previous one using RDF.TYPE or RDF.Value. (instead of RDF.PROPERTY)
The thing you're after is any subject that has a owl:hasKey property, regardless of value. So both the subject and the object are wildcards, you just want to filter by property name. The way to do that is like this:
model.filter(null, OWL.HASKEY, null)
Now, furthermore you say that you want to know the properties that have been used as annotation using this owl:hasKey property. In your example, that would be ex:isDataProperty. Note that in your model, this is not the subject of the owl:hasKey relation - it's in the object values:
model.filter(null, OWL.HASKEY, null).objects()
To further complicate matters, the object values in your example are not simply single values. Instead, each class is annotated using a list of properties, so the object value is a list object (a.k.a. an RDF Collection). To process this list, there are some utility methods provided by the Models and RDFCollections classes.
For each of the objects you can do this to get the actual list of values:
RDFCollections.asValues(model, objectNode, new ArrayList<Value>())
(where objectNode is one of the values that .objects() returned)
Edit since objects() returns objects of type Value and RDFCollections expects a Resource, you'll either have to do a cast, or if you want to do all of this in a fluent way, you can use Models.objectResources instead. The whole thing then becomes:
Models.objectResources(model.filter(null, OWL.HASKEY, null))
.asScala.map(o => RDFCollections.asValues(model, o, new ArrayList[Value]()));
(I may have the Scala-specific bits of this wrong, but you get the gist hopefully)
For more information on how to work with the rdf4j Model API and with RDF Collections, see the rdf4j documentation.
I have the following problem - I want to test REST api with Codeception.
When I want to make sure in JSON response I have array:
'data' => [
'sth' => 'whathever'
]
I can use seeResponseJsonMatchesXpath this way:
$I->seeResponseJsonMatchesXpath('//data/sth');
But what to do if I want to make sure I don't have in response sth? I would like to use for example:
$I->seeResponseJsonMatchesXpath('//data');
$I->dontSeeResponseJsonMatchesXpath('//data/sth');
but obviously there is no dontSeeResponseJsonMatchesXpath method in Codeception.
I also don't know what will be exact value in sth so probably I cannot use here dontSeeResponseContainsJson.
The question is - how to make the following check?
(Disclaimer: Entirely unfamiliar with codeception, only with XPath)
JSON is not supposed to be checked against XPath. But the check you could probably do is
$I->seeResponseJsonMatchesXpath('not(//data/sth)');
Which would return true or 1 if there is no data and sth - and false or 0 if there is.
EDIT: As a response to your comments:
Probably this is something close I need but I want to make sure only sth is not present inside data whereas data should exist (but I don't need to check it in this expression)
The expression already does exactly that - not(//data/sth) returns false for a document like
<data>
<sth/>
</data>
but returns true for a document containing data only:
<data/>
or anything else. But it seems to me there could be pitfalls with converting JSON to XML.
I checked both solutions - yours and //data/not(sth) but it doesn't seem to work
Yes, that does not work because you are using an XPath 1.0 engine. Your attempt would be a valid XPath 2.0 expression. Use the following expression to independently test data and sth:
//data and not(//data/sth)
This only returns true if at least one data element exists and if there is no data element that has an sth element as a child.
I'm unable to run the FindBy magic function property in Extbase MVC
$title=array(0 =>'Books Day');
$each_event=$this->eventRepository->findByTitle($title);
$each_event is returning an object of type TYPO3\CMS\Extbase\Persistence\Generic\QueryResult .
How do I make this work?
I also tried passing in a string to findByTitle and findByOne. Both don;t work! :(
I'm using TYPO3 6.1 and extension builder.
The last part of those magic functions always needs to be a field in the database. So "title" must be in your model. You might have a field "one" for your object, but I guess you meant findOneByTitle?
The object type QueryResult is correct. You can turn it into an array for debugging purpose for example:
$foo = $query->execute()->toArray();
By the way: check wether your eventRepository is null or not and you could try this to see if it works at all:
$result = $this->myRepository->findAll();
Try
$each_event=$this->eventRepository->findByTitle($title)->toArray();
Reference to the QueryResult.
As said in the documentation, it returns a QueryResultInterface|array.
As a consequence you have to loop over the result like this:
foreach($each_event as $single_event) {
$single_event->getProperty();
}
If you are sure that it returns only one single value you could also access it by the index 0:
$each_event[0]->getProperty();
I have created a doctype in umbraco which has one of the following property:
Property - Case study link
Datatype - Content picker
I need to fetch the URL of this document in a Razor macro and assign it to a hyperlink.
Currently am doing it in this way but it's giving me an error:
#foreach (var item in #Model.OurWork){
Read case study
}
And here is the error I get on viewing the page:
Error loading Razor Script OurWorkGrid.cshtml The best overloaded
method match for 'umbraco.library.NiceUrl(int)' has some invalid
arguments
I have tried outputting the node id without using the niceURL() function and it works fine (outputs 1088).
Read case study
results in this:
Read case study
But as soon as I put back NiceURL() function, it chokes again.
I really don't know what am I doing wrong here!
Instead of using the umbraco library method, try loading the node with the ID first, and then using the Url property to get the nice URL.
#foreach (var item in #Model.OurWork){
var caseStudyNode = #Model.NodeById(item.caseStudyLink);
Read case study
}
Also, add some form of a check to make sure the value is set, in case it's not a mandatory property on the doc type. Here's one example:
if (#item.HasProperty("caseStudyLink") && !string.IsNullOrEmpty(#item.caseStudyLink))
{
...
}
Try something like:
#foreach (var item in #Model.OurWork){
Read case study
}
You may want to check first whether item.caseStudyLink contains a value because this will throw an error otherwise.