예제 #1
0
 /**
  * Gets the user based on it's ID
  *
  * @param $email string the email of the user
  * @return mixed the User that is in the database
  *          -1 the user doesn't exist
  *          -2 connection problem
  */
 public function getUserByEmail($email)
 {
     // Creating a CPS_Simple instance
     $cpsSimple = new \CPS_Simple($this->cpsConn);
     $query = CPS_Term($email, 'email');
     $list = array('id' => 'yes');
     try {
         $documents = $cpsSimple->search($query, NULL, NULL, $list);
     } catch (Exception $e) {
         return -2;
     }
     foreach ($documents as $id => $document) {
         return Converter::XML2Array($document);
     }
     return -1;
 }
<?php

// includes
require_once 'config.php';
require_once '../cps_simple.php';
try {
    // creating a CPS_Connection instance
    $cpsConnection = new CPS_Connection($config['connection'], $config['database'], $config['username'], $config['password'], 'document', '//document/id', array('account' => $config['account']));
    // creating a CPS_Simple instance
    $cpsSimple = new CPS_Simple($cpsConnection);
    // search for items with category == 'cars' and car_params/year >= 2010
    $query = CPS_Term('cars', 'category') . CPS_Term('>=2010', 'car_params/year');
    // return documents starting with the first one - offset 0
    $offset = 0;
    // return not more than 5 documents
    $docs = 5;
    // return these fields from the documents
    $list = array('id' => 'yes', 'car_params/make' => 'yes', 'car_params/model' => 'yes', 'car_params/year' => 'yes');
    // order by year, from largest to smallest
    $ordering = CPS_NumericOrdering('car_params/year', 'descending');
    $documents = $cpsSimple->search($query, $offset, $docs, $list, $ordering);
    foreach ($documents as $id => $document) {
        echo $document->car_params->make . ' ' . $document->car_params->model . '<br />';
        echo 'first registration in ' . $document->car_params->year . '<br />';
    }
} catch (CPS_Exception $e) {
    var_dump($e->errors());
    exit;
}