Comment QA extends the default Drupal commenting system by adding questions and answers (Q&A) capabilities to the Drupal commenting system.

Drupal comments, by default, will produce a sequence (or thread) of comments entered by users. This works for most sites featuring blogs, forums, etc. But it is not enough for sites where users need to ask questions and get answers from other users or from the owner of the node; a situation very common on B2B sites and communities of practice.

With Comment QA the administrator can designate roles that can create questions and the roles that can create answers. This designation is done from the permissions page where all other Drupal permissions are managed.

This module adds also new check boxes to the comment section of the content type configuration form so that administrators can enable or disable the (Q&A) capabilities for specific content types.

Project page: http://drupal.org/sandbox/jcmartinez/1144278

Code repository: git.drupal.org:sandbox/jcmartinez/1144278.git

Comments

haza’s picture

Status: Needs review » Needs work

Your sandbox seems to be empty

tim.plunkett’s picture

Component: new project application » module
Status: Needs work » Closed (won't fix)

Closing, feel free to re-open if this was a mistake.

jcmartinez’s picture

Status: Closed (won't fix) » Needs work

Code repository: git.drupal.org:sandbox/jcmartinez/1144278.git

jcmartinez’s picture

Status: Needs work » Needs review

Needs review.

atul.bhosale’s picture

Status: Needs review » Needs work
StatusFileSize
new9.9 KB

Automated Review

http://ventral.org/pareview/httpgitdrupalorgsandboxjcmartinez1144278git

The automated review scripts are flagging you on quite a number of points. Please check the Drupal coding standards.

It appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git

See attachment for more details

jcmartinez’s picture

Status: Needs work » Needs review

Created 7.x-1.x branch on Git and shifted work from master to the 7.x-1.x branch.
Cleaned out master branch as recommended on http://drupal.org/node/1127732 step #5.
Made various edits to meet Drupal code standards.

pflame’s picture

Status: Needs review » Needs work

The module seems to be working fine. I could able to add question and answers as comments. But when I access admin/content/comment url there is a drupal_set_message with the comments array. It should be removed.

jcmartinez’s picture

Status: Needs work » Needs review

All instances of drupal_set_message used for development have been removed from code. Thanks for the feedback.

seyv’s picture

Status: Needs review » Needs work

First off: Looks nice !

When you don't set Q&A capabilities for a content type it returns a notice:

Notice: Uninitialized string offset: 0 in comment_qa_form_alter() (line 127 of /sites/all/modules/review/comment_qa/comment_qa.module).

Use a isset($settings) to check if any settings are returned.

At the settings:

Defaul status for original (Q&A) comments
Defaul status for follow-up (Q&A) comments

change to

Default status for original (Q&A) comments
Default status for follow-up (Q&A) comments
itsekhmistro’s picture

Hi,
the code looks good.
manually reviewed on fresh drupal installation:

1) When you don't set Q&A capabilities for a content type it returns a notice:

Notice: Uninitialized string offset: 0 in comment_qa_form_alter() (line 127 of D:\xampp\virtual\drupal7.my\sites\all\modules\1144278\comment_qa.module).

2) When you don't set Q&A capabilities for a content type it returns a notice and tries to add a comment to a node:
You get

Error
The website encountered an unexpected error. Please try again later.

and details:

Notice: Uninitialized string offset: 0 in comment_qa_form_alter() (line 127 of D:\xampp\virtual\drupal7.my\sites\all\modules\1144278\comment_qa.module).
Notice: Undefined property: stdClass::$cqa in comment_qa_comment_insert() (line 282 of D:\xampp\virtual\drupal7.my\sites\all\modules\1144278\comment_qa.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cqa' cannot be null: INSERT INTO {comment_qa} (cid, cqa) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => ) in comment_qa_comment_insert() (line 284 of D:\xampp\virtual\drupal7.my\sites\all\modules\1144278\comment_qa.module).

jcmartinez’s picture

Status: Needs work » Needs review

Committed changes to correct typo on settings page of the module (from Defaul to Default) and fixed a wrong condition that produced "Notice: Uninitialized string offset: 0 in comment_qa_form_alter()" when a user tried to create a new node of a content type that was not configured to use Q&A capabilities.

This addresses issues from comments #9 and #10. Thanks to SeyVaneerdewegh and itsekhmistro.

itsekhmistro’s picture

Hi,

still can't "Add new comment" on an Article node on fresh Drupal installation - the `Comment QA` module was enabled - but I haven't appied any settings/configuration, just trying to add new comment produce an error:

Error
The website encountered an unexpected error. Please try again later. 

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cqa' cannot be null: INSERT INTO {comment_qa} (cid, cqa) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => ) in comment_qa_comment_insert() (line 284 of D:\xampp\virtual\drupal7.my\sites\all\modules\1144278\comment_qa.module).
jcmartinez’s picture

I was able to reproduce issue from comment #12 and applied fixes. Noticed that same issue would apply not only to new comments but also to comments being edited. Also fixed.

itsekhmistro’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed manually, now works fine for me.

patrickd’s picture

Status: Reviewed & tested by the community » Needs work
  1. Your readme is quite detailed, please put the some more information onto your project page
  2.  * 0 => usually means Disabled or Comments
     * 1 => usually means Questions
     * 2 => usually means Answers

    You should define() constants instead, that would really improve readability

  3. variable_get('cqa_d...prefix all variables with the full module name
  4. Your currently only deleting variable_del('comment_qa_' . $node_type); but there are more with cqa prefix
  5. comment_qa_comment_viewif the hook does nothing, either remove it complete or comment it out completely, so it won't be implemented for nothing
  6. * @todo Please document this function.better a bad description than none, some todos will never happen ;)
  7. whenever possible you should use hook_form_FORM_ID_alter for all forms

That's it for now :)

jcmartinez’s picture

Status: Needs work » Needs review

The following are the steps taken to address some of the issues that were pointed out on comment #15 (every item below correspond to the item of the same number from comment #15):

  1. The project page has been updated with information from the README file.
  2. Logic implemented in this module uses not only the values but also the indexes defined in the array. It would take considerable time and effort the implementation of this recommendation. I will welcome contributed patches that will improve the legibility of the module. In the meantime, a more explicit comment has been added to the function.
  3. Changes have been made so that only variables using the module name as prefix are kept on the variable table.
  4. The change implemented above (item 3) solves this issue.
  5. The function comment_qa_comment_view has been commented out so that it won’t be called until its development is completed.
  6. A comment has been added.
  7. In this case is more convenient using hook_form_alter() because we need to target dynamically any content type that could be created.

Thanks to patrickd for the thorough review.

patrickd’s picture

Status: Needs review » Needs work
  1. .install: you don't have to uninstall the schema manually here, installing and removing schemas is handled automatically in d7
  2. Note that when your module is installed through drush the links will not be clickable, generally I don't know how much sense such a message makes as pretty much any module needs permissions/configuration after it was installed. But that's your choice.
  3. /**
     * Implements hook_help.
     *
     * Displays help and module information.
     *
     * @param path 
     *   Which path of the site we're using to display help
     * @param arg 
     *   Array that holds the current path as returned from arg() function
     */
    function current_posts_help($path, $arg) {

    This code will never be invoked because the prefixing module name is not correct.
    Also you don't have to make any documentation about parameters and returned variables of hooks if your using them the standart way (but okay if you like it that way).

  4. it is unlikely to put php containing file into subdirectories (/includes) in drupal (especially if there's only a single file in that make more work then sense)
    By following this convention you can apply the following:
    Current: include_once DRUPAL_ROOT . '/' . $path . 'settings_comments.inc';
    Best practice: module_load_include('inc', 'comment_qa', 'settings_comments');
    Best performance: include_once dirname(__FILE__) . '/settings_comments.inc';
  5. variable_get('comment_qa_' . $type, '');There's always an array expected from this, you should set array() as default value (even when this never happens)
  6. don't use and/or, use &&/|| instead
  7. if (arg(0) == 'node' && is_numeric(arg(1))) {
            $node = node_load(arg(1));....

    using menu_get_object() is probably a better solution here.

  8. I actually don't like this comment_qa_purge() thing, I mean.. variables get created, then a variable gets created that contains the same variables, then we delete the other variables... this feels like a unnecessary overhead, IMHO you should find a better solution for this ;-)
    Also stuff like
    $defaults = comment_qa_elements_default();
    '#default_value' => isset($settings['comment_qa_switch']) ? $settings['comment_qa_switch'] : $defaults['comment_qa_switch'],
    

    makes your life complicated.
    just using variables the common way would make it more simple I think..
    generally you should not try to reinvent the configuration system ;-)

  9. t(".... <em>@perm</em> ...", array('@perm' => 'administer comments')),
    If you want to keep the "administer comments" translatable you have to wrap it within t() separately. But I'm not sure whether inserting a hardcoded translatable string into a hardcoded translatable string makes sense (maybe you should just put them into one string). Anyway, you don't have to use em-tags here if you want to do it this way you can just use % instead of @.
  10. array(0 => t("Comment"), 1 => t("Question"), 2 => t("Answer")) If you got the luck to have a list that is 1,2,3... you should make use of your luck and remove that numbers because php will count them this way automatically (and they look ugly and will make you more work if you got to change something later).
  11. if I see this right your inserting the settings form when editing any content type, also if it's not configured yet and no type specific variable are set but are needed. So if you really want to use your configuration workaround functions, why not doing this:
    function comment_qa_get_settings($type) {
      return variable_get('comment_qa_' . $type, comment_qa_elements_default());
    }

    That would at least make it a little more simple.

  12. Also keep an eye on the automated report: http://ventral.org/pareview/httpgitdrupalorgsandboxjcmartinez1144278git

We do really need more hands in the application queue and highly recommend to get a review bonus so we can come back to your application sooner.

jcmartinez’s picture

Status: Needs work » Needs review

Made changes addressing issues that were pointed out on comment #17.

d2ev’s picture

StatusFileSize
new57.76 KB

i have install this module with core comment module. The question and answer commenting system is working fine but when you edit a question or answer comment and save it then it again appending a 'Q:' or 'A:' to comment subject. if want to make a existing comment to question or answer then this is not working.

i have attached a screen shot.

jcmartinez’s picture

Solved issue pointed out by D2ev on comment #19.

frob’s picture

Status: Needs review » Needs work

It passed PAReview, so that is good.

Manual Review:
I noticed that you are using get_t() in the install hook. In the install hook you should use st(). get_t() is for code that could be run durring install but doesn't have to be run at install time. Because this is the install hook and that will only run durring install time your should just use st().

In comment_qa_comment_load($comments) you are using case 1: case 2: etc. I would use defines to make the code a bit more readable. <- don't quote me on this, I am not sure of the recommended Drupal policy on defines.

Line 12 of the .module file has a @todo comment. You should resolve this @todo.

jcmartinez’s picture

Status: Needs work » Needs review

I noticed that you are using get_t() in the install hook. In the install hook you should use st().

Good catch; it has been corrected. Thanks!

In comment_qa_comment_load($comments) you are using case 1: case 2: etc.

This was pointed out earlier on comment #15. These values are NOT constants therefore we are NOT using define() intentionally. I have rewritten the comment near these values in order to make the point more clear to future reviewers.
Even if the script could be rewritten to use define(); at the moment I don't have the time or the intention to make that change unless it is proven that the construction that is being used is against Drupal best practices, or affects the work of the module, or has a negative effect on performance, or that it would compromise security.

Line 12 of the .module file has a @todo comment. You should resolve this @todo.

This @todo comment was a reminder to myself about adding more information to the existing paragraph that I had provided on the hook_help. More information has been added to the paragraph and the @todo comment has been deleted.

patrickd’s picture

Status: Needs review » Reviewed & tested by the community
  1. .module: 82: Your still generating the path - but you don't need and don't use it
  2.   // Ensure translations don't break at install time.
      $t = st();

    Your doing that wrong - now install actually breaks ;-)
    Replace this with
    $t = get_t();
    Don't forget to test your module after you applied changes

  3. As it makes no sense to show all settings on the content type edit form when "Add Question & Answer (Q&A) functionality to comments" is set to Disabled, I'd suggest you to hide all the other items by #states, See forms docu
  4. The "Type of comment" selection looks pretty ugly, maybe you better use a select widget instead of radios
  5. .module: 84: There's no reason to use a #hidden form value you can just put your value in directly into the form by prefixing it with '#'. that way there won't a html hidden field generated and no information exposed to the commenter.
  6. point 7 of comment #17 was not addressed - did it not work out for you?
  7. .module 158: your still using "or" instead of ||
  8. please use more self-explaining variable names then $v, $k
  9. consider using drupal_write_record() instead of handling with insert's directly - it possibly takes a lot of work of your shoulders
  10. As the comment_qa_settings_submit() function belong to the comment form you should also put it into settings_comment.inc (btw the usual name of the setting-form containing file is $modulename.admin.inc)

After all I don't see major issues with this module, therefore (after one year) let's push this forward

patrickd’s picture

Status: Reviewed & tested by the community » Fixed

(no further feedback for a week, I think I was nitpicking enough here)

Thanks for your contribution and welcome to the community of project contributors on drupal.org!

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

Thanks to the dedicated reviewer(s) as well.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Adding repository address to description.

avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

Title: Comment QA » [D7] Comment QA