/** * Publishes the action in the queue. If the user is not specified the action is public. * Otherwise it is directed to the specified user. * * @param string $name Name of the action * @param array $commandData Data of the action * @param WiseChatUser $user Recipient of the action * @throws Exception */ public function publishAction($name, $commandData, $user = null) { $name = trim($name); if (strlen($name) === 0) { throw new Exception('Action name cannot be empty'); } $action = new WiseChatAction(); $action->setCommand(array('name' => $name, 'data' => $commandData)); $action->setTime(time()); if ($user !== null) { $action->setUserId($user->getId()); } $this->actionsDAO->save($action); }
/** * Converts raw object into WiseChatAction object. * * @param stdClass $rawActionData * * @return WiseChatAction */ private function populateActionData($rawActionData) { $action = new WiseChatAction(); if ($rawActionData->id > 0) { $action->setId(intval($rawActionData->id)); } $action->setTime(intval($rawActionData->time)); if ($rawActionData->user_id > 0) { $action->setUserId(intval($rawActionData->user_id)); } $action->setCommand(json_decode($rawActionData->command, true)); return $action; }