__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
/**
* @package DPCalendar
* @copyright Copyright (C) 2020 Digital Peak GmbH. <https://www.digital-peak.com>
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*/
namespace DigitalPeak\Component\DPCalendar\Administrator\Model;
defined('_JEXEC') or die();
use DigitalPeak\Component\DPCalendar\Administrator\Helper\DPCalendarHelper;
use DigitalPeak\Component\DPCalendar\Administrator\Table\BasicTable;
use Joomla\CMS\Application\CMSWebApplicationInterface;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Uri\Uri;
class CouponModel extends AdminModel
{
protected $text_prefix = 'COM_DPCALENDAR_COUPON';
protected function canDelete($record)
{
if (!empty($record->state) && $record->state != -2) {
return false;
}
return parent::canDelete($record);
}
public function getItem($pk = null)
{
$item = parent::getItem($pk);
if ($item === false) {
return $item;
}
$item->calendars = $item->calendars && is_string($item->calendars) ? explode(',', $item->calendars) : [];
$item->users = $item->users && is_string($item->users) ? explode(',', $item->users) : [];
return $item;
}
public function getItemByCode(string $code, string $calid = '0', string $email = '', string $userId = '0'): ?\stdClass
{
if ($code === '' || $code === '0') {
return null;
}
$item = $this->getItem(['code' => $code, 'state' => 1]);
if (!$item || !$item->id) {
return null;
}
// Check calendars
if ($item->calendars && !in_array($calid, $item->calendars)) {
return null;
}
// Check mail
if ($item->emails && !in_array($email, explode(PHP_EOL, (string)$item->emails))) {
return null;
}
// Check users
if ($item->users && !in_array($userId, $item->users)) {
return null;
}
// Check publishing state
$now = DPCalendarHelper::getDate();
if ($item->publish_up && $now->toSql() < $item->publish_up) {
return null;
}
if ($item->publish_down && $now->toSql() > $item->publish_down) {
return null;
}
// Check limit
if ($item->limit) {
$this->getDatabase()->setQuery('select count(id) as total from #__dpcalendar_bookings where coupon_id = ' . (int)$item->id);
$count = $this->getDatabase()->loadAssoc();
if ($count['total'] >= $item->limit) {
return null;
}
}
return (object)(array)$item;
}
public function getTable($type = 'Coupon', $prefix = 'Administrator', $config = [])
{
return parent::getTable($type, $prefix, $config);
}
public function getForm($data = [], $loadData = true, string $controlName = 'jform')
{
// Get the form.
return $this->loadForm('com_dpcalendar.coupon', 'coupon', ['control' => $controlName, 'load_data' => $loadData]);
}
protected function loadFormData()
{
$app = Factory::getApplication();
$data = $app instanceof CMSWebApplicationInterface ? $app->getUserState('com_dpcalendar.edit.coupon.data', []) : [];
if (empty($data)) {
$data = $this->getItem();
}
$this->preprocessData('com_dpcalendar.coupon', $data);
return $data instanceof BasicTable ? $data->getData() : $data;
}
protected function populateState()
{
$app = Factory::getApplication();
$pk = $app->getInput()->getInt('co_id', 0);
$this->setState('coupon.id', $pk);
$this->setState('form.id', $pk);
$return = $app->getInput()->get('return', '', 'base64');
if (!Uri::isInternal(base64_decode((string)$return))) {
$return = '';
}
$this->setState('return_page', base64_decode((string)$return));
$this->setState('params', $app instanceof SiteApplication ? $app->getParams() : ComponentHelper::getParams('com_dpcalendar'));
}
public function getReturnPage(): string
{
return base64_encode((string)($this->getState('return_page', '') ?: Uri::base(true)));
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| BookingsModel.php | File | 6.99 KB | 0664 |
|
| CaldavModel.php | File | 1.97 KB | 0664 |
|
| CalendarModel.php | File | 2.07 KB | 0664 |
|
| CountriesModel.php | File | 3.99 KB | 0664 |
|
| CountryModel.php | File | 2.86 KB | 0664 |
|
| CouponModel.php | File | 3.76 KB | 0664 |
|
| CouponsModel.php | File | 4.04 KB | 0664 |
|
| CpanelModel.php | File | 4.27 KB | 0664 |
|
| EventModel.php | File | 31.73 KB | 0664 |
|
| EventsModel.php | File | 14.48 KB | 0664 |
|
| ExtcalendarModel.php | File | 5.59 KB | 0664 |
|
| ExtcalendarsModel.php | File | 4.92 KB | 0664 |
|
| FieldsOrderModel.php | File | 5.69 KB | 0664 |
|
| GeoModel.php | File | 19.01 KB | 0664 |
|
| IcalModel.php | File | 14.86 KB | 0664 |
|
| ImportModel.php | File | 7.32 KB | 0664 |
|
| LayoutModel.php | File | 722 B | 0664 |
|
| LocationModel.php | File | 11.99 KB | 0664 |
|
| LocationsModel.php | File | 8.92 KB | 0664 |
|
| PluginModel.php | File | 783 B | 0664 |
|
| TaxrateModel.php | File | 3.58 KB | 0664 |
|
| TaxratesModel.php | File | 4.33 KB | 0664 |
|
| TicketsModel.php | File | 8.96 KB | 0664 |
|
| ToolsModel.php | File | 1.61 KB | 0664 |
|