Collecting a referenced app's values - podio

I am trying to cleanup and optimize my come I am running on podio's API. What I am currently doing is using the filter query to return a collection from one app. I then loop over that collection. On each item I use Podio get_field_value to return the value(s) of a field in a referenced app. This creates a lot of API calls. I would like to retrieve everything in one API call Here is a simple version of my current code:
$collection = PodioItem::filter(WHSE_ID, array(
"filters" => array(
WHSE_EQUP_STATUS => array(2),
),
"sort_by" => WHSE_LOAD_IN,
"sort_desc" => false,
"limit" => 50
)
);
foreach ($collection as $item) {
// Table-A ID
$whId = $item->item_id;
// Referenced App Item(s)
$nucId = $item->fields[0]->values[0]->item_id;
// Get Referenced App Item Field
$app_b_value = PodioItem::get_field_value($nucId, NUC_LOAD_OUT);
echo $app_b_value;
}
Is there a more efficient way of doing this? I am thinking inline with the way you would use JOIN in a mysql query.
Thank you for any help you can provide!

if you are trying to get value from each item from filtered collection, you don't need to make podio calls each time.
Podio filter call will give you item with values. you just have to get value from each item.
like following
foreach ($podioFilterData['items'] as $itemData) {
$itemFields = $itemData['fields'];
foreach ($itemFields as $field) {
$value = $field['values'][0];
}
}

Related

How to filter a list of Pages by Category to display as a navigation

In Sitefinity v12.x I would like to create a widget that allows the user to select one or more Categories (Hierarchical Taxons) to use as filter criteria, and after which the widget would query for Pages that have these Categories assigned to them. This seems simple enough on the surface but I can't seem to pull it all together.
I've added "Category" as a Custom Field to the Page data and I've created my test pages. What I'm struggling with is forming the query that can access the custom field "Category" and then compare those against the categories provided by the user.
I've tinkered for awhile but it seems the issue I'm having is retrieving the Categories assigned to a Page from within the Linq query. I've tried var categories = pageNode.GetValue("Category") on it's own and that works as expected. But when I try to use the .GetValue("Category") method in a Linq query this does not seem to be valid, here is an example of what I mean:
var pageManager = PageManager.GetManager();
var pages = pageManager.GetPageDataList().Where(pageData =>
(pageData.Culture == "en" ||
pageData.NavigationNode.LocalizationStrategy != Telerik.Sitefinity.Localization.LocalizationStrategy.Split) &&
pageData.NavigationNode.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard &&
pageData.NavigationNode.RootNodeId == Telerik.Sitefinity.Abstractions.SiteInitializer.CurrentFrontendRootNodeId &&
pageData.Status == ContentLifecycleStatus.Live)
.Select(x => x.NavigationNode);
foreach (PageNode page in pages)
{
// This properly retrieves Categories assigned to a Page in the Debug window
var categories = page.GetValue("Category");
}
// This does not work, error message below .Any() reads: 'object' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'object' could be found
var categoryPages = pages
.Where(pageData => pageData.GetValue("Category").Any())
.ToList();
Is there a way I can use/access the Custom Field "Category" on a Page from within a Linq query? Or do I have to go about this some other way?
Thank you in advance for any guidance!
As a note, don't forget to filter the pages for visible and not deleted.
pageData.Status == ContentLifecycleStatus.Live && pageData.IsDeleted == false && pageData.Visible == true)
You should cast pageData.GetValue("Category") to either Guid? or IEnumerable<Guid?> depending how exactly you have set the custom field up.
Thank you for the tips everyone! I was able to sort it out by specifying the type of the Custom Value in the Linq query, like so: pageData.GetValue<TrackedList<Guid>>("Category"), here's what I came up with:
var pageManager = PageManager.GetManager();
var pages = pageManager.GetPageDataList().Where(pageData =>
(pageData.Culture == "en" ||
pageData.NavigationNode.LocalizationStrategy != Telerik.Sitefinity.Localization.LocalizationStrategy.Split) &&
pageData.NavigationNode.NodeType == NodeType.Standard &&
pageData.NavigationNode.RootNodeId == Telerik.Sitefinity.Abstractions.SiteInitializer.CurrentFrontendRootNodeId &&
pageData.Status == ContentLifecycleStatus.Live && pageData.Visible == true)
.Select(x => x.NavigationNode);
var filteredPages = pages
.Where(pageData => categoriesQuery.All(c => pageData.GetValue<TrackedList<Guid>>("Category").Contains(c)))
.ToList();

Google Sheet API - How to get only updated rows

I could not able to find in the documentation on how to get only updated records/rows from Google Sheets API.
Is there a way, that I can get a timestamp of each record when it was last modified?
any guidance or any links that would solve this issue.
Thanks!
You cannot do this directly with Sheets API. You can keep track of the changes in a file using Drive API, though, but I don't think this is what you want to do.
I'd propose using an onEdit trigger using Apps Script. Every time the spreadsheet is modified, you could retrieve the data of the edited range and store it somewhere, as well as the current date.
It could be something on the following lines:
function onEdit(e) {
var timestamp = new Date();
var range = e.range;
var editedRow = range.getRow();
// Store timestamp and editedRow index somewhere you can retrieve it later (it could be in the spreadsheet itself)
}
Update:
You can create the trigger remotely using Apps Script API. First you should create a project bound to your spreadsheet and then add the corresponding code by calling projects.updateContent (you should add two files, the script itself, which contains the onEdit trigger, and the manifest file). Just beware that you can only use simple triggers with this API, not installable ones. But in your situation, that's more than enough.
I hope this is of any help.
WRITE OPERATION:
For $response = $service->spreadsheets_values->update() process (Writting file after creating it), response will be as follow:
Google_Service_Sheets_UpdateValuesResponse Object
(
[spreadsheetId] => XXX
[updatedCells] => 7
[updatedColumns] => 7
[updatedDataType:protected] => Google_Service_Sheets_ValueRange
[updatedDataDataType:protected] =>
[updatedRange] => Sheet1!A1:G1
[updatedRows] => 1
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
To Get Rows = $response->getUpdatedRows();
To Get Cells = $response->getUpdatedCells();
To Get Columns= $response->getUpdatedColumns();
and so on...
APPEND OPERATION:
For $response = $service->spreadsheets_values->append() process, response will be as follow:
Google_Service_Sheets_AppendValuesResponse Object
(
[spreadsheetId] => XXXX
[tableRange] => Sheet1!A1:G1
[updatesType:protected] => Google_Service_Sheets_UpdateValuesResponse
[updatesDataType:protected] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
[updates] => Array
(
[spreadsheetId] => XXXX
[updatedRange] => Sheet1!A2:G7
[updatedRows] => 6
[updatedColumns] => 7
[updatedCells] => 42
)
)
[processed:protected] => Array
(
)
)
To Get Rows = $response->getUpdates()->getUpdatedRows();
To Get Cells = $response->getUpdates()->getUpdatedCells();
To Get Columns= $response->getUpdates()->getUpdatedColumns();
and so on...

Filter Podio Items by Item ID

I'm having a bit of an issue getting a collection of Podio items from an app by item ids.
According to this post, Andreas said that "... you can now filter by item_id (and app_item_id). Just use item_id or app_item_id as the filter key and give it an array of item ids ...".
So I'm trying to get a bunch of items in one shot to reduce API calls with:
$attributes = ["filter" => [
"item_id" => [12345,23456]
]];
$items = PodioItem::filter( $app_id, $attributes );
But I'm always getting all items back from the app, not just the 2 items listed in the filter.
Anyone come across this anomaly before? Workarounds?
You are passing the $attributes array in the wrong format.
You have to pass it in filters array like,
$attributes = ["filters" => [
"item_id" => [12345,23456]
]];
$items = PodioItem::filter( $app_id, $attributes );
You will get back only the mentioned items [12345,23456].

How do you get the value of a "embed"?

I have a link field called lien. When I get it from the API through the Item it belongs to, I receive the following array:
[lien] => Array(
[0] => Array(
[embed] => 49935230
[file] => 129256002
)
)
I have no problem with the file.
How do you get the URL value?
The Embeds documentation: https://developers.podio.com/doc/embeds
A similar issue exists when getting the value of a category field through the Item object. It's an array of the selected option_id, it doesn't hold the option_text. The workaround is to get the corresponding App object and search for the option_text using the provided option_id.
The field's values are returned as a collection of embed objects. You can see documentation at: http://podio.github.io/podio-php/fields/#linkembed-field
E.g.:
$item = PodioItem::get_basic(123);
$field_id = 'embed';
$collection = $item->fields[$field_id]->values;
foreach ($collection as $embed) {
print "Embed id: ".$embed->embed_id;
print "Embed URL: ".$embed->original_url;
}

Accessing magento's checkout/cart using REST API

I'm trying to integrate a cart-synchronisation-solution for my rest-clients.
The goal should be that I can have the same cart wherever I access my store from.
So I'll have to first of all deliver the existing items out to the client using the authenticated api-user.
But I get stuck at the very beginning:
protected function _retrieveCollection()
{
$cart = Mage::getSingleton('checkout/cart')->getQuote();
$cart->setCustomerId($this->getApiUser()->getUserId());
$cart->setStoreId(4);
$cart->load();
return $cart->getAllItems();
}
returns an empty array even though I have products in my cart.
Anyone any hints? Have that feeling I'm totally on the wrong side...
Found a solution. Getting the quote by Customer which is the other way around worked pretty well:
Mage::app()->setCurrentStore(4);
$cart = Mage::getModel('sales/quote')->loadByCustomer($this->getApiUser()->getUserId());
$items = array();
foreach ($cart->getAllVisibleItems() as $key => $item) {
$items[] = array(
'name' => $item->getName(),
'entity_id' => $item->getProductId(),
'description' => $item->getDescription(),
'final_price_with_tax' => $item->getBasePriceInclTax(),
'qty' => $item->getQty()
);
}