Your IP : 216.73.216.84


Current Path : /home/helpink/www/components/com_jbusinessdirectory/models/
Upload File :
Current File : /home/helpink/www/components/com_jbusinessdirectory/models/managemessage.php

<?php
/**
 * @package    J-BusinessDirectory
 *
 * @author     CMSJunkie http://www.cmsjunkie.com/
 * @copyright  Copyright (C) 2007 - 2022 CMSJunkie. All rights reserved.
 * @license    https://www.gnu.org/licenses/agpl-3.0.en.html
 */
defined('_JEXEC') or die('Restricted access');
JTable::addIncludePath(DS.'components'.'com_jbusinessdirectory'.DS.'tables');
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'controllers'.DS.'message.php');
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'models'.DS.'message.php');

class JBusinessDirectoryModelManageMessage extends JBusinessDirectoryModelMessage {

	/**
	 * Method to test whether a record can be deleted.
	 *
	 * @param   object	A record object.
	 *
	 * @return  boolean  True if allowed to delete the record. Defaults to the permission set in the component.
	 */
	protected function canDelete($record) {
		return true;
	}

	/**
	 * Return array with all companies based on some letter it may include
	 * @return array
	 */
	public function readMessage() {
		$table = $this->getTable();
		$id = JFactory::getApplication()->input->get('id', null);

		$result = $table->readMessage($id);

		return $result;
	}

	public function changeStatus($id, $value) {
		$table = $this->getTable();
		return $table->changeStatus($id, $value);
	}

	public function sendMessageReply($data){

		$table = $this->getTable("MessageReply");
		$user = JBusinessUtil::getUser();
		$data["user_id"]= $user->id;

		// Bind the data.
		if (!$table->bind($data)) {
			$this->setError($table->getError());
			return false;
		}

		// Check the data.
		if (!$table->check()) {
			$this->setError($table->getError());
			return false;
		}

		// Store the data.
		if (!$table->store()) {
			$this->setError($table->getError());
			return false;
		}

		$menuItemId = JBusinessUtil::getActiveMenuItem();
		$url = JRoute::_('index.php?option=com_jbusinessdirectory&view=managemessages'.$menuItemId, false, -1);
		$url = "<a href=\"".$url."\">".$url."</a>";
		$subject = JText::_("LNG_MESSAGE_REPLY_SUBJECT");
		$content =  JText::sprintf("LNG_MESSAGE_REPLY_MESSAGE", $url);

		$message = $this->getTable();
		$message->load($data["message_id"]);
		$message->read = 0;
		$message->store();

		$userId = $user->id;
		$email = $user->email;
		if($message->user_id !=  $user->id){
			$userId = $message->user_id;
			$email = $message->email;
		}

		EmailService::sendUserMessage($subject, $content, $userId, $email);

		return true;
		
	}
}