| Current Path : /home/helpink/www/administrator/components/com_jbusinessdirectory/tables/ |
| Current File : /home/helpink/www/administrator/components/com_jbusinessdirectory/tables/emailtemplate.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');
use Joomla\Utilities\ArrayHelper;
class JTableEmailTemplate extends JTable {
/**
* Constructor
*
* @param object Database connector object
*/
public function __construct(&$db) {
parent::__construct('#__jbusinessdirectory_emails', 'email_id', $db);
}
public function setKey($k) {
$this->_tbl_key = $k;
}
/**
* Method to set the publishing state for a row or list of rows in the database
* table. The method respects checked out rows by other users and will attempt
* to checkin rows that it can after adjustments are made.
*
* @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used.
* @param integer $state The publishing state. eg. [0 = unpublished, 1 = published]
* @param integer $userId The user id of the user performing the operation.
*
* @return boolean True on success.
*
*/
public function publish($pks = null, $state = 1, $userId = 0) {
$k = $this->_tbl_key;
// Sanitize input.
ArrayHelper::toInteger($pks);
$userId = (int) $userId;
$state = (int) $state;
// If there are no primary keys set check to see if the instance key is set.
if (empty($pks)) {
if ($this->$k) {
$pks = array($this->$k);
}
// Nothing to set publishing state on, return false.
else {
$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
return false;
}
}
// Build the WHERE clause for the primary keys.
$where = $k . '=' . implode(' OR ' . $k . '=', $pks);
// Determine if there is checkin support for the table.
if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) {
$checkin = '';
} else {
$checkin = ' AND (checked_out = 0 OR checked_out = ' . (int) $userId . ')';
}
// Update the publishing state for rows with the given primary keys.
$query = $this->_db->getQuery(true)
->update($this->_db->quoteName($this->_tbl))
->set($this->_db->quoteName('status') . ' = ' . (int) $state)
->where('(' . $where . ')' . $checkin);
$this->_db->setQuery($query);
try {
$this->_db->execute();
} catch (RuntimeException $e) {
$this->setError($e->getMessage());
return false;
}
// If the JTable instance value is in the list of primary keys that were set, set the instance.
if (in_array($this->$k, $pks)) {
$this->status = $state;
}
$this->setError('');
return true;
}
public function getEmailTypes() {
$db = JFactory::getDBO();
$query = "SELECT email_id AS value, email_type AS text FROM #__jbusinessdirectory_emails ORDER BY email_type";
$db->setQuery($query);
return $db->loadObjectList();
}
public function changeState($emailId) {
$db = JFactory::getDbo();
$emailId = (int) $emailId;
$query = "UPDATE #__jbusinessdirectory_emails SET status = IF(status, 0, 1) WHERE email_id = " . $emailId;
$db->setQuery($query);
if (!$db->execute()) {
return false;
}
return true;
}
}