예제 #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();
         }
     }
 }
예제 #2
0
파일: Topic.php 프로젝트: skybird/phalcon
 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();
         }
     }
 }
예제 #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();
         }
     }
 }
예제 #4
0
 /**
  * @operationName("Upload Media")
  * @operationDescription("Upload Media")
  */
 public function indexAction()
 {
     if (!$this->request->isPost() || !$this->request->hasFiles()) {
         $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 {
         $files = $this->request->getUploadedFiles();
         //Only allow upload the first file by force
         $file = $files[0];
         $file = $upload->upload($file);
         if ($file) {
             $fileinfo = $file->toArray();
             $fileinfo['localUrl'] = $file->getLocalUrl();
         }
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $upload->getMessages());
     }
     return $this->response->setJsonContent($fileinfo);
 }
예제 #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();
 }
예제 #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());
     }
 }
예제 #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);
     }
 }