protected function generateIdentifier($prefix = ''){

        $relatedItem = $this->getRelatedItem();
        if(is_null($relatedItem)){
            throw new QtiModelException('cannot generate the identifier because the element does not belong to any item');
        }
        $identifiedElementsCollection = $relatedItem->getIdentifiedElements();
        
        $index = 1;
        $suffix = '';

        if(empty($prefix)){
            $clazz = get_class($this);
            if(preg_match('/[A-Z]{1}[a-z]*$/', $clazz, $matches)){
                $prefix = $matches[0];
            }else{
                $prefix = substr($clazz, strripos($clazz, '_')+1);
            }
            $suffix = '_'.$index;
        }else{
            $prefix = preg_replace('/_[0-9]+$/', '_', $prefix); //detect incremental id of type choice_12, response_3, etc.
            $prefix = preg_replace('/[^a-zA-Z0-9_]/', '_', $prefix);
            $prefix = preg_replace('/(_)+/', '_', $prefix);
        }

        do{
            $exist = false;
            $id = $prefix.$suffix;
            if($identifiedElementsCollection->exists($id)){
                $exist = true;
                $suffix = '_'.$index;
                $index++;
            }
        } while($exist);
        
        return $id;
    }
protected function generateIdentifier($prefix = ''){

        $relatedItem = $this->getRelatedItem();
        if(is_null($relatedItem)){
            throw new QtiModelException('cannot generate the identifier because the element does not belong to any item');
        }
        $identifiedElementsCollection = $relatedItem->getIdentifiedElements();
        
        $index = 1;
        $suffix = '';

        if(empty($prefix)){
            $clazz = get_class($this);
            if(preg_match('/[A-Z]{1}[a-z]*$/', $clazz, $matches)){
                $prefix = $matches[0];
            }else{
                $prefix = substr($clazz, strripos($clazz, '_')+1);
            }
            $suffix = '_'.$index;
        }else{
            $prefix = preg_replace('/_[0-9]+$/', '_', $prefix); //detect incremental id of type choice_12, response_3, etc.
            $prefix = preg_replace('/[^a-zA-Z0-9_]/', '_', $prefix);
            $prefix = preg_replace('/(_)+/', '_', $prefix);
        }

        do{
            $exist = false;
            $id = $prefix.$suffix;
            if($identifiedElementsCollection->exists($id)){
                $exist = true;
                $suffix = '_'.$index;
                $index++;
            }
        } while($exist);
        
        return $id;
    }
protected function generateIdentifier ( $ prefix = '' ) { $ relatedItem = $ this -> getRelatedItem ( ) ; if ( is_null ( $ relatedItem ) ) { throw new QtiModelException ( 'cannot generate the identifier because the element does not belong to any item' ) ; } $ identifiedElementsCollection = $ relatedItem -> getIdentifiedElements ( ) ; $ index = 1 ; $ suffix = '' ; if ( empty ( $ prefix ) ) { $ clazz = get_class ( $ this ) ; if ( preg_match ( '/[A-Z]{1}[a-z]*$/' , $ clazz , $ matches ) ) { $ prefix = $ matches [ 0 ] ; } else { $ prefix = substr ( $ clazz , strripos ( $ clazz , '_' ) + 1 ) ; } $ suffix = '_' . $ index ; } else { $ prefix = preg_replace ( '/_[0-9]+$/' , '_' , $ prefix ) ; //detect incremental id of type choice_12, response_3, etc. $ prefix = preg_replace ( '/[^a-zA-Z0-9_]/' , '_' , $ prefix ) ; $ prefix = preg_replace ( '/(_)+/' , '_' , $ prefix ) ; } do { $ exist = false ; $ id = $ prefix . $ suffix ; if ( $ identifiedElementsCollection -> exists ( $ id ) ) { $ exist = true ; $ suffix = '_' . $ index ; $ index ++ ; } } while ( $ exist ) ; return $ id ; }
Create a unique identifier, based on the class if the qti element.

@access protected
@author Sam, <sam@taotesting.com>

@param string $prefix

@return mixed
@throws QtiModelException
Create a unique identifier based on the class if the qti element .