input->post; $id = $input->getCmd('id', 'new'); $clubid = $input->getInt('clubid'); $positionid = $input->getInt('positionid'); $state = $input->getCmd('state', 'regular'); $admin = $input->getCmd('admin', '0'); $userid = $input->getInt('userid', -1); $address = $input->getString('address'); $mail = $input->getString('mail'); $phone = $input->getString('phone'); $clubFactory = new CommonClubsModelFactoryClub(); $club = $clubFactory->loadById($clubid); $positionFactory = new CommonClubsModelFactoryPosition(); $position = $positionFactory->loadById($positionid); $assocFactory = new CommonClubsModelFactoryUserassoc(); if($id === 'new') { $assoc = $assocFactory->createNew(); } else { $assoc = $assocFactory->loadById((int) $id); } if($userid != -1) { $userFactory = new CommonClubsModelFactoryUser(); $user = $userFactory->loadById($userid); } else { $user = null; } if($state === 'vacant') $user = null; $assoc->setUser($user); $assoc->setState($state); $assoc->setAddress($address === '' ? null : $address); $assoc->setMail($mail === '' ? null : $mail); $assoc->setPhone($phone === '' ? null : $phone); $assoc->setClub($club); $assoc->setAdmin($admin); $assoc->setPosition($position); $assoc->save(); $ret = array('new' => ($id === 'new'), 'id' => $assoc->getId()); echo new JsonResponse($ret, null, false, true); // jexit(); } public function delete() { $app = Factory::getApplication(); $input = $app->input->get; $id = $input->getInt('id'); $factory = new CommonClubsModelFactoryUserassoc(); $ua = $factory->loadById($id); $ua->delete(); $ret = array('id' => $id); echo new JsonResponse($ret, null, false, true); } }