public function createItem()
    {
        if(!\tao_helpers_Request::isAjax()){
            throw new common_exception_BadRequest('wrong request mode');
        }
        $clazz = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
        if ($clazz->isClass()) {
            $clazz = new \core_kernel_classes_Class($clazz);
        } else {
            foreach ($clazz->getTypes() as $type) {
                // determine class from selected instance
                $clazz = $type;
                break;
            }
        }
        $service = \taoItems_models_classes_ItemsService::singleton();

        $label = $service->createUniqueLabel($clazz);
        $item = $service->createInstance($clazz, $label);

        if(!is_null($item)){
            $service->setItemModel($item, new \core_kernel_classes_Resource(ItemModel::MODEL_URI));
            $this->getEventManager()->trigger(new ItemCreatedEvent($item->getUri()));
            $response = array(
                'label'	=> $item->getLabel(),
                'uri' 	=> $item->getUri()
            );
        } else {
            $response = false;
        }
        $this->returnJson($response);
    }
public function createItem()
    {
        if(!\tao_helpers_Request::isAjax()){
            throw new common_exception_BadRequest('wrong request mode');
        }
        $clazz = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
        if ($clazz->isClass()) {
            $clazz = new \core_kernel_classes_Class($clazz);
        } else {
            foreach ($clazz->getTypes() as $type) {
                // determine class from selected instance
                $clazz = $type;
                break;
            }
        }
        $service = \taoItems_models_classes_ItemsService::singleton();

        $label = $service->createUniqueLabel($clazz);
        $item = $service->createInstance($clazz, $label);

        if(!is_null($item)){
            $service->setItemModel($item, new \core_kernel_classes_Resource(ItemModel::MODEL_URI));
            $this->getEventManager()->trigger(new ItemCreatedEvent($item->getUri()));
            $response = array(
                'label'	=> $item->getLabel(),
                'uri' 	=> $item->getUri()
            );
        } else {
            $response = false;
        }
        $this->returnJson($response);
    }
public function createItem ( ) { if ( ! \ tao_helpers_Request :: isAjax ( ) ) { throw new common_exception_BadRequest ( 'wrong request mode' ) ; } $ clazz = new \ core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'id' ) ) ; if ( $ clazz -> isClass ( ) ) { $ clazz = new \ core_kernel_classes_Class ( $ clazz ) ; } else { foreach ( $ clazz -> getTypes ( ) as $ type ) { // determine class from selected instance $ clazz = $ type ; break ; } } $ service = \ taoItems_models_classes_ItemsService :: singleton ( ) ; $ label = $ service -> createUniqueLabel ( $ clazz ) ; $ item = $ service -> createInstance ( $ clazz , $ label ) ; if ( ! is_null ( $ item ) ) { $ service -> setItemModel ( $ item , new \ core_kernel_classes_Resource ( ItemModel :: MODEL_URI ) ) ; $ this -> getEventManager ( ) -> trigger ( new ItemCreatedEvent ( $ item -> getUri ( ) ) ) ; $ response = array ( 'label' => $ item -> getLabel ( ) , 'uri' => $ item -> getUri ( ) ) ; } else { $ response = false ; } $ this -> returnJson ( $ response ) ; }
create a new QTI item

@throws common_exception_BadRequest
@throws common_exception_Error

@requiresRight id WRITE
create a new QTI item