function getCouponPerUserEvent($zhaohu_guid, $user_guid) { $options = array('event_guid' => $zhaohu_guid, 'user_guid' => $user_guid, 'offset' => 0, 'limit' => 0); $res = zh_find_coupons($options); if ($res['count'] != 1) { register_error(elgg_echo("coupon:notfound") . elgg_echo("zhaohu:sorry")); elgg_log("ZHError ,sendCoupon, cannot find coupon, zhaohu_guid {$zhaohu_guid}, user_guid {$user_guid}", "ERROR"); return null; } return $res['entities']['0']; }
<?php // this is for letting a user view coupons in his/her profile // Only logged in users gatekeeper(); elgg_set_context('profile_edit'); $title = elgg_echo('coupon:user:title'); $entity = elgg_get_page_owner_entity(); if (!elgg_instanceof($entity, 'user') || !$entity->canEdit()) { register_error(elgg_echo('coupon:nopermission')); forward(REFERER); } $content = '<div class="zhaohu-profile">'; // render owner block $content .= elgg_view('profile/owner_block'); $content .= '<div id="zhaohu_profile_picture_edit">'; $options = array('user_guid' => $entity->guid, 'offset' => 0, 'limit' => ZHAOHU_MANAGER_SEARCH_LIST_LIMIT); $res = zh_find_coupons($options); $entities = $res["entities"]; $count = $res["count"]; if ($count) { $content .= elgg_view("coupons/view", array("entities" => $entities, "count" => $count, "isUserProfile" => true)); } else { $content .= elgg_echo('coupon:noresults'); } $content .= '</div></div>'; $params = array('content' => $content); $body = elgg_view_layout('one_column', $params); echo elgg_view_page($title, $body);
private static function try_get_coupon_by_code($code) { $options = array('count_only' => true, 'code' => $code, 'offset' => 0, 'limit' => 0); $res = zh_find_coupons($options); return $res['count'] > 0; }