Example #1
0
 /**
  * @operationName("Media List")
  * @operationDescription("Get Media list")
  */
 public function indexAction()
 {
     $limit = $this->request->getQuery('per_page', 'int', 25);
     $limit = $limit > 100 ? 100 : $limit;
     $limit = $limit < 10 ? 10 : $limit;
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => $this->request->getQuery('status', 'string'), 'uid' => $this->request->getQuery('uid', 'int'), 'extension' => $this->request->getQuery('extension', 'string'), 'image' => $this->request->getQuery('image', 'int'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     $form = new Forms\FilterForm();
     $form->setValues($this->request->getQuery());
     $this->view->setVar('form', $form);
     $fileManager = new Models\FileManager();
     $medias = $fileManager->findFiles($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $medias, "limit" => $limit, "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
 }
Example #2
0
 /**
  *
  * @SWG\Api(
  *   path="/admin/media/{mediaId}",
  *   description="Media related api",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="DELETE",
  *       summary="Delete media by ID",
  *       notes="Returns deleted media",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="mediaId",
  *           description="ID of media",
  *           paramType="path",
  *           required=true,
  *           type="integer"
  *         )
  *       )
  *     )
  *   )
  * )
  * @operationName("删除文件")
  * @operationDescription("删除文件")
  */
 public function deleteAction()
 {
     $id = $this->dispatcher->getParam('id');
     $media = Models\FileManager::findFirst($id);
     if (!$media) {
         throw new Exception\ResourceNotFoundException('Request media not exist');
     }
     $mediainfo = $media->dump(Models\FileManager::$defaultDump);
     try {
         $media->delete($id);
         return $this->response->setJsonContent($mediainfo);
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $media->getMessages());
     }
 }