Пример #1
0
 public static function is_array_empty($InputVariable)
 {
     $Result = true;
     if (is_array($InputVariable) && count($InputVariable) > 0) {
         foreach ($InputVariable as $Value) {
             $Result = $Result && is_array_empty($Value);
         }
     } else {
         $Result = empty($InputVariable);
     }
     return $Result;
 }
function is_array_empty($input)
{
    $result = true;
    if (is_array($input) && count($input) > 0) {
        foreach ($input as $val) {
            $result = $result && is_array_empty($val);
        }
    } else {
        $result = empty($input);
    }
    return $result;
}
 function handle($params = '')
 {
     $ci =& get_instance();
     $this->params = $params;
     //registry_objects/<id>/method1/method2
     $id = isset($params[1]) ? $params[1] : false;
     $method1 = isset($params[2]) ? $params[2] : 'get';
     $method2 = isset($params[3]) ? $params[3] : false;
     $useCache = $ci->input->get('useCache') ? false : true;
     $cache_id = $id . '-' . $method1;
     $all = implode($this->valid_methods, '-') . '-';
     if ($method1 == $all) {
         $cache_id = 'ro-api-' . $id . '-' . 'portal';
     }
     if ($method1 == 'get' || strpos($method1, 'rda') !== false) {
         $method1 = implode($this->valid_methods, '-');
         $cache_id = 'ro-api-' . $id . '-' . 'portal';
     }
     // $ci->load->library('benchmark');
     $ci->benchmark->mark('code_start');
     $result = array();
     if ($id) {
         $ci->load->model('registry_object/registry_objects', 'ro');
         $this->ro = new _registry_object($id);
         //check in cache
         $ci->load->driver('cache');
         //            $cache_id = $id.'-'.$method1;
         $updated = (int) $this->ro->getAttribute('updated');
         if (($cache = $ci->cache->file->get($cache_id)) && $useCache) {
             $result = json_decode($cache, true);
             //check cache updated
             $meta = $ci->cache->file->get_metadata($cache_id);
             if ($updated < $meta['mtime']) {
                 $ci->benchmark->mark('code_end');
                 $benchmark = array('elapsed' => $ci->benchmark->elapsed_time('code_start', 'code_end'), 'cached' => $meta['mtime'], 'updated' => $updated, 'memory_usage' => $ci->benchmark->memory_usage());
                 return $this->formatter->display($result, $benchmark);
             }
         }
         //delete the cache at the portal side, because the record is updated
         $ci->cache->delete('ro-api-' . $id);
         //fill the result with data
         $this->populate_resource($id);
         $method1s = explode('-', $method1);
         foreach ($method1s as $m1) {
             if ($m1 && in_array($m1, $this->valid_methods)) {
                 switch ($m1) {
                     case 'get':
                     case 'registry':
                         $result[$m1] = $this->ro_handle('core');
                         break;
                     case 'relationships':
                         $result[$m1] = $this->relationships_handler();
                         break;
                     default:
                         try {
                             $r = $this->ro_handle($m1);
                             if (!is_array_empty($r)) {
                                 $result[$m1] = $r;
                             }
                         } catch (Exception $e) {
                             $result[$m1] = array();
                         }
                         break;
                 }
             }
         }
         //store result in cache
         $cache_content = json_encode($result, true);
         $ci->cache->file->save($cache_id, $cache_content, 36000);
     } else {
         $result = $this->searcher($params);
     }
     $ci->benchmark->mark('code_end');
     $benchmark = array('elapsed' => $ci->benchmark->elapsed_time('code_start', 'code_end'), 'memory_usage' => $ci->benchmark->memory_usage());
     return $this->formatter->display($result, $benchmark);
 }