Getting the external ids from fields in Podio app - php

I'm creating a class with different methods to get values out of Podio fields.
My idea was to create a program being able to get an X number of fields from an app. And it should be possible to delete fields or create new fields in the Podio app.
I have created the application but somehow the program stops getting the values from the app, when I make some changes in Podio. I think the issue is in this method. This method should get all the external values of the fields, but the method stops getting some of the them when I change the app in Podio.
I hope it makes sense. Otherwise please ask me for further details. The method is here:
public function getAllExternalIds(){
// Get the first item of the app, only 1 item
$items = PodioItem::filter($this->app_id,array('limit' => 1));
// Create external_id array
$exIds = array();
// find all the external Ids of the item and put them in the array
for($j=0;$j <count($items['items'][0]->fields) ;$j++){
$exIds[$j] = $items['items'][0]->fields[$j]->external_id;
}
//return the external Id array;
return $exIds;
}
The same issue is in this method:
public function getAllFieldNames(){
$items = PodioItem::filter($this->app_id,array('limit' => 1));
$fieldNames = [];
for($j=0;$j <count($items['items'][0]->fields) ;$j++){
$fieldNames[$j] = $items['items'][0]->fields[$j]->label;
}
return $fieldNames;
}

Podio is extremely flexible platform and you can change app template (list of fields) and keep existing items unchanged, and I'm afraid that this is exactly what you are facing.
Let's review it on example:
There is an app, let's call it 'Projects', and app template has only 2 fields: 'Title' and 'Deadline'.
Then you create 1 item with 'Title' and 'Deadline' fields.
Then you can change app template and add 'Details' field and remove 'Deadline' field.
And create 1 more item.
And then you can change app template again and remove both
'Title' and 'Details' fields and add 'Responsible' field.
Now items_1 has 'Title' and 'Deadline' fields and your methods will get those 2 fields, and item_2 has 'Title' and 'Details' fields, and app template actually has only 'Responsible' field and doesn't match none of those.
So, you should probably use https://developers.podio.com/doc/applications/get-app-22349 method to read current app configuration and settings.

Related

How to make referenced column sortable in drupal 7 view

I have one view in Drupal 7, which displays user information like (Name, address, Status, etc..). I have one column in this (Table)view as "Published event". Basically events are created by users do I want to make this column sortable. I have attached image for more reference.
I tried with applying relationship but no success.
table settings
my handler code is like below :
$handler->display->display_options['sorts']['event_count_published'] ['id'] = 'event_count_published';
$handler->display->display_options['sorts']['event_count_published'] ['table'] = 'search_api_index_user_search_index';
$handler->display->display_options['sorts']['event_count_published'] ['field'] = 'event_count_published';
$handler->display->display_options['sorts']['event_count_published'] ['order'] = 'DESC';
'mail' => array(
'sortable' => 1,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'event_count_published' => array(
'align' => '',
'separator' => '',
'empty_column' => 0,
'sortable' => 1,
),
above code is in "tcd_reporting.views_default.inc" file, if I put 'sortable => 1', it still does not provide sorting
field is created by below code:
$properties['event_count_published'] = array(
'label' => t('Published Events'),
'description' => t('Number of published events authored by user.'),
'type' => 'integer',
'getter callback' => 'tcd_event_content_type_count_published_get',
'computed' => TRUE,
'entity views field' => TRUE,
);
[Introduction] Which function is responsible for 'click sort' in views?
Click sort -this checkbox from your second screen- in views table settings is function which is enabled only for fields which have properly defined handlers. As you may know each field in views have few handlers (for displaying, filtering, sorting). And for click sort to be possible on specified column its field handler must have two functions defined: click_sortable and click_sort. First one just need to return true, while second need to properly implements sorting on view. For example see handler: [views_module_path]/handlers/views_handler_field.inc.
Your case:
It seems that your column "Published event" have defined handler which does not have click_sortable and click_sort functions (or click_sortable simply returns false).
Possible fix:
Find place where you defined your view source (it depends on how you informed views about it, if I understand its something like "User info" - maybe in hook_entity_info function or hook_views_data function), check what handler is assigned to your "Published event" field and change it.
It's hard to tell where you need to look as it depends on your implementation.
I suggest you to try create hook_views_data_alter function and dpm() it for start. Later you can alter it like that:
mymodule_views_data_alter(&$data) {
$data['some_view_info']['published_event']['field']['handler'] = 'views_handler_field_numeric';
}
Edit 1
First could you tell where this code is? Is it inside handler class, or maybe some views hook? Views gives you a lot of flexibility but this make them hard to understand, and I'm not sure what exactly you achieve and how.
Assuming your field works properly you can try to simply enable click sort.
Example: I created hook_views_data_alter function to see content of views data
function mymodule_views_data_alter(&$data) {
dpm($data,'d');
}
You might need to clear cache to see dpm of *_alter hooks.
Inside dpm'ed array I found "users" for generic example, and its field name looks like this:
I suggest you to try alter your field with click_sortable = TRUE and see what happens. If this wont help please provide more information about your field, how you created it, how it looks in hook_views_data_alter and which handlers it has defined.
Edit 2
Ok, so you have your views exported to code into views_default file. But this only allows you to export view you created from database to code, so it is basically a reflection of what you done in views web editor (eg. page yourwebsite.com/admin/structure/views/view/your_view_name/edit). What you need to do is to change behavior of one of your fields so it became sortable (add click_sortable and click_sort functions in handler class) or change handler of this field to one with sorting option (change field handler to other one like views_handler_field_numeric). If you don't have experience in creating handlers and this is one of generic handlers i suggest you to go back to my Edit 1, examine your dpm, and try to alter $data array to find solution.
Edit 3
Little explanation to prevent confusion. When creating new view you select collection on which this particular view base on (simpliest example - it may be MySQL table, and view will use SQL queries to retrieve data from it). By digging down we have:
Collection - eg. User which is database table user, it is what you select as source when creating new view.
Field - eg. mail which is database column mail, this fields you add to your view.
Field handler - eg. views_handler_field_numeric, this is class name of handler to use by specified field
Now, if you don't created your own handler then your field "Published event" have one of generic views handler. You shouldn't ever change code of contributed modules - especially so widely used as views handlers. That's why my suggestion to add functions click_sortable and click_sort is incorrect. Instead you should change handler responsible for field "Published event".
Best way is to define proper handler in place where you define your field "Published event". If it's somehow impossible the only way I can think of is hook_views_data_alter see docs for more info and examples. I suppose you should try to redefine handler of your field to generic numeric handler views_handler_field_numeric as it should have full sorting functionallity, or try to add click_sortable property to field array as you can see in first image of my post, but I can't provide you fully tested example.

Symfony 1.4 linkToDeleteMenu Confirm not making JavaScript

I had to make an entity called ProfileSchema with some fields, which one is Project_id. I needed to make a List, Edit, New, etc., for which I used the admin generator. The problem was as follows.
I have a list of projects, which they link to the list of the ProfileSchemas that have the same project_id, so I needed a route like: /backend/project/:project_id/ListProfileSchema
I couldn't find a way to do this with the admin generator (getting the project_id into the route), so I coded by hand all the routes (around 12, the new, edit, delete, batch actions, etc.), and change all the code generated by the admin generator to use the project_id passed as a parameter and the code generated by the adming generator as a guide.
==Questions==
Is there a way more simple to do something like this?
Now I need to add the confirmation JavaScript on the delete action on the actions of the list, which is generated by the method linkToDeleteMenu
public function linkToDeleteMenu($object, $params){
$url = url_for('project_delete_profile_schema', array('project_id' => $this->project_id, 'profile_schema_id' => $object->getId() ));
// $url = '/backend/project/1/DeleteProfileSchema/16'
return link_to(__($params['label'], array(), 'sf_admin'), $url, $object, array('confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm'], 'project_id' => $this->project_id, 'profile_schema_id' => $object->getId()));
}
The above code doesn't get the JavaScript. This code below generates the link well and it works, but I can't make the confirmation for the JavaScript appear.
return link_to(__($params['label'], array(), 'sf_admin'), $url, $object);
And the confirmation data is set, as replacing $url with $this->getUrlForAction('delete') does the trick but with the incorrect URL (the one generated by the admin generator).
By the way, I searched a lot trying to find something similar. The only similar question was this:
Routing exception in symfony ("The "/league/:id_league/members/new" route has some missing mandatory parameters (:id_league)")
But the answer didn't help me (as the default value is not dynamic and can't get to override it)
I forgot to close this question. After some time i found that the solution was this:
return link_to('Delete', 'project_delete_profile_schema', array('project_id' => $object->getProjectId(), 'profile_schema_id' => $object->getId()), array( 'confirm' => !empty($params['confirm']) ? __($params['confirm'], array(), 'sf_admin') : $params['confirm']));
You pass the name displayed for the link as the 1st argument , the route name as the 2nd arguments, and the needed variables in the array in the 3rd parameter to generate the route. Finally, you pass the array to generate the confirmation code. My route is
project_delete_profile_schema:
url: /project/:project_id/DeleteProfileSchema/:profile_schema_id

Cakephp Web Service issue on "add"

I am trying to setup a simple Restfull api using cakephp.
I followed the documentation from the Cakephp site.
But I am encountering the following issue.
I am using Postman plugin to test the Api calls.
I have a table called 'Categories' and in its controller have an action add().
public function add() {
if ($this->request->is('post')) {
$this->Category->create();
if ($this->Category->save($this->data)) {
$message = 'Saved';
}
else {
$message = 'Error';
}
$this->set(array(
'message' => $message,
'_serialize' => array('message')
));
}
}
and in db, I have Category table with schema (id (int 11, PK, A_I), name(varchar(40)), created (datetime), modified(datetime)).
So from postman I send POST requests to http://myProject/categories.json.
From my understanding when i send key:name and value: test, it must save into the database, which works fine. But I must get error when I replace the "key" with something other than name. i.e for exmaple key: name123 and value: test2, But this data too is getting saved in the db without any error except for the name field. i.e it is saving (id:some value, name:"", created:somevalue, modified:someValue)
I dont understand how. Any help will be greatly appreciated.
You will need to provide more info because what you say doesn't make sense. For example what do your posted data look like? Is there any kind of validation in the model? How do you expect a key/value pair to be stored in only one field (specifically name) in the DB?
What happens now is that you tell Cake to save the supplied data ($this->Category->save($this->data)) although you don't check (via cake's validation rules in the model or any other means) that it contains useful arguments and especially Category.name.
As computers will just do what you tell them to do and not what you imply or have in mind, it goes on and sends the calculated created/modified fields to the DB which in turn saves them with the autoincremented ID. Since name doesn't have a UNIQUE or NOT NULL field condition in the DB it is saved as NULL or empty string.

Save multiple hasMany data with saveAll() in CakePHP without writing id's in the view

I FINALLY got my hasMany data to save using saveAll() - (an Event that hasMany Schedules).
I got it to work by repeating through the $this->data['Schedule'] data on the events/admin_edit.ctp, and building out all the fields for any/all schedules that are related to that event.
This seems fine (I think), but my question/problem is - I had to add the Schedule.id and Schedule.event_id fields as hidden fields so it'd know what data to save. This seems awfully unsecure/wrong... 1) is it the right way to do it? and 2) Couldn't someone just edit the field to another ID, and hit save to update a different event's information?
My next assumption is that I'll have to build in some kind of checks into the controller before doing the saveAll()... but the more I write, the more complicated it's going to get, and the less Cake-like it seems.
Any thoughts/suggestions on how to better do what I'm doing, or insight as to what to check before doing the saveAll() is greatly appreciated.
I assume you have users that are allowed to edit their own events. If that's the case, the easiest way is to add a validation rule that verifies that the user is allowed to edit the submitted schedule.
In your action, before the save() is called, inject the current user id into each record. ie:
$this->data['Schedule'][0]['user_id'] = $this->Auth->user('id');
This may not work exactly, but should get you close. In your Schedule model, add a validation rule:
var $validate = array(
'user_id' => array(
'rule' => 'checkAuth'
'message' => 'Nice try buddy.',
'on' => 'update'
)
);
function checkAuth() {
$authorized = true;
if(!$this->hasAny(array(
'Schedule.id'=>$this->data['Schedule']['id'],
'Schedule.user_id' => $this->data['Schedule']['user_id']))) {
$authorized = false;
}
return $authorized;
}

Getting list of products by category in Magento using SOAP-based API

I need to get all products belonging to a specific category in Magento using the web services API. I tried this method:
$product_filter = array(
'category_ids' => array('eq' => '41')
);
$product_templates = $magento_client -> call($magento_session, 'product.list');
But it returns an error. I can only assume it's because category_ids is an array, so it won't really ever equal one specific value.
I did some research and found another method called category.assignedProducts and tried:
$product_templates =
$magento_client ->
call($magento_session, 'catalog_category.assignedProducts', array('41'));
But this returned an 'Access Denied' error. I went and looked at my sandbox of Magneto and saw that 'Assigned Products' has 3 options: 'Remove', 'Update', 'Assign', and I know that the admin for the system I'm linking to has set my access to 'Read-Only'. So I'm guessing that we'd have to check off 'assign' in that list, which would give me more access than they want to give.
I could retrieve all of the data and do the filtering on my end, but I wanted to check if anyone knew of a better way.
Thanks.
assignedProducts sounds like what you need but you shouldn't need to be passing along an array but an integer value and the store ID or code.
See the arguments required: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_category#catalog_category.assignedproducts
I think I found the answer on http://www.magentocommerce.com/boards/viewthread/207099/ which basically says it can't be done from the product any more. We must now look at the problem from the category point of view.
category_ids no longer works in 1.4, they changed the table
structures around so that the categories are not available on the
product. Use the code below to get the products from the category and
then do a catalog_product.list call. To make it faster you can also
create a custom api solution to combine these in Magento and perform
just one call instead of two.
$proxy = new SoapClient($soapUrl.’api/soap/?wsdl’); $sessionId =
$proxy->login($apiUser, $apiPass);
$productList = $proxy->call($sessionId,
‘catalog_category.assignedProducts’, array(’4’));
$proxy->endSession($sessionId); print_r($productList);

Categories