public function upload(EntityInterface $entity) { $file = null; foreach ($this->fields as $field) { $getter = CamelCasizer::underScoretToCamelCase('get_' . $field); if (method_exists($entity, $getter)) { /** @var UploadedFile $file */ $file = call_user_func_array(array($entity, $getter), array()); } if ($file instanceof UploadedFile) { $fileName = sha1(uniqid('SIAB_', true)) . '.' . $file->getClientOriginalExtension(); if (!$file->isExecutable()) { $file->move($this->dirPath, $fileName); } $setter = CamelCasizer::underScoretToCamelCase('set_' . $field); if (method_exists($entity, $setter)) { call_user_func_array(array($entity, $setter), array($fileName)); } } } }
/** * @param Request $request * @param EntityInterface $data * @param array $showFields */ public function showDetail(Request $request, EntityInterface $data, array $showFields) { $session = $this->container->get('session'); $referer = $session->get('referer'); $refererHeader = $request->headers->get('referer'); if ($refererHeader) { $referer = $refererHeader; $session->set('referer', $refererHeader); } $output = array(); foreach ($showFields as $key => $property) { $method = CamelCasizer::underScoretToCamelCase('get_' . $property); if (method_exists($data, $method)) { array_push($output, array('name' => $property, 'value' => call_user_func_array(array($data, $method), array()))); } else { $method = CamelCasizer::underScoretToCamelCase('is_' . $property); if (method_exists($data, $method)) { array_push($output, array('name' => $property, 'value' => call_user_func_array(array($data, $method), array()))); } } } $event = new FilterFormEvent(); $event->setData($output); $this->fireEvent(Event::PRE_SHOW, $event); $translator = $this->container->get('translator'); $translationDomain = $this->container->getParameter('symfonian_id.admin.translation_domain'); $viewParams['data'] = $output; $viewParams['menu'] = $this->container->getParameter('symfonian_id.admin.menu'); $viewParams['action_method'] = $translator->trans('page.show', array(), $translationDomain); $viewParams['back'] = $referer; $viewParams['action'] = $this->container->getParameter('symfonian_id.admin.grid_action'); $viewParams['number'] = $this->container->getParameter('symfonian_id.admin.number'); $viewParams['upload_dir'] = $this->container->getParameter('symfonian_id.admin.upload_dir'); $this->viewParams = array_merge($this->viewParams, $viewParams); }