Exemple #1
0
 function get()
 {
     $this->setAddlCond();
     //if (!$this->cond) $this->setForms();
     $graph = array($this);
     $tracked = array();
     $nestingRef = array("brand_" => array("@id" => "{$this->root}/brand/{id}/about", "@type" => "brand"));
     $sql = "SELECT promo_id, \n\t\t\t\tp.brand_id AS brand_id, \n\t\t\t\tbrands.name AS brand_name, \n\t\t\t\tp.name AS name, \n\t\t\t\tp.description AS description, \n\t\t\t\tamount, \n\t\t\t\timageURL, \n\t\t\t\tinfoURL, \n\t\t\t\tp.created, \n\t\t\t\tp.updated, \n\t\t\t\tp.expires, \n\t\t\t\tkeyword,\n\t\t\t\tby_all_limit, \n\t\t\t\tby_brand_limit, \n\t\t\t\tby_user_limit, \n\t\t\t\tby_user_wait,\n\t\t\t\tnumUsers\n\t\t\tFROM promos p\n\t\t\tJOIN (\n\t\t\t\tSELECT promo_id, COUNT(DISTINCT from_user) as numUsers\n\t\t\t\tFROM records\n\t\t\t\twhere status=7 AND TIMESTAMPDIFF(DAY,created,NOW())<100\n\t\t\t\tGROUP BY promo_id\n\t\t\t\tORDER BY numUsers DESC\n\t\t\t) records USING (promo_id)\n\t\t\tJOIN relays USING (relay_id)\n\t\t\tJOIN brands USING (brand_id)\n\t\t\tWHERE promo_id {$this->ltgt} {$this->limitID} {$this->cond}\n\t\t\t\tAND (expires IS NULL OR expires>NOW())\n\t\t\t\tAND by_user_limit > 0 AND by_brand_limit > 0 AND by_all_limit > 0\n\t\t\tORDER BY promo_id {$this->pageOrder}\n\t\t\tLIMIT {$this->itemsLimit}";
     $items = DBquery::get($sql, $this->condVals);
     Requester::detectMemberships();
     foreach ($items as &$r) {
         $r['id'] = $r['promo_id'];
         $r['@id'] = "{$this->root}/promo/" . $r['promo_id'];
         $r['@type'] = 'promo';
         if (Requester::isMember($r['brand_id'])) {
             $r['edit'] = '/form/promo-edit';
         }
         $this->nestResources($r, $nestingRef, $graph, $tracked);
         $r['promoPage'] = Requester::$ProtDomain . "/ad/{$r['promo_id']}";
         $r['code'] = "{$r['keyword']}-{$r['promo_id']}";
         $r['payURL'] = Requester::$ProtDomain . "/for/{$r['code']}";
         $r['amount'] = round($r['amount'], 2);
         if (!$r['imageURL']) {
             //$r['imageURL'] = "/ui/logo.php?brand=". $r['brand_name'];
             //$images[] = BrandLogo::wrap($r['brand_name'], $r['imageURL'], 'base64svg');
             //$r['imageURL'] = BrandLogo::base64svg($r['brand_name'], $r['imageURL']);
             //$r['imageURL'] = BrandLogo::dataURL($r['brand_name']);
             $r['imageTemplate'] = "/ui/logo.php";
         }
         if (!$r['expires']) {
             $r['expires'] = "2019-12-31 11:59:59";
         }
         $this->{$this->collectionOf}[] = $r['@id'];
         $p[] = $r;
         $graph[] = $r;
     }
     $this->setPageOf(array("brand_id", "for", "keyword", "id"));
     $this->paginate('promo_id', $p);
     if ($this->cond) {
         return $graph;
     }
     return array_merge($graph, array(BrandLogo::svgTemplate()));
 }