/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = QuestionAlias::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->andFilterWhere(['a_fr_id' => $this->a_fr_id]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['al_id' => $this->al_id]);
     return $dataProvider;
 }
 public function actionDeleteAlias($id, $alid)
 {
     QuestionAlias::deleteAll(['a_fr_id' => $id, 'al_id' => $alid]);
     return $this->redirect(['question/' . $id . '/aliases']);
 }
Exemplo n.º 3
0
 public function getAliasesCount()
 {
     return QuestionAlias::find()->where(['a_fr_id' => $this->fr_id])->count();
 }
Exemplo n.º 4
0
 private function parseQuestions($text, $separator, $condition = "", &$qcount, $bank_id = null)
 {
     $data = explode($separator, trim($text));
     $tmp = array();
     foreach ($data as $val) {
         $entry = array();
         $cmd = trim($val);
         $hidden = false;
         $aslist = false;
         $horizontal = false;
         if ($cmd != "") {
             switch ($cmd[0]) {
                 case "#":
                     $entry['cmd'] = "header";
                     $entry['text'] = substr($cmd, 1);
                     $entry['condition'] = $condition;
                     $tmp[] = $entry;
                     break;
                 case "@":
                     $entry['cmd'] = "pagebreak";
                     $entry['condition'] = $condition;
                     $tmp[] = $entry;
                     break;
                 case "w":
                     $cond = array();
                     $stat = "";
                     for ($i = 4; $i < strlen($cmd); $i++) {
                         if ($cmd[$i] == "(") {
                             if ($stat == "condition") {
                                 $stat = "commands";
                             } else {
                                 $stat = "condition";
                             }
                         }
                         if ($cmd[$i] != "(" && $cmd[$i] != ")") {
                             if (!isset($cond[$stat])) {
                                 $cond[$stat] = '';
                             }
                             $cond[$stat] .= $cmd[$i];
                         }
                     }
                     $sub = $this->parseQuestions($cond['commands'], ",", $cond['condition'], $qcount);
                     foreach ($sub as $entry) {
                         $tmp[] = $entry;
                     }
                     break;
                 case "H":
                 case "L":
                 case "N":
                     $prefix = $cmd[0];
                     $cmd = substr($cmd, 1);
                     if ($prefix == "H") {
                         $hidden = true;
                     }
                     if ($prefix == "L") {
                         $aslist = true;
                     }
                     if ($prefix == "N") {
                         $horizontal = true;
                     }
                 default:
                     $entry = Question::find()->where(['fr_id' => $cmd])->asArray()->one();
                     if (!$entry) {
                         return 0;
                     }
                     //var_dump($entry);
                     $entry['cmd'] = "question";
                     $entry['condition'] = $condition;
                     $entry['pos'] = $qcount;
                     if ($hidden) {
                         $entry['hidden'] = true;
                     } else {
                         $entry['hidden'] = false;
                     }
                     if ($aslist) {
                         $entry['aslist'] = true;
                     } else {
                         $entry['aslist'] = false;
                     }
                     if ($horizontal) {
                         $entry['horizontal'] = true;
                     } else {
                         $entry['horizontal'] = false;
                     }
                     $qcount++;
                     if (strpos($cmd, "!")) {
                         $oal = explode("!", $cmd);
                         $entry2 = Question::find()->where(['fr_id' => $oal[0]])->asArray()->one();
                         if (isset($entry2['frage'])) {
                             $entry['frage'] = $entry2['frage'];
                             $entry['dset'] = $oal[1];
                         }
                     }
                     if (strpos($cmd, "/")) {
                         $al = explode("/", $cmd);
                         $al = QuestionAlias::find()->where(['a_fr_id' => $al[0], 'al_id' => $al[1]])->asArray()->one();
                         if ($al) {
                             $entry['frage'] = $al['alias'];
                         }
                     }
                     //bank alias!
                     if ($bank_id !== null) {
                         $al = Alias::find()->where(['b_id' => $bank_id])->asArray()->all();
                         if (count($al)) {
                             foreach ($al as $replacement) {
                                 $entry['frage'] = str_replace($replacement['original'], $replacement['alias'], $entry['frage']);
                             }
                         }
                     }
                     $tmp[] = $entry;
                     break;
             }
         }
     }
     $data = $tmp;
     return $data;
 }