Neo4j php addLabels - php

I am beginner with Neo4j Rest API. I am using Everyman php library to develop my application. I have problem with creating node with labels.
use Everyman\Neo4j\Client,
Everyman\Neo4j\Transport,
Everyman\Neo4j\Node,
Everyman\Neo4j\Relationship;
use Everyman\Neo4j\Cypher;
public function indexAction()
{
$client = new Client('localhost', 7474);
$user = new Node($client);
$user->setProperty('name', 'Rohan Chingula');
$user->save()->addLabels(array('Users'));
}
while I run code I am getting
/var/www/zf2-tutorial/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Command/SetLabels.php:43
Message:
Cannot set a non-label

Try this:
$userLabel = $client->makeLabel('Users');
$user->save()->addLabels(array($userLabel));
User::addLabels expects an array of Label objects.
https://github.com/jadell/neo4jphp/wiki/Labels#wiki-adding-labels-to-a-node
Aside: if adding a bare string as a label is functionality you would like to see, please submit a feature request: https://github.com/jadell/neo4jphp/issues

I'm no PHP coder, but a quick look at the source suggests you should be passing an array of Label objects not strings. Your code is not using Everyman\Neo4j\Label
$labelSet = implode(':', array_map(function ($label) {
if (!($label instanceof Label)) {
throw new InvalidArgumentException("Cannot set a non-label");

Related

How to remove DataValidationRule via Google Sheets API

Currently I'm using the Google Sheets API via their PHP library to build a dynamic spreadsheet. I've set validation rules on a spreadsheet, specifically to create a dropdown list of states to select.
I have since updated the spreadsheet to have the state dropdown list in a different column. Upon doing this however, it seems the DataValidationRule that was set for the previous column, is still there.
I've attempted to create a method to REMOVE all validation from my sheet before re-applying any validation I want, but it does not seem to be working.
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#conditiontype
When setting a Condition Type, I'd like to revert the validation back to CONDITION_TYPE_UNSPECIFIED, however the API simply returns an error if I do so. I've attempted to use others such as ONE_OF_LIST, but then every cell errors saying:
Invalid: Input must be an item on specified list
Which makes sense, considering there is no list being generated (nor do I want one).
The rest of the columns can be any sort of combination of numbers/dates/text so I'd like to simply remove all validation before applying validation again.
Here's my current clearValidation code:
public function clearSpreadsheetValidations($spreadsheetId) {
$client = $this->getClient();
$service = new Google_Service_Sheets($client);
$conditions = new Google_Service_Sheets_BooleanCondition();
$conditions->setType('CONDITION_TYPE_UNSPECIFIED');
$conditions->setValues(null);
$setRule= new Google_Service_Sheets_DataValidationRule();
$setRule->setCondition($conditions);
$setRule->setInputMessage(null);
$setRule->setShowCustomUi(false);
$valReq = new Google_Service_Sheets_SetDataValidationRequest();
$valReq->setRule($setRule);
$sheetReq = new Google_Service_Sheets_Request();
$sheetReq->setSetDataValidation($valReq);
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requestBody->setRequests($sheetReq);
$service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
}
How can I call the sheets API to remove all previously set DataValidationRules in a spreadsheet?
Thanks!
Okay, as noted here
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request
SetDataValidationRequest
Sets a data validation rule to every cell in the range. To clear
validation in a range, call this with no rule specified.
So all I had to do, was simply not declare a range, or set a rule, and ran this method on the existing spreadsheet to clear all existing validations
public function clearSpreadsheetValidations($spreadsheetId) {
$client = $this->getSheetsClient();
$service = new Google_Service_Sheets($client);
$valReq = new Google_Service_Sheets_SetDataValidationRequest();
$sheetReq = new Google_Service_Sheets_Request();
$sheetReq->setSetDataValidation($valReq);
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requestBody->setRequests($sheetReq);
$service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
}
For java this code worked in my case.
public BatchUpdateSpreadsheetResponse removeAllDataValidation(String spreadsheetId, Sheets service)
throws IOException {
// [START sheets_conditional_formatting]
List<Request> requests = Arrays.asList(new Request().setSetDataValidation(
new SetDataValidationRequest()));
BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest().setRequests(requests);
BatchUpdateSpreadsheetResponse result = service.spreadsheets().batchUpdate(spreadsheetId, body).execute();
System.out.printf("%d cells updated.", result.getReplies().size());
// [END sheets_conditional_formatting]
return result;
}

Get the form name of Facebook lead ads using webhook

I have two different Facebook leads ad campaigns (A and B) connected to the same F.B page, I've connected it to a webhook following this guide using Facebook ads PHP sdk, and pass the leads to my C.R.M, everything works fine, the problem is that I can't tell if the lead came from form A or B.
I've tried to pull the from name like this:
$input = json_decode(file_get_contents('php://input'), true);
if($input)
{
$form_id = $input['entry'][0]['changes'][0]['value']['form_id'];
$form = AdsWebhookHandler::getFormName($form_id);
}
From the AdsWebhookHandlerclass:
public static function getFormName($form_id)
{
$form = new LeadgenForm($form_id);
if(!$form) return $form_id;
return $form->read();
}
But the form always returns empty ({}) for some reason.
Does anybody know how can I pull the form name? or even better - is it possible to pass custom hidden fields in the form?
Thank you all for an answer :)
O.K so I figure out how to get the form name, all I needed to do is use the getData() function included in the Facebook PHP SDK, my code looks like this now:
public function getFormName($form_id)
{
$form = new LeadgenForm($form_id,null,$this->fb_instance);
if(!$form) return $form_id;
$data = $form->read()->getData();
return isset($data['name']) ? $data['name'] : $form_id;
}
Hope it'll help someone in the future :)

Azure PHP SDK: get the asset by asset name

Is it possible to get the asset details using asset name with Azure PHP sdk. I can get all the asset list, but it's loading first 1000 assets only.
getAssetList();
I can get single asset details using asset id.
getAsset($asset);
But in my case, I don't have asset id with me. I just have asset name alone. Now how do I get the asset details using this?
EDIT:
I got some help from Azure support saying that, we can use $skip parameter for pagination. I got code snippet in c#
for (int i = 0; i < _context.Assets.Count(); i += 1000 )
{
var assets = _context.Assets.Skip(i);
foreach (IAsset objIAsset in assets)
{
Console.WriteLine(objIAsset.Name.ToString());
}
}
How can I use this param in PHP SDK.
It seem that Azure SDK for PHP don't support skip method. However, I used the fiddler to monitor C# skip method and got the URL like this:
https://***-hs.cloudapp.net/api/Assets()?$skip=1000
So I think we can bulid up the request path like above in our PHP project and we can modify the getAssetList method in "MediaServicesRestProxy" file.
I add a function named "getAssetListBySkip($number)" into "MediaServicesRestProxy" class, the code like this:
/**
* Get asset list using skip number
*
* */
public function getAssetListBySkip($number)
{
$propertyList = $this->_getEntityList("Assets()?".'$skip='.$number);
$result = array();
foreach ($propertyList as $properties) {
$result[] = Asset::createFromOptions($properties);
}
return $result;
}
We can call this method like this:
$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
new MediaServicesSettings("**","**/**="));
$result=$mediaServiceProxy->getAssetListBySkip(1000);
Azure Media services supports filtering by name. You can construct web request to be like
/api/assets()?$filter=Name%20eq%20'Your Name'&$top=1
You can also filter by other properties
Have you tried REST API that are used when creating, processing, managing, and delivering Assets. https://msdn.microsoft.com/en-us/library/azure/hh974277.aspx#list_an_asset but I do think we can list asset via a name directly since id is an unique indentifier of asset entity. PHP Azure SDK leverages assetId to get an Asset as well:
public function getAsset($asset)
{
$assetId = Utilities::getEntityId(
$asset,
'WindowsAzure\MediaServices\Models\Asset'
);
return Asset::createFromOptions($this->_getEntity("Assets('{$assetId}')"));
}
But in my case, I don't have asset id with me. I just have asset name
alone. Now how do I get the asset details using this?
Here are some test function code snippets for your reference:
public function testListAllAssets(){
// Setup
$asset1 = new Asset(Asset::OPTIONS_NONE);
$asset1->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
$asset2 = new Asset(Asset::OPTIONS_NONE);
$asset2->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
// Test
$asset1 = $this->createAsset($asset1);
$asset2 = $this->createAsset($asset2);
$result = $this->restProxy->getAssetList();
// Assert
$this->assertCount(2, $result);
$names = array(
$result[0]->getName(),
$result[1]->getName()
);
$id = array(
$result[0]->getId(),
$result[1]->getId()
);
$this->assertContains($asset1->getName(), $names);
$this->assertContains($asset2->getName(), $names);
$this->assertContains($asset1->getId(), $id);
$this->assertContains($asset2->getId(), $id);
}
public function testGetAnAssetReference(){
// Setup
$assetName = TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix();
$asset = new Asset(Asset::OPTIONS_NONE);
$asset->setName($assetName);
$asset = $this->createAsset($asset);
// Test
$result = $this->restProxy->getAsset($asset);
// Assert
$this->assertEquals($asset->getId(), $result->getId());
$this->assertEquals($asset->getName(), $result->getName());
}
From: https://github.com/Azure/azure-sdk-for-php/blob/master/tests/functional/WindowsAzure/MediaServices/MediaServicesFunctionalTest.php
According to my testing, it seems that we can’t use Asset’s name to get the information of asset in Media Service.
$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
new MediaServicesSettings("**","******"));
$asset = new Asset(Asset::OPTIONS_NONE);
$asset->setName('For-Test-wmv-Source');
//$asset don't have the value of id,
// unless execute ‘createAsset($asset)’, "$asset1" will be set the ID
$asset1 =$mediaServiceProxy->createAsset($asset);
$result2=$mediaServiceProxy->getAsset($asset1);
PHP SDK support the method named “getAsset($asset)”. Actually, the method get the Asset information by Asset id, just like the Aka's reference code.And Azure REST API don’t support the method queried by Asset’s name.
Please refer to the official document.
Alternative approach is that you can store your assets information (such as Id,URl,name and ect.) into Azure table storage when you upload them into media service. If you want to use it, you can fetch and filter the data of Asset’s name you wants from table storage.

Creating Multiple Custom Attibutes For Product with google-api-php-client

According to that answer https://support.google.com/merchants/answer/4588281?hl=en-GB
if I want set multiple promotions ids for the product with the API I can specify multiple lines of:
<sc:attribute name="promotion_id">PROMOTION_ID</sc:attribute>
I am using this lib https://github.com/google/google-api-php-client
My question is how can i do it with this library. Should I use custom attributes? for example.
$feed_entry = new Google_Service_Content_Product();
$promotions_ids = array (20,21,22);
foreach ($promotions_ids as $promotion_id ) {
$promotion = new Google_Service_Content_ProductCustomAttribute();
$promotion->setName('promotion_id');
$promotion->setValue($promotion_id);
$feed_entry->setCustomAttributes($promotion);
}
But that would just set this attribute over again for different ids. I am not even sure if I am doing this in a right way. Probably missing something. The full code example would be really helpful.
I couldn't find a definitive code sample for PHP. That being said, if you look at API libraries for other languages you find that:
For Java it uses a List<ProductCustomAttribute>:
public Product setCustomAttributes(java.util.List<ProductCustomAttribute> customAttributes)
Source
For JavaScript it uses a map:
setCustomAttributes(map)
setCustomAttributes({ 'size': 'Large', 'color': 'Green' })
Source
Conclusion:
there's a very good chance the PHP method in question uses an array of Google_Service_Content_ProductCustomAttribute objects:
public function setCustomAttributes($customAttributes)
$feed_entry = new Google_Service_Content_Product();
$promotions_ids = array (20,21,22);
$customAttributes = array();
foreach ($promotions_ids as $promotion_id ) {
$promotion = new Google_Service_Content_ProductCustomAttribute();
$promotion->setName('promotion_id');
$promotion->setValue($promotion_id);
$customAttributes[] = $promotion;
}
$feed_entry->setCustomAttributes($customAttributes);
Try it!

How would I format Zend_Form_Element_Radio so the label comes after the input

I have been trying to implement the solution in an earlier version of this question at:
How would I format Zend_Form_Element_Radio so the label follows the input?
By creating an extended helper MyLib_View_Helper_FormRadio but must be missing something obvious with this!
My question is how do I get Zend_Form_Element_Radio() to use this now instead of the version of the helper in Zend_View_Helper_FormRadio?
I thought initially that this was done by creating the element with
$radio = new MyLib_View_Helper_FormRadio();
but realised its not.
Changing the way the label and input are ordered in the Zend_View_Helper_FormRadio.php does the trick but I realise that the Zend files should not be altered.
If anyone can help me with t his I would be very grateful!
In your MyLib_View_Helper_FormRadio class, you have a method, like this (it's an example):
public function formRadioCustom($name, $value = null, $attribs = null,
$options = null, $listsep = "<br />\n"){...}
So to call it instead of formRadio of Zend_View_Helper_FormRadio, if I'm not mistaken, you have to do:
$element->addDecorators(array(array('ViewHelper',array('helper' => 'formRadioCustom'))));
And in your bootstrap add a method to add helper like this:
protected function _initViewHelpers() {
$view = new Zend_View();
$view->->addHelperPath('MyLib/View/Helper/', 'MyLib_View_Helper');
}

Categories