| | 533 | |
| | 534 | /* |
| | 535 | * function api_searchByPartNumber |
| | 536 | * @param array $requestData Array containing the "partnumber" key. |
| | 537 | * @param bool $returnUuid If true, returns result's uuid , if |
| | 538 | * false, the id. |
| | 539 | * @return array An array containing response information |
| | 540 | * @returnf string 'type' The type of response (e.g. 'error' or 'result') |
| | 541 | * @returnf string 'message' Message explaining the type / result |
| | 542 | * @returnf array details Either the array of uuid / ids if no errors |
| | 543 | * were encountered, or the original $requestData if there was an error |
| | 544 | */ |
| | 545 | |
| | 546 | function api_searchByPartNumber($requestData, $returnUuid = true) { |
| | 547 | |
| | 548 | /** |
| | 549 | * do error search |
| | 550 | */ |
| | 551 | if(!isset($requestData["partnumber"])){ |
| | 552 | $response["type"] = "error"; |
| | 553 | $response["message"] = "Data does not contain a key of 'partnumber'."; |
| | 554 | $response["details"] = $requestData; |
| | 555 | return $response; |
| | 556 | }//end if |
| | 557 | |
| | 558 | /** |
| | 559 | * do query search |
| | 560 | */ |
| | 561 | $querystatement = " |
| | 562 | SELECT |
| | 563 | `id`, |
| | 564 | `uuid` |
| | 565 | FROM |
| | 566 | `products` |
| | 567 | WHERE |
| | 568 | `partnumber` = '".mysql_real_escape_string($requestData["partnumber"])."' |
| | 569 | "; |
| | 570 | |
| | 571 | $queryresult = $this->db->query($querystatement); |
| | 572 | |
| | 573 | /** |
| | 574 | * report result |
| | 575 | */ |
| | 576 | $thereturn["message"] = "The function api_searchByPartNumber has been run successfully."; |
| | 577 | $thereturn["type"] = ""; |
| | 578 | $thereturn["details"] = array(); |
| | 579 | while($therecord = $this->db->fetchArray($queryresult)){ |
| | 580 | |
| | 581 | if($returnUuid) |
| | 582 | $thereturn["details"][] = $therecord["uuid"]; |
| | 583 | else |
| | 584 | $thereturn["details"][] = $therecord["id"]; |
| | 585 | |
| | 586 | }//end while |
| | 587 | |
| | 588 | return $thereturn; |
| | 589 | |
| | 590 | }//end function --api_searchByPartNumber-- |