function display_categories($type = 'simple') { $options = array('decorate' => true, 'rootOpen' => '<ul>', 'rootClose' => '</ul>', 'childOpen' => '<li>', 'childClose' => '</li>', 'nodeDecorator' => function ($row) use($type) { $category_id = $row['iid']; $courseId = $row['cId']; $tmpobj = new Testcategory($category_id); $nb_question = $tmpobj->getCategoryQuestionsNumber(); $nb_question_label = $nb_question == 1 ? $nb_question . ' ' . get_lang('Question') : $nb_question . ' ' . get_lang('Questions'); $nb_question_label = Display::label($nb_question_label, 'info'); $actions = null; if ($courseId == 0 && $type == 'simple') { $actions .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); } else { $actions .= '<a href="' . api_get_self() . '?action=editcategory&category_id=' . $category_id . '&type=' . $type . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>'; } if ($nb_question > 0 && $courseId == 0 && $type == 'simple') { $actions .= '<a href="javascript:void(0)" onclick="alert(\'' . protectJSDialogQuote(get_lang('CannotDeleteCategory')) . '\')">'; $actions .= Display::return_icon('delete_na.png', get_lang('CannotDeleteCategory'), array(), ICON_SIZE_SMALL); $actions .= '</a>'; } else { $rowname = protectJSDialogQuote($row['title']); $actions .= ' <a href="' . api_get_self() . '?action=deletecategory&category_id=' . $category_id . '&type=' . $type . '"'; $actions .= 'onclick="return confirmDelete(\'' . protectJSDialogQuote(get_lang('DeleteCategoryAreYouSure') . '[' . $rowname) . '] ?\', \'id_cat' . $category_id . '\');">'; $actions .= Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; } return $row['title'] . ' ' . $nb_question_label . ' ' . $actions; }); // @todo put this in a function $repo = Database::getManager()->getRepository('ChamiloCoreBundle:CQuizCategory'); $query = null; if ($type == 'global') { $query = Database::getManager()->createQueryBuilder()->select('node')->from('ChamiloCoreBundle:CQuizCategory', 'node')->where('node.cId = 0')->orderBy('node.root, node.lft', 'ASC')->getQuery(); } else { $query = Database::getManager()->createQueryBuilder()->select('node')->from('ChamiloCoreBundle:CQuizCategory', 'node')->where('node.cId = :courseId')->orderBy('node.root, node.lft', 'ASC')->setParameter('courseId', api_get_course_int_id())->getQuery(); } $htmlTree = $repo->buildTree($query->getArrayResult(), $options); /* $htmlTree = $repo->childrenHierarchy( null, //starting from root nodes false, //load all children, not only direct $options );*/ echo $htmlTree; return true; }
/** * @Route("/delete_category") * @Method({"GET"}) * @param int $id * * @return Response */ public function deleteCategoryAction($id) { $repo = $this->getManager()->getRepository('Chamilo\\CoreBundle\\Entity\\CQuizCategory'); $category = $repo->find($id); if (empty($category)) { $this->abort(404); } $count = $repo->childCount($category); if ($count == 0) { $testCategory = new \Testcategory($id); $count = $testCategory->getCategoryQuestionsNumber(); if ($count == 0) { $objcat = new \Testcategory($id); $objcat->removeCategory(); $url = $this->generateUrl('admin_questions'); } return $this->redirect($url); } else { $this->abort(401); } }
/** * @param Application $app * @param int $id * * @return Response */ public function deleteCategoryAction(Application $app, $id) { $repo = $app['orm.ems']['db_write']->getRepository('Entity\\CQuizCategory'); $category = $repo->find($id); if (empty($category)) { $app->abort(404); } $count = $repo->childCount($category); if ($count == 0) { $testCategory = new \Testcategory($id); $count = $testCategory->getCategoryQuestionsNumber(); if ($count == 0) { $objcat = new \Testcategory($id); $objcat->removeCategory(); $url = $app['url_generator']->generate('admin_questions'); } return $app->redirect($url); } else { $app->abort(401); } }
/** * @param int $courseId * @param int $sessionId * @return string */ public function displayCategories($courseId, $sessionId = 0) { $categories = $this->getCategories($courseId, $sessionId); $html = null; foreach ($categories as $category) { $tmpobj = new Testcategory($category['id']); $nb_question = $tmpobj->getCategoryQuestionsNumber(); $rowname = self::protectJSDialogQuote($category['title']); $nb_question_label = $nb_question == 1 ? $nb_question . ' ' . get_lang('Question') : $nb_question . ' ' . get_lang('Questions'); $html .= '<div class="sectiontitle" id="id_cat' . $category['id'] . '">'; $html .= "<span style='float:right'>" . $nb_question_label . "</span>"; $html .= $category['title']; $html .= '</div>'; $html .= '<div class="sectioncomment">'; $html .= $category['description']; $html .= '</div>'; $html .= '<div>'; $html .= '<a href="' . api_get_self() . '?action=editcategory&category_id=' . $category['id'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>'; $html .= ' <a href="' . api_get_self() . '?action=deletecategory&category_id=' . $category['id'] . '" '; $html .= 'onclick="return confirmDelete(\'' . self::protectJSDialogQuote(get_lang('DeleteCategoryAreYouSure') . '[' . $rowname) . '] ?\', \'id_cat' . $category['id'] . '\');">'; $html .= Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; $html .= '</div>'; } return $html; }