concrete/blocks/form/controller.php
protected function questionVersioning($data = [])
    {
        $data += [
            'ignoreQuestionIDs' => '',
            'pendingDeleteIDs' => '',
        ];
        $db = Database::connection();
        $oldBID = intval($data['bID']);

        //if this block is being edited a second time, remove edited questions with the current bID that are pending replacement
        //if( intval($oldBID) == intval($this->bID) ){
            $vals = [intval($data['oldQsID'])];
        $pendingQuestions = $db->getAll('SELECT msqID FROM btFormQuestions WHERE bID=0 && questionSetId=?', $vals);
        foreach ($pendingQuestions as $pendingQuestion) {
            $vals = [intval($this->bID), intval($pendingQuestion['msqID'])];
            $db->query('DELETE FROM btFormQuestions WHERE bID=? AND msqID=?', $vals);
        }
        //}

        //assign any new questions the new block id
        $vals = [intval($data['bID']), intval($data['qsID']), intval($data['oldQsID'])];
        $rs = $db->query('UPDATE btFormQuestions SET bID=?, questionSetId=? WHERE bID=0 && questionSetId=?', $vals);

        //These are deleted or edited questions.  (edited questions have already been created with the new bID).
        $ignoreQuestionIDsDirty = explode(',', $data['ignoreQuestionIDs']);
        $ignoreQuestionIDs = [0];
        foreach ($ignoreQuestionIDsDirty as $msqID) {
            $ignoreQuestionIDs[] = intval($msqID);
        }
        $ignoreQuestionIDstr = implode(',', $ignoreQuestionIDs);

        //remove any questions that are pending deletion, that already have this current bID
        $pendingDeleteQIDsDirty = explode(',', $data['pendingDeleteIDs']);
        $pendingDeleteQIDs = [];
        foreach ($pendingDeleteQIDsDirty as $msqID) {
            $pendingDeleteQIDs[] = intval($msqID);
        }
        $vals = [$this->bID, intval($data['qsID'])];
        $pendingDeleteQIDs = implode(',', $pendingDeleteQIDs);
        $unchangedQuestions = $db->query('DELETE FROM btFormQuestions WHERE bID=? AND questionSetId=? AND msqID IN (' . $pendingDeleteQIDs . ')', $vals);
    }
protected function questionVersioning($data = [])
    {
        $data += [
            'ignoreQuestionIDs' => '',
            'pendingDeleteIDs' => '',
        ];
        $db = Database::connection();
        $oldBID = intval($data['bID']);

        //if this block is being edited a second time, remove edited questions with the current bID that are pending replacement
        //if( intval($oldBID) == intval($this->bID) ){
            $vals = [intval($data['oldQsID'])];
        $pendingQuestions = $db->getAll('SELECT msqID FROM btFormQuestions WHERE bID=0 && questionSetId=?', $vals);
        foreach ($pendingQuestions as $pendingQuestion) {
            $vals = [intval($this->bID), intval($pendingQuestion['msqID'])];
            $db->query('DELETE FROM btFormQuestions WHERE bID=? AND msqID=?', $vals);
        }
        //}

        //assign any new questions the new block id
        $vals = [intval($data['bID']), intval($data['qsID']), intval($data['oldQsID'])];
        $rs = $db->query('UPDATE btFormQuestions SET bID=?, questionSetId=? WHERE bID=0 && questionSetId=?', $vals);

        //These are deleted or edited questions.  (edited questions have already been created with the new bID).
        $ignoreQuestionIDsDirty = explode(',', $data['ignoreQuestionIDs']);
        $ignoreQuestionIDs = [0];
        foreach ($ignoreQuestionIDsDirty as $msqID) {
            $ignoreQuestionIDs[] = intval($msqID);
        }
        $ignoreQuestionIDstr = implode(',', $ignoreQuestionIDs);

        //remove any questions that are pending deletion, that already have this current bID
        $pendingDeleteQIDsDirty = explode(',', $data['pendingDeleteIDs']);
        $pendingDeleteQIDs = [];
        foreach ($pendingDeleteQIDsDirty as $msqID) {
            $pendingDeleteQIDs[] = intval($msqID);
        }
        $vals = [$this->bID, intval($data['qsID'])];
        $pendingDeleteQIDs = implode(',', $pendingDeleteQIDs);
        $unchangedQuestions = $db->query('DELETE FROM btFormQuestions WHERE bID=? AND questionSetId=? AND msqID IN (' . $pendingDeleteQIDs . ')', $vals);
    }
protected function questionVersioning ( $ data = [ ] ) { $ data += [ 'ignoreQuestionIDs' => '' , 'pendingDeleteIDs' => '' , ] ; $ db = Database :: connection ( ) ; $ oldBID = intval ( $ data [ 'bID' ] ) ; //if this block is being edited a second time, remove edited questions with the current bID that are pending replacement //if( intval($oldBID) == intval($this->bID) ){ $ vals = [ intval ( $ data [ 'oldQsID' ] ) ] ; $ pendingQuestions = $ db -> getAll ( 'SELECT msqID FROM btFormQuestions WHERE bID=0 && questionSetId=?' , $ vals ) ; foreach ( $ pendingQuestions as $ pendingQuestion ) { $ vals = [ intval ( $ this -> bID ) , intval ( $ pendingQuestion [ 'msqID' ] ) ] ; $ db -> query ( 'DELETE FROM btFormQuestions WHERE bID=? AND msqID=?' , $ vals ) ; } //} //assign any new questions the new block id $ vals = [ intval ( $ data [ 'bID' ] ) , intval ( $ data [ 'qsID' ] ) , intval ( $ data [ 'oldQsID' ] ) ] ; $ rs = $ db -> query ( 'UPDATE btFormQuestions SET bID=?, questionSetId=? WHERE bID=0 && questionSetId=?' , $ vals ) ; //These are deleted or edited questions.  (edited questions have already been created with the new bID). $ ignoreQuestionIDsDirty = explode ( ',' , $ data [ 'ignoreQuestionIDs' ] ) ; $ ignoreQuestionIDs = [ 0 ] ; foreach ( $ ignoreQuestionIDsDirty as $ msqID ) { $ ignoreQuestionIDs [ ] = intval ( $ msqID ) ; } $ ignoreQuestionIDstr = implode ( ',' , $ ignoreQuestionIDs ) ; //remove any questions that are pending deletion, that already have this current bID $ pendingDeleteQIDsDirty = explode ( ',' , $ data [ 'pendingDeleteIDs' ] ) ; $ pendingDeleteQIDs = [ ] ; foreach ( $ pendingDeleteQIDsDirty as $ msqID ) { $ pendingDeleteQIDs [ ] = intval ( $ msqID ) ; } $ vals = [ $ this -> bID , intval ( $ data [ 'qsID' ] ) ] ; $ pendingDeleteQIDs = implode ( ',' , $ pendingDeleteQIDs ) ; $ unchangedQuestions = $ db -> query ( 'DELETE FROM btFormQuestions WHERE bID=? AND questionSetId=? AND msqID IN (' . $ pendingDeleteQIDs . ')' , $ vals ) ; }
Ties the new or edited questions to the new block number.
New and edited questions are temporarily given bID=0, until the block is saved... painfully complicated.

@param array $data
Ties the new or edited questions to the new block number . New and edited questions are temporarily given bID = 0 until the block is saved ... painfully complicated .