Blog of Attomsoft Inc.
Posts tagged Drupal
How to build a stackoverflow or Yahoo! Answers like system using Drupal (Part2)
Apr 26th
We’ll create the two content types which will be used by our Q&A system in today’s part-2.
The Questions content-type fields:
- Question title(Module form [title])
- Question description(Module form [body])
- Disable comment option if you don’t want users comment on the question itself.
- Points: field_question_points, type[integer], default value[0], set as required, minimum value also as 0
- Answers: field_question_answers, type[nodereference count], set as required, the “nodereference field that can be counted” option should be set to the field name that we’ll create it in “Answers” content-type in step 2. (So you could just process #5 field)
- Best answer: field_question_best_answer, type[nodereference]. Save the content type here and we will refine it later.
The Answers content-type fields:
- Set “Automatic title generation” option to “Automatically generate the title and hide the title field”, you can set the automated title pattern using tokens available there.
- Disable the comment option if you don’t want user comment on answers themselves. Or leave it R/W just like Stackoverflow.
- Target Question field: type[nodereference][nodereference from url], select our previously created ‘Questions’ type for referring.
- Selected Answer field: type[integer][Single on/off checkbox], set allowed values as ’0|No’ and ’1|Yes’ (that’s separated lines)
Here, we’ll go back to the “Questions” type and re-configure it:
- The “nodereference field that can be counted” of the “Answers” field should be set to our just created “Target Question” field.
- The “Content types that can be referenced” of the “Best answer” field should be set to our just created “Answers” type.
If you want to allow free tagging feature, here’s how:
- Create new vocabulary named “Tags” or something you prefer.
- Select the content types we just created which will allow using terms below this vocabulary and its free tagging feature.
- Enable the “Tags” option for this vocabulary to allow users free tagging
That’s all basic content types we needed for our Q&A system, we’ll build the needed views and panels in our next part tutorial.
See ya.
How to build a stackoverflow or Yahoo! Answers like system using Drupal (Part1)
Apr 23rd
Do you believe that? Stackoverflow or Yahoo! Answers interactive sites will replace old forums. Because users on most interactive sites treat finding solutions or help people as their daily job, traditional forum style systems are good at entertaining users, but not solution oriented.
From this post start, I’ll tell you how to build a stackoverflow or Yahoo! Answers like system using Drupal only, on this topic completion, we will have a Question&Answer system with following features:
- Users can post and answer question with granted access; (ACL)
- Every question can be assigned “Points” by its author, and the points will be granted to the author of the best question which picked up by the author of question; (Awarding)
- On the questions list page, users can see how many answers have been posted to single question, and whether the best answer has been picked up;
- On the question detail page, users can see the question itself and information including tags, points, authors, posted date, and all answers following the question;
- On the question detail page, if the best answer has been picked up, the question will be marked as “Closed” and the best answer will be on the top of the answers list and marked as “Best Answer”;
- If the author of a question had picked up the best answer, other users will not be able to post answers anymore, and the author himself will not be able to pick another answer as the best;
The following modules will be used by this little project:
- Drupal (itself, of cause)
- CCK (with build-in plugins and additional nodereference and the nodereference_url widget)
- Nodereference Count module
- Automatic nodetitles
- Views
- Panels
- Userpoints
- Our custom Q&A module
We’ve set our gold and list tools we’ll need later, we’ll start the building this Q&A system from next part of this topic.
See ya.
Nodereference field from custom url in Panels pane
Apr 20th
Nodereference field is a powerful CCK field type for relationship handling for Drupal, the nodereference_url module is a plugin supplying it with referenced nid from url path. I use them a lot in daily Drupal based solutions.
Nodereference Url works under path like node/add/NODETYPE/NODE_ID situation by default, it’s sufficient for normal problem such as “Post reply”, “Add comment”, etc. You just need to build the link with proper NODE_ID.
One of our projects need to build a system like “StackOverflow” with simple Question&Answers workflow. I created “Question” type and “Answer” type which has a filed referring to the “Question” type, then I used Panels to integrate single “Question” node with its related “Answer”s node.
Everything works as will, until I tried to add a “Answer Add Form” below the created panel page, the form displayed but the field referring “Question” node gave out “Referenced content not found” error.
I could find out why, until I read the document of Nodereference URL module carefully.
The reason why above solution not worked is that, the Nodereference URL module supports /add/NODETYPE/NODE_ID by default, and that’s the only pattern it works on.
At last, the solution laid just in the README.txt file with the module itself. Silly me!
It said:
By default Node Reference URL Widget will only work with node form paths that
match the standard Drupal install: "node/add/%type", where %type is a node type
like "blog" or "story". If you want to use Node Reference URL Widget on
non-standard URLs, you may do so by informing Node Reference URL Widget of these
special paths.
To do so, add additional paths to your settings.php with the following code:
$conf['nodereference_url_paths'] = array(
'node/add/%type/%nid',
'node/%/add/%type/%nid',
);
So, remained work just as easy as put above lines of code to my settings.php. And then, magic happens.
Great Drupal module “View Attach” for node relationship
Mar 23rd
Views’ “Relations” mechanism is great for node relationship displays, but the “View Attach” makes it more powerful and easy to use.
The basic idea behind the “View Attach” module is providing a way to display nodes which have refereed the current node, it’s perfect for “friends list”, “also bought”, “companies support this”, etc.
It’s really a great module, although you can’t figure out what to do with it at first glance, but if you know it well, unstoppable power comes to you.
Customzie Drupal 6 front page using multiple views
Mar 20th
Drupal Views module may be the most powerful, useful and handy tool for Drupal webmasters, The Views2 module gets much better and powerful.
We received a request from one of our client that they wanted to list all of their newest ratings tables on the front page. We had done such job by customize a view filled with CCK fields and set the view as the default front page.
This time, I want a different approach to this request,a more extensible, more professional way.
Here is the solution I used.
- Create all views to be displayed on the front page, like foo-view, bar-view, etc. And theming them as usual.
- Create a new view which you will set it as the new front page, or just enable the front page emulation view from the Views 2 distribution. Name it frontpage-view or something meaningful.
- On the frontpage-view edit page, configure all parameters for normal front page display, such as filters for display news, blog posts, etc.
- Here comes the magics: Lets suppose we want to display the previous created foo-view, bar-view on the to of our new front page. Choose the “Page” display of the frontpage-view, click “Header” link in the “Basic settings” section, choose PHP code as the input format.(If it was not available, enable the module first.)
- Code in the “Header” textarea:
<?php
print views_embed_view(“foo-view”,”page”);
print views_embed_view(“bar-view”,”page”);
?> - Update the settings.
- Set the “Path” of the “Page settings” section as “frontpage” or something meaningful, update the settings and save the view.
- On the “admin->settings->site information” page, set the “Default front page” path as “frontpage” just same as #7 settings. And save.
OK, now just reload your home page, everything should be displayed as we supposed.
Note: The “views_embed_view” function is introduced to Views 2, not available in Views 1.
Tips:
- If you want the foo-view, bar-view display on the bottom of the frontpage-view, move the #5 code to “Footer” settings;
- If the frontpage-view got nothing to display, the whole page will be blank, to make it work in a blank “container”, make the “Display even if view has no result” option checked, the option is just above the textarea which you enter the #5 code.
- You can pass parameters to the “views_embed_view” function of #5 code, details goes here.
Make no sense? Ok, maybe I should post some basic tutorials above Views 2 some day to make this post easy to understand.