コード例 #1
0
ファイル: list.php プロジェクト: nemein/openpsa
 /**
  * Internal helper to check if the requested group belongs to the haystack
  *
  * @param int $id
  * @param int $owner
  */
 public static function belongs_to($id, $owner)
 {
     do {
         if ($id === $owner) {
             return true;
         }
         $mc = midcom_db_group::new_collector('id', $id);
         $mc->set_limit(1);
         $keys = $mc->get_values('owner');
         // Get the first array key
         foreach ($keys as $key) {
             if ($key === 0) {
                 return false;
             }
             $id = $key;
         }
     } while ($mc->count() > 0);
     return false;
 }
コード例 #2
0
ファイル: list.php プロジェクト: nemein/openpsa
 /**
  * Internal helper for showing the groups recursively
  *
  * @param int $id
  * @param array &$data
  * @param int $level
  */
 private function list_groups_for_select($id, &$data, $level)
 {
     $mc = midcom_db_group::new_collector('owner', (int) $id);
     $mc->add_value_property('name');
     $mc->add_value_property('official');
     $mc->add_value_property('id');
     // Set the order
     $mc->add_order('metadata.score', 'DESC');
     $mc->add_order('official');
     $mc->add_order('name');
     // Get the results
     $mc->execute();
     $keys = $mc->list_keys();
     // Hide empty groups
     if ($mc->count() === 0) {
         return;
     }
     $data['parent_id'] = $id;
     foreach ($keys as $guid => $array) {
         $group['guid'] = $guid;
         $group['id'] = $mc->get_subkey($guid, 'id');
         $group['name'] = $mc->get_subkey($guid, 'name');
         if ($title = $mc->get_subkey($guid, 'official')) {
             $group['title'] = $title;
         } else {
             $group['title'] = $group['name'];
         }
         if (!$group['title']) {
             $group['title'] = "#{$group['id']}";
         }
         $group['level'] = $level;
         $data['groups_for_select'][] = $group;
         $level++;
         $this->list_groups_for_select($group['id'], $data, $level);
         $level--;
     }
 }