Beispiel #1
0
 /**
  * get a new name, that does not exist under specified $pid
  *
  * If there is no any active (not deleted) object with specied name under $pid
  * then same name is returned.
  * If name exists then a new name will be generated with " (<number>)" at the end.
  * Note that extension is not changed.
  * Extension is considered any combination of chars delimited by dot
  * at the end of an object and its length is less than 5 chars.
  *
  * @param  int     $pid  parent id
  * @param  varchar $name desired name
  * @return varchar new name
  */
 public static function getAvailableName($pid, $name)
 {
     $newName = $name;
     $a = explode('.', $name);
     $ext = '';
     if (sizeof($a) > 1 && sizeof($a) < 5) {
         $ext = array_pop($a);
     }
     $name = implode('.', $a);
     /* get similar names*/
     $names = DM\Tree::getChildNames($pid, $name, $ext);
     $i = 1;
     while (in_array($newName, $names)) {
         $newName = $name . ' (' . $i . ')' . (empty($ext) ? '' : '.' . $ext);
         $i++;
     }
     return $newName;
 }