original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Set a tag for a paragraph
  
  @param   int     $paragraphId
  @param   string  $tag
  @return  int
docstring_tokens: Set a tag for a paragraph