/** * Widget entity interface. * Data should be validated first before passing it here * @param string $method post|get * @param string $action the controller action * @param array $data validated; assoc array * @param Zbase\Widgets\Widget $widget * @return boolean */ public function widgetController($method, $action, $data, \Zbase\Widgets\Widget $widget) { if (!empty($this->message_recipient_id)) { $recipient = new Recipient(); $msgRecipient = $recipient->repository()->byId($this->message_recipient_id); } if ($action == 'read') { if (empty($msgRecipient->read_status)) { $msgRecipient->read_status = 1; $msgRecipient->save(); } } if (strtolower($method) == 'post') { if (!empty($data['msg'])) { $oMessage = $this->fetchByAlphaId($data['msg']); } if (!empty($oMessage)) { /** * Action is read, but posting, means that it is a reply */ if ($action == 'read' || $action == 'reply') { $message = $data['content']; $subject = 'RE: ' . $oMessage->subject(); $sender = zbase_auth_user()->id(); $recipient = $oMessage->sender_id; if (!empty($oMessage->node_id) && !empty($oMessage->node_prefix)) { $options['node_id'] = $oMessage->node_id; $options['node_prefix'] = $oMessage->node_prefix; if (!empty($oMessage->parent_id)) { $options['parent_id'] = $oMessage->parent_id; } else { $options['parent_id'] = $oMessage->id(); } } $messageObject = zbase_entity($this->entityName, [], true); $newMessage = $messageObject->newMessage($message, $subject, $sender, $recipient, $options); $msgRecipient->reply_status = 1; $msgRecipient->save(); $this->_actionMessages[$action]['success'][] = _zt('Message sent.', ['%title%' => $newMessage->subject()]); return true; } } if ($action == 'trash') { $msgRecipient->trash_status = 1; $msgRecipient->save(); $this->_actionMessages[$action]['success'][] = _zt('Message trashed.', ['%title%' => $this->subject()]); return true; } $this->_actionMessages[$action]['error'][] = _zt('Message reference not found. Kindly check.', ['%title%' => $this->title, '%id%' => $this->id()]); return false; } return true; }