public function updateModeratorForMany($newForums = [], $oldForums = [])
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $add = [];
            foreach ($newForums as $forum) {
                if (!in_array($forum, $oldForums, true) && (new Query)->from(Forum::tableName())->where(['id' => $forum])->exists()
                        && (new Query)->from(Mod::tableName())->where(['forum_id' => $forum, 'user_id' => $this->id])->exists() === false) {
                    $add[] = [$forum, $this->id];
                }
            }
            $remove = [];
            foreach ($oldForums as $forum) {
                if (!in_array($forum, $newForums, true) && (new Query)->from(Mod::tableName())->where(['forum_id' => $forum, 'user_id' => $this->id])->exists()) {
                    $remove[] = $forum;
                }
            }
            if (!empty($add) && !Podium::getInstance()->db->createCommand()->batchInsert(Mod::tableName(), ['forum_id', 'user_id'], $add)->execute()) {
                throw new Exception('Moderators adding error!');
            }
            if (!empty($remove) && !Podium::getInstance()->db->createCommand()->delete(Mod::tableName(), ['forum_id' => $remove, 'user_id' => $this->id])->execute()) {
                throw new Exception('Moderators deleting error!');
            }
            Podium::getInstance()->podiumCache->delete('forum.moderators');
            Log::info('Moderators updated', null, __METHOD__);
            $transaction->commit();
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
public function updateModeratorForMany($newForums = [], $oldForums = [])
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $add = [];
            foreach ($newForums as $forum) {
                if (!in_array($forum, $oldForums, true) && (new Query)->from(Forum::tableName())->where(['id' => $forum])->exists()
                        && (new Query)->from(Mod::tableName())->where(['forum_id' => $forum, 'user_id' => $this->id])->exists() === false) {
                    $add[] = [$forum, $this->id];
                }
            }
            $remove = [];
            foreach ($oldForums as $forum) {
                if (!in_array($forum, $newForums, true) && (new Query)->from(Mod::tableName())->where(['forum_id' => $forum, 'user_id' => $this->id])->exists()) {
                    $remove[] = $forum;
                }
            }
            if (!empty($add) && !Podium::getInstance()->db->createCommand()->batchInsert(Mod::tableName(), ['forum_id', 'user_id'], $add)->execute()) {
                throw new Exception('Moderators adding error!');
            }
            if (!empty($remove) && !Podium::getInstance()->db->createCommand()->delete(Mod::tableName(), ['forum_id' => $remove, 'user_id' => $this->id])->execute()) {
                throw new Exception('Moderators deleting error!');
            }
            Podium::getInstance()->podiumCache->delete('forum.moderators');
            Log::info('Moderators updated', null, __METHOD__);
            $transaction->commit();
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
public function updateModeratorForMany ( $ newForums = [ ] , $ oldForums = [ ] ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ add = [ ] ; foreach ( $ newForums as $ forum ) { if ( ! in_array ( $ forum , $ oldForums , true ) && ( new Query ) -> from ( Forum :: tableName ( ) ) -> where ( [ 'id' => $ forum ] ) -> exists ( ) && ( new Query ) -> from ( Mod :: tableName ( ) ) -> where ( [ 'forum_id' => $ forum , 'user_id' => $ this -> id ] ) -> exists ( ) === false ) { $ add [ ] = [ $ forum , $ this -> id ] ; } } $ remove = [ ] ; foreach ( $ oldForums as $ forum ) { if ( ! in_array ( $ forum , $ newForums , true ) && ( new Query ) -> from ( Mod :: tableName ( ) ) -> where ( [ 'forum_id' => $ forum , 'user_id' => $ this -> id ] ) -> exists ( ) ) { $ remove [ ] = $ forum ; } } if ( ! empty ( $ add ) && ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> batchInsert ( Mod :: tableName ( ) , [ 'forum_id' , 'user_id' ] , $ add ) -> execute ( ) ) { throw new Exception ( 'Moderators adding error!' ) ; } if ( ! empty ( $ remove ) && ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( Mod :: tableName ( ) , [ 'forum_id' => $ remove , 'user_id' => $ this -> id ] ) -> execute ( ) ) { throw new Exception ( 'Moderators deleting error!' ) ; } Podium :: getInstance ( ) -> podiumCache -> delete ( 'forum.moderators' ) ; Log :: info ( 'Moderators updated' , null , __METHOD__ ) ; $ transaction -> commit ( ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Updates moderator assignment for given forums.
@param array $newForums new assigned forum IDs
@param array $oldForums old assigned forum IDs
@return bool
@since 0.2
Updates moderator assignment for given forums .