A
A
akula222016-01-20 22:26:00
Yii
akula22, 2016-01-20 22:26:00

How to get a certain status in the grid?

There is a database of personal messages {pm} id, user_id(message to whom), sender_id(who sends) and
status
self::STATUS_UNREAD => 'Unread', 0
self::STATUS_READ => 'Read', 1
self::STATUS_DELETE = > 'Deleted', 2
When the user enters the messages, he sees a list of people who sent him messages, I display them through the Gridview
with this request

$query = self::find()->where('
        user_id = :user_id AND sender_id != :user_id AND status != :status', 
        [
            'user_id' => Yii::$app->user->id,
            'status' => Pm::STATUS_DELETE,
        ])
        ->groupBy('sender_id')
        ->with(['profile'])
        ->orderBy('id DESC');

Everything outputs well, BUT in the grid where ActionColumn I have to display envelopes, if there are messages with STATUS_UNREAD status (at least one message) display a closed envelope if all have been read, then
now I have
[
                'class' => 'yii\grid\ActionColumn',
                'headerOptions' => ['width' => '50'],
                'template' => '{view}  {delete}',
                'buttons' => [
                    'view' => function ($url, $data) 
                    {
                        $icon = $data->status == 0 ? '<i class="fa fa-envelope"></i>' : '<i class="fa fa-envelope-o"></i>';
                        return Html::a($icon, ['view', 'id' => $data->sender_id]);
                    },
                    'delete' => function ($url, $data) 
                    {
                        return Html::a('<i class="fa fa-trash"></i>', ['delete', 'id' => $data->sender_id], ['data' => ['confirm' => 'Вы уверены?']]);
                    },
                ],
            ],

but it does not work, I need to somehow find out if there is at least one message not read. (status = 0)
That is, somewhere in the request I need to fake it, but I don’t know, do you have any thoughts?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question