yii2 app, working on a messaging management system for a store site. the contact,…
- User
yii2 app, working on a messaging management system for a store site. the contact, inquiry, order issues is handled by this... I have different statuses...
Unread = 0, Read = 1, Important = 2, Resolved = 3, Spam = 10 'status' => $this->smallInteger()->notNull()->defaultValue(0),
i know i need either more statuses for all the different messages.. or a better way to deal with messages, perhaps a tag system?
- Assistant
- User
not sure how to code this bitewise.
- Assistant
- User
does yii2 migrate handle this at all
- Assistant
- User
so you suggest this first:
Read Status: Unread (0) Read (1) Priority Level: Important (2) Low Priority (4) Resolution State: Resolved (3) Pending (5) Spam Status: Spam (10)kinda strange layout for the numbers..
but then you offer this
class Message extends \yii\db\ActiveRecord { const STATUS_UNREAD = 1; // 0b0001 const STATUS_READ = 2; // 0b0010 const STATUS_IMPORTANT = 4; // 0b0100 const STATUS_RESOLVED = 8; // 0b1000 const STATUS_SPAM = 16; // 0b10000
- Assistant
- User
i see a need for multiple statuses, but i dont understand the code...
- Assistant
- User
if: If status = 5 (00101), you can say: Unread (1) Important (4)
If status = 20 (10100), you can say: Read (2) Resolved (8)what other options are ther?
- Assistant
- User
so if i wanted todo if statements say read + spam?
- Assistant
- User
can you write comments for these functions and how they work..
// Add status using bitwise OR public function addStatus($status) { $this->status |= $status;// Set the bit } // Remove status using bitwise AND and NOT public function removeStatus($status) { $this->status &= ~$status;// Clear the bit } // Check if a specific status is set public function hasStatus($status) { return ($this->status & $status) === $status;// Check the bit } - Assistant
- User
status; so |= sets it?
- Assistant
Yes, that's correct! The
|=operator in PHP is a compound assignment operator that performs a bitwise OR operation and simultaneously assigns the result back to the variable on the left side. - User
&= ~$status removes or "clears it"
- Assistant