0

I'm using drupal 7.20 with Views 3 module.

I've a content type "Homework" and a content type "Solution". The Solution content type has an entity reference field that references nodes of type "Homework".

Well, I'm trying to set up with Views a new Tab in the user profile menu: "Pending Homeworks" that lists all Homeworks that has no Solution referencing them and published by that user.

Best an example:

"Homework 1" <- "Solution (by user 1)"
             <- "Solution (by user 2)"
             <- "Solution (by user 3)"

"Homework 2" <- "Solution (by user 1)"
             <- "Solution (by user 3)"

"Homework 3" <- "Solution (by user 3)"

In this example, user 2 hasn't published yet his Solution for Homework 2 and Homework 3, so, the View I want, must output: Homework 2 and Homework 3.

Thanks in advance.

2 Answers 2

1

This has already been answered here.

A simple view will not do what you want.

0

Thank you, Triskelion, for pointing me in the right direction.

Finally, I've set up a block with PHP and a single query:

<?php
global $user;
if (isset($user->uid)) {
  // Get uid of user logged in
  $x_uid = $user->uid;
  // If user is not empty or 0
  if ($x_uid) {
    // Subselect: Get desafio nids that have solutions published by $x_uid
    $select2 = db_select('field_data_field_enlace_al_enunciado','r');
    $select2->leftjoin('node','no','r.entity_id = no.nid');
    $select2->fields('r',array('field_enlace_al_enunciado_target_id'))
      ->condition('no.uid',$x_uid);
    // Get all desafio nids that are not in subselect
    $select = db_select('node','n')
      ->fields('n',array('nid','title'))
      ->condition('type','desafio')
      ->condition('n.nid',$select2,'NOT IN');
    // Execute the whole query
    $result = $select->execute();
    // Get results and print them out
    while ($record = $result->fetchAssoc()) {
      print '<a href="/'.drupal_get_path_alias('node/'.$record['nid']).'">'.$record['title'].'</a><br/>';
    }
  }
}
?>

It works! ;-)

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.