public function DeleteAction() { $request = Project::getRequest(); $user_id = (int) Project::getUser()->getDbUser()->id; $question_model = new QuestionModel(); $question_model->load($request->getKeyByNumber(0)); if ($question_model->user_id == $user_id) { $question_model->delete($request->getKeyByNumber(0)); } Project::getResponse()->redirect($request->createUrl('QuestionAnswer', 'UserQuestions')); }
public function EditQuestionAction() { $request = Project::getRequest(); $id = $request->getKeyByNumber(0); $data = array(); if (!$request->getKeyByNumber(1)) { if ($id > 0) { $model = new QuestionModel(); $cat_model = new QuestionCatModel(); $tag_model = new QuestionTagModel(); $data['question'] = $model->load($id); $data['cat_list'] = $cat_model->loadAll(); $tags_model = new QuestionTagModel(); $tags = $tags_model->loadWhere(null, null, $id); foreach ($tags as $tag) { $data['tags'] .= $tag['name'] . ', '; } $data['tags'] = rtrim($data['tags'], ', '); $this->BaseAdminData(); $this->_view->EditQuestion($data); $this->_view->ajax(); } } else { if ($id > 0) { $model = new QuestionModel(); $model->load($id); $model->q_text = $request->question_text; $model->questions_cat_id = (int) $request->cat_id; $id = $model->save(); $tag_model = new QuestionTagModel(); $question_tag_model = new QTagModel(); $tags_ar = array(); $tags_ar = explode(",", $request->tags); foreach ($tags_ar as $tag) { $tag = trim($tag); if (count($tag_model->loadByName($tag)) > 0) { if (count($question_tag_model->loadWhere($id, $tag_model->id)) <= 0) { $question_tag_model->question_id = $id; $question_tag_model->question_tag_id = $tag_model->id; $question_tag_model->save(); $question_tag_model->clear(); } } else { $tag_model->name = $tag; $tag_id = $tag_model->save(); $tag_model->clear(); $question_tag_model->question_id = $id; $question_tag_model->question_tag_id = $tag_id; $question_tag_model->save(); $question_tag_model->clear(); } } } Project::getResponse()->Redirect($request->createUrl('AdminQuestionAnswer', 'QuestionList')); } }