/** * Create an event * @return void */ private function createEvent() { // if post data is set, we are creating an event if (isset($_POST) && count($_POST) > 0) { require_once FRAMEWORK_PATH . 'models/event.php'; $event = new Event($this->registry, 0); $event->setName($this->registry->getObject('db')->sanitizeData($_POST['name'])); $event->setDescription($this->registry->getObject('db')->sanitizeData($_POST['description'])); $event->setDate($this->registry->getObject('db')->sanitizeData($_POST['date']), false); $event->setStartTime($this->registry->getObject('db')->sanitizeData($_POST['start_time'])); $event->setEndTime($this->registry->getObject('db')->sanitizeData($_POST['end_time'])); $event->setCreator($this->registry->getObject('authenticate')->getUser()->getID()); $event->setType($this->registry->getObject('db')->sanitizeData($_POST['type'])); if (isset($_POST['invitees']) && is_array($_POST['invitees']) && count($_POST['invitees']) > 0) { // assumes invitees are added to a table using javascript, with a hidden field with name invitees[] for the ID of invitee $is = array(); foreach ($_POST['invitees'] as $i) { $is[] = intval($i); } $event->setInvitees($is); } $event->save(); $this->registry->redirectUser($this->registry->buildURL(array('event', 'view', $event->getID()), '', false), 'Event created', 'Thanks, the event has been created', false); } else { $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/create.tpl.php', 'footer.tpl.php'); } }
public static function generate($array) { $event = new Event(); $event->setType($array["type"]); $event->setParentClass(get_class($array["parent"])); $event->setParentId($array["parent"]->getId()); //$event->setParentName($array["parent_name"]); switch ($array["type"]) { case "Inventory": $parent = $event->getParent(); //create stockentry if (get_class($parent) == "Invoicedetail") { $stockentry = StockTable::createStockOut(SettingsTable::fetch("default_warehouse_id"), $parent->getProductId(), $parent->getQty(), $parent->getInvoice()->getDate(), $parent); } else { if (get_class($parent) == "Purchasedetail") { $stockentry = StockTable::createStockIn(SettingsTable::fetch("default_warehouse_id"), $parent->getProductId(), $parent->getQty(), $parent->getPurchase()->getDate(), $parent); } } $event->setChildClass("Stockentry"); $event->setChildrenId($stockentry->getId()); break; } $event->save(); }
public static function findEvents($entityManager, $date) { error_log("date: " . $date->format('Y-m-d')); $query = $entityManager->createQuery('SELECT count(e) FROM Event e WHERE e.date LIKE :date'); $query->setParameter("date", "%" . $date->format('m-d')); $eventNumber = $query->getSingleScalarResult(); if ($eventNumber) { error_log("events for " . $date->format('Y-m-d') . " already exist."); return "1"; } $dim = new \ThisDayIn\Music($date->format('j'), $date->format('F')); $evs = $dim->getEvents(); foreach ($evs as $ev) { $date = new \DateTime($ev['date']); if ($ev['type'] === 'Death') { $ev['description'] = sprintf('%s, %s', $ev['name'], $ev['description']); } //unlike the death events, the birth events do not include enough information in the description. if ($ev['type'] === 'Birth') { $ev['description'] = sprintf('%s, %s was born', $ev['name'], $ev['description']); } //must find artist name for these kind of events if ($ev['type'] == 'Event') { $artist = self::findEventArtist($ev['description']); $ev['name'] = $artist['name']; if (isset($artist['spotifyId'])) { $ev['spotifyId'] = $artist['spotifyId']; } } #TODO: find artist spotify id for the other event types //set current event $event = new \Event(); $event->setDate($date); $event->setDescription($ev['description']); $event->setType($ev['type']); $event->setSource($dim->getSource()); //connects the event to an artist if ($ev['name']) { $artist = $entityManager->getRepository('Artist')->findBy(array('name' => $ev['name'])); $artist = array_shift($artist); if (!$artist) { $artist = new \Artist(); $artist->setName($ev['name']); if (isset($ev['spotifyId'])) { $artist->setSpotifyId($ev['spotifyId']); } } error_log("artist name: " . $artist->getName()); $event->setArtist($artist); $entityManager->persist($event); $artist->assignToEvent($event); $entityManager->persist($artist); #one must save here so it copes for repeated artist in the event list $entityManager->flush(); } $entityManager->persist($event); } //insert all events to db if (count($evs)) { $entityManager->flush(); } return 0; }