library/Garp/Model/Behavior/Article.php
public function relateChapters(array $chapters, Garp_Model_Db $model, $articleId) {
        // Start by unrelating all chapters
        Garp_Content_Relation_Manager::unrelate(
            array(
                'modelA' => $model,
                'modelB' => 'Model_Chapter',
                'keyA'   => $articleId,
            )
        );
        // Reverse order since the Weighable behavior sorts chapter by weight DESC,
        // giving each new chapter the highest weight.
        $chapters = array_reverse($chapters);
        foreach ($chapters as $chapterData) {
            $chapterData = $this->_getValidChapterData($chapterData);

            /**
             * Insert a new chapter.
             * The chapter will take care of storing and relating the
             * content nodes.
             */
            $chapterModel = new Model_Chapter();
            $chapterId = $chapterModel->insert(
                array(
                    'type'    => $chapterData['type'],
                    'content' => $chapterData['content'],
                )
            );

            Garp_Content_Relation_Manager::relate(
                array(
                    'modelA' => $model,
                    'modelB' => 'Model_Chapter',
                    'keyA'   => $articleId,
                    'keyB'   => $chapterId,
                )
            );
        }
    }
public function relateChapters(array $chapters, Garp_Model_Db $model, $articleId) {
        // Start by unrelating all chapters
        Garp_Content_Relation_Manager::unrelate(
            array(
                'modelA' => $model,
                'modelB' => 'Model_Chapter',
                'keyA'   => $articleId,
            )
        );
        // Reverse order since the Weighable behavior sorts chapter by weight DESC,
        // giving each new chapter the highest weight.
        $chapters = array_reverse($chapters);
        foreach ($chapters as $chapterData) {
            $chapterData = $this->_getValidChapterData($chapterData);

            /**
             * Insert a new chapter.
             * The chapter will take care of storing and relating the
             * content nodes.
             */
            $chapterModel = new Model_Chapter();
            $chapterId = $chapterModel->insert(
                array(
                    'type'    => $chapterData['type'],
                    'content' => $chapterData['content'],
                )
            );

            Garp_Content_Relation_Manager::relate(
                array(
                    'modelA' => $model,
                    'modelB' => 'Model_Chapter',
                    'keyA'   => $articleId,
                    'keyB'   => $chapterId,
                )
            );
        }
    }
public function relateChapters ( array $ chapters , Garp_Model_Db $ model , $ articleId ) { // Start by unrelating all chapters Garp_Content_Relation_Manager :: unrelate ( array ( 'modelA' => $ model , 'modelB' => 'Model_Chapter' , 'keyA' => $ articleId , ) ) ; // Reverse order since the Weighable behavior sorts chapter by weight DESC, // giving each new chapter the highest weight. $ chapters = array_reverse ( $ chapters ) ; foreach ( $ chapters as $ chapterData ) { $ chapterData = $ this -> _getValidChapterData ( $ chapterData ) ; /**
             * Insert a new chapter.
             * The chapter will take care of storing and relating the
             * content nodes.
             */ $ chapterModel = new Model_Chapter ( ) ; $ chapterId = $ chapterModel -> insert ( array ( 'type' => $ chapterData [ 'type' ] , 'content' => $ chapterData [ 'content' ] , ) ) ; Garp_Content_Relation_Manager :: relate ( array ( 'modelA' => $ model , 'modelB' => 'Model_Chapter' , 'keyA' => $ articleId , 'keyB' => $ chapterId , ) ) ; } }
Relate Chapters.
Called after insert and after update.

@param array $chapters
@param Garp_Model_Db $model The subject model
@param int $articleId The id of the involved article
@return void
Relate Chapters . Called after insert and after update .