edusoho零主題開(kāi)發(fā)案例

```

<?php

namespace ZeroPlugin\Controller\AdminV2;

use AppBundle\Common\ArrayToolkit;

use AppBundle\Controller\BaseController;

use Biz\Content\Service\FileService;

use Biz\System\Service\SettingService;

use Symfony\Component\HttpFoundation\JsonResponse;

use Symfony\Component\HttpFoundation\Request;

class AdvertisementSettingController extends BaseController

{

? ? public function setAdvertisementAction(Request $request)

? ? {

? ? ? ? $advertisementSetting = $this->setting('zeroAdvertisement', array());

? ? ? ? if ($request->getMethod() == 'POST') {

? ? ? ? ? ? $data = $request->request->all();

? ? ? ? ? ? $data['startTime'] = strtotime($data['startTime']);

? ? ? ? ? ? $data['endTime'] = strtotime($data['endTime']);

? ? ? ? ? ? $this->getSettingService()->set('zeroAdvertisement', $data);

? ? ? ? }

? ? ? ? return $this->render('ZeroPlugin:ZeroAdminV2:advertisement-setting.html.twig', array(

? ? ? ? ? ? 'advertisementSetting' => $advertisementSetting,

? ? ? ? ));

? ? }

? ? public function showUploadModalAction()

? ? {

? ? ? ? return $this->render('ZeroPlugin:ZeroAdminV2:advertisement-upload.html.twig', array(

? ? ? ? ? ? 'pictureUrl' => '',

? ? ? ? ));

? ? }

? ? public function cropAction(Request $request)

? ? {

? ? ? ? if ($request->getMethod() == 'POST') {

? ? ? ? ? ? $data = $request->request->all();

? ? ? ? ? ? $files = $this->changePicture($data['images']);

? ? ? ? ? ? foreach ($files as $key => $file) {

? ? ? ? ? ? ? ? $files[$key]['file']['url'] = $this->get('web.twig.extension')->getFilePath($file['file']['uri']);

? ? ? ? ? ? }

? ? ? ? ? ? return new JsonResponse($files);

? ? ? ? }

? ? ? ? $fileId = $request->getSession()->get('fileId');

? ? ? ? list($pictureUrl, $naturalSize, $scaledSize) = $this->getFileService()->getImgFileMetaInfo($fileId, 270, 270);

? ? ? ? return $this->render('ZeroPlugin:ZeroAdminV2:advertisement-crop.html.twig', array(

? ? ? ? ? ? 'pictureUrl' => $pictureUrl,

? ? ? ? ? ? 'naturalSize' => $naturalSize,

? ? ? ? ? ? 'scaledSize' => $scaledSize,

? ? ? ? ));

? ? }

? ? protected function changePicture($data)

? ? {

? ? ? ? $fileIds = ArrayToolkit::column($data, 'id');

? ? ? ? $files = $this->getFileService()->getFilesByIds($fileIds);

? ? ? ? $data = ArrayToolkit::index($data, 'type');

? ? ? ? $files = ArrayToolkit::index($files, 'id');

? ? ? ? foreach ($data as $key => $value) {

? ? ? ? ? ? if ($key == 'origin') {

? ? ? ? ? ? ? ? $file = $this->getFileService()->getFileObject($value['id']);

? ? ? ? ? ? ? ? $file = $this->getFileService()->uploadFile('default', $file);

? ? ? ? ? ? ? ? $data[$key]['file'] = $file;

? ? ? ? ? ? ? ? $this->getFileService()->deleteFileByUri($files[$value['id']]['uri']);

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? $data[$key]['file'] = $files[$value['id']];

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? return $data;

? ? }

? ? /**

? ? * @return SettingService

? ? */

? ? protected function getSettingService()

? ? {

? ? ? ? return $this->createService('System:SettingService');

? ? }

? ? /**

? ? * @return FileService

? ? */

? ? protected function getFileService()

? ? {

? ? ? ? return $this->createService('Content:FileService');

? ? }

}

```

在線演示案例 http://zero.shop1a.cn/

1
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容