/**
  * Get all user defined metadata names for all directories(collections) on the server.
  * @return array of strings (metadata names).
  */
 public function getMetadataNamesForAllDirs()
 {
     $flds = array("COL_META_COLL_ATTR_NAME" => NULL);
     $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
     $condition = new RODSGenQueConds();
     $condition->add('COL_COLL_ID', '>=', '0');
     $conn = RODSConnManager::getConn($this->account);
     $results = $conn->query($select, $condition);
     RODSConnManager::releaseConn($conn);
     if ($results->getNumRow() < 1) {
         return array();
     } else {
         $values = $results->getValues();
         return $values['COL_META_COLL_ATTR_NAME'];
     }
 }
Ejemplo n.º 2
0
 /**
  * query metadata, and find matching diretories.
  * @param array $terms an assositive array of search conditions, supported ones are:
  * -    'name' (string) - partial name of the target (file or dir)
  * -    'descendantOnly' (boolean) - whether to search among this directory's decendents. default is false.
  * -    'recursive'      (boolean) - whether to search recursively, among all decendents and their children. default is false. This option only works when 'descendantOnly' is true
  * -    'smtime'         (int)     - start last-modified-time in unix timestamp. The specified time is included in query, in other words the search can be thought was "mtime >= specified time"
  * -    'emtime'         (int)     - end last-modified-time in unix timestamp. The specified time is not included in query, in other words the search can be thought was "mtime < specified time"
  * -    'owner'          (string)  - owner name of the dir
  * -    'metadata' (array of RODSMeta) - array of metadata.
  * @param int &$total_count This value (passed by reference) returns the total potential count of search results
  * @param int $start starting index of search results.
  * @param int $limit up to how many results to be returned. If negative, give all results back.
  * @param array $sort_flds associative array with following keys:
  * -     'name'      - name of the dir
  * -     'mtime'     - last modified time
  * -     'ctime'     - creation time
  * -     'owner'     - owner of the dir
  * The results are sorted by specified array keys.
  * The possible array value must be boolean: true stands for 'asc' and false stands for 'desc', default is 'asc'
  * @return array of ProdsPath objects (ProdsFile or ProdsDir).
  */
 public function findDirs(array $terms, &$total_count, $start = 0, $limit = -1, array $sort_flds = array())
 {
     $flds = array("COL_COLL_NAME" => NULL, "COL_COLL_ID" => NULL, "COL_COLL_OWNER_NAME" => NULL, 'COL_COLL_OWNER_ZONE' => NULL, "COL_COLL_CREATE_TIME" => NULL, "COL_COLL_MODIFY_TIME" => NULL, "COL_COLL_COMMENTS" => NULL);
     foreach ($sort_flds as $sort_fld_key => $sort_fld_val) {
         switch ($sort_fld_key) {
             case 'name':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'mtime':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_MODIFY_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_MODIFY_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'ctime':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_CREATE_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_CREATE_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'owner':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_OWNER_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_OWNER_NAME'] = 'order_by_asc';
                 }
                 break;
             default:
                 /*
                 throw new RODSException("Sort field name '$sort_fld_key' is not valid",
                   'PERR_USER_INPUT_ERROR');
                 */
                 break;
         }
     }
     $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
     $descendantOnly = false;
     $recursive = false;
     $condition = new RODSGenQueConds();
     foreach ($terms as $term_key => $term_val) {
         switch ($term_key) {
             case 'name':
                 //$condition->add('COL_COLL_NAME', 'like', '%'.$term_val.'%');
                 $condition->add('COL_COLL_NAME', 'like', $term_val);
                 break;
             case 'smtime':
                 $condition->add('COL_COLL_MODIFY_TIME', '>=', $term_val);
                 break;
             case 'emtime':
                 $condition->add('COL_COLL_MODIFY_TIME', '<', $term_val);
                 break;
             case 'owner':
                 $condition->add('COL_COLL_OWNER_NAME', '=', $term_val);
                 break;
             case 'metadata':
                 $meta_array = $term_val;
                 foreach ($meta_array as $meta) {
                     $condition->add('COL_META_COLL_ATTR_NAME', '=', $meta->name);
                     if (isset($meta->op)) {
                         $op = $meta->op;
                     } else {
                         $op = '=';
                     }
                     if ($op == 'like') {
                         //$value='%'.$meta->value.'%';
                         $value = $meta->value;
                     } else {
                         $value = $meta->value;
                     }
                     $condition->add('COL_META_COLL_ATTR_VALUE', $op, $value);
                 }
                 break;
             case 'descendantOnly':
                 if (true === $term_val) {
                     $descendantOnly = true;
                 }
                 break;
             case 'recursive':
                 if (true === $term_val) {
                     $recursive = true;
                 }
                 break;
             default:
                 throw new RODSException("Term field name '{$term_key}' is not valid", 'PERR_USER_INPUT_ERROR');
                 break;
         }
     }
     if ($descendantOnly === true) {
         // eliminate '/' from children, if current path is already root
         if ($this->path_str == '/') {
             $condition->add('COL_COLL_NAME', '<>', '/');
         }
         if ($recursive === true) {
             $condition->add('COL_COLL_PARENT_NAME', 'like', $this->path_str . '/%', array(array('op' => '=', 'val' => $this->path_str)));
         } else {
             $condition->add('COL_COLL_PARENT_NAME', '=', $this->path_str);
         }
     }
     $conn = RODSConnManager::getConn($this->account);
     $results = $conn->query($select, $condition, $start, $limit);
     RODSConnManager::releaseConn($conn);
     $total_count = $results->getTotalCount();
     $result_values = $results->getValues();
     $found = array();
     for ($i = 0; $i < $results->getNumRow(); $i++) {
         $full_path = $result_values['COL_COLL_NAME'][$i];
         $acctual_name = basename($result_values['COL_COLL_NAME'][$i]);
         $stats = new RODSDirStats($acctual_name, $result_values['COL_COLL_OWNER_NAME'][$i], $result_values['COL_COLL_OWNER_ZONE'][$i], $result_values['COL_COLL_MODIFY_TIME'][$i], $result_values['COL_COLL_CREATE_TIME'][$i], $result_values['COL_COLL_ID'][$i], $result_values['COL_COLL_COMMENTS'][$i]);
         $found[] = new ProdsDir($this->account, $full_path, false, $stats);
     }
     return $found;
 }