Download & Extend

Print flag for views row

Project:Views PHP
Version:7.x-1.x-dev
Component:Documentation
Category:bug report
Priority:normal
Assigned:smouhaer
Status:active
Issue tags:Flag, views php

Issue Summary

I'm trying to print flags related to row of my view using Views PHP
print flag_create_link('myflag', $row->nid);
No result. Any idea?

Comments

#1

Component:Code» Documentation
Assigned to:Anonymous» smouhaer

try this method

$myflagl=flag_create_link('myflag', $row->nid);
print $myflag;

#2

Status:active» fixed

I know, why it wasn't rendered.

I've put:

<?php
print flag_create_link('myflag', $row->nid);
?>

into wrong place...

It should be in Output code (and I've put it in Value code, which was wrong). Now it is working fantastic!

I've checked dblog where goes things like those:
Notice: Undefined variable: flag in __lambda_func() (line 1 from .../sites/all/modules/views_php/plugins/views/views_php_handler_field.inc(131) : runtime-created function).
and
Notice: Undefined property: stdClass::$views_php_15 in views_php_handler_field->render() (line 223 from .../sites/all/modules/views_php/plugins/views/views_php_handler_field.inc).

#3

Status:fixed» closed (fixed)

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

#4

Status:closed (fixed)» active

How do I print a flag link for users and use a user reference field instead.
I have tried different method. The last one I tried was

<?php
$requester_firstd
= $data->_field_data['nid']['entity']->field_requester_user['und'][0]['value'];
print
flag_create_link('date_showup', $requester_firstd);
?>
and
<?php
$requester_firstd
= $data->_field_data['nid']['entity']->field_requester_user['und'][0]['uid'];
print
flag_create_link('date_showup', $requester_firstd);
?>
but it didn't work.

I got Notice: Undefined index: value in __lambda_func() and Notice: Undefined index: uid in __lambda_func()

#5

My solution:

<?php
global $user;

$requester_user = db_query("SELECT field_requester_user_target_id FROM {field_data_field_requester_user} WHERE entity_id IN ($row->nid)")->fetchField();

$requestee_user = db_query("SELECT field_requestee_user_target_id FROM {field_data_field_requestee_user} WHERE entity_id IN ($row->nid)")->fetchField();

$current_user = $user->uid;

if(
$current_user == $requester_user)
{print
flag_create_link('date_showup', $requestee_user_1st);}
else if(
$current_user == $requestee_user)
{print
flag_create_link('date_showup', $requester_user);}
?>