public function buildCourts() { $items = \Own\Bus\Court\Data::loadAll(); $courts = \Own\Bus\MembershipCourt\Data::loadAllByMembershipId($this->getModel()->getId()); $selectedValues = []; foreach ($courts as $court) { $selectedValues[] = $court->getCourtId(); } return Util\Form::buildCheckboxList('court' . $this->unique, $items, 'id', 'title', $selectedValues); }
public function membership() { Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/'); $this->setTpl(); $membershipId = Util\Converter::toInt('id'); if (!isset($membershipId)) { Util\Session::adminError('item.not.found', [Util\Lang::lang('membership'), $membershipId], '/own/memberships'); } $membership = \Own\Bus\Membership\Data::loadById($membershipId, true); $membershipForm = new \Own\Bus\Membership\Form($membership); // action $save = Util\Converter::toString('save', 'post'); $courtIds = Util\Converter::toArray('court', 'post'); if (isset($save)) { if ($membershipForm->setFromPost()->validate()->isValid()) { \Own\Bus\MembershipCourt\Data::deleteByMembershipId($membership->getId()); $newCourts = []; if (isset($courtIds)) { foreach ($courtIds as $courtId) { $membershipCourt = new \Own\Bus\MembershipCourt\Model(); $membershipCourt->setMembershipId($membership->getId()); $membershipCourt->setCourtId($courtId); $newCourts[] = $membershipCourt; } } \Own\Bus\MembershipCourt\Data::saveAll($newCourts); $membership->save(); Util\Session::adminSuccess('saved', '/own/memberships'); } else { Util\Session::set('adminError', $membershipForm->getValidation()->getMessage()); } } $tplEditor = new Util\Template(Util\Template::SITE, ['admin']); $tplEditor->set('item', $membershipForm); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => $tplEditor->render('membership-editor')]); }