getFreeAccountName ( )
protectedinherited

GetFreeAccountName.

Todo:
Document.
See also
getDefaultAccount()

References CesBankExchange\$code.

Referenced by CesBankExchange\getDefaultAccount().

1601  {
1602  // NOTE: this function is highly inefficient. It can be changed with a
1603  // single specific DB query if causes performance problems.
1604  $s = new IcesSerializer('CesBankLocalAccount');
1605  $accounts = $s->loadCollection(array(
1606  'exchange' => $this->id,
1607  'kind' => array(0, 1, 2, 3, 4),
1608  ),
1609  'name'
1610  );
1611  $start = floor((count($accounts) - 1) / 2);
1612  // This is a bit tricky.
1613  $code = !empty($accounts) ? $accounts[$start]->getCode() : 0;
1614  if (!is_numeric($code)) {
1615  $code = 0;
1616  }
1617  for ($i = $start + 1; $i < count($accounts); $i++) {
1618  $acccode = $accounts[$i]->getCode();
1619  if (is_numeric($acccode)) {
1620  if ($acccode - $code > 1) {
1621  break;
1622  }
1623  else {
1624  $code = $acccode;
1625  }
1626  }
1627  }
1628  $code = '' . ($code + 1);
1629  while (drupal_strlen($code) < 4) {
1630  $code = '0' . $code;
1631  }
1632  return $this->code . $code;
1633  }
Loads and saves to db objects of class IcesDBObject.
Definition: common.db.logic.inc:17
$code
Code.
Definition: ces_bank.logic.inc:1455