if im handling statuses in my yii2 app const STATUSUNREAD = 1;// 0b00001 const…
- User
if im handling statuses in my yii2 app
const STATUS_UNREAD = 1;// 0b00001 const STATUS_READ = 2;// 0b00010 const STATUS_IMPORTANT = 4;// 0b00100 const STATUS_RESOLVED = 8;// 0b01000 const STATUS_SPAM = 16;// 0b10000 const STATUS_ARCHIVED = 32;// 0b100000 const STATUS_FLAGGED = 64;// 0b110000and if the status is set as unread and spam turns to 17.. how do i handle these in my view index?
something like this:
[ 'attribute' => 'status', 'format' => 'html', 'filter' => [ '0' => 'Processing', '1' => 'Paid', '2' => 'Failed', '3' => 'Shipped', '10' => 'Completed', '30' => 'Cancellation', '40' => 'Canceled', ], 'filterInputOptions' => ['prompt' => 'All Statuses', 'class' => 'form-control', 'id' => null], 'value' => function ($model) { $attribute = Html::encode($model->status); switch ($model->status) { case 1 : $orderStatus = 'Paid, being packaged'; $orderBadge = 'badge text-bg-success';break; case 2 : $orderStatus = 'Payment failure'; $orderBadge = 'badge text-bg-warning';break; case 3 : $orderStatus = 'Shipped'; $orderBadge = 'badge text-bg-success';break; case 10 : $orderStatus = 'Completed'; $orderBadge = 'badge text-bg-secondary';break; case 30 : $orderStatus = 'Cancellation request'; $orderBadge = 'badge text-bg-danger';break; case 40 : $orderStatus = 'Canceled'; $orderBadge = 'badge text-bg-secondary';break; case 50 : $orderStatus = 'Refund'; $orderBadge = 'badge text-bg-danger';break; case 55 : $orderStatus = 'Refunded'; $orderBadge = 'badge text-bg-secondary';break; default : $orderStatus = 'Processing'; $orderBadge = 'badge text-bg-primary';break; } return Html::tag('span', $orderStatus, ['class' => $orderBadge]); }, //'contentOptions' => ['width' => '10%'], ], - Assistant
- User
these are the restrictions I have for the statuses..
public function validateStatus($attribute, $params): void { // Unread and Read conflict. $unreadAndRead = self::STATUS_UNREAD | self::STATUS_READ; if (($this->status & $unreadAndRead) === ($unreadAndRead)) { $this->addError($attribute, "Message cannot be both unread and read."); } // Important and Resolved conflict. $importantAndResolved = self::STATUS_IMPORTANT | self::STATUS_RESOLVED; if (($this->status & $importantAndResolved) === $importantAndResolved) { $this->addError($attribute, "Message cannot be both important and resolved."); } // Archive check. if ($this->status & self::STATUS_ARCHIVED) { if ($this->status & (self::STATUS_UNREAD | self::STATUS_READ)) { $this->addError($attribute, "Archived messages should not be marked as read or unread."); } } // Important and Spam conflict. if (($this->status & self::STATUS_IMPORTANT) && ($this->status & self::STATUS_SPAM)) { $this->addError($attribute, "Message cannot be both important and spam."); } }maybe you could write the gridview attribute function.
- Assistant
- User
will search even work for bits
- Assistant
- User
so how would the search file look?
- Assistant
- User
within the search file:
foreach() argument must be of type array|object, string given
- Assistant
- User
im not actually using the search view file.. i search using the index gridView
- Assistant
- User
class MessageSearch extends Message { /** * Rules * @url * @return array */ public function rules(): array { return [ [['id', 'type', 'product_id', 'status', 'new_message', 'repliedTime', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'], [['name', 'email', 'subject', 'body', 'replied', 'created_ip', 'updated_ip'], 'safe'], ]; }
- Assistant
- User
doesnt seem to work
- Assistant
- User
my guess it has something todo with the if (!empty(this->status) && is_array(this->status)) {... and not reading it now since its not in a array. but i need to dig deeper another time.
- Assistant