Пример #1
0
    /**
     * Returns a promotion bean for the
     * given scope and id with the following populated values
     * title, next start time as date, id, primary genre as genre, 
     * summary, gallery id as image and schedule note 
     * 
     * @param String scope
     * @param int oid of the event
     * @return Promotion bean
     */
    function getPromotion($scope, $id)
    {
        global $logger;
        $logger->debug(get_class($this) . "::getPromotion({$scope}, {$id})");
        $db =& JFactory::getDBO();
        // Program or Exhibition differences
        if ($scope == 'Program') {
            $query = 'SELECT distinct e.eoid as id, "Program" as scope, e.title,' . '	e.gallery as image, e.summary, e.scheduleNote,' . '	s.startTime as start, s.endTime as end ' . '	FROM Program as e, Schedule as s, _ez_relation_ as r' . '	WHERE s.eoid = r.oid_b ' . '		AND r.class_b = "Schedule"' . '		AND r.oid_a IN ( ' . '			SELECT distinct r1.oid_b ' . '			FROM _ez_relation_ as r1 ' . '			WHERE oid_a = ' . $id . '				AND class_a="Program"' . '				AND class_b="Performance"' . '		) AND e.eoid =' . $id . '	ORDER BY s.startTime';
        } else {
            $query = 'SELECT distinct	e.eoid as id, "Exhibition" as scope, e.title, ' . '	e.gallery as image, e.summary, e.scheduleNote, ' . '	s.startTime as start, s.endTime as end ' . ' FROM Exhibition as e, Schedule as s, _ez_relation_ as r' . ' WHERE s.eoid = r.oid_b ' . '	AND r.class_b = "Schedule"' . '	AND r.class_a = "Exhibition"' . '	AND r.oid_a = e.eoid' . '	AND e.eoid = ' . $id . ' ORDER BY s.startTime';
        }
        $db->setQuery($query);
        $rows = $db->loadAssocList();
        $promo = new Promotion($rows[0]);
        // get the promotion date
        // in Programs it is the next performance (or the most recent if no next)
        // in Exhibitions it is the start date if future or end date if start date past
        $date = null;
        foreach ($rows as $row) {
            if ($scope == "Exhibition") {
                $date = $row['end'];
                if ($row['start'] > time()) {
                    $date = $row['start'];
                }
            } else {
                $date = $row['start'];
                if ($date > time()) {
                    break;
                }
            }
        }
        $promo->setDate($date);
        // now get the primary genre information
        $query = 'SELECT DISTINCT c.eoid as oid, c.name 
			FROM Category as c, _ez_relation_ as r
			WHERE c.eoid = r.oid_b
			AND r.var_a = "primaryGenre"
			AND r.oid_a = ' . $promo->getId();
        $db->setQuery($query);
        $pg = new Genre($db->loadAssoc());
        $promo->setPrimaryGenre($pg);
        return $promo;
    }