first commit
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/appWishesPlugin
|
||||
*
|
||||
*
|
||||
* @package appWishesPlugin
|
||||
* @author Bartosz Alejski <whiteface@whiteface.pl>
|
||||
*/
|
||||
class appWishesBackendActions extends sfActions{
|
||||
|
||||
public function executeResponsiveConfig(){
|
||||
|
||||
$this->forward_parameters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/appWishesResponsiveConfigBackend/site_forward_parameters');
|
||||
|
||||
$this->config = stConfig::getInstance($this->getContext(), 'appWishesResponsiveConfigBackend');
|
||||
|
||||
$this->config->setCulture($this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
|
||||
$video_array = unserialize($this->config->get('wishes_responsive_video'));
|
||||
|
||||
$images_array = unserialize($this->config->get('wishes_responsive_images'));
|
||||
|
||||
$number_of_elements = count($images_array);
|
||||
|
||||
$number_of_elements_video = count($video_array);
|
||||
|
||||
if ($this->getRequest()->getMethod() == sfRequest::POST){
|
||||
|
||||
$this->config->set('wishes_responsive_on', $this->getRequestParameter('wishes[wishes_responsive_on]'));
|
||||
$this->config->set('wishes_responsive_description', $this->getRequestParameter('wishes[wishes_responsive_description]'), true);
|
||||
$this->config->set('wishes_responsive_link_on', $this->getRequestParameter('wishes[wishes_responsive_link_on]'));
|
||||
$this->config->set('wishes_responsive_music_on', $this->getRequestParameter('wishes[wishes_responsive_music_on]'));
|
||||
$this->config->set('wishes_responsive_music_autoplay', $this->getRequestParameter('wishes[wishes_responsive_music_autoplay]'));
|
||||
$this->config->set('wishes_responsive_song_number', $this->getRequestParameter('wishes[wishes_responsive_song_number]'));
|
||||
|
||||
|
||||
// ustawienie aktywnego zdjęcia
|
||||
if ($this->getRequestParameter('wishes[image_radio]') || $this->getRequestParameter('wishes[video_radio]') ){
|
||||
|
||||
// zerowanie tabel
|
||||
for ($i = 0; $i <= $number_of_elements-1; $i++){
|
||||
$images_array[$i]['active'] = 0;
|
||||
}
|
||||
for ($i = 0; $i <= $number_of_elements_video-1; $i++){
|
||||
$video_array[$i]['active'] = 0;
|
||||
}
|
||||
|
||||
|
||||
if ($this->getRequestParameter('wishes[image_radio]')){
|
||||
|
||||
foreach ($images_array as $key => $image){
|
||||
|
||||
if($image['name'] == $this->getRequestParameter('wishes[image_radio]')){
|
||||
$new_active = $key;
|
||||
}
|
||||
}
|
||||
$images_array[$new_active]['active'] = 1;
|
||||
|
||||
$fileName = $this->getRequestParameter('wishes[image_radio]');
|
||||
|
||||
|
||||
}elseif($this->getRequestParameter('wishes[video_radio]')){
|
||||
|
||||
foreach ($video_array as $key => $video){
|
||||
|
||||
if($video['name'] == $this->getRequestParameter('wishes[video_radio]')){
|
||||
$new_active = $key;
|
||||
}
|
||||
|
||||
}
|
||||
$video_array[$new_active]['active'] = 1;
|
||||
|
||||
$fileName = $this->getRequestParameter('wishes[video_radio]');
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// załadowanie nowego zdjęcia
|
||||
if ($this->getRequest()->getFileSize('wishes[image]')){
|
||||
|
||||
$fileName = $this->getRequest()->getFileName('wishes[image]');
|
||||
|
||||
$ext = $this->getRequest()->getFileExtension('wishes[image]');
|
||||
|
||||
if($ext=='.jpg' || $ext=='.gif' || $ext=='.png' || $ext=='.jpeg'){
|
||||
|
||||
$this->getRequest()->moveFile('wishes[image]', sfConfig::get('sf_upload_dir') . '/wishes_picture/' . $fileName);
|
||||
|
||||
for ($i = 0; $i <= $number_of_elements-1; $i++){
|
||||
$images_array[$i]['active'] = 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i <= $number_of_elements_video-1; $i++){
|
||||
$video_array[$i]['active'] = 0;
|
||||
}
|
||||
|
||||
$images_array[$number_of_elements]['name'] = $fileName;
|
||||
$images_array[$number_of_elements]['active'] = 1;
|
||||
|
||||
}elseif($ext == '.bin'){
|
||||
|
||||
$this->getRequest()->moveFile('wishes[image]', sfConfig::get('sf_upload_dir') . '/wishes_picture/' . $fileName);
|
||||
|
||||
for ($i = 0; $i <= $number_of_elements-1; $i++){
|
||||
$images_array[$i]['active'] = 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i <= $number_of_elements_video-1; $i++){
|
||||
$video_array[$i]['active'] = 0;
|
||||
}
|
||||
|
||||
$video_array[$number_of_elements_video]['name'] = $fileName;
|
||||
$video_array[$number_of_elements_video]['active'] = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->config->set('wishes_responsive_images', serialize($images_array));
|
||||
|
||||
$this->config->set('wishes_responsive_video', serialize($video_array));
|
||||
|
||||
$this->config->set('wishes_responsive_active_image', $fileName);
|
||||
|
||||
$this->config->save();
|
||||
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
$this->setFlash('notice', 'Twoje zmiany zostały zapisane');
|
||||
|
||||
$this->redirect('appWishesBackend/responsiveConfig?culture='.$this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
}
|
||||
|
||||
$this->images_array = $images_array;
|
||||
|
||||
$this->video_array = $video_array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function executeDelete(){
|
||||
|
||||
$fileName = $this->getRequestParameter('name');
|
||||
|
||||
$this->config = stConfig::getInstance($this->getContext(), 'appWishesResponsiveConfigBackend');
|
||||
|
||||
$images_array = unserialize($this->config->get('wishes_responsive_images'));
|
||||
|
||||
$this->config->setCulture($this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
|
||||
$i = 0;
|
||||
$set_default = 0;
|
||||
foreach ($images_array as $key=>$image){
|
||||
if($image['name'] == $fileName){
|
||||
$new_active = $key;
|
||||
|
||||
if($image['active']==1){
|
||||
$set_default = 1;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
unset($images_array[$new_active]);
|
||||
|
||||
if($set_default==1){
|
||||
|
||||
$images_array[3]['active'] = 1;
|
||||
}
|
||||
|
||||
$this->config->set('wishes_responsive_images', serialize($images_array));
|
||||
|
||||
if($set_default==1){
|
||||
$this->config->set('wishes_responsive_active_image', 'responsive1.jpg');
|
||||
}
|
||||
|
||||
$this->config->save();
|
||||
stFastCacheManager::clearCache();
|
||||
$this->redirect('appWishesBackend/responsiveConfig?culture='.$this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
}
|
||||
|
||||
public function executeDeleteVideo(){
|
||||
|
||||
$fileName = $this->getRequestParameter('name');
|
||||
|
||||
$this->config = stConfig::getInstance($this->getContext(), 'appWishesResponsiveConfigBackend');
|
||||
|
||||
$video_array = unserialize($this->config->get('wishes_responsive_video'));
|
||||
|
||||
$this->config->setCulture($this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
|
||||
$i = 0;
|
||||
|
||||
$set_default = 0;
|
||||
|
||||
foreach ($video_array as $key=>$video){
|
||||
|
||||
if($video['name'] == $fileName){
|
||||
|
||||
$new_active = $key;
|
||||
|
||||
if($image['active']==1){
|
||||
$set_default = 1;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
unset($video_array[$new_active]);
|
||||
|
||||
if($set_default==1){
|
||||
$video_array[1]['active'] = 1;
|
||||
}
|
||||
|
||||
$this->config->set('wishes_responsive_video', serialize($video_array));
|
||||
|
||||
if($set_default==1){
|
||||
$this->config->set('wishes_responsive_active_image', 'chistmas-video1.mp4');
|
||||
}
|
||||
|
||||
$this->config->save();
|
||||
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
$this->redirect('appWishesBackend/responsiveConfig?culture='.$this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user