Code Duplication    Length = 45-46 lines in 2 locations

main/inc/lib/icalcreator/iCalcreator.class.php 2 locations

@@ 747-791 (lines=45) @@
744
     * @param mixed $arg2 optional, ordno if arg1 = component type
745
     * @return object
746
     */
747
    function getComponent( $arg1=FALSE, $arg2=FALSE ) {
748
        $index = $argType = null;
749
        if ( !$arg1 ) {
750
            $argType = 'INDEX';
751
            $index   = $this->compix['INDEX'] =
752
                ( isset( $this->compix['INDEX'] )) ? $this->compix['INDEX'] + 1 : 1;
753
        }
754
        elseif ( ctype_digit( (string) $arg1 )) {
755
            $argType = 'INDEX';
756
            $index   = (int) $arg1;
757
            unset( $this->compix );
758
        }
759
        elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {
760
            unset( $this->compix['INDEX'] );
761
            $argType = strtolower( $arg1 );
762
            if( !$arg2 )
763
                $index = $this->compix[$argType] =
764
                    ( isset( $this->compix[$argType] )) ? $this->compix[$argType] + 1 : 1;
765
            else
766
                $index = (int) $arg2;
767
        }
768
        $index  -= 1;
769
        $ckeys =  array_keys( $this->components );
770
        if( !empty( $index) && ( $index > end(  $ckeys )))
771
            return FALSE;
772
        $cix1gC = 0;
773
        foreach ( $this->components as $cix => $component) {
774
            if( empty( $component )) continue;
775
            unset( $component->propix );
776
            if(( 'INDEX' == $argType ) && ( $index == $cix ))
777
                return $component->copy();
778
            elseif( $argType == $component->objName ) {
779
                if( $index == $cix1gC )
780
                    return $component->copy();
781
                $cix1gC++;
782
            }
783
            elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {
784
                unset( $component->propix );
785
                return $component->copy();
786
            }
787
        }
788
        /* not found.. . */
789
        unset( $this->compix );
790
        return FALSE;
791
    }
792
    /**
793
     * select components from calendar on date basis
794
     *
@@ 6658-6703 (lines=46) @@
6655
     * @param mixed $arg2 optional, ordno if arg1 = component type
6656
     * @return object
6657
     */
6658
    function getComponent ( $arg1=FALSE, $arg2=FALSE ) {
6659
        if( !isset( $this->components )) return FALSE;
6660
        $index = $argType = null;
6661
        if ( !$arg1 ) {
6662
            $argType = 'INDEX';
6663
            $index   = $this->compix['INDEX'] =
6664
                ( isset( $this->compix['INDEX'] )) ? $this->compix['INDEX'] + 1 : 1;
6665
        }
6666
        elseif ( ctype_digit( (string) $arg1 )) {
6667
            $argType = 'INDEX';
6668
            $index   = (int) $arg1;
6669
            unset( $this->compix );
6670
        }
6671
        elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {
6672
            unset( $this->compix['INDEX'] );
6673
            $argType = strtolower( $arg1 );
6674
            if( !$arg2 )
6675
                $index = $this->compix[$argType] =
6676
                    ( isset( $this->compix[$argType] )) ? $this->compix[$argType] + 1 : 1;
6677
            else
6678
                $index = (int) $arg2;
6679
        }
6680
        $index  -= 1;
6681
        $ckeys = array_keys( $this->components );
6682
        if( !empty( $index) && ( $index > end( $ckeys )))
6683
            return FALSE;
6684
        $cix2gC = 0;
6685
        foreach( $this->components as $cix => $component ) {
6686
            if( empty( $component )) continue;
6687
            unset( $component->propix );
6688
            if(( 'INDEX' == $argType ) && ( $index == $cix ))
6689
                return $component->copy();
6690
            elseif( $argType == $component->objName ) {
6691
                if( $index == $cix2gC )
6692
                    return $component->copy();
6693
                $cix2gC++;
6694
            }
6695
            elseif( !$argType && ( $arg1 == $component->getProperty( 'uid' ))) {
6696
                unset( $component->propix );
6697
                return $component->copy();
6698
            }
6699
        }
6700
        /* not found.. . */
6701
        unset( $this->compix );
6702
        return false;
6703
    }
6704
    /**
6705
     * add calendar component as subcomponent to container for subcomponents
6706
     *