예제 #1
0
 public function executeEditPair(sfWebRequest $request)
 {
     $route_params = $this->getRoute()->getParameters();
     if (isset($route_params['new'])) {
         $mapping = MappingTable::getInstance()->find($request->getParameter('id'));
         if (!$mapping) {
             return $this->notFound();
         }
         $pair = new MappingPair();
         $pair->setMapping($mapping);
     } else {
         $pair = MappingPairTable::getInstance()->find($request->getParameter('id'));
         if (!$pair) {
             return $this->notFound();
         }
         /* @var $pair MappingPair */
         $mapping = $pair->getMapping();
     }
     $form = new MappingPairForm($pair);
     $was_new = $pair->isNew();
     if ($request->isMethod('post')) {
         $form->bind($request->getPostParameter($form->getName()));
         if ($form->isValid()) {
             $form->save();
             if ($was_new) {
                 return $this->ajax()->remove('#pair_form_new')->appendPartial('#pairs tbody', 'pair_row', array('pair' => $pair))->render();
             } else {
                 return $this->ajax()->remove('#pair_form_' . $pair->getId())->replaceWithPartial('#pair_' . $pair->getId(), 'pair_row', array('pair' => $pair))->render();
             }
         } else {
             return $this->ajax()->form($form)->render();
         }
     }
     if ($was_new) {
         return $this->ajax()->remove('#pair_form_new')->appendPartial('#pairs tbody', 'pair_form', array('pair' => $pair, 'form' => $form))->render();
     } else {
         return $this->ajax()->remove('#pair_form_' . $pair->getId())->afterPartial('#pair_' . $pair->getId(), 'pair_form', array('pair' => $pair, 'form' => $form))->render();
     }
 }
 public function getMapping()
 {
     $mapping_id = $this->utilGetFieldFromArray('data_json', 'mapping_id', null);
     if ($mapping_id) {
         return MappingTable::getInstance()->findOneById($mapping_id);
     }
     return null;
 }