protected function setTagFor( $paragraphId, $tag )
    {
        $rows       = 0;
        $tagSql     = $this->sql( $this->getTableInSchema( static::$tagTableName ) );
        $tagJoinSql = $this->sql( $this->getTableInSchema( static::$tagJoinTableName ) );
        $tagId      = $this->getTagIdByName( $tag );

        if ( empty( $tagId ) )
        {
           $insert = $tagSql->insert()
                            ->values( array(
                                'locale'   => $this->getLocale(),
                                'name'     => $tag,
                            ) );

           $rows += $tagSql->prepareStatementForSqlObject( $insert )
                           ->execute()
                           ->getAffectedRows();

           $tagId = $this->getTagIdByName( $tag );
        }

        $data = array(
            'paragraphId'   => $paragraphId,
            'tagId'         => $tagId,
        );

        $select = $tagJoinSql->select()
                             ->where( $data );

        if ( ! $tagJoinSql->prepareStatementForSqlObject( $select )
                          ->execute()
                          ->getAffectedRows() )
        {
            $insert = $tagJoinSql->insert()
                                 ->values( $data );

            $rows += $tagJoinSql->prepareStatementForSqlObject( $insert )
                                ->execute()
                                ->getAffectedRows();
        }

        return $rows;
    }
protected function setTagFor( $paragraphId, $tag )
    {
        $rows       = 0;
        $tagSql     = $this->sql( $this->getTableInSchema( static::$tagTableName ) );
        $tagJoinSql = $this->sql( $this->getTableInSchema( static::$tagJoinTableName ) );
        $tagId      = $this->getTagIdByName( $tag );

        if ( empty( $tagId ) )
        {
           $insert = $tagSql->insert()
                            ->values( array(
                                'locale'   => $this->getLocale(),
                                'name'     => $tag,
                            ) );

           $rows += $tagSql->prepareStatementForSqlObject( $insert )
                           ->execute()
                           ->getAffectedRows();

           $tagId = $this->getTagIdByName( $tag );
        }

        $data = array(
            'paragraphId'   => $paragraphId,
            'tagId'         => $tagId,
        );

        $select = $tagJoinSql->select()
                             ->where( $data );

        if ( ! $tagJoinSql->prepareStatementForSqlObject( $select )
                          ->execute()
                          ->getAffectedRows() )
        {
            $insert = $tagJoinSql->insert()
                                 ->values( $data );

            $rows += $tagJoinSql->prepareStatementForSqlObject( $insert )
                                ->execute()
                                ->getAffectedRows();
        }

        return $rows;
    }
protected function setTagFor ( $ paragraphId , $ tag ) { $ rows = 0 ; $ tagSql = $ this -> sql ( $ this -> getTableInSchema ( static :: $ tagTableName ) ) ; $ tagJoinSql = $ this -> sql ( $ this -> getTableInSchema ( static :: $ tagJoinTableName ) ) ; $ tagId = $ this -> getTagIdByName ( $ tag ) ; if ( empty ( $ tagId ) ) { $ insert = $ tagSql -> insert ( ) -> values ( array ( 'locale' => $ this -> getLocale ( ) , 'name' => $ tag , ) ) ; $ rows += $ tagSql -> prepareStatementForSqlObject ( $ insert ) -> execute ( ) -> getAffectedRows ( ) ; $ tagId = $ this -> getTagIdByName ( $ tag ) ; } $ data = array ( 'paragraphId' => $ paragraphId , 'tagId' => $ tagId , ) ; $ select = $ tagJoinSql -> select ( ) -> where ( $ data ) ; if ( ! $ tagJoinSql -> prepareStatementForSqlObject ( $ select ) -> execute ( ) -> getAffectedRows ( ) ) { $ insert = $ tagJoinSql -> insert ( ) -> values ( $ data ) ; $ rows += $ tagJoinSql -> prepareStatementForSqlObject ( $ insert ) -> execute ( ) -> getAffectedRows ( ) ; } return $ rows ; }
Set a tag for a paragraph

@param   int     $paragraphId
@param   string  $tag
@return  int
Set a tag for a paragraph