public static function ajaxDeleteCategory($data, $func) { if (!current_user_can('wpProQuiz_edit_quiz')) { return json_encode(array()); } $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $category = new WpProQuiz_Model_Category($data); $categoryMapper->delete($category->getCategoryId()); return json_encode(array()); }
public function save(WpProQuiz_Model_Category $category) { $data = array('category_name' => $category->getCategoryName()); $format = array('%s'); $type = $category->getType(); if ($category->getCategoryId() == 0) { $this->_wpdb->insert($this->_tableCategory, array('category_name' => $category->getCategoryName(), 'type' => empty($type) ? 'QUESTION' : $type), array('%s', '%s')); $category->setCategoryId($this->_wpdb->insert_id); } else { $this->_wpdb->update($this->_tableCategory, array('category_name' => $category->getCategoryName()), array('category_id' => $category->getCategoryId()), array('%s'), array('%d')); } return $category; }
/** * @deprecated */ private function show($quizId) { if (!current_user_can('wpProQuiz_show_statistics')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $this->showNew($quizId); return; $view = new WpProQuiz_View_Statistics(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $questions = $questionMapper->fetchAll($quizId); $category = $categoryMapper->fetchAll(); $categoryEmpty = new WpProQuiz_Model_Category(); $categoryEmpty->setCategoryName(__('No category', 'wp-pro-quiz')); $list = array(); $cats = array(); foreach ($category as $c) { $cats[$c->getCategoryId()] = $c; } $cats[0] = $categoryEmpty; foreach ($questions as $q) { $list[$q->getCategoryId()][] = $q; } $view->quiz = $quizMapper->fetch($quizId); $view->questionList = $list; $view->categoryList = $cats; $view->forms = $formMapper->fetch($quizId); if (has_action('pre_user_query', 'ure_exclude_administrators')) { remove_action('pre_user_query', 'ure_exclude_administrators'); $users = get_users(array('fields' => array('ID', 'user_login', 'display_name'))); add_action('pre_user_query', 'ure_exclude_administrators'); } else { $users = get_users(array('fields' => array('ID', 'user_login', 'display_name'))); } array_unshift($users, (object) array('ID' => 0)); $view->users = $users; $view->show(); }
public function saveImport($ids) { $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $data = $this->getImportData(); $categoryArray = $categoryMapper->getCategoryArrayForImport(); $categoryArrayQuiz = $categoryMapper->getCategoryArrayForImport(WpProQuiz_Model_Category::CATEGORY_TYPE_QUIZ); foreach ($data['master'] as $quiz) { if (get_class($quiz) !== 'WpProQuiz_Model_Quiz') { continue; } $oldId = $quiz->getId(); if ($ids !== false && !in_array($oldId, $ids)) { continue; } $quiz->setId(0); $quiz->setCategoryId(0); if (trim($quiz->getCategoryName()) != '') { if (isset($categoryArrayQuiz[strtolower($quiz->getCategoryName())])) { $quiz->setCategoryId($categoryArrayQuiz[strtolower($quiz->getCategoryName())]); } else { $categoryModel = new WpProQuiz_Model_Category(); $categoryModel->setCategoryName($quiz->getCategoryName()); $categoryModel->setType(WpProQuiz_Model_Category::CATEGORY_TYPE_QUIZ); $categoryMapper->save($categoryModel); $quiz->setCategoryId($categoryModel->getCategoryId()); $categoryArrayQuiz[strtolower($quiz->getCategoryName())] = $categoryModel->getCategoryId(); } } $quizMapper->save($quiz); if (isset($data['forms']) && isset($data['forms'][$oldId])) { $sort = 0; foreach ($data['forms'][$oldId] as $form) { $form->setQuizId($quiz->getId()); $form->setSort($sort++); } $formMapper->update($data['forms'][$oldId]); } $sort = 0; foreach ($data['question'][$oldId] as $question) { if (get_class($question) !== 'WpProQuiz_Model_Question') { continue; } $question->setQuizId($quiz->getId()); $question->setId(0); $question->setSort($sort++); $question->setCategoryId(0); if (trim($question->getCategoryName()) != '') { if (isset($categoryArray[strtolower($question->getCategoryName())])) { $question->setCategoryId($categoryArray[strtolower($question->getCategoryName())]); } else { $categoryModel = new WpProQuiz_Model_Category(); $categoryModel->setCategoryName($question->getCategoryName()); $categoryMapper->save($categoryModel); $question->setCategoryId($categoryModel->getCategoryId()); $categoryArray[strtolower($question->getCategoryName())] = $categoryModel->getCategoryId(); } } $questionMapper->save($question); } } return true; }
private function importData($o, $ids = false, $version = '1') { $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $categoryArray = $categoryMapper->getCategoryArrayForImport(); $categoryArrayQuiz = $categoryMapper->getCategoryArrayForImport(WpProQuiz_Model_Category::CATEGORY_TYPE_QUIZ); foreach ($o['master'] as $master) { if (get_class($master) !== 'WpProQuiz_Model_Quiz') { continue; } $oldId = $master->getId(); if ($ids !== false) { if (!in_array($oldId, $ids)) { continue; } } $master->setId(0); if ($version == 3) { if ($master->isQuestionOnSinglePage()) { $master->setQuizModus(WpProQuiz_Model_Quiz::QUIZ_MODUS_SINGLE); } else { if ($master->isCheckAnswer()) { $master->setQuizModus(WpProQuiz_Model_Quiz::QUIZ_MODUS_CHECK); } else { if ($master->isBackButton()) { $master->setQuizModus(WpProQuiz_Model_Quiz::QUIZ_MODUS_BACK_BUTTON); } else { $master->setQuizModus(WpProQuiz_Model_Quiz::QUIZ_MODUS_NORMAL); } } } } $master->setCategoryId(0); if (trim($master->getCategoryName()) != '') { if (isset($categoryArrayQuiz[strtolower($master->getCategoryName())])) { $master->setCategoryId($categoryArrayQuiz[strtolower($master->getCategoryName())]); } else { $categoryModel = new WpProQuiz_Model_Category(); $categoryModel->setCategoryName($master->getCategoryName()); $categoryModel->setType(WpProQuiz_Model_Category::CATEGORY_TYPE_QUIZ); $categoryMapper->save($categoryModel); $master->setCategoryId($categoryModel->getCategoryId()); $categoryArrayQuiz[strtolower($master->getCategoryName())] = $categoryModel->getCategoryId(); } } $quizMapper->save($master); if (isset($o['forms']) && isset($o['forms'][$oldId])) { foreach ($o['forms'][$oldId] as $form) { /** @var WpProQuiz_Model_Form $form **/ $form->setFormId(0); $form->setQuizId($master->getId()); } $formMapper->update($o['forms'][$oldId]); } $sort = 0; foreach ($o['question'][$oldId] as $question) { if (get_class($question) !== 'WpProQuiz_Model_Question') { continue; } $question->setQuizId($master->getId()); $question->setId(0); $question->setSort($sort++); $question->setCategoryId(0); if (trim($question->getCategoryName()) != '') { if (isset($categoryArray[strtolower($question->getCategoryName())])) { $question->setCategoryId($categoryArray[strtolower($question->getCategoryName())]); } else { $categoryModel = new WpProQuiz_Model_Category(); $categoryModel->setCategoryName($question->getCategoryName()); $categoryMapper->save($categoryModel); $question->setCategoryId($categoryModel->getCategoryId()); $categoryArray[strtolower($question->getCategoryName())] = $categoryModel->getCategoryId(); } } $questionMapper->save($question); } } return true; }