I'm trying to achieve this...

A Views that shows as result the names of people who do not appear in list of published nodes of a content type. (List of people who will not attend an event...)


Content Type Event: Person field, supports adding more than one (multivalue), using autocomplete. This field is of the entity reference type and displays the list of possible names obtained from the result of a view.

Assuming that the list of persons is total A B C and D.

I create 1 node of event type And I included people A and B.

The result of the views should be... People C and D.

Is this achievable?


Previous setup: Create a new computed field for the content type where you want to work: Extract the names from the multivalue field (entity referenced field)

foreach ($entity->field_campos as $field) {
foreach ($entity->field_campos as $field) {
foreach ($field as $index => $valores) {
$terminos[] = $valores['value'];
$item2 = field_collection_item_load_multiple($terminos, $reset = FALSE);

$referenced_titles = array(); 
foreach ($item2 as $indice => $values) {
  $referenced_node = node_load($values->field_nombre_2['und'][0]['target_id']);
$entity_field[]['value'] = $referenced_node->title;

Now that every node from this content type has a special field for extracting the values in a more "flat" way we can compare two views. The first with the name list (usually partial) and the second, a views containing the full name list.

$result = views_get_view_result('calendari_intern', 'nombres');
$result2 = views_get_view_result('nom_expedients', 'entityreference_1');

First load both arrays. The first one, is the view result with partial name list. The second, is the view of the full name list.

Extract and create a new array saving only the names from the arrays:

foreach ($result2 as $index => $val) {
$expedient[] = $val->node_title;

Do the same in the other one:

foreach ($result as $index => $values) {
$entidades[] = $values->_field_data[nid][entity];
foreach ($entidades as $indice => $valores) {
if ($valores->field_nombres[und] !=NULL)
$casi[] = $valores->field_nombres[und];
foreach ($casi as $indice2 => $valores2) {
 foreach ($valores2 as $indice3 => $valores3) {
if ($valores3["value"] != NULL) {
$misnombres[] = $valores3["value"];

Then compare the arrays with array_diff function.

$diferencia = array_diff($expedient, $misnombres);
echo '<pre>';
print_r ($diferencia);
echo  '</pre>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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