示例#1
0
 /**
  *  Update Edge
  *
  *  Request to update a edge in the collection
  *
  * @param array/Edge  $data - Array of the data for edge / Edge Object to replace .
  * @param string  $collection - specify the collectionID to update the edge from.
  * @param string  $id - specify the edge ID to update the edge.
  * @param array  $param - Array of parameters to send to the database as a options for edge request.
  *
  * @return array/Edge $response/$data - Return a response array of the request/Edge object.
  */
 public function UpdateEdge($data, $collection = NULL, $id = NULL, $param = NULL)
 {
     $option = array();
     if (isset($param['waitForSync'])) {
         $option['waitForSync'] = $param['waitForSync'];
     }
     if (isset($param['keepNull'])) {
         $option['keepNull'] = $param['keepNull'];
     }
     if (isset($param['mergeObjects'])) {
         $option['mergeObjects'] = $param['mergeObjects'];
     }
     if (isset($param['rev'])) {
         $option['rev'] = $param['rev'];
     }
     if (isset($param['policy'])) {
         $option['policy'] = $param['policy'];
     }
     $header = array();
     if (isset($param['ifmatch'])) {
         $header['If-Match'] = $param['ifmatch'];
     }
     if ($data instanceof Edge) {
         $jdata = $data->getData();
         $collection = $data->getCollectionID();
         $id = $data->getID();
         $response = $this->patch('edge/' . $collection . '/' . $id, $jdata, 'json', $option, $header);
         if ($response->code == '201' or $response->code == '202' or $response->code == '200') {
             $data->setData($response);
             return $data;
         } else {
             return $response;
         }
     } else {
         $jdata = $data;
         $response = $this->patch('edge/' . $collection . '/' . $id, $jdata, 'json', $option, $header);
         return $response;
     }
 }
示例#2
0
 /**
  *  Create Edge
  *
  *  Request to create a new edge in the collection
  *
  * @param array/Edge  $index - Collection ID / Edge Object to create .
  * @param string  $type - specify the type of index.
  * @param array  $data - Array of the data for index.
  * @param array  $param - Array of parameters to send to the database as a options for edge request.
  *
  * @return array/Edge $response/$data - Return a response array of the request/Edge object.
  */
 public function CreateIndex($index, $type = NULL, $data = NULL, $param = NULL)
 {
     $option = array();
     if ($data instanceof Index) {
         $jdata = array();
         $jdata['type'] = strtolower($index->getType());
         switch (strtolower($index->getType())) {
             case 'cap':
                 if (isset($param['size'])) {
                     $jdata['size'] = intval($param['size']) > 0 ? $param['size'] : 0;
                 }
                 if (isset($param['byteSize'])) {
                     $jdata['byteSize'] = intval($param['byteSize']) > 16384 ? $param['byteSize'] : 0;
                 }
                 break;
             case 'geo':
                 if ($data != NULL) {
                     $jdata['fields'] = $data;
                 } else {
                     return array("error" => "Fields Required");
                 }
                 if (isset($param['geoJson'])) {
                     $jdata['geoJson'] = $param['geoJson'];
                 }
                 break;
             case 'hash':
             case 'skiplist':
                 if ($data != NULL) {
                     $jdata['fields'] = $data;
                 } else {
                     return array("error" => "Fields Required");
                 }
                 if (isset($param['unique'])) {
                     $jdata['unique'] = $param['unique'];
                 }
                 if (isset($param['sparse'])) {
                     $jdata['sparse'] = $param['sparse'];
                 }
                 break;
             case 'fulltext':
                 if ($data != NULL) {
                     $jdata['fields'] = $data;
                 } else {
                     return array("error" => "Fields Required");
                 }
                 if (isset($param['mineLngth'])) {
                     $jdata['minLength'] = $param['minLength'];
                 }
                 break;
         }
         $option['collection'] = $index->getCollectionID();
         $response = $this->post('index', $jdata, 'json', $option);
         if ($response->code == '201' or $response->code == '202' or $response->code == '200') {
             $data->setData($response);
             return $index;
         } else {
             return $response;
         }
     } else {
         $jdata = array();
         $jdata['type'] = strtolower($type);
         switch (strtolower($type)) {
             case 'cap':
                 if (isset($param['size'])) {
                     $jdata['size'] = intval($param['size']) > 0 ? $param['size'] : 0;
                 }
                 if (isset($param['byteSize'])) {
                     $jdata['byteSize'] = intval($param['byteSize']) > 16384 ? $param['byteSize'] : 0;
                 }
                 break;
             case 'geo':
                 if ($data != NULL) {
                     $jdata['fields'] = $data;
                 } else {
                     return array("error" => "Fields Required");
                 }
                 if (isset($param['geoJson'])) {
                     $jdata['geoJson'] = $param['geoJson'];
                 }
                 break;
             case 'hash':
             case 'skiplist':
                 if ($data != NULL) {
                     $jdata['fields'] = $data;
                 } else {
                     return array("error" => "Fields Required");
                 }
                 if (isset($param['unique'])) {
                     $jdata['unique'] = $param['unique'];
                 }
                 if (isset($param['sparse'])) {
                     $jdata['sparse'] = $param['sparse'];
                 }
                 break;
             case 'fulltext':
                 if ($data != NULL) {
                     $jdata['fields'] = $data;
                 } else {
                     return array("error" => "Fields Required");
                 }
                 if (isset($param['mineLngth'])) {
                     $jdata['minLength'] = $param['minLength'];
                 }
                 break;
         }
         $option['collection'] = $index;
         $response = $this->post('index', $jdata, 'json', $option);
         return $response;
     }
 }