mgd_fetch_to_array()

This is a small helper function, that allows you to transform a fetchable to an ID-Array. Just for your convenience.

Calling Syntax

array mgd_fetch_to_array (object $fetchable);

Parameter Syntax

$fetchable must be an Midgard-Object, that can be traversed by calling $fetchable->fetch(). The Objects must have a member "$fetchable->id" which identifies the primary key. These keys are put together into an Array leaving the sorting order intact.

Variants

Two special cases of this function exist: mgd_memberships_to_uid and mgd_memberships_to_gid. You can use them to transform Membership-Records into User- ord Group-ID Lists. (Who needs Membership Records...) Using those two functions always in conjunction with mgd_list_members and similar, you can avoid a lot of errors...

Hints

Since it does some error checking, you can combine these calls to something like:

$articles = mgd_fetch_to_array(mgd_list_articles(...));

Code

<?php

function mgd_fetch_to_array ($fetchable) {
  
$result = array();
  
  if (!
$fetchable)
    return
false;
  
  while (
$fetchable->fetch())
    
$result[] = $fetchable->id;
  
  return
$result;
}

function
mgd_memberships_to_uid ($fetchable) {
  
$result = array();

  if (!
$fetchable)
    return
false;
  
  while (
$fetchable->fetch())
    
$result[] = $fetchable->uid;
  
  return
$result;
}

function
mgd_memberships_to_gid ($fetchable) {
  
$result = array();
  
  if (!
$fetchable)
    return
false;
  
  while (
$fetchable->fetch())
    
$result[] = $fetchable->gid;
  
  return
$result;
}

?>