Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. public function put_webservice_initial(){
  2.  
  3. $arraycall = json_decode($_POST['my_object']);
  4.  
  5. $prefixORsufix = $arraycall->prefixORsufix;
  6. $id_asset = $arraycall->id_asset;
  7. $id_resource = $arraycall->id_resource;
  8. $prefix = $arraycall->prefix;
  9. $suffix = $arraycall->suffix;
  10. $parameter = $arraycall->parameter;
  11.  
  12. //para ir buscar o id da entidade que está selecionada na dropdown na TopBar
  13. $member = Member::currentUser();
  14. $entity_ID_at_moment = $member->entity_in_workID;
  15.  
  16. $asset_current = ttAsset::get()->ByID($id_asset);
  17. $endpoint_id = $asset_current->endpoint_id;
  18.  
  19. //obter os contratos da entidade que estabeleceu o contrato e que ainda esteja ativo
  20. $contracts = ttContract::get()->filter(array('entity_establishedID' => $entity_ID_at_moment, 'valid' => 1));
  21.  
  22. $list = ArrayList::create();
  23.  
  24. if($contracts->Count()!=0){
  25.  
  26. foreach ($contracts as $contract) { //os contractos que têm webservices associados
  27. $webservice=$contract->webservices()->filter(array('recycled' => 0))
  28. ->sort("date_doc DESC")
  29. ->limit(1);
  30. $list->merge($webservice);
  31. }
  32.  
  33. //como o array ja esta ordenado de forma descendente pela start_date, basta obter os values da posicao 0.
  34. $recent_contract = $list[0];
  35.  
  36. //echo "<pre>";print_r($recent_contract);die();
  37. foreach($recent_contract as $contract){
  38. $url = $contract->url;
  39. $port = $contract->port;
  40. $user = $contract->user;
  41. }
  42.  
  43. $resources = ttSCResource::get()->ByID($id_resource);
  44. $res_verb = $resources->verbs()->ByID(2);
  45.  
  46. $list = ArrayList::create();
  47.  
  48.  
  49. $valor_dis=null;
  50.  
  51. $object_send = new stdClass;
  52.  
  53. $variables=$resources->variable();
  54.  
  55. foreach($variables as $variable){
  56.  
  57. $validations = $variable->validation();
  58.  
  59. foreach($validations as $validation){
  60.  
  61. $className = $validation->ClassName;
  62. $valid = $className::get()->ByID($validation->ID);
  63.  
  64. if($valid->ClassName == 'ttValidationDecimal'){
  65. $object_send->minimum = $valid->min_decimal;
  66. $object_send->maximum = $valid->max_decimal;
  67. $object_send->type = "decimal";
  68. }
  69.  
  70. else if($valid->ClassName == 'ttValidationInt'){
  71. $object_send->minimum = $valid->min_integer;
  72. $object_send->maximum = $valid->max_integer;
  73. $object_send->type = "int";
  74. }
  75.  
  76. else if($valid->ClassName == 'ttSetDisjoint'){
  77.  
  78. $values_disjoint = ttSetValuesDisjoint::get()->filter(array('set_disjointID' => $valid->variableID));
  79. foreach($values_disjoint as $value_dis){
  80. $valor_dis = $valor_dis.$value_dis->Title . "|";
  81. }
  82.  
  83. $object_send->disjoint = $valor_dis;
  84. }
  85. }
  86. }
  87.  
  88.  
  89. foreach($res_verb as $res){
  90. $msg_body=$res->msg_body;
  91. $value=$this->convert_json_to_object($msg_body);
  92.  
  93. $object_send->json = $value;
  94. }
  95.  
  96. return json_encode($object_send);
  97.  
  98. }
  99. else {
  100. $value=_t("ttRealTimeControlHolder.ERRORCONTRACT", "É necessário ter um contrato válido.");
  101. return json_encode($value);
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement