Пример #1
0
 /**
  * returns a list of data sources an organisational role has access to
  * @return [type] [description]
  */
 public function get_datasources()
 {
     $record_owner = $this->input->get('record_owner');
     $record_owner = rawurldecode($record_owner);
     if ($record_owner) {
         $this->load->model('data_source/data_sources', 'ds');
         $data_sources = $this->ds->getByAttribute('record_owner', $record_owner);
         if ($data_sources) {
             $response['status'] = 'OK';
             $response['numFound'] = sizeof($data_sources);
             $response['result'] = array();
             foreach ($data_sources as $ds) {
                 $response['result'][] = array('id' => $ds->id, 'key' => $ds->key, 'title' => $ds->title, 'registry_url' => registry_url('data_source/manage#!/view/' . $ds->id));
             }
         } else {
             $response['status'] = 'OK';
             $response['numFound'] = 0;
             $response['message'] = 'No data sources found';
         }
     } else {
         $response['status'] = 'WARNING';
         $response['message'] = 'Missing record_owner identifier';
     }
     formatResponse($response, 'json');
 }
function formatResponse($resp, $indent = '', $varName = null)
{
    global $DATE_FIELD_SUFFIXES;
    $returnCode = 0;
    switch (gettype($resp)) {
        case 'integer':
            if ($resp > MIN_TIME_STAMP && $resp < MAX_TIME_STAMP) {
                foreach ($DATE_FIELD_SUFFIXES as $dateSuffix) {
                    if (substr($varName, -strlen($dateSuffix)) === $dateSuffix) {
                        return array("{$resp}\t(" . date('Y-m-d H:i:s', $resp) . ")", $returnCode);
                    }
                }
            }
        case 'boolean':
        case 'double':
        case 'string':
        case 'NULL':
            return array((string) $resp, $returnCode);
        case 'array':
            $result = "array";
            foreach ($resp as $index => $elem) {
                list($value, $internalReturnCode) = formatResponse($elem, $indent . "\t", $index);
                $result .= "\n{$indent}\t{$index}\t{$value}";
            }
            if ($indent == "" && isset($resp['objectType']) && strpos($resp['objectType'], 'Exception') !== false) {
                $returnCode = 1;
            }
            return array($result, $returnCode);
        case 'object':
            $properties = get_object_vars($resp);
            $result = $properties['__PHP_Incomplete_Class_Name'];
            unset($properties['__PHP_Incomplete_Class_Name']);
            foreach ($properties as $name => $value) {
                if ($name == '__PHP_Incomplete_Class_Name') {
                    continue;
                }
                list($value, $internalReturnCode) = formatResponse($value, $indent . "\t", $name);
                $result .= "\n{$indent}\t{$name}\t{$value}";
            }
            return array($result, $returnCode);
    }
}
Пример #3
0
 public function get_registry_object($id = null, $format = 'xml')
 {
     if ($id) {
         try {
             $this->load->model('registry_object/registry_objects', 'ro');
             $ro = $this->ro->getByID($id);
             $response = array();
             $response['status'] = 'OK';
             $response['message'] = $ro->getXML();
             formatResponse($response, $format);
         } catch (Exception $e) {
             $response['status'] = 'ERROR';
             $response['message'] = $e->getMessage();
             formatResponse($response, $format);
         }
     } else {
         $response['status'] = 'WARNING';
         $response['message'] = 'Missing ID identifier for Registry Object';
         formatResponse($response, $format);
     }
 }