Орла
Области
Компаний
Пользователи
Галерея
Фиксированные новости
Орла
Отзывы о фирмах
Тарифы
Пользователи
Области
Банкоматы
Торговые точки
Доска объявлений
Курсы валют
Скидки
организации Орла
организации области
товары
сайты
сайты Орел
Данные
Разделы
Поиск
Поиск запросы
Статистика
Показы каталога организаций
Статистика клиенты
Пользователи
Сайты
Управление сайтом
Анкета
Аптеки
Афиша
Афиша новая
Баннеры
Бизнес >
Викторина
Голосование
Гость на сайте
Истории
Календарь событий
Каталоги >
Конкурс красоты
Конкурс аудио
Консультации
Меню
Новое на сайте
Новости >
Организации >
Программа ТВ
Публикации
Разделы сайта
Рассылка
Рестораны
Секрет фирмы >
Сервисы >
Ссылки
Тесты
Файловый менеджер
Форум
Фотогалерея
Обратная связь
Недвижимость
Новый год
Тексты
Пользователи
Юридический рейтинг
Отзывы на товары
Бан пользователей
Жалобы
Новые тесты
Коронавирус
Файловый менеджер
Имя файла
EditProductForm.php
Содержимое
<?php namespace app\organizations\form; use app\core\models\Form; use app\core\storage\ImageUploader; use app\organizations\Organizations; use app\organizations\shop\ProductRepository; class EditProductForm extends Form { public $id; public $id_firm = 0; public $name; public $url; public $price; public $description; public $status = 1; private $productRepository; private $image = ''; public function __construct() { parent::__construct(); $this->productRepository = new ProductRepository(); } public function rules() { return [ ['name', 'required', 'message' => 'Укажите название товара'], ['price', 'required', 'message' => 'Укажите стоимость товара'], ['id_firm', 'required', 'message' => 'Укажите организацию'], ['status', 'required', 'message' => 'Укажите статус товара'] ]; } public function validate() { if (parent::validate() == false) { return false; } if (Organizations::isMyOrganization($this->id_firm) == false) { $this->addError('id_firm', 'Доступ запрещен'); return false; } // можно ли добавлять товары? if (Organizations::isAllowProducts($this->id_firm) == false) { $this->addError('id', 'На вашем тарифе товаров нет'); return false; } // а можно ли еще добавлять товары? if ($this->id == 0 && Organizations::isAllowAddProducts($this->id_firm) == false) { $this->addError('id', 'Достигнут лимит товаров'); return false; } // можно ли редактировать этот товар? if ($this->id > 0 && Organizations::isMyProduct($this->id, $this->id_firm) == false) { $this->addError('name', 'Доступ к редактированию товара запрещен'); return false; } // проверим, было ли загружено изображение (если товар новый) if ($this->id == 0 && empty($_FILES['img_index'])) { $this->addError('img_index', 'Для нового товара изображение обязательно'); } return true; } public function save() { // если у нас есть товар, положим в изображение старую картинку if ($this->id > 0) { $product = $this->productRepository->findById($this->id); $this->image = $product['img_index']; } if (empty($_FILES['img_index']) == false && is_uploaded_file($_FILES['img_index']['tmp_name'])) { $this->image = ImageUploader::upload_foto( $_FILES['img_index']['tmp_name'], 430, 800, 1, 1, 'user_foto/tovar', 1 ); } $result = $this->productRepository->save([ 'id' => (int) $this->id, 'id_firm' => (int) $this->id_firm, 'name' => strip_tags($this->name), 'url' => strip_tags($this->url), 'price' => strip_tags($this->price), 'img_index' => $this->image, 'description' => strip_tags($this->description), 'status' => $this->status == 1 ? 1 : 0 ]); if ($result === true) { return true; } $this->addError('id', 'Не удалось сохранить товар'); return false; } }
/app/organizations/form/
Имя
Дата
Размер
..
2020-04-06
filters
2019-04-03
AddCommentForm.php
2026-05-25
3 кб.
AddCommentForm.php~
2017-08-16
2 кб.
AddOrganizationForm.php
2026-05-25
6 кб.
AddOrganizationForm.php~
2019-04-03
5 кб.
AddPhotoForm.php
2017-03-24
2 кб.
ChangeDeliveryForm.php
2020-04-10
2 кб.
DeletePhotoForm.php
2017-03-24
2 кб.
DeleteProductForm.php
2020-04-06
1 кб.
EditInformationForm.php
2020-02-25
3 кб.
EditOrganizationContactForm.php
2020-04-06
8 кб.
EditProductForm.php
2020-04-10
4 кб.
VoteForm.php
2017-01-25
1 кб.
/app/organizations/form
Загрузить файлы
Файл 1
Файл 2
Файл 3