Esempio n. 1
0
 public function beforeSave()
 {
     $this->updatedAt = time();
     if ($this->type == 'data') {
         //Auto update title if finance data
         $this->title = \Eva\EvaEngine\Text\Substring::substrCn(strip_tags($this->getContentHtml()), 100);
     }
     //Data importance will overwrite news importance
     if ($data = $this->getData()) {
         $this->importance = $data->importance;
     }
     if ($this->getDI()->getRequest()->hasFiles()) {
         $upload = new UploadModel();
         $files = $this->getDI()->getRequest()->getUploadedFiles();
         if (!$files) {
             return;
         }
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $this->imageId = $file->id;
             $this->image = $file->getLocalUrl();
         }
     }
 }
Esempio n. 2
0
 public function beforeSave()
 {
     if ($this->getDI()->getRequest()->hasFiles()) {
         $upload = new UploadModel();
         $files = $this->getDI()->getRequest()->getUploadedFiles();
         if (!$files) {
             return;
         }
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $this->imageId = $file->id;
             $this->image = $file->getLocalUrl();
         }
     }
 }
Esempio n. 3
0
 public function beforeSave()
 {
     if ($this->password) {
         $this->password = self::passwordHash($this->password);
     }
     if ($this->getDI()->getRequest()->hasFiles()) {
         $upload = new UploadModel();
         $files = $this->getDI()->getRequest()->getUploadedFiles();
         if (!$files) {
             return;
         }
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $this->avatarId = $file->id;
             $this->avatar = $file->getFullUrl();
         }
     }
 }
Esempio n. 4
0
 /**
  * @operationName("Upload Encoded Media")
  * @operationDescription("Upload Base64 encoded media (from Browser drag and drop)")
  */
 public function encodeAction()
 {
     if (!$this->request->isPost()) {
         $this->response->setStatusCode('400', 'No Upload Files');
         return $this->response->setJsonContent(array('errors' => array(array('code' => 400, 'message' => 'ERR_FILE_NO_UPLOAD'))));
     }
     $upload = new Models\Upload();
     $fileinfo = array();
     try {
         $file = $upload->uploadByEncodedData($this->request->getPost('file'), $this->request->getPost('name'), $this->request->getPost('type'));
         if ($file) {
             $fileinfo = $file->toArray();
             $fileinfo['localUrl'] = $file->getLocalUrl();
         }
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $upload->getMessages());
     }
     return $this->response->setJsonContent($fileinfo);
 }
Esempio n. 5
0
 public function updateCategory()
 {
     if ($this->getDI()->getRequest()->hasFiles()) {
         $upload = new UploadModel();
         $files = $this->getDI()->getRequest()->getUploadedFiles();
         if (!$files) {
             return;
         }
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $this->imageId = $file->id;
             $this->image = $file->getFullUrl();
         }
     }
     $this->save();
 }
Esempio n. 6
0
 /**
  *
  * @SWG\Api(
  *   path="/admin/media",
  *   description="Media related api",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="POST",
  *       summary="Create new media",
  *       notes="Returns a media based on ID",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="upload",
  *           description="Media info",
  *           paramType="body",
  *           required=true,
  *           type="file"
  *         )
  *       )
  *     )
  *   )
  * )
  * @operationName("上传文件")
  * @operationDescription("上传文件")
  */
 public function postAction()
 {
     if (!$this->request->isPost() || !$this->request->hasFiles()) {
         throw new Exception\InvalidArgumentException('No data input');
     }
     $upload = new Models\Upload();
     try {
         $files = $this->request->getUploadedFiles();
         //Only allow upload the first file by force
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $data = $file->dump(Models\FileManager::$defaultDump);
             return $this->response->setJsonContent($data);
         }
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $upload->getMessages());
     }
 }
Esempio n. 7
0
 /**
  * @param array $data
  */
 public function updateCategory(array $data)
 {
     if ($this->getDI()->getRequest()->hasFiles()) {
         $upload = new UploadModel();
         $files = $this->getDI()->getRequest()->getUploadedFiles();
         if (!$files) {
             return;
         }
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $this->imageId = $file->id;
             $this->image = $file->getFullUrl();
         }
     }
     $pinyin = new Pinyin();
     $this->initial = substr($pinyin->transformUcwords($this->categoryName), 0, 1);
     if ($this->save()) {
         $parents = isset($data['parents']) ? $data['parents'] : array();
         $cateCate = new CategoryCategory();
         $cateCate->forFullUpdateCategoryByParentId($this->id, $parents);
     }
 }