Fork me on GitHub

Categories  Bottom

  • Hi all,

    I am implementing categories in a module that I am developing. The guide has gotten me quite a ways there -- I can display the correct category menu in my forms where I want it. However, I am a bit confused how this information get saved with the other data the user is adding. Let me be specific to my problem and maybe people can explain this. I am writing a hookable quiz module that you can add to other content modules that will attach a gradable quiz to the end of the content. Right now I am just working on the questions, which I would like the user to be able to place into categories. So I have the form set up with text areas for the question and then an answer area, etc. And also this displays the category menu. When the user hits the create button, I grab the data and put it in the DB table, and that is all fine and good.

    • My question is, do I need to grab the category information, and if so, how do I do that.
    • If I later want to edit that information, do I need to do anything special to make sure the category menu displays the right category for a question? (I looked at the Pages module and it seems like I don't)
    • I also want the user to be able organize the questions, into quizzes. These quizzes are what will actually be hookable to other content pages. When I display a create quiz interface, I want the questions to display, organized by categories. How do I get the category information?
  • do a search for the string '__CATEGORIES__' in code from Pages or News or PostCalendar (v6+) and you will probably find answers to most questions.

    your questions;
    1. yes. you need to grab it and place it into your 'item/object' and then use a proper DBUtil call to save the information to the tables (this assumes you associated your tables with the categories tables in your pninit, etc)
    2. you don't need to do anything special if you edit unless you intent to edit the category data.
    3. The categories will be in your item/object array if you pull using the right DBUtil call.
  • Wow
    a nice test case for the Categories.

    1) If you use pnForm it will save them automagically. If not, as Pages does, you build the object array with the __CATEGORIES__ field as Craig mention. Pages build the object in the same create form.

    Code

    <input name="page[title]" ...
    <select name="page[__CATEGORIES__]" ...

    2. This is related to the Category registries, and Pages loops all the existing registries for it, then put the category_selector with the corresponding selected value. That's all in the edit form.
    3. I get the point about Categorized Answers, but how do you plan to display the Answers when creating a Quiz? Autocompleter? A collapsable tree? Drag'n drop?

    You get the categories list with the Category Registry, and what comes to my mind here, is an "Ajax tree", that loads the corresponding answers for a leaf Category, to drag them to the quiz container. JavaScript make this stuff usable. But also, you may have a "cyclic 2-steps form" to:
    a) choose the category to surf, b) choose the answer to add, repeat until finish.

    Well, I hope to be clear enough, any doubt, don't hesitate to re-ask icon_wink

    --
    - Mateo T. -
    Mis principios... son mis fines
  • craigh

    do a search for the string '__CATEGORIES__' in code from Pages or News or PostCalendar (v6+) and you will probably find answers to most questions.

    your questions;
    1. yes. you need to grab it and place it into your 'item/object' and then use a proper DBUtil call to save the information to the tables (this assumes you associated your tables with the categories tables in your pninit, etc)
    2. you don't need to do anything special if you edit unless you intent to edit the category data.
    3. The categories will be in your item/object array if you pull using the right DBUtil call.


    Thanks to both of you for the quick replies!
    #1 Yep, I followed the tutorial and added the tables to my pninit method. So this means I need to save it to my table (and thus have a category item in the table?

    #2. I don't intend to edit the category data. I assume that is taken care of in the category module where you can change them there.

    #3 That then is the question, what is the right DBUtil call?
  • Quote

    and thus have a category item in the table?

    no - there is a separate table for the category data

    Quote

    what is the right DBUtil call?

    Stick with the 'Object' calls in DBUtil
    e.g. selectObject, updateObject, etc.

    again - see how it is done in the modules I listed above.

    Quote

    I assume that is taken care of in the category module where you can change them there.

    possibly a miss-communication here. I mean the object-specific category data (you assign a cat to an object and then wish to edit that cat). In any case, you should likely be using updateObject anyway. icon_wink
  • nestormateo

    Wow
    a nice test case for the Categories.

    1) If you use pnForm it will save them automagically. If not, as Pages does, you build the object array with the __CATEGORIES__ field as Craig mention. Pages build the object in the same create form.

    Code

    <input name="page[title]" ...
    <select name="page[__CATEGORIES__]" ...

    2. This is related to the Category registries, and Pages loops all the existing registries for it, then put the category_selector with the corresponding selected value. That's all in the edit form.
    3. I get the point about Categorized Answers, but how do you plan to display the Answers when creating a Quiz? Autocompleter? A collapsable tree? Drag'n drop?

    You get the categories list with the Category Registry, and what comes to my mind here, is an "Ajax tree", that loads the corresponding answers for a leaf Category, to drag them to the quiz container. JavaScript make this stuff usable. But also, you may have a "cyclic 2-steps form" to:
    a) choose the category to surf, b) choose the answer to add, repeat until finish.
    Well, I hope to be clear enough, any doubt, don't hesitate to re-ask icon_wink


    #1 I am using pnForm, which is really, really useful. I assume you are talking about the last part of the Dev Docs on categories where it talks about using pnForm. I have been able to get the code snippet in the docs to work, and it displays a nice menu. Does that do anything more for me? It seems like it does. Care to explain what is going on here?

    #2 Ah, I think I have this now. I basically copied the code from the Pages example. What it is doing is looping the category variable that you placed in there and marking the one that you had.

    #3 The categories I am using are more for the person creating the quiz. I could imagine them writing questions for various topics. Take my example, I plan on using this to create concept checks at the ends of various sections for a textbook I have written. I have an old module I have written that handles this, but all the questions are in one big table and a pain to pick out. By being able to organize them it will be easier to choose questions for the exam. Also, I plan on having a random test bank where you can choose what percentage of questions you want out of a category and it will create a quiz for you.

    Right now I was imagining that the student makes their choices for what they think is the right answer, and then they click a button that grades the quiz. It then displays the corrects answers for the quiz. You can see an example of how this works http://www.microbiol…ayarticle&art_id=23



    edited by: Paustian, datetimebrief
  • Quote

    I am using pnForm

    this may change my advice above. I don't use pnForm, so don't really know.
  • Ok, try the pnFormCategorySelector:

    Code

    <!--[pnformcategoryselector id=$property category=$catID enableDBUtil=1]-->
    it should store the object fine for each property that you have registered for your module, inside the loop you copied from Pages.

    --
    - Mateo T. -
    Mis principios... son mis fines

This list is based on users active over the last 60 minutes.