/** * 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 find($id) { $event_query = getEvent($id); $event = new Event(); $event->setId($event_query["id"]); $event->setDate($event_query["date"]); $event->setDescription($event_query["description"]); $event->setName($event_query["name"]); $event->setPublic($event_query["public"]); $event->setOwner($event_query["owner"]); $event->setImagePath($event_query["imagePath"]); return $event; }
protected function processForm(sfWebRequest $request, sfForm $form) { //var_dump($request->getParameter('event[start_time]')); $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { //$event = $form->save(); $name = $form->getValue('name'); $venue = $form->getValue('venue'); $description = $form->getValue('description'); $price = $form->getValue('price'); $c_ids = $form->getValue('category_ids'); $event_url = $form->getValue('event_url'); $start_time = $form->getValue('start_time'); $end_time = $form->getValue('end_time'); $date = $form->getValue('date'); $o_id = $form->getValue('organizer_id'); $event = null; if (!$form->getObject()->isNew()) { $event = $form->getObject(); //Delete previous relations to genres Doctrine_Core::getTable('EventCategory')->createQuery()->delete()->where('event_id = ?', $event->getId())->execute(); } else { $event = new Event(); } if ($event === null) { $event = new Event(); } //$event = new Event(); //$event->setCategoryId($c_id); $event->setName($name); $event->setDescription($description); $event->setPrice($price); $event->setVenue($venue); $event->setEventUrl($event_url); $event->setStartTime($start_time); $event->setEndTime($end_time); $event->setOrganizerId($o_id); $sql_date = date("Y-m-d", strtotime($date)); $event->setDate($sql_date); $event->save(); foreach ($c_ids as $cid) { $ec = new EventCategory(); $ec->setEventId($event->getId()); $ec->setCategoryId($cid); $ec->save(); } $this->getUser()->setAttribute('m', 1); $this->redirect('organize/edit?id=' . $event->getId() . '&m=1'); } }
function find($criteria = null, $order = null, $limit = 1000, $from = 0) { $result = $this->database->query($this->buildFindQuery($criteria, $order, $limit, $from)); if (!is_null($result->getError())) { return $result->getError(); } $events = array(); while ($row = $result->fetchRow()) { $event = new Event(); $value = $row[0]; $event->setId($value); $value = $row[1]; $event->setPid($value); $value = $row[2]; $event->setCid($value); $value = $row[3]; $event->setSid($value); $value = $row[4]; $event->setValid_date($value); $value = $row[5]; $event->setReminde_date($value); $value = $row[6]; $event->setAmount($value); $value = $row[7]; $event->setState($value); $value = $row[8]; $event->setMoved($value); $value = $row[9]; $value = $this->database->toBoolean($value); $event->setDelay($value); $value = $row[10]; $event->setDelays($value); $value = $row[11]; $event->setComment($value); $value = $row[12]; $event->setIncome($value); $value = $row[13]; $event->setCost($value); $value = $row[14]; $event->setProfit($value); $value = $row[15]; $event->setWasted_time($value); $value = $row[16]; $event->setR_date($value); $value = $row[17]; $event->setDate($value); if ($order != null) { array_push($events, $event); } else { $events[$event->getId()] = $event; } } return $events; }
function saveFirsEvent($client, $getResponse) { $projectID = $client->getPid(); $clientID = $client->getId(); $stage = $this->getStageID($projectID, 1, $getResponse); if (!$stage) { return false; } $stageID = $stage->getID(); $event = new Event(); $event->setPid($projectID); $event->setCid($clientID); $event->setSid($stageID); $event->setState(0); $event->setR_date(Date::getCurrentDatr()); $event->setDate(Date::getCurrentDatr()); $store = $this->storeEvent($event, $getResponse); if (!$store) { return false; } return true; }
function saveFirsEvent($client) { $projectID = $client->getPid(); $clientID = $client->getId(); $stage = $this->getStageID($projectID, 1); if (!$stage) { return false; } $stageID = $stage->getID(); $event = new Event(); $validDate = $this->countEventTime($stage->getPeriod_type(), $stage->getPeriod()); $event->setPid($projectID); $event->setCid($clientID); $event->setSid($stageID); $event->setState(1); $event->setValid_date($validDate["validateDate"]); $event->setReminde_date($validDate["remindeDate"]); $event->setR_date(Date::getCurrentDatr()); $event->setDate(Date::getCurrentDatr()); $store = $this->storeEvent($event, false, false); if (!$store) { return false; } return true; }
if (isset($_POST["end_time"])) { $end_time = htmlspecialchars($_POST["end_time"]); } if (isset($_POST["location"])) { $location = htmlspecialchars($_POST["location"]); } if (isset($_POST["description"])) { $description = htmlspecialchars($_POST["description"]); } if (isset($_POST["max_attendance"])) { $max_attendance = htmlspecialchars($_POST["max_attendance"]); } // set up event object $event = new Event(); $event->setTitle($title); $event->setDate($date); $event->setStartTime($start_time); $event->setEndTime($end_time); $event->setLocation($location); $event->setDescription($description); $event->setMaxAttendance($max_attendance); $event->setCreatorUserId($_SESSION['uid']); $failure_messages = array(); if (!$event->validate()) { foreach ($event->getValidationFailures() as $failure) { $message = '<p><strong>Error in ' . $failure->getPropertyPath() . ' field!</strong> ' . $failure->getMessage() . '</p>'; array_push($failure_messages, $message); // clear out the bad data $_POST[$failure->getPropertyPath()] = ''; } unset($message);
/** * Install a consumable to a printer */ public function installTo($printer) { global $db; #printf('Installing consumable %s to printer %s.', $this->getName(), $printer->getName()); #fCore::dump($printer); // Validation checks // 1. Check printer model is compatible $models = $this->getModels(); if (!in_array($printer->getModelId(), $models)) { $this->err = sprintf('Consumable %s not compatible with printer %s.', $this->getName(), $printer->getName()); return FALSE; } // 2. Check quantity if ($this->getQty() < 1) { $this->err = sprintf('No stock of the consumable %s.', $this->getName()); return FALSE; } // Finished validation // Add 'event' try { $e = new Event(); $e->setPrinterId($printer->getId()); $e->setConsumableId($this->getId()); $e->setDate(date('Y-m-d H:i:s')); $e->setCost($this->getCost()); $e->store(); } catch (fExpectedException $e) { #fMessaging::create('error', fURL::get(), $e->getMessage()); $this->err = $e->getMessage(); return FALSE; } catch (fSQLException $e) { #fMessaging::create('error', fURL::get(), 'Database error: ' . $e->getMessage()); $this->err = $e->getMessage(); return FALSE; } // Decrease stock try { $sql = 'UPDATE consumables SET qty = qty - 1 WHERE id = %i LIMIT 1'; $query = $db->execute($sql, $this->getId()); } catch (fSQLException $e) { $this->err = $e->getMessage(); return FALSE; } // Return true #echo 'Done!'; return TRUE; }
/** * Run method with main page logic * * Populate template and display form for creating a new event entry. Regular users are allowed to create events but an * admin must approve them before they are visible on the site. Trusted users are allowed to create * events that will immediately be visible on the event calendar. For POST request, * validate form data and save information to database. Available to members only * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); //if (!$user || !$user->isAdmin ()) { if (!$user || !$user->validUser()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $form_errors = array(); $form_values = array("title" => "", "description" => "", "sanctioned" => "", "status" => "", "date" => "", "platform" => ""); $eventDAO = EventDAO::getInstance(); //$event_array = $eventDAO->all (); if (!empty($_POST)) { $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : ""; $form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : ""; $form_values["platform"] = isset($_POST["platform"]) ? trim($_POST["platform"]) : ""; $form_values["sanctioned"] = isset($_POST["sanctioned"]) ? trim($_POST["sanctioned"]) : ""; $form_values["status"] = isset($_POST["status"]) ? trim($_POST["status"]) : ""; $form_values["date"] = isset($_POST["date"]) ? trim($_POST["date"]) : ""; if (empty($form_values["title"])) { $form_errors["title"] = "No title specified"; } if (empty($form_values["description"])) { $form_errors["description"] = "No description specified"; } if (empty($form_values["platform"])) { $form_errors["platform"] = "No platform specified"; } else { if (!is_numeric($form_values["platform"])) { $form_errors["platform"] = "Platform choice must be an integer value"; } else { $platform = intval($form_values["platform"]); $tmp = new Event(); try { $tmp->setPlatformId($platform); } catch (Exception $e) { $form_errors["platform"] = "Invalid value for platform"; } } } if ($user->isAdmin() && empty($form_values["sanctioned"])) { $form_errors["sanctioned"] = "No sanctioned flag specified"; } else { if ($user->isAdmin() && strcmp($form_values["sanctioned"], "true") != 0 && strcmp($form_values["sanctioned"], "false") != 0) { $form_errors["sanctioned"] = "sanctioned flag must be a boolean value"; } } if ($user->isAdmin() && empty($form_values["status"])) { $form_errors["status"] = "No status flag specified"; } else { if ($user->isAdmin() && !is_numeric($form_values["status"])) { $form_errors["status"] = "Status flag must be an integer value"; } else { if ($user->isAdmin()) { $status = intval($form_values["status"]); $tmp = new Event(); try { $tmp->setStatus($status); } catch (Exception $e) { $form_errors["status"] = "Invalid value for status"; } } } } if (empty($form_values["date"])) { $form_errors["date"] = "No date specified"; } else { if (strtotime($_POST["date"]) == 0) { $form_errors["date"] = "An invalid date was specified"; $form_values["date"] = ""; } } if (empty($form_errors)) { $event = new Event(); $event->setTitle($form_values["title"]); $event->setDescription($form_values["description"]); $event->setPlatformId(intval($form_values["platform"])); if ($user->isAdmin() || $user->validUser() && $user->getUserType() == User::TRUSTED_TYPE) { $sanctioned_value = strcmp($form_values["sanctioned"], "true") == 0 ? true : false; $event->setSanctioned($sanctioned_value); $event->setStatus($form_values["status"]); } else { if ($user->validUser()) { $event->setSanctioned(false); $event->setStatus(Event::PENDING_STATUS); } } $pubtimestamp = strtotime($_POST["date"]); $event->setDate($pubtimestamp); $event->setUserId($user->id); //print_r ($event); if ($eventDAO->insert($event)) { $session->setMessage("Event details saved"); header("Location: edit_event.php?id={$event->id}"); return; } else { $session->setMessage("Event details could not be saved", Session::MESSAGE_ERROR); } } } $platformDAO = PlatformDAO::getInstance(); $platform_array = $platformDAO->all(); $this->template->render(array("title" => "Create Event", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "create_event_tpl.php", "session" => $session, "form_errors" => $form_errors, "form_values" => $form_values, "platform_array" => $platform_array)); }
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; }