Exemple #1
0
 /**
  * A sample detail bean for use in rendering the template.
  * If a course is supplied, it will copy thevalues of the
  * given bean over the top of the demo bean.
  * @return
  */
 private function getDemoCourseDetail($crse)
 {
     require_once WEB_INF . '/beans/Performance.php';
     require_once WEB_INF . '/beans/Schedule.php';
     require_once WEB_INF . '/beans/Venue.php';
     global $logger;
     $logger->debug(get_class($this) . "::getDemoCourseDetail({$crse})");
     $bean = new Course();
     $bean->setTitle("Demo Course Detail Bean");
     $desc = "<p>This is a description of the course. Malian Grammy Award nominee Mamadou Diabate is a virtuoso kora player descended from a long line of Manding musician-storytellers. Dolor dignissim exerci feugiat. Lobortis ut, luptatum facilisis. Augue volutpat facilisis at, eum consequat adipiscing accumsan blandit molestie. </p>\n\t\t\t\t <p>Lobortis eros at hendrerit luptatum consequat feugiat ut facilisi commodo esse autem consequat at ex ullamcorper hendrerit wisi, commodo nostrud nisl wisi eum autem eu esse eu iriure. Tation, magna ad nibh at eum, ea praesent eum lorem eu erat enim commodo dolore?</p>\n \t\t\t\t <p>Crisare enim sed ex eros hendrerit blandit illum qui sciurus autem nulla enim luptatum. Quis enim eum feugait elit blandit, hendrerit consequat, velit ut luptatum nostrud wisi ea. Dignissim consequat dolore aliquam eum volutpat, wisi dolore et exerci nisl veniam luptatum ut ullamcorper consequatvel nulla delenit.</p>\n\t\t\t\t";
     $bean->setDescription($desc);
     $bean->setPrimaryGenre("Music");
     // Performances
     $perf = new Performance();
     $schd = new Schedule();
     $schd->setStartTime(time());
     $perf->setSchedule($schd);
     $logger->debug("Performance time: " . $perf->getSchedule()->getStartTime());
     $perf->setTicketCode("21");
     $bean->setChildren(array($perf));
     $logger->debug("Number of set performaces: " . count($bean->getChildren()));
     // Venues
     $v1 = new Venue();
     $v1->setName('Hurd Gallery');
     $bean->setDefaultVenue($v1);
     if (get_class($crse) == 'Course') {
         $crse->setPerformances(null);
         $option = new CopyBeanOption();
         $option->setIgnoreNullValues(true);
         BeanUtil::copyBean($crse, $bean, $option);
     }
     return $bean;
 }
Exemple #2
0
 /**
  * Converts the incoming exhibition bean object to PDO instances.
  * This includes the conversion from nested list of
  * linked elements stored as arrays of oids to their
  * PDO instances.
  *
  * @access private
  * @param bean $bean an Exhibition bean
  * @param bean $copyOption an optional CopyOptionBean (for ignore null values)
  */
 private function exhibitionBeanToPdo($bean, $copyOption = null)
 {
     global $logger;
     $logger->debug(get_class($this) . "::exhibitionBeanToPdo({$bean},{$copyOption})");
     if (get_class($bean) != 'Exhibition') {
         trigger_error("Incoming object is not a valid Event", E_USER_ERROR);
         return;
     }
     if ($copyOption == null) {
         $copyOption = new CopyBeanOption();
         $copyOption->setScalarsOnly(true);
     }
     // Check to see if there is a event OID
     if ($bean->getOid() > 0) {
         $pdo = $this->fetchEventById('Exhibition', $bean->getOid());
     } else {
         // Get a new event PDO
         $epm = epManager::instance();
         $pdo = $epm->create('Exhibition');
     }
     // Copy the bean values over the top of the PDO values
     BeanUtil::copyBean($bean, $pdo, $copyOption);
     // schedule pdo
     $schedule = $this->fetchSchedule($bean->getSchedule(), 'Exhibition');
     //print_r($schedule);
     //print_r($bean->getSchedule());
     $bean->getSchedule()->setScope('Exhibition');
     BeanUtil::copyBean($bean->getSchedule(), $schedule, $copyOption);
     //print_r($schedule);
     $pdo->setSchedule($schedule);
     //print_r($pdo->getSchedule());
     // pubState from string to pdo
     $pubState = $this->fetchPubState($bean->getPubState());
     $pdo->setPubState($pubState);
     // eventStatus from string to pdo
     $eventStatus = $this->fetchEventStatus($bean->getEventStatus());
     $pdo->setEventStatus($eventStatus);
     // venues from array of oids to array of pdos
     $venues = $bean->getVenues();
     if ($venues != null) {
         $vpdos = array();
         foreach ($venues as $venue) {
             if ($venue->getOid() == 0) {
                 continue;
             }
             $vpdos[] = $this->fetchVenueById($venue->getOid());
         }
         $pdo->getVenues()->removeAll();
         $pdo->setVenues($vpdos);
     }
     // categories from keyed array of oids to array of pdos
     $cats = $bean->getCategories();
     if ($cats != null) {
         $cpdos = array();
         foreach ($cats as $key => $value) {
             foreach ($value as $cat) {
                 if ($cat->getOid() == 0) {
                     continue;
                 }
                 $cpdos[] = $this->fetchCategoryById(ucfirst($key), $cat->getOid());
             }
         }
         $pdo->getCategories()->removeAll();
         $pdo->setCategories($cpdos);
     }
     // related programs from keyed array of oids to array of pdos
     $programs = $bean->getPrograms();
     if ($programs != null) {
         $epdos = array();
         foreach ($programs as $program) {
             if ($program->getOid() == 0) {
                 continue;
             }
             $epdos[] = $this->fetchEventById('Program', $program->getOid());
         }
         $pdo->getPrograms()->removeAll();
         $pdo->setPrograms($epdos);
     }
     // related courses from keyed array of oids to array of pdos
     $courses = $bean->getCourses();
     if ($courses != null) {
         $epdos = array();
         foreach ($courses as $course) {
             if ($course->getOid() == 0) {
                 continue;
             }
             $epdos[] = $this->fetchEventById('Course', $course->getOid());
         }
         $pdo->getCourses()->removeAll();
         $pdo->setCourses($epdos);
     }
     // related artists
     $artists = $bean->getArtists();
     if ($artists != null) {
         $ps = $this->getPersonService();
         $epdos = array();
         foreach ($artists as $artist) {
             if ($artist->getOid() == 0) {
                 continue;
             }
             $epdos[] = $ps->fetchPersonById('Artist', $artist->getOid());
         }
         $pdo->getArtists()->removeAll();
         $pdo->setArtists($epdos);
     }
     return $pdo;
 }
Exemple #3
0
 /**
  * A convenience method to copy attributes from the PDO
  * to the Bean. Will automatically set the useTargetVars 
  * attribute of the CopyBeanOption.
  * 
  * @access private
  * @param pdo The Venue PDO object (source)
  * @return bean The Venue bean
  */
 private function pdoToBean($pdo)
 {
     global $logger;
     $logger->debug(get_class($this) . "::pdoToBean({$pdo})");
     $copyOption = new CopyBeanOption();
     $copyOption->setUseTargetVars(true);
     $copyOption->setScalarsOnly(true);
     $bean = new Venue();
     $bean = BeanUtil::copyBean($pdo, $bean, $copyOption);
     // Convert the pubState to a string
     $ps = '';
     if ($pdo->getPubState() != null) {
         $ps = $pdo->getPubState()->getValue();
     }
     $bean->setPubState($ps);
     $logger->debug("pubstate: " . $bean->getPubState());
     // Convert the Address to bean
     $addrBean = new Address();
     if ($pdo->getAddress() != null) {
         $addrBean = BeanUtil::copyBean($pdo->getAddress(), $addrBean, $copyOption);
     }
     $bean->setAddress($addrBean);
     $logger->debug("address: " . $bean->getAddress());
     // related events from array of pdos to keyed array of oids
     $events = $pdo->getEvents();
     $logger->debug("events: " . count($events));
     if (!empty($events) && '' != get_class($events[0])) {
         $es = new EventService();
         $related = array();
         foreach ($events as $event) {
             $logger->debug("event: " . $event);
             $related[] = $es->getEventById($event->getScope(), $event->getOid());
         }
         $bean->setEvents($related);
     }
     return $bean;
 }
Exemple #4
0
 /**
  * A convenience method to copy attributes from the PDO
  * to the Bean. Will automatically set the useTargetVars 
  * attribute of the CopyBeanOption.
  * 
  * @access private
  * @param pdo The HomePage PDO object (source)
  * @return bean The HomePage bean
  */
 private function pdoToBean($pdo)
 {
     global $logger;
     $logger->debug(get_class($this) . "::pdoToBean({$pdo})");
     $copyOption = new CopyBeanOption();
     $copyOption->setUseTargetVars(true);
     $copyOption->setScalarsOnly(true);
     $bean = new HomePage();
     $bean = BeanUtil::copyBean($pdo, $bean, $copyOption);
     // Convert the pubState to a string
     $ps = '';
     if ($pdo->getPubState() != null) {
         $ps = $pdo->getPubState()->getValue();
     }
     $bean->setPubState($ps);
     return $bean;
 }
Exemple #5
0
 /**
  * sets the EventStatus to the value set by the incoming
  * request and returns the summary model
  */
 function toggleEventStatus($mainframe)
 {
     global $logger;
     $logger->debug(get_class($this) . '::toggleEventStatus()');
     $status = $this->getFormToggleValue();
     $oids = $this->getFormOids();
     // should be an array of 1
     $service = $this->getEventService();
     $logger->debug("\n\nIncomong oid:" . $oids[0]);
     $event_bean = $service->getEventById('Exhibition', $oids[0]);
     $logger->debug("\n\nEvent Object oid:" . $event_bean->getOid());
     $event_bean->setEventStatus($status);
     $copyOption = new CopyBeanOption();
     $copyOption->setIgnoreNullValues(true);
     $service->updateEvent('Exhibition', $event_bean, $copyOption);
     // return the summaries
     return $this->setSummaryModel($mainframe);
 }
Exemple #6
0
 /**
  * Copy the values of the attribute from another object.  Will by defaule
  * copy all values from source to target.  An optional CopyBeanOptions bean
  * may be passed in to flag additional functionality.
  *
  * The copyBean method currently supports the following attributes of the
  * CopyBeanOption object:
  *
  * $strict: Setting the strict parameter to true will cause the method
  *          to throw an exception if a matching target attribute is
  *          not found for a given source.
  *
  * $use_target_vars: By default, the attributes of the source object
  *          $source) will determine the list of attributes to be
  * 			copied. Set the $useTargetVars parameter to true if the
  * 			target object should determine the list of atttributes.
  *
  * $ignore_null_values: By default, all attribute values will be copied from
  * 			the source bean to the target bean, even if the value is null.
  * 			Set the $ignoreNullValues parameter to require the value to be
  * 			non-null (and non-empty string) before copying to the target bean.
  * 			This allows for a bean to be safely updated when only a partial
  * 			source bean is available.
  *
  * @param bean $source
  * @param bean|string $target
  * @param [bean CopyBeanOption]
  * @return $target as a bean
  */
 public static function copyBean($source, $target, $option = null)
 {
     // validate input arguments
     if ($source == null || $target == null) {
         trigger_error("Invalid copy; source and/or target is null", E_USER_ERROR);
         return;
     }
     if (is_string($target)) {
         $result = new $target();
     } else {
         if (is_object($target)) {
             $result = $target;
         } else {
             trigger_error("Invalid copy; target is not an object", E_USER_ERROR);
             return;
         }
     }
     // Set the options
     if ($option == null) {
         $option = new CopyBeanOption();
     } else {
         if (get_class($option) != 'CopyBeanOption') {
             trigger_error("Incoming CopyBeanOption not valid. Using default options.", E_USER_WARNING);
             $option = new CopyBeanOption();
         }
     }
     $source_vars = $option->getUseTargetVars() ? get_class_vars(get_class($result)) : get_class_vars(get_class($source));
     $target_vars = $option->getUseTargetVars() ? get_class_vars(get_class($source)) : get_class_vars(get_class($result));
     // check for strict attribute enforcment
     if ($option->getStrict()) {
         $diff = array_diff_assoc($source_vars, $target_vars);
         if (count($diff) > 0) {
             trigger_error("Invalid copy; {$getter} not found", E_USER_ERROR);
             return;
         }
     }
     // copy over values from input
     foreach ($source_vars as $name => $value) {
         if (is_string($name) && (empty($option->includes) || in_array($name, $option->includes)) && (empty($option->excludes) || !in_array($name, $option->excludes)) && !($name == "false" || $name == "true" || $name == "null" || $name == '')) {
             // build the accessor names
             $getter = 'get' . ucfirst($name);
             if (!method_exists($source, $getter)) {
                 $getter = 'get_' . $name;
                 if (!method_exists($source, $getter) && !method_exists($source, '__call')) {
                     if ($option->getStrict()) {
                         trigger_error("Invalid copy; {$getter} not found", E_USER_ERROR);
                         return;
                     } else {
                         continue;
                     }
                 }
             }
             $setter = 'set' . ucfirst($name);
             if (!method_exists($target, $setter)) {
                 $setter = 'set_' . $name;
                 if (!method_exists($target, $setter) && !method_exists($target, '__call')) {
                     if ($option->getStrict()) {
                         trigger_error("Invalid copy; {$setter} not found", E_USER_ERROR);
                         return;
                     } else {
                         continue;
                     }
                 }
             }
             $value = $source->{$getter}();
             // Add to the target if all conditions are met
             $valid = true;
             if ($option->getIgnoreNullValues() && $value == null) {
                 $valid = false;
             }
             if ($option->getScalarsOnly() && (is_array($value) || is_object($value))) {
                 $valid = false;
             }
             if ($valid) {
                 $target->{$setter}($value);
             }
         }
     }
     return $result;
 }
Exemple #7
0
 /**
  * A convenience method to copy attributes from the PDO
  * to the Bean. Will automatically set the useTargetVars 
  * attribute of the CopyBeanOption.
  * 
  * @access private
  * @param pdo The Venue PDO object (source)
  * @return bean The Venue bean
  */
 private function pdoToBean($pdo)
 {
     global $logger;
     $logger->debug(get_class($this) . "::pdoToBean({$pdo})");
     $copyOption = new CopyBeanOption();
     $copyOption->setUseTargetVars(true);
     $copyOption->setScalarsOnly(true);
     $bean = new $pdo->scope();
     $bean = BeanUtil::copyBean($pdo, $bean, $copyOption);
     // pubState to a string
     $ps = '';
     if ($pdo->getPubState() != null) {
         $ps = $pdo->getPubState()->getValue();
     }
     $bean->setPubState($ps);
     // related events from array of pdos to keyed array of oids
     $events = $pdo->getEvents();
     if (!empty($events)) {
         $es = new EventService();
         $related = array();
         foreach ($events as $event) {
             $related[] = $es->getEventById($event->getScope(), $event->getOid());
         }
         $bean->setEvents($related);
     }
     return $bean;
 }