first commit
This commit is contained in:
331
admin/photos.php
Normal file
331
admin/photos.php
Normal file
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
use KupShop\ContentBundle\Util\ImageLocator;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
$main_class = 'AdminPhotos';
|
||||
|
||||
class AdminPhotos extends Window
|
||||
{
|
||||
protected $tableName = 'photos';
|
||||
protected $template = 'window/photos.tpl';
|
||||
|
||||
public function get_vars()
|
||||
{
|
||||
$vars = parent::get_vars();
|
||||
$pageVars = getVal('body', $vars);
|
||||
|
||||
$acn = $this->getAction();
|
||||
$ID = $this->getID();
|
||||
|
||||
$SQL = sqlQuery(' select group_concat(b.id) as ids from blocks as b
|
||||
inner join blocks as br ON br.id_root = b.id
|
||||
inner join photos_blocks_new_relation pbnr on br.id = pbnr.id_block
|
||||
where pbnr.id_photo = :id', ['id' => $ID]);
|
||||
|
||||
$idsBlock = sqlFetchAssoc($SQL);
|
||||
|
||||
$SQL = sqlQuery('SELECT p.id, p.title
|
||||
FROM photos_products_relation AS php, products AS p
|
||||
WHERE (php.id_product=p.id AND php.id_photo=:id)
|
||||
GROUP BY p.id', ['id' => $ID]);
|
||||
|
||||
$pageVars['photos_products'] = sqlFetchAll($SQL);
|
||||
|
||||
if (findModule(\Modules::PRODUCTS, \Modules::SUB_DESCR_PLUS)) {
|
||||
$SQL = sqlQuery(
|
||||
'SELECT p.id, p.title
|
||||
FROM products AS p
|
||||
LEFT JOIN photos_products_descr_plus_relation as ppdpr ON p.id = ppdpr.id_product
|
||||
WHERE (ppdpr.id_product=p.id AND ppdpr.id_photo=:id) OR (p.id_block IN(:idsBlock))
|
||||
GROUP BY p.id',
|
||||
['id' => $ID, 'idsBlock' => $idsBlock['ids']]
|
||||
);
|
||||
$pageVars['photos_products'] = array_merge($pageVars['photos_products'], sqlFetchAll($SQL));
|
||||
}
|
||||
|
||||
$SQL = sqlQuery('SELECT a.id, a.title
|
||||
FROM photos_articles_relation AS pha, articles AS a
|
||||
WHERE (pha.id_art=a.id AND pha.id_photo=:id ) OR (a.id_block IN(:idsBlock))', ['id' => $ID, 'idsBlock' => $idsBlock['ids']]);
|
||||
|
||||
$pageVars['photos_articles'] = sqlFetchAll($SQL);
|
||||
|
||||
$SQL = sqlQuery('SELECT hp.id, hp.name
|
||||
FROM photos_menu_relation AS ppr, menu_links AS hp
|
||||
WHERE (ppr.id_menu=hp.id AND ppr.id_photo=:id) OR (hp.id_block IN(:idsBlock))
|
||||
GROUP BY hp.id', ['id' => $ID, 'idsBlock' => $idsBlock['ids']]);
|
||||
$pageVars['photos_pages'] = sqlFetchAll($SQL);
|
||||
|
||||
if (findModule(\Modules::PRODUCERS)) {
|
||||
$SQL = sqlQuery('SELECT p.id, p.name
|
||||
FROM producers AS p
|
||||
LEFT JOIN photos_producers_relation AS ppr ON ppr.id_producer=p.id
|
||||
WHERE (ppr.id_photo = :id) OR (p.id_block IN(:idsBlock))
|
||||
GROUP BY p.id', ['id' => $ID, 'idsBlock' => $idsBlock['ids']]);
|
||||
$pageVars['photos_producers'] = sqlFetchAll($SQL);
|
||||
}
|
||||
if (findModule(\Modules::SLIDERS)) {
|
||||
$pageVars['photos_sliders'] = sqlQueryBuilder()
|
||||
->select('si.id_slider,s.id,s.name')
|
||||
->from('sliders_images', 'si')
|
||||
->join('si', 'sliders', 's', 's.id= si.id_slider')
|
||||
->where(\Query\Operator::equals(['si.id_photo' => $ID]))
|
||||
->execute()->fetchAllAssociative();
|
||||
}
|
||||
|
||||
if (findModule(\Modules::PRODUCTS_SECTIONS)) {
|
||||
$pageVars['photos_sections'] = sqlQueryBuilder()
|
||||
->select('psr.id_section,s.id,s.name')
|
||||
->from('photos_sections_relation', 'psr')
|
||||
->join('psr', 'photos', 'p', 'p.id = psr.id_photo')
|
||||
->join('psr', 'sections', 's', 's.id=psr.id_section')
|
||||
->where(\Query\Operator::equals(['psr.id_photo' => $ID]))
|
||||
->execute()->fetchAllAssociative();
|
||||
}
|
||||
if ($acn == 'edit') {
|
||||
$pageVars['data']['photo'] = ServiceContainer::getService(ImageLocator::class)->getImage($pageVars['data']);
|
||||
}
|
||||
|
||||
$pageVars['data']['data'] = json_decode($pageVars['data']['data'] ?? '', true);
|
||||
$vars['type'] = 'photos';
|
||||
$vars['body'] = $pageVars;
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
public function fetchObject($table, $ID)
|
||||
{
|
||||
$qb = sqlQueryBuilder()->select('p.*')->from('photos', 'p')
|
||||
->where(\Query\Operator::equals(['p.id' => $ID]));
|
||||
|
||||
if (findModule(Modules::VIDEOS)) {
|
||||
$qb->addSelect('v.id_cdn id_video')
|
||||
->leftJoin('p', 'videos', 'v', 'p.id = v.id_photo');
|
||||
}
|
||||
|
||||
return $qb->execute()->fetchAssociative();
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
$data = parent::getData();
|
||||
|
||||
if ($this->getAction() == 'add') {
|
||||
$data['date'] = date('Y-m-d H:i:s');
|
||||
} else {
|
||||
$customData = $this->getCustomData();
|
||||
|
||||
[$centerPointX, $centerPointY] = $this->getCenterPoints();
|
||||
if ($centerPointX && $centerPointY) {
|
||||
$customData['center_point']['x'] = $centerPointX;
|
||||
$customData['center_point']['y'] = $centerPointY;
|
||||
}
|
||||
$data['data'] = $customData;
|
||||
|
||||
$this->serializeCustomData($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function handleUpdate()
|
||||
{
|
||||
$ID = $this->getID();
|
||||
$acn = $this->getAction();
|
||||
$data = $this->getData();
|
||||
|
||||
if ($acn == 'add' && empty($_FILES['picture']['name'])) {
|
||||
$ErrStr = 'Nesprávně vyplněno';
|
||||
redirect("launch.php?s=photos.php&acn={$acn}&ID={$ID}&ErrStr={$ErrStr}");
|
||||
}
|
||||
|
||||
parent::handleUpdate();
|
||||
|
||||
$this->updatePhotos($data['descr']);
|
||||
|
||||
[$centerPointX, $centerPointY] = $this->getCenterPoints();
|
||||
if ($centerPointX && $centerPointY) {
|
||||
$photo = new \Photos();
|
||||
$photo->newImage($this->getID());
|
||||
$photo->clearThumbnails();
|
||||
$photo->updateDateUpdated();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getCenterPoints(): array
|
||||
{
|
||||
$originalData = getVal('data', default: []);
|
||||
|
||||
$centerPointX = $originalData['data']['center_point']['x'] ?? false;
|
||||
$centerPointY = $originalData['data']['center_point']['y'] ?? false;
|
||||
|
||||
return [$centerPointX, $centerPointY];
|
||||
}
|
||||
|
||||
private function updatePhotos(string $description): void
|
||||
{
|
||||
$files = [
|
||||
'picture' => Photos::PHOTO_VERSION_DESKTOP,
|
||||
'pictureTablet' => Photos::PHOTO_VERSION_TABLET,
|
||||
'pictureMobile' => Photos::PHOTO_VERSION_MOBILE,
|
||||
];
|
||||
|
||||
foreach ($files as $file => $version) {
|
||||
if (!empty($_FILES[$file]['name'])) {
|
||||
$img = Photos::get($this->getID(), $version);
|
||||
$img->uploadPhotoOrVideo($_FILES[$file], $_FILES[$file]['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function handleDelete()
|
||||
{
|
||||
global $cfg;
|
||||
$ID = $this->getID();
|
||||
if (!findRight('PHOTOS_ERASE')) {
|
||||
redirect('launch.php?s=error.php&id=1');
|
||||
}
|
||||
|
||||
writeDownActivity(sprintf(getTextString('photos', 'activityDeleted'), $ID));
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TRIDA PRO UPRAVU OBRAZKU
|
||||
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$img = new Photos('none');
|
||||
$img->newImage($ID);
|
||||
$img->deletePhoto();
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Obrázek byl smazán
|
||||
$ErrStr = getTextString('photos', 'errorDeleted');
|
||||
|
||||
redirect('launch.php?s=photos.php&acn=erased&ErrStr='.urlencode($ErrStr));
|
||||
}
|
||||
|
||||
public function handleDeleteVersion()
|
||||
{
|
||||
if (!findRight('PHOTOS_ERASE')) {
|
||||
redirect('launch.php?s=error.php&id=1');
|
||||
}
|
||||
|
||||
$version = getVal('version');
|
||||
$IDph = getVal('ID');
|
||||
|
||||
writeDownActivity(sprintf(getTextString('photos', 'activityDeleted'), $IDph));
|
||||
|
||||
$img = new Photos('none');
|
||||
$img->newImage($IDph);
|
||||
$img->erasePhotoVersion($IDph, $version);
|
||||
|
||||
// Obrázek byl smazán
|
||||
$ErrStr = translate('errorDeleted', 'photos');
|
||||
|
||||
redirect('launch.php?s=photos.php&acn=edit&ID='.$IDph.'&ErrStr='.urlencode($ErrStr));
|
||||
}
|
||||
|
||||
public function handleDeletePhotoRelation()
|
||||
{
|
||||
$type = getVal('relationType');
|
||||
$ID = $this->getID();
|
||||
$IDpr = getVal('IDpr');
|
||||
|
||||
switch ($type) {
|
||||
case 'articles':
|
||||
$SQL = sqlQueryBuilder()
|
||||
->delete('photos_articles_relation')
|
||||
->where(\Query\Operator::equals(['id_art' => $IDpr]))
|
||||
->execute();
|
||||
|
||||
Photos::checkLeadPhoto('photos_articles_relation', 'id_art', $IDpr);
|
||||
|
||||
// Zařazení ke článku bylo odstraněno
|
||||
$ErrStr = getTextString('photos', 'errorArticleRelationDeleted');
|
||||
|
||||
break;
|
||||
|
||||
case 'products':
|
||||
$SQL = sqlQueryBuilder()
|
||||
->delete('photos_products_relation')
|
||||
->where(\Query\Operator::equals(['id_product' => $IDpr]))
|
||||
->execute();
|
||||
|
||||
Photos::checkLeadPhoto('photos_products_relation', 'id_product', $IDpr);
|
||||
|
||||
// Zařazení ke zboží bylo odstraněno
|
||||
$ErrStr = getTextString('photos', 'errorProductRelationDeleted');
|
||||
break;
|
||||
|
||||
case 'pages':
|
||||
$SQL = sqlQueryBuilder()
|
||||
->delete('photos_menu_relation')
|
||||
->where(\Query\Operator::equals(['id_menu' => $IDpr]))
|
||||
->execute();
|
||||
|
||||
Photos::checkLeadPhoto('photos_menu_relation', 'id_menu', $IDpr);
|
||||
// Zařazení ke stránce bylo odstraněno
|
||||
$ErrStr = getTextString('photos', 'errorPageRelationDeleted');
|
||||
|
||||
break;
|
||||
|
||||
case 'producers':
|
||||
$SQL = sqlQueryBuilder()
|
||||
->delete('photos_producers_relation')
|
||||
->where(where(\Query\Operator::equals(['id_producers' => $IDpr])))
|
||||
->execute();
|
||||
|
||||
Photos::checkLeadPhoto('photos_producers_relation', 'id_producers', $IDpr);
|
||||
|
||||
// Zařazení k výrobci bylo odstraněno
|
||||
$ErrStr = getTextString('photos', 'errorProducerRelationDeleted');
|
||||
|
||||
break;
|
||||
|
||||
case 'sliders':
|
||||
$SQL = sqlQueryBuilder()
|
||||
->delete('sliders_images')
|
||||
->where(\Query\Operator::equals(['id_slider' => $IDpr]))
|
||||
->execute();
|
||||
|
||||
// Zařazení k banneru bylo odstraněno
|
||||
$ErrStr = getTextString('photos', 'errorSliderRelationDeleted');
|
||||
|
||||
break;
|
||||
|
||||
case 'sections':
|
||||
$SQL = sqlQueryBuilder()
|
||||
->delete('photos_sections_relation')
|
||||
->where(\Query\Operator::equals(['id_section' => $IDpr]))
|
||||
->execute();
|
||||
|
||||
Photos::checkLeadPhoto('photos_sections_relation', 'id_section', $IDpr);
|
||||
|
||||
// Zařazení k sekci bylo odstraněno
|
||||
$ErrStr = getTextString('photos', 'errorSectionRelationDeleted');
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$this->returnOK($ErrStr);
|
||||
}
|
||||
|
||||
public function handleRefreshVideoThumbnail()
|
||||
{
|
||||
$photo = $this->getObject();
|
||||
|
||||
if (!empty($photo['id_video'])) {
|
||||
$img = new Photos('none');
|
||||
$img->newImage($photo['id']);
|
||||
if (!$img->refreshVideoThumbnail($photo)) {
|
||||
$this->returnError('Nelze aktualizovat náhled: Chyba stažení náhledového obrázku.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->returnOK();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user