phpBMS

Changeset 758

Show
Ignore:
Timestamp:
01/14/10 15:34:20 (2 years ago)
Author:
nate
Message:
  • Made certain methods in the apiwrapper class have easier to use (and clearer) options.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/api/apiwrapper.php

    r754 r758  
    7373     * @param string $tabledefuuid The uuid of the tabledefinition that you wish to insert records. 
    7474     * @param array $data An array of associative arrays consising of fieldname => value pairs. 
    75      * @param array $options An associative array of options. Possible options are : 'useUuid', 'dateFormat', 'timeFormat', 'keepDestId' 
     75     * @param bool $generateUuid Whether to generate a new uuid for the inserted record (and ignore any passed uuid field). 
     76     * @param bool $keepDestId This option dictates whether or not to keep the destination's id field if "replacing" (via the mysql replace) when there is no id field set. 
     77     * @param string $dateFormat The format of the dates (if any) in $data.  Possible choices are : 'SQL', 'English, US', 'English, UK', or 'Dutch, NL'.  If none of these are chosen, it will default to 'SQL'. 
     78     * @param string $timeFormat The format of the times (if any) in $data.  Possible choices are : '24 Hour' or '12 Hour'.  If none of these are chosen, it will default to '24 Hour'. 
     79     *  
    7680     * 
    7781     * @return array An array of associative arrays of responses for each insert 
     
    8286     */ 
    8387     
    84     public function insertRecords($tabledefuuid, $data, $options = NULL) { 
    85          
    86        return $this->_runTableCommnad("insert", $tabledefuuid, $data, $options); 
     88    public function insertRecords($tabledefuuid, $data, $generateUuid = true, $keepDestId = true, $dateFormat = NULL, $timeFormat = NULL) { 
     89         
     90        if($generateUuid !== true) 
     91            $generateUuid = false; 
     92         
     93        if($keepDestId !== true) 
     94            $keepDestId = false; 
     95             
     96        switch($dateFormat){ 
     97             
     98            case "SQL": 
     99            case "English, US": 
     100            case "English, UK": 
     101            case "Dutch, NL": 
     102            break; 
     103 
     104            default: 
     105                $dateFormat = "SQL"; 
     106            break; 
     107         
     108        }//end switch 
     109         
     110        switch($timeFormat){ 
     111             
     112            case "24 Hour": 
     113            case "12 Hour": 
     114            break; 
     115 
     116            default: 
     117                $timeFormat = "24 Hour"; 
     118            break; 
     119         
     120        }//end switch 
     121         
     122        $options = array( 
     123                    "useUuid" => $generateUuid, 
     124                    "dateFormat" => $dateFormat, 
     125                    "timeFormat" => $timeFormat, 
     126                    "keepDestId" => $keepDestId 
     127                    ); 
     128         
     129        return $this->_runTableCommnad("insert", $tabledefuuid, $data, $options); 
    87130         
    88131    }//end function 
     
    94137     * @param string $tabledefuuid The uuid of the tabledefinition that you wish to update records. 
    95138     * @param array $data An array of associative arrays consising of fieldname => value pairs. 
    96      * @param array $options An associative array of options. Possible options are : 'useUuid', 'dateFormat', 'timeFormat', 'keepDestId' 
     139     * @param bool $useUuid Whether to use the id (false) or the uuid (true) in the update whereclause. 
     140     * @param string $dateFormat The format of the dates (if any) in $data.  Possible choices are : 'SQL', 'English, US', 'English, UK', or 'Dutch, NL'.  If none of these are chosen, it will default to 'SQL'. 
     141     * @param string $timeFormat The format of the times (if any) in $data.  Possible choices are : '24 Hour' or '12 Hour'.  If none of these are chosen, it will default to '24 Hour'. 
    97142     * 
    98143     * @return array An array of associative arrays of responses for each update 
     
    102147     */ 
    103148     
    104     public function updateRecords($tabledefuuid, $data, $options = NULL) { 
     149    public function updateRecords($tabledefuuid, $data, $useUuid = true, $dateFormat = NULL, $timeFormat = NULL) { 
     150         
     151        if($useUuid !== true) 
     152            $useUuid = false; 
     153         
     154        switch($dateFormat){ 
     155             
     156            case "SQL": 
     157            case "English, US": 
     158            case "English, UK": 
     159            case "Dutch, NL": 
     160            break; 
     161 
     162            default: 
     163                $dateFormat = "SQL"; 
     164            break; 
     165         
     166        }//end switch 
     167         
     168        switch($timeFormat){ 
     169             
     170            case "24 Hour": 
     171            case "12 Hour": 
     172            break; 
     173 
     174            default: 
     175                $timeFormat = "24 Hour"; 
     176            break; 
     177         
     178        }//end switch 
     179         
     180        $options = array( 
     181                    "useUuid" => $useUuid, 
     182                    "dateFormat" => $dateFormat, 
     183                    "timeFormat" => $timeFormat 
     184                    ); 
    105185         
    106186        return $this->_runTableCommnad("update", $tabledefuuid, $data, $options); 
     
    113193     *  
    114194     * @param string $tabledefuuid The uuid of the tabledefinition that you wish to get records. 
    115      * @param array $data An array of associative arrays of table uuids (or integer ids if useUuid option is set to false).  The key=>value format is 'uuid'=>'{the actual uuid}' 
    116      * @param array $options An associative array of options. Possible options are : 'useUuid', 'dateFormat', 'timeFormat' 
     195     * @param mixed $ids Either an array uuids (or ids if $useUuid = false), or an individual uuid (or id). 
     196     * @param bool $useUuid Whether the data is an array of uuids or ids 
    117197     * 
    118198     * @return array An array of associative arrays of responses for each get 
     
    123203     */ 
    124204     
    125     public function getRecords($tabledefuuid, $data, $options = NULL) { 
     205    public function getRecords($tabledefuuid, $ids, $useUuid = true) { 
     206         
     207        if($useUuid !== true) 
     208            $useUuid = false; 
     209         
     210        if($useUuid) 
     211            $keyName = "uuid"; 
     212        else 
     213            $keyName = "id"; 
     214             
     215        if(!is_array($ids)) 
     216            $ids = array($ids); 
     217         
     218        $data = array(); 
     219        foreach($ids as $id){ 
     220             
     221            if($useUuid) 
     222                $id = (string)$id; 
     223            else 
     224                $id = (int)$id; 
     225            $data[][$keyName] = $id; 
     226             
     227        }//end foreach 
     228         
     229        $options = array( 
     230                         "useUuid" => $useUuid 
     231                        ); 
    126232         
    127233        return $this->_runTableCommnad("get", $tabledefuuid, $data, $options); 
     
    133239     * function deleteRecords 
    134240     *  
    135      * @param string $tabledefuuid The uuid of the tabledefinition that you wish to delete records. 
    136      * @param array $data An array associative arrays with the key 'uuid' (or 'id' if useUuid option is set to false) and the relevant value. 
    137      * @param array $options An associative array of options. Possible options are : 'useUuid' 
     241     * @param string $tabledefuuid The uuid of the tabledefinition that you wish to delete (or inactivate, depending upon the tabledef) records. 
     242     * @param mixed $ids Either an array uuids (or ids if $useUuid is false), or an individual uuid (or id). 
     243     * @param bool $useUuid Whether the data is an array of uuids or ids. 
    138244     * 
    139245     * @return array An array of associative arrays of responses for each delete 
     
    143249     */ 
    144250     
    145     public function deleteRecords($tabledefuuid, $records, $options = NULL) { 
    146          
    147         return $this->_runTableCommnad("delete", $tabledefuuid, $records, $options); 
     251    public function deleteRecords($tabledefuuid, $ids, $useUuid = true) { 
     252         
     253        if($useUuid !== true) 
     254            $useUuid = false; 
     255         
     256        if($useUuid) 
     257            $keyName = "uuid"; 
     258        else 
     259            $keyName = "id"; 
     260             
     261        if(!is_array($ids)) 
     262            $ids = array($ids); 
     263         
     264        $data = array(); 
     265        foreach($ids as $id){ 
     266             
     267            if($useUuid) 
     268                $id = (string)$id; 
     269            else 
     270                $id = (int)$id; 
     271            $data[][$keyName] = $id; 
     272             
     273        }//end foreach 
     274         
     275        $options = array( 
     276                         "useUuid" => $useUuid 
     277                        ); 
     278         
     279        return $this->_runTableCommnad("delete", $tabledefuuid, $data, $options); 
    148280         
    149281    }//end function 
     
    204336     * function searchClientByEmail 
    205337     * @param string $email The email to be searched for 
    206      * @param array $options An associative array of options. Possible options are : 'useUuid' 
     338     * @param bool $useUuid Whether to return uuids or ids. 
    207339     * 
    208340     * @return array An associative array response for the get 
     
    212344     */ 
    213345     
    214     public function searchClientByEmail($email, $options = NULL) { 
     346    public function searchClientByEmail($email, $useUuid = true) { 
    215347         
    216348        $method = "api_searchByEmail"; 
    217349        $tabledefuuid = "tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083"; 
    218350        $data["email"] = (string)$email; 
     351         
     352        if($useUuid !== true) 
     353            $useUuid = false; 
     354         
     355        $options = array( 
     356                          "useUuid" => $useUuid   
     357                        ); 
    219358         
    220359        $response = $this->runApiMethod($method, $tabledefuuid, $data, $options); 
     
    232371     * @param name $lastname The last name to search for in the client's table 
    233372     * @param name $postalcode The postal code to search for in the client's table 
    234      * @param array $options An associative array of options. Possible options are : 'useUuid' 
     373     * @param bool $useUuid Whether to return uuids or ids. 
    235374     * 
    236375     * @return array An associative array response for the get 
     
    240379     */ 
    241380     
    242     public function searchClientByNameAndPostalcode($firstname, $lastname, $postalcode, $options = NULL) { 
     381    public function searchClientByNameAndPostalcode($firstname, $lastname, $postalcode, $useUuid = true) { 
    243382         
    244383        $method = "api_searchByNameAndPostalcode"; 
     
    248387        $data["postalcode"] = (string)$postalcode; 
    249388         
     389        if($useUuid !== true) 
     390            $useUuid = false; 
     391         
     392        $options = array( 
     393                          "useUuid" => $useUuid   
     394                        ); 
     395         
    250396        $response = $this->runApiMethod($method, $tabledefuuid, $data, $options); 
    251397         
     
    262408     * @param string $username The username to search for in the client's table 
    263409     * @param string $password The password to search for in the client's table 
    264      * @param array $options An associative array of options. Possible options are : 'useUuid' 
     410     * @param bool $useUuid Whether to return uuids or ids. 
    265411     * 
    266412     * @return array An associative array response for the get 
     
    270416     */ 
    271417     
    272     public function searchClientByUsernameAndPassword($username, $password, $options = NULL) { 
     418    public function searchClientByUsernameAndPassword($username, $password, $useUuid = true) { 
    273419         
    274420        $method = "api_searchByUsernameAndPassword"; 
     
    276422        $data["username"] = (string)$username; 
    277423        $data["password"] = (string)$password; 
     424         
     425        if($useUuid !== true) 
     426            $useUuid = false; 
     427         
     428        $options = array( 
     429                          "useUuid" => $useUuid   
     430                        ); 
    278431         
    279432        $response = $this->runApiMethod($method, $tabledefuuid, $data, $options); 
     
    293446     * @param string $startdate The sql encoded DATETIME lower range of creation dates. 
    294447     * @param string $enddate The sql encoded DATETIME upper range of creation dates. 
    295      * @param array $options An associative array of options. Possible options are : 'useUuid' 
     448     * @param bool $useUuid Whether to return uuids or ids. 
    296449     * 
    297450     * @return array An associative array response for the get 
     
    301454     */ 
    302455     
    303     function searchSalesOrdersByClientUuid($clientuuid, $ordertype = NULL, $startdate = NULL, $enddate = NULL, $options = NULL) { 
     456    function searchSalesOrdersByClientUuid($clientuuid, $ordertype = NULL, $startdate = NULL, $enddate = NULL, $useUuid = true) { 
    304457         
    305458        $method = "api_searchByClientUuid"; 
     
    312465        if($enddate !== NULL) 
    313466            $data["enddate"] = $enddate; 
     467             
     468        if($useUuid !== true) 
     469            $useUuid = false; 
     470         
     471        $options = array( 
     472                          "useUuid" => $useUuid   
     473                        ); 
    314474             
    315475        $response = $this->runApiMethod($method, $tabledefuuid, $data, $options); 
Scanned by Orvant Copyright © 2010 Kreotek, LLC. All Rights reserved.