I need your help I need to make a very custom way of scoring quizzes and need some opinions and ideas.

I'm making a job applicants website, when you try to apply to a job in the website you have to take a quiz, and if you pass it your resume is sent to the creator of the job.

The complex part is that the quiz for the job is bound in the job content type with an entity reference field, the creator of the job can choose the quiz with an autocomplete field.

Now, I already have that part until the applicant finishes the quiz and then notify the creator of the job (instead of the creator of the quiz) if the applicant passed the quiz.

What I do not know how to do, is that the result of the quiz must be scored by the creator of the job, and not by the creator of the quiz.

A quiz can be reference to unlimited jobs, but when a quiz is bound into a job and somebody applies to a job, and answer the quiz, the results must be scored by the creator of the job instead of the creator of the quiz.

Any ideas how to achieve this?

1 Answer 1


When the quiz is completed I guess you need to email the job creator. You could do this using hook_node_insert().


function hook_node_insert($node) {
  if($node->type == 'quiz') {

    // Get the job nid from the quiz nid
    $job_nid = db_select('field_data_field_quiz', 'q')
      ->condition('field_quiz_target_id', $node->nid)
      ->condition('entity_type', 'node')
      ->condition('bundle', 'job')
      ->condition('deleted', 0)

    $job = node_load($job_nid);

    $job_author = user_load($job->uid);

    drupal_mail (
      // The name of your module
      // An arbitrary mail key, that you decide (used in hook_mail())
      // The destination mail address
      // The language that the mail should be sent in (requires translation if not English)
      // Some parameters we can use in hook_mail()
      array (
        'account' => $job_author, // Pass the user account to hook_mail


function my_module_mail($key, &$message, $params) {
  // The key allows for a module to define multiple mails. This
  // key needs to be the same as the first parameter in drupal_mail() above
  if($key ==  'new_quiz_submission') {
    $message['subject'] = t('New Quiz submission');
    // Each element of the body array becomes a new line in the email.
    $message['body'][] = t('Hello @user', array('@user' => format_username($params['to'])));
    // Adding an empty string to the body array adds an extra line in the email
    $message['body'][] = '';
    $message['body'][] = t('A user submitted a quiz. To see the results <a href="#link-to-site">click here</a>.');

I pretty much just copied and pasted the code for sending simple emails from here.

I would create a view with a contextual filter that shows all of a particular authors quizzes that need scoring and then the link the in the email could just link to that view.

When they marked the quiz then I would also use a boolean field to mark the quiz as scored.

  • Hello thanks for you help, I will explain this better. User A creates a quiz - User B creates a job post - User B bind the test of the user A into his job post - User C applies to the job and anwer the quiz questions - the permissions for score the quiz are for default of the creator of the quiz (User A) I need this permissions for the creator of the job (User B), but it becomes more complex when you know that the quiz of the user A can be used in unlimited job posts....
    – svelandiag
    Commented Apr 25, 2014 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.