コード例 #1
0
 /**
  * Create
  *
  * @param array   $data
  * @return Question $q
  */
 protected function air_create($data)
 {
     if (!isset($data['ques_template']) && !isset($data['duplicate'])) {
         throw new Rframe_Exception(Rframe::BAD_DATA, "Missing required param: ques_template OR duplicate");
     }
     if (isset($data['ques_template']) && $data['ques_template'] == 'fileupload') {
         if ($this->parent_rec->has_file_upload_question()) {
             throw new Rframe_Exception(Rframe::BAD_DATA, "Only one file upload question allowed per query");
         }
     }
     $q = new Question();
     $q->ques_inq_id = $this->parent_rec->inq_id;
     // rethrow as api exceptions
     try {
         if (isset($data['ques_template'])) {
             AIR2_QueryBuilder::make_question($q, $data['ques_template']);
         } elseif (isset($data['duplicate'])) {
             AIR2_QueryBuilder::copy_question($q, $data['duplicate']);
         }
     } catch (Exception $e) {
         throw new Rframe_Exception(RFrame::BAD_DATA, $e->getMessage());
     }
     // optionally fix the whole sequence
     if (isset($data['resequence'])) {
         $this->_fix_sequence($q, $data['resequence']);
     }
     return $q;
 }
コード例 #2
0
 /**
  * See if the permission question is needed.
  *
  *
  * @param bool    $force (optional) force creation
  */
 public function check_permission_question($force = false)
 {
     // get all existing questions
     if (!$force) {
         $q = AIR2_Query::create()->from('Question q');
         $q->where('q.ques_inq_id = ?', $this->inq_id);
         $q->andWhere('q.ques_public_flag = 1');
         $q->andWhereNotIn('q.ques_type', array(Question::$TYPE_CONTRIBUTOR, Question::$TYPE_PERMISSION_HIDDEN, Question::$TYPE_PERMISSION, Question::$TYPE_PICK_COUNTRY, Question::$TYPE_PICK_STATE));
         $count = $q->count();
     }
     if ($force || $count) {
         $permq = $this->_fetch_permission_question();
         if (!$permq && !$this->_has_permission_question) {
             // doctrine doesn't seem to notice the question below right away
             // this is a backstop to prevent adding duplicates
             $this->_has_permission_question = true;
             $question = new Question();
             $question->ques_inq_id = $this->inq_id;
             $question->ques_dis_seq = 99;
             $template = Question::$TKEY_PERMISSION;
             AIR2_QueryBuilder::make_question($question, $template);
             // save question
             $question->save();
         }
         // update flag on this inquiry if necessary
         if (!$this->inq_public_flag) {
             $this->inq_public_flag = 1;
             $this->save();
         }
     } elseif (!$count && $this->inq_type == self::$TYPE_FORMBUILDER) {
         // legacy queries allowed to have permission question
         // with no accompanying public questions.
         // so no-op here. See redmine #7785
     } else {
         $permq = $this->_fetch_permission_question();
         if ($permq) {
             $permq->delete();
             // update flag on this inquiry if necessary
             if ($this->inq_public_flag) {
                 $this->inq_public_flag = 0;
                 $this->save();
             }
         }
     }
 }