2017-07-06 81 views
1

我正在使用php包裝,嘗試創建項目,一切正常,項目正在創建,但我無法更改狀態,嘗試了不同的方式,但無法找到正確的方法。Podio api - 創建項目時如何設置類別字段

需要更改狀態爲 「關閉」 - http://prntscr.com/fsrwc3

代碼不工作:

$fields = new PodioItemFieldCollection([ 
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]), 
]); 
$item = new PodioItem([ 
    'app' => new PodioApp($app_id), 
    'fields' => $fields 
]); 
$item->save(); 

$fields = new PodioItemFieldCollection([ 
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]), 
]); 
$item = new PodioItem([ 
    'app' => new PodioApp($app_id), 
    'fields' => $fields 
]); 
$item->save(); 
$get_item = PodioItem::get_basic($item->item_id); 
$get_item->fields['status']->values = ['id'=>13]; 
$get_item->save(); 

後創建(new PodioItem...後)項,如果我在這之後得到場代碼(只是得到$item->fieldsPodioItem::get_basic...),我可以看到正確的狀態,只有在代碼中,只有立即創建項目後,但如果我在另一個代碼中獲得這個項目(只是PodioItem::get_basic...),我會看到默認值,所以代碼不會改變狀態,看起來像我只看到一些緩存。

如果我在一個腳本創建項目:

$fields = new PodioItemFieldCollection([ 
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]), 
]); 
$item = new PodioItem([ 
    'app' => new PodioApp($app_id), 
    'fields' => $fields 
]); 
$item->save(); 

然後,在另一個腳本更新領域,這將是改變:

$get_item = PodioItem::get_basic('639637317'); 
$get_item->fields['status']->values = ['id'=>13]; 
$get_item->save(); 

更新 - 調試信息:

通過測試代碼獲取日誌 -

PodioItem::create($app_id, ['fields' => ['status'=>[13], 'category'=>[3], 'contract-type'=>[4]]]); 

(簡單變種,用於創建一個項目,有一個像new PodioItem...同樣的問題)

所有領域都有類別類型,但:

status - 有直列式顯示 - 不chnages

category - 有下拉秀類型 - 正在改變

contract-type - 有下拉秀類型 - 正在改變

登錄:

2017-07-08 11:07:22 200 POST /item/app/12152727/ 
2017-07-08 11:07:22 Request body: {"fields":{"status":[8],"category":[3],"contract-type":[4]}} 
2017-07-08 11:07:22 Reponse: { 
"presence": { 
    "ref_type": "item", 
    "ref_id": 641331142, 
    "user_id": 4194774, 
    "signature": "c165b85090e6ad28e74ae4baf93ee56113f88bc9" 
}, 
"app": { 
    "status": "active", 
    "sharefile_vault_url": null, 
    "name": "Projects", 
    "default_view_id": null, 
    "url_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new", 
    "icon_id": 378, 
    "link_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new", 
    "app_id": 12152727, 
    "current_revision": 141, 
    "item_name": "Project", 
    "link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects", 
    "url": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects", 
    "url_label": "projects", 
    "config": { 
     "item_name": "Project", 
     "icon_id": 378, 
     "type": "standard", 
     "name": "Projects", 
     "icon": "378.png" 
    }, 
    "space_id": 3466816, 
    "icon": "378.png" 
}, 
"created_on": "2017-07-10 15:31:16", 
"last_event_on": "2017-07-10 15:31:16", 
"linked_account_data": null, 
"sharefile_vault_folder_id": null, 
"app_item_id_formatted": "3988", 
"recurrence": null, 
"title": "ACSC", 
"participants": {}, 
"created_by": { 
    "user_id": 4194774, 
    "name": "Anton Mikhailov", 
    "url": "https:\/\/podio.com\/users\/4194774", 
    "type": "user", 
    "image": null, 
    "avatar_type": "file", 
    "avatar": null, 
    "id": 4194774, 
    "avatar_id": null, 
    "last_seen_on": "2017-07-10 15:31:15" 
}, 
"priority": 641331142.0, 
"created_via": { 
    "url": null, 
    "auth_client_id": 25162, 
    "display": true, 
    "name": "importer", 
    "id": 25162 
}, 
"subscribed_count": 1, 
"reminder": null, 
"ref": null, 
"revision": 0, 
"app_item_id": 3988, 
"link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/3988", 
"item_id": 641331142, 
"sharefile_vault_url": null, 
"rights": ["subscribe", "grant", "add_conversation", "rate", "update", "delete", "add_file", "grant_view", "view", "comment", "add_task"], 
"fields": [{ 
    "status": "active", 
    "type": "category", 
    "field_id": 93352415, 
    "label": "Division", 
    "values": [{ 
     "value": { 
      "status": "active", 
      "text": "ACSC", 
      "id": 3, 
      "color": "D2E4EB" 
     } 
    }], 
    "config": { 
     "default_value": null, 
     "unique": false, 
     "description": null, 
     "hidden_create_view_edit": false, 
     "required": true, 
     "mapping": null, 
     "label": "Division", 
     "visible": true, 
     "delta": 5, 
     "hidden": false, 
     "settings": { 
      "multiple": false, 
      "options": [{ 
       "status": "active", 
       "text": "ACSE", 
       "id": 1, 
       "color": "DCEBD8" 
      }, { 
       "status": "active", 
       "text": "ACSB", 
       "id": 2, 
       "color": "F7F0C5" 
      }, { 
       "status": "active", 
       "text": "ACSC", 
       "id": 3, 
       "color": "D2E4EB" 
      }], 
      "display": "dropdown" 
     } 
    }, 
    "external_id": "category" 
}, { 
    "status": "active", 
    "type": "category", 
    "field_id": 148215928, 
    "label": "Contract Type", 
    "values": [{ 
     "value": { 
      "status": "active", 
      "text": "No Contract", 
      "id": 4, 
      "color": "DDDDDD" 
     } 
    }], 
    "config": { 
     "default_value": null, 
     "unique": false, 
     "description": null, 
     "hidden_create_view_edit": false, 
     "required": true, 
     "mapping": null, 
     "label": "Contract Type", 
     "visible": true, 
     "delta": 7, 
     "hidden": false, 
     "settings": { 
      "multiple": false, 
      "options": [{ 
       "status": "active", 
       "text": "PO \/ Purchase \/ T&M", 
       "id": 1, 
       "color": "FFD5C2" 
      }, { 
       "status": "active", 
       "text": "Original Contract", 
       "id": 2, 
       "color": "D2E4EB" 
      }, { 
       "status": "active", 
       "text": "Service Rider", 
       "id": 3, 
       "color": "DCEBD8" 
      }, { 
       "status": "active", 
       "text": "No Contract", 
       "id": 4, 
       "color": "DDDDDD" 
      }], 
      "display": "dropdown" 
     } 
    }, 
    "external_id": "contract-type" 
}, { 
    "status": "active", 
    "type": "category", 
    "field_id": 93034840, 
    "label": "Instal Status", 
    "values": [{ 
     "value": { 
      "status": "active", 
      "text": "Closed", 
      "id": 13, 
      "color": "E1D8ED" 
     } 
    }], 
    "config": { 
     "default_value": null, 
     "unique": false, 
     "description": null, 
     "hidden_create_view_edit": false, 
     "required": true, 
     "mapping": null, 
     "label": "Instal Status", 
     "visible": true, 
     "delta": 13, 
     "hidden": false, 
     "settings": { 
      "multiple": false, 
      "options": [{ 
       "status": "deleted", 
       "text": "To Be Reviewed", 
       "id": 2, 
       "color": "F7F0C5" 
      }, { 
       "status": "deleted", 
       "text": "ACS Accounting Review", 
       "id": 5, 
       "color": "FFD5C2" 
      }, { 
       "status": "deleted", 
       "text": "Ignite Setup", 
       "id": 10, 
       "color": "DCEBD8" 
      }, { 
       "status": "active", 
       "text": "To Be Scheduled", 
       "id": 8, 
       "color": "D2E4EB" 
      }, { 
       "status": "active", 
       "text": "In Progress", 
       "id": 6, 
       "color": "DCEBD8" 
      }, { 
       "status": "active", 
       "text": "Warranty", 
       "id": 11, 
       "color": "F7F0C5" 
      }, { 
       "status": "active", 
       "text": "Complete", 
       "id": 3, 
       "color": "D1F3EC" 
      }, { 
       "status": "deleted", 
       "text": "Closed", 
       "id": 7, 
       "color": "DDDDDD" 
      }, { 
       "status": "active", 
       "text": "Cancelled", 
       "id": 9, 
       "color": "DDDDDD" 
      }, { 
       "status": "deleted", 
       "text": "VA in Progress", 
       "id": 4, 
       "color": "E1D8ED" 
      }, { 
       "status": "deleted", 
       "text": "Submitted", 
       "id": 1, 
       "color": "F7F0C5" 
      }, { 
       "status": "active", 
       "text": "On Hold", 
       "id": 12, 
       "color": "F7D1D0" 
      }, { 
       "status": "active", 
       "text": "Closed", 
       "id": 13, 
       "color": "E1D8ED" 
      }], 
      "display": "inline" 
     } 
    }, 
    "external_id": "status" 
}], 
"initial_revision": { 
    "item_revision_id": 1664054437, 
    "created_via": { 
     "url": null, 
     "auth_client_id": 25162, 
     "display": true, 
     "name": "importer", 
     "id": 25162 
    }, 
    "created_by": { 
     "user_id": 4194774, 
     "name": "Anton Mikhailov", 
     "url": "https:\/\/podio.com\/users\/4194774", 
     "type": "user", 
     "image": null, 
     "avatar_type": "file", 
     "avatar": null, 
     "id": 4194774, 
     "avatar_id": null, 
     "last_seen_on": "2017-07-10 15:31:15" 
    }, 
    "created_on": "2017-07-10 15:31:16", 
    "user": { 
     "user_id": 4194774, 
     "name": "Anton Mikhailov", 
     "url": "https:\/\/podio.com\/users\/4194774", 
     "type": "user", 
     "image": null, 
     "avatar_type": "file", 
     "avatar": null, 
     "id": 4194774, 
     "avatar_id": null, 
     "last_seen_on": "2017-07-10 15:31:15" 
    }, 
    "type": "creation", 
    "revision": 0 
}, 
"current_revision": { 
    "item_revision_id": 1664054437, 
    "created_via": { 
     "url": null, 
     "auth_client_id": 25162, 
     "display": true, 
     "name": "importer", 
     "id": 25162 
    }, 
    "created_by": { 
     "user_id": 4194774, 
     "name": "Anton Mikhailov", 
     "url": "https:\/\/podio.com\/users\/4194774", 
     "type": "user", 
     "image": null, 
     "avatar_type": "file", 
     "avatar": null, 
     "id": 4194774, 
     "avatar_id": null, 
     "last_seen_on": "2017-07-10 15:31:15" 
    }, 
    "created_on": "2017-07-10 15:31:16", 
    "user": { 
     "user_id": 4194774, 
     "name": "Anton Mikhailov", 
     "url": "https:\/\/podio.com\/users\/4194774", 
     "type": "user", 
     "image": null, 
     "avatar_type": "file", 
     "avatar": null, 
     "id": 4194774, 
     "avatar_id": null, 
     "last_seen_on": "2017-07-10 15:31:15" 
    }, 
    "type": "creation", 
    "revision": 0 
}, 
"linked_account_id": null, 
"push": { 
    "timestamp": 1499700676, 
    "expires_in": 21600, 
    "channel": "\/item\/641331142", 
    "signature": "b8a816ff367da6bc730071c875ca3fdca2d2c344" 
}, 
"external_id": null 
} 

回答

1

你試過http://podio.github.io/podio-php/fields/#category-field

設置值
使用option_id設置單個值。您也可以 添加值與add_value()

$item = PodioItem::get_basic(123); 
$field_id = 'category'; 

// Set value to a single option 
$item->fields[$field_id]->values = 4; // option_id=4 

// Add value to existing selection 
$item->fields[$field_id]->add_value(4); // option_id=4 

使用數組來設置多個值

$item = PodioItem::get_basic(123); 
$field_id = 'category'; 
$item->fields[$field_id]->values = array(4,5,6); // option_ids: 4, 5 and 6 

與創造價值的項目:

$fields = new PodioItemFieldCollection([ 
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>array(13)]), 
]); 
$item = new PodioItem([ 
    'app' => new PodioApp($app_id), 
    'fields' => $fields 
]); 
$item->save(); 
+0

它只有在重新啓動腳本後才起作用,當我創建一個項目並立即設置值(通過您的方法或我的)時,它不起作用。如果我只是得到現有的項目,並改變它的狀態它的作品當我創建一個項目時,我需要設置狀態,在同一個會話中,這將是最好的方式。 – Bookin

+0

您能否創建2個示例並向他們解釋什麼是工作,哪些不是?還請包括您可以從跑道界面看到的值。 –

+0

更新後的問題 – Toxa

相關問題