1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom Attachment Handler

Discussion in 'XenForo Development Discussions' started by ragtek, Feb 17, 2011.

  1. ragtek

    ragtek Guest

    I've created a own content type, where i want to use the uploader.

    On the page, i'm having the editor and the upload button, after the upload it shows 100%, but then nothing happens.
    contenttype.PNG


    The console shows:
    content2.PNG
    My files:

    installcode:
    PHP:
        public function _install1(){
            
    $query = array();
            
    $query[]= "INSERT INTO xf_content_type
            (content_type, addon_id, fields)
        VALUES
            ('ragtek_article', 'ragtekAS', '')"
    ;

            
    $query[] = "
                        INSERT INTO xf_content_type_field
                            (content_type, field_name, field_value)
                        VALUES
                            ('ragtek_article', 'news_feed_handler_class', 'Ragtek_AS_NewsFeedHandler_Article'),
                            ('ragtek_article', 'alert_handler_class', 'Ragtek_AS_AlertHandler_Article'),
                            ('ragtek_article', 'search_handler_class', 'Ragtek_AS_Search_DataHandler_Article'),
                            ('ragtek_article', 'attachment_handler_class', 'Ragtek_AS_AttachmentHandler_Article'),
                            ('ragtek_article', 'like_handler_class', 'Ragtek_AS_LikeHandler_Article')"
    ;


            
    $query[] = "
                         CREATE TABLE  `xf`.`ragtek_article` (
                        `article_id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
                        `user_id` INT( 10 ) NOT NULL ,
                        `date` INT( 10 ) NOT NULL ,
                        `message` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
                        `attachcount` SMALLINT( 5 ) NOT NULL ,
                        `likes` INT( 10 ) NOT NULL ,
                        `likeusers` BLOB NOT NULL ,
                        PRIMARY KEY (  `article_id` )
                        ) ENGINE = MYISAM ;"
    ;

            
    XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache();
    controller
    PHP:
    class Ragtek_AS_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract {

        public function 
    actionIndex() {
            
    $articleModel $this->getArticleModel();
            
    $id 1;
            
    $article $articleModel->getArticleFromId($id);

            die(
    print_r($article));
        }

        public function 
    actionCreateArticle() {
            
    $articleModel $this->getArticleModel();
            
    $attachmentParams $articleModel->getAttachmentParams(array(
                    ));


            
    $viewParams = array(
                
    'attachmentParams' => $attachmentParams,
                
    'attachmentConstraints' => $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentConstraints(),
            );
            return 
    $this->responseView('Ragtek_AS_View_Create''article_create'$viewParams);
        }

    my attachment handler
    PHP:
    <?php

    class Ragtek_AS_AttachmentHandler_Article extends XenForo_AttachmentHandler_Abstract{

        protected 
    $articleModel null;

        protected 
    $contentIdKey 'article_id';


        protected function 
    _canUploadAndManageAttachments(array $contentData, array $viewingUser){
            return 
    true;
        }

        public function 
    _canViewAttachment(array $attachment, array $viewingUser){
            return 
    true;
        }

        public function 
    attachmentPostDelete(array $attachmentZend_Db_Adapter_Abstract $db){
        }

    }
     
  2. ragtek

    ragtek Guest

    I've tried to find the problem, but no chance:(

    In XenForo_Model_Attachment->public function getAttachmentHandler($contentType)

    the cachekey is: attachmentHandler_ragtek_article
    but these element isn't a object.
    so the code runs the query and gets: Ragtek_AS_AttachmentHandler_Article back

    now it's trying to create the new object

    $object = ($class ? new $class() : null);

    but that's not working.
    If i put a die('here'); under the creating of the object, nothing happens, above it, i'm getting the "here" message.

     
  3. Jaxel

    Jaxel Well-Known Member

    have you figured out how to make a custom attachment handler yet?

    Do you mind posting your getAttachmentParams function?
     
  4. Jaxel

    Jaxel Well-Known Member

    I now have the same problem as ragTek... it reaches 100% and then just stops...

    There is no entry for the item in the database either.
     
  5. ragtek

    ragtek Guest

    Yes, it's working now for me, but i don't know what the problem was, because we refactored the whole project to use more of the xenforo framework stuff.
     
  6. Jaxel

    Jaxel Well-Known Member

    Do you mind posting your code?
     

Share This Page