public static function getQuestions($blockId)
 {
     $criteria = new CDbCriteria();
     $relationTableName = QuestionsBlockQuestion::model()->tableName();
     $criteria->addCondition("id NOT IN (SELECT DISTINCT questionId FROM {$relationTableName} WHERE questionBlockId = :blockId)");
     $criteria->params = array(':blockId' => $blockId);
     return CHtml::listData(SurveyPurposeQuestion::model()->findAll($criteria), 'id', 'title');
 }
 public function actionDeleteQuestion($id, $questionId)
 {
     $relation = QuestionsBlockQuestion::model()->findByAttributes(array('questionId' => $questionId, 'questionBlockId' => $id));
     if ($relation) {
         $relation->delete();
     }
     $this->redirect(array('view', 'id' => $id));
 }
 protected function afterDelete()
 {
     QuestionsBlockQuestion::model()->deleteAllByAttributes(array('questionId' => $this->idCache));
     parent::afterDelete();
 }