Cockpit CMS reordering Repeater field - php

I have a repeater of set fields in my Collection in Cockpit CMS.
Options is:
{
"fields": [
{
"type": "set",
"label": "Some Block",
"options": {
"fields": [
{
"name": "title",
"type": "text"
},
{
"name": "picture",
"type": "image"
}
]
}
}
]
}
How to use display option in repeater for display title field with re-ordering mode? If it's possible.
The cockpit docs are not sufficiently informative, and it says:
"display": null // display value on re-order
And how to use this option in other cases, except null?

OK. I found the solution.
Option display can be a part of options of set field:
{
"fields": [
{
"type": "set",
"label": "Some Block",
"options": {
"display": "title", // it must be placed here
"fields": [
{
"name": "title",
"type": "text"
},
{...}
]
}
}
]
}

Related

Google Analytics API in inserting goals using PHP

I need help regarding the returned error after initiating request:
Here's the request body:
{
"name": "Test Leads",
"id": "2",
"type": "Event",
"active": true,
"eventDetails": {
"eventConditions": [
{
"type": "Category",
"comparisonType": "EQUAL",
"expression": "Leads"
},
{
"type": "ACTION",
"comparisonType": "EQUAL",
"expression": "Create"
}
],
"useEventValue": true
}
}
Error:
{"error":{
"errors":[
{"domain":"global","reason":"backendError","message":"Backend Error"}
],
"code":500,
"message":"Backend Error"
}
}
Expected Goal Details when successfully posted:
https://www.screencast.com/t/5QOJ28Tnk
Can someone check the code and see what's wrong or missing?
Thanks.
"name": "Test Leads",
"kind": "analytics#goal",
"id": "2",
"type": "Event",
"active": true,
"eventDetails": {
"eventConditions": [
{
"type": "CATEGORY",
"matchType": "EXACT",
"expression": "Leads"
},
{
"type": "ACTION",
"matchType": "EXACT",
"expression": "Create"
}
],
"useEventValue": true
}
}```

Json Schema - Validate an infinite recursive structure

I'm trying to validate a json object using the "justinrainbow/json-schema" package for php.
Here's the json that i'm trying to validate:
{
"questions": [
{
"type": "section",
"name": "Section one",
"questions": [
{
"type": "section",
"name": "Subsection 1.1"
"questions":[
{
"type": "section",
"name": "Subsection 1.1"
"questions":
[
{
...
}
]
}
]
}
]
}
]
The questions property can always be present inside questions property ....
How can i validate it?
Thank you for your answers
You can use $ref to define a recursive structure.
{
"type": "object",
"properties": {
"type": { "type": "string" },
"name": { "type": "string" },
"questions": { "type": "array", "items": { "$ref": "#"} }
}
}

PHP json_decode error: Array value found, but an object is required

I am trying to decode following JSON file
{
"email": "mail#gmail.com",
"password": "12345",
"languageProficiency": {
"language": "English",
"proficiency": 4
},
"tags": [
{
"name": "singing"
},
{
"name": "dance"
}
]
}
When I do this
$data = json_decode($jsonContent, true);
echo $data;
die();
I have following error:
Array value found, but an object is required
Question
1) How can I view data from JSON
2) How can I access property of each object in tags array
I am validating Json content againsts this schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
},
"languageProficiency": {
"type": "object",
"properties": {
"language": {
"type": "string"
},
"proficiency": {
"type": "integer"
}
},
"required": [
"language",
"proficiency"
]
},
"tags": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
}
}
},
"required": [
"email",
"password",
"languageProficiency",
"tags"
]
}
UPDATE
I tried following to view json content
print_r($data)
But I still get same error
$data = json_decode($jsonContent, true);
Above line of code will return Array, for which you can not use echo directly to print an array.
To print specific value of an array (e.g. email), do it like this:
echo $data["email"];
Tip:
Use print_r() to know the array structure like this,
echo "<pre>";
print_r($data);
you can try print_r($data) to explore values

Elasticsearch Updating / Deleting Nested

I've gone through a few examples and documentations and kind find a solution update a nested object in the this result set.
I can add one (if one does not exist)
I can append to it (if one does exist)
Can't figure out how to delete a selected entry.
Is there a method I can use (using the php client) to add an entry if it does not exist / update an entry if it does exist / delete the second entry.
I'm inheriting this problem and am new to Elastic search.
Thanks.
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "products",
"_type": "categories",
"_id": "AUpRjtKZfXI7LIe9OpNx",
"_score": 1,
"_source": {
"name": "Primary",
"description": "Primary Category",
"slug": "Primary",
"created": "2014-12-16 00:25:22",
"parent": [
{
"name": "First One",
"description": "Test",
"id": "ae74ea4e2e865ed3fd60c18a06e69c65",
"slug": "first-one"
},
{
"name": "Second One",
"description": "Testing Again",
"id": "c8dbe5143c8dfd6957fa33e6cea7a0a8",
"slug": "second-one"
}
]
}
}
]
}
}
Do you want to do all three in the same operation?
Deleting the second nested object is achieved through a script which removes the second element:
PUT /products
{
"mappings": {
"categories": {
"properties": {
"parent": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"id": { "type": "string", "index": "not_analyzed" },
"slug": { "type": "string" }
}
}
}
}
}
}
PUT /products/categories/1
{
"name": "Primary",
"description": "Primary Category",
"slug": "Primary",
"created": "2014-12-16 00:25:22",
"parent": [
{
"name": "First One",
"description": "Test",
"id": "ae74ea4e2e865ed3fd60c18a06e69c65",
"slug": "first-one"
},
{
"name": "Second One",
"description": "Testing Again",
"id": "c8dbe5143c8dfd6957fa33e6cea7a0a8",
"slug": "second-one"
}
]
}
POST /products/categories/1/_update
{
"script" : "ctx._source.parent.remove(1)",
"lang": "groovy"
}
GET /products/categories/1
So in PHP code (using the official PHP client), the update would look like:
$params = [
'index' => 'products',
'type' => 'categories',
'id' => 1,
'body' => [
'script' => 'ctx._source.parent.remove(1)',
'lang' => 'groovy'
]
];
$result = $client->update($params);

PHP getting values from nested json

I have this json listed below. I was using json_decode to get some of the values. Such as getting the id value:
$decoded_array = json_decode($result, true);
foreach($decoded_array['issue'] as $issues ){
$value[] = $issues["id"];
This method is working for getting the id value, however, I want to get the emailAddress values for both Bob and John. I believe you can get a single value by doing this:
$value[] = $issues["fields"][people][0][emailAddress];
Is it possible to get both email addresses in an efficient manner?
Edited --------
How would you get data with an expanded dataset? Example:
{
"startAt": 0,
"issue": [
{
"id": "51526",
"fields": {
"people": [
{
"name": "bob",
"emailAddress": "bob#gmail.com",
"displayName": "Bob Smith",
},
{
"name": "john",
"emailAddress": "john#gmail.com",
"displayName": "John Smith",
}
],
"skill": {
"name": "artist",
"id": "1"
}
}
},
{
"id": "2005",
"fields": {
"people": [
{
"name": "jake",
"emailAddress": "jake#gmail.com",
"displayName": "Jake Smith",
},
{
"name": "frank",
"emailAddress": "frank#gmail.com",
"displayName": "Frank Smith",
}
],
"skill": {
"name": "writer",
"id": "2"
}
}
}
]
}
I only want to extract the email addresses from both "fields". Is there an easy way to loop through all the "fields" to get "emailAddress" data?
You need to delve deeper into the array.
foreach ($decoded_array['issue'][0]['fields']['people'] as $person) {
echo $person['emailAddress'];
}

Categories