Example #1
0
         if (!empty($body['user-id-list'])) {
             $list = explode(',', $body['user-id-list']);
             foreach ($list as $userId) {
                 if (empty($userId)) {
                     continue;
                 }
                 // Add records linking the users to the sponsor
                 $sponsorUser = new \Conftrack\Model\SponsorUser($container->get('db'));
                 $sponsorUser->load(['sponsor_id' => $sponsor->id, 'user_id' => $userId]);
                 $sponsorUser->save();
             }
         }
         $message = 'Sponsor created successfully!';
         $data['success'] = true;
     } catch (\Exception $e) {
         $message = "Error: " . implode("\n", $sponsor->getMessages());
     }
     $type = $data['success'] == false ? 'danger' : 'success';
     $this->flash->addMessage($type, $message);
     $this->view->render($response, 'sponsor/create.twig', $data);
 });
 $app->get('/edit/{sponsorId}', function ($request, $response, $args) {
     $sponsor = new \Conftrack\Model\Sponsor($this->getContainer()->get('db'));
     $sponsor->findById($args['sponsorId']);
     $users = new \Conftrack\Collection\Users($this->getContainer()->get('db'));
     $users->findAll();
     $data = ['sponsor' => $sponsor->toArray(), 'sponsorUsers' => $sponsor->users->toArray(true), 'action' => 'edit', 'users' => $users->toArray(true)];
     $this->view->render($response, 'sponsor/create.twig', $data);
 });
 $app->get('/image/{sponsorId}', function ($request, $response, $args) {
 });