diff --git a/apps/mobile_frontend/modules/community/actions/actions.class.php b/apps/mobile_frontend/modules/community/actions/actions.class.php index 3b4624c..5fb35d0 100644 --- a/apps/mobile_frontend/modules/community/actions/actions.class.php +++ b/apps/mobile_frontend/modules/community/actions/actions.class.php @@ -140,15 +140,4 @@ class communityActions extends opCommunityAction $this->redirect('community/configImage?id='.$this->id); } } - /** - * Executes edit action - * - * @param sfRequest $request A request object - */ - public function executeEdit(opWebRequest $request) - { - $this->unusedFileForm = true; - - return parent::executeEdit($request); - } } diff --git a/lib/action/opCommunityAction.class.php b/lib/action/opCommunityAction.class.php index 8085a77..9a33c86 100644 --- a/lib/action/opCommunityAction.class.php +++ b/lib/action/opCommunityAction.class.php @@ -91,34 +91,49 @@ abstract class opCommunityAction extends sfActions $this->communityForm = new CommunityForm($this->community); $this->communityConfigForm = new CommunityConfigForm(array(), array('community' => $this->community)); - if (!$this->unusedFileForm){$this->communityFileForm = new CommunityFileForm(array(), array('community' => $this->community));} - - if ($request->isMethod('post')) + $this->communityFileForm = null; + if (!sfConfig::get('app_is_mobile', false)) { - $params = $request->getParameter('community'); - $params['id'] = $this->id; - $this->communityForm->bind($params); - $this->communityConfigForm->bind($request->getParameter('community_config')); - if($this->communityFileForm) - { - $this->communityFileForm->bind($request->getParameter('community_file'), $request->getFiles('community_file')); - if ($this->communityForm->isValid() && $this->communityConfigForm->isValid() && $this->communityFileForm->isValid()) - { - $this->communityForm->save(); - $this->communityConfigForm->save(); - $this->communityFileForm->save(); + $this->communityFileForm = new CommunityFileForm(array(), array('community' => $this->community)); + } - $this->redirect('@community_home?id='.$this->community->getId()); - } - } - elseif ($this->communityForm->isValid() && $this->communityConfigForm->isValid()) - { - $this->communityForm->save(); - $this->communityConfigForm->save(); + if ($request->isMethod(sfRequest::POST) && $this->processForms($this->communityForm, $this->communityConfigForm, $this->communityFileForm)) + { + $this->redirect('@community_home?id='.$this->community->getId()); + } + } - $this->redirect('@community_home?id='.$this->community->getId()); + protected function processForms(CommunityForm $communityForm, CommunityConfigForm $communityConfigForm, CommunityFileForm $communityFileForm = null) + { + $request = $this->getRequest(); + $forms = array($communityForm, $communityConfigForm); + if ($communityFileForm) + { + $forms[] = $communityFileForm; + } + + $okCount = 0; + foreach ($forms as $form) + { + $name = $form->getName(); + $form->bind($request->getParameter($name), $request->getFiles($name)); + if ($form->isValid()) + { + $okCount++; } } + + if ($okCount !== count($forms)) + { + return false; + } + + foreach ($forms as $form) + { + $form->save(); + } + + return true; } /**