Ejemplo n.º 1
0
 /**
  * Adds the new book-assignments to the given entity
  * @param int    $bookId       The book-id of the book to assign
  * @param string $type         The type of the entity to assign the books
  *                             to
  * @param int    $id           The identifier of the entity
  * @param int    $schoolyearId The schoolyear-id of the entities and
  *                             assignments
  */
 protected function assignmentsToEntityAdd($bookId, $type, $id, $schoolyearId)
 {
     $book = $this->_em->getReference('DM:SchbasBook', $bookId);
     $schoolyear = $this->_em->getReference('DM:SystemSchoolyears', $schoolyearId);
     try {
         $users = $this->usersGetByEntity($type, $id, $schoolyear);
         if ($users) {
             $addedCount = 0;
             $jumpedCount = 0;
             foreach ($users as $user) {
                 $existingAssignments = $user->getBooksToLend();
                 foreach ($existingAssignments as $assignment) {
                     $existingBook = $assignment->getBook();
                     if ($existingBook == $book) {
                         $jumpedCount++;
                         continue 2;
                     }
                 }
                 $entry = new \Babesk\ORM\SchbasUserShouldLendBook();
                 $entry->setUser($user);
                 $entry->setBook($book);
                 $entry->setSchoolyear($schoolyear);
                 $this->_em->persist($entry);
                 $addedCount++;
             }
             $this->_em->flush();
             $usercount = count($users);
             die("Die Zuweisungen wurden erfolgreich hinzugefügt.<br>" . "<b>{$addedCount}</b> wurden hinzugefügt,<br>" . "<b>{$jumpedCount}</b> wurden übersprungen");
         } else {
             dieHttp('Konnte die Benutzer zum Hinzufügen nicht abrufen', 500);
         }
     } catch (\Exception $e) {
         $this->_logger->logO('Could not add the assignments', ['sev' => 'error', 'moreJson' => ['bookId' => $bookId, 'entityType' => $type, 'entityId' => $id, 'schoolyearId' => $schoolyearId, 'msg' => $e->getMessage()]]);
         dieHttp('Ein Fehler ist beim Hinzufügen der Zuweisungen ' . 'aufgetreten', 500);
     }
 }
Ejemplo n.º 2
0
 protected function entryAdd($user, $book)
 {
     $entry = new \Babesk\ORM\SchbasUserShouldLendBook();
     $entry->setUser($user);
     $entry->setBook($book);
     $entry->setSchoolyear($this->_schoolyear);
     $this->_em->persist($entry);
 }