Exemplo n.º 1
0
 /**
  * Update one or more records.  Object types can be mixed and can be either standard or custom.
  * Check the developer documentation to see which standard objects are supported in this method
  *
  * @param Array       $records an array of records to update.  Follow the pattern
  * $records = array(array('mycustomobjecttype' => array('id' => 112233, // you must pass the id value
  *                                                      'updatefield' => 'updateValue')),
  *                  array('mystandardobjecttype' => array('recordno' => 555, // you must pass the recordno value for standard objects
  *                                                        'updatefield' => 'updateValue')));
  * @param api_session $session api_session object with a valid connection
  *
  * @throws Exception
  * @return array An array of 'ids' updated in the method invocation
  */
 public static function update($records, api_session $session)
 {
     if (count($records) > 100) {
         throw new Exception("Attempting to update more than 100 records.");
     }
     // convert the $records array into an xml structure
     $updateXml = "<update>";
     $node = '';
     foreach ($records as $record) {
         $nodeAry = array_keys($record);
         $node = $nodeAry[0];
         $objXml = api_util::phpToXml($node, $record[$node]);
         $updateXml = $updateXml . $objXml;
     }
     $updateXml = $updateXml . "</update>";
     $res = api_post::post($updateXml, $session);
     return api_post::processUpdateResults($res, $node);
 }