X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Ffunctions.php;h=985c02b83574a9a620d1a51b932136e0164cb7e9;hb=8608b888fb708fadeb23ae113ad83516cc5e4176;hp=eda41532a2b7d1a9647200578dd72b751fbee83f;hpb=f632680f1afa481ad11b7d9b8e6fae18761b0f23;p=readifood.git diff --git a/lib/functions.php b/lib/functions.php index eda4153..985c02b 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -252,6 +252,27 @@ return $q->orderByDate()->find(); } + function get_available_offers($contact = null) { + $q = new OfferQuery; + $q->where("(valid_from is null or valid_from<=now())"); + $q->where("(valid_to is null or valid_to>now())"); + if (! is_null($contact)) { + $qq = new OfferStateQuery; + $qq->filterByContactId($contact->getId()); + $ids = Array(); + foreach ($qq->find() as $state) $ids[] = $state->getOfferId(); + if (count($ids)) $q->_or()->filterById($ids); + } + return $q->orderById()->find(); + } + + function get_offer_state($contact, $offer) { + $q = new OfferStateQuery; + $q->filterByOfferId($offer->getId()); + $q->filterByContactId($contact->getId()); + return $q->orderByUpdated('desc')->findOne(); + } + function get_user_by_contact_id($id, $verbose = true) { $q = new UserQuery; $user = $q->findOneByContactId($id);