function get() { $forms = array(); $graph = array($this); $sql = "CALL userAccounts(?)"; $items = DBquery::get($sql, array($this->user_id)); $this->setForms(); $tracked = array(); $nestingRef = array("account_" => array("@id" => "{$this->root}/account/{id}", "@type" => "account", "records" => "{$this->root}/account/{id}/records"), "brand_" => array("@id" => "{$this->root}/team/{id}", "@type" => "brand", "members" => "{$this->root}/team/{id}/members", "accounts" => "{$this->root}/team/{id}/accounts", "throttles" => "{$this->root}/team/{id}/throttles", "records" => "{$this->root}/budget/{id}/records", "about" => "{$this->root}/brand/{id}/about", "promos" => "{$this->root}/brand/{id}/promos", "tally" => "{$this->root}/brand/{id}/tally", "edit" => "/form/brand-edit"), "user_" => array("@id" => "{$this->root}/user/{id}", "@type" => "user"), "throttle_" => array("@id" => "{$this->root}/throttle/{id}", "@type" => "throttle")); foreach ($items as &$r) { if (!$r['alias']) { $r['alias'] = $r['account_name']; } $this->nestResources($r, $nestingRef, $graph, $tracked, $skip); $r['relay'] = array(); $r['@type'] = 'userAccount'; $r['@id'] = $this->{'@id'} . "?holder_id={$r['id']}"; $this->setAllowedActions($r, $graph[$tracked[$r['account']]]); //$r['holder-edit'] = "$this->root/form/holder-edit"; $r['edit'] = "{$this->root}/form/holder-edit"; $r['relays'] = "{$this->root}/holder/{$r['id']}/relays"; $graph[] = $r; $this->holding[] = $r['@id']; } $this->items = array(); //$this->{$this->collectionOf} = $this->items; return $graph; }
function setTally($brand_id, $weekCreated) { $sql = "SELECT tally_id, n_start_bal, p_start_bal, issued, intrause, inflow, outflow, week\n\t\t\tFROM tallies \n\t\t\tWHERE brand_id={$brand_id} \n\t\t\tORDER BY week DESC LIMIT 1"; $row = DBquery::get($sql); if (!$row) { $tally_id = $this->insertTally($brand_id, $weekCreated, 0, 0); //insert beginning tally $row = DBquery::get("SELECT * FROM tallies WHERE tally_id={$tally_id}"); } //update previous tally, plus insert a new tally for the current week $nBal = $row[0]['n_start_bal']; $pBal = $row[0]['p_start_bal']; $tally_id = $row[0]['tally_id']; $numUpdated = 0; for ($i = $row[0]['week']; $i < $this->currWeek; $i++) { $day1 = date("Y-m-d", strtotime("2015W" . sprintf("%02u", $i) . "1")) . " 00:00:00"; $day7 = date("Y-m-d", strtotime("2015W" . sprintf("%02u", $i) . "7")) . " 00:00:00"; $b = DBquery::get("CALL tally({$brand_id}, '{$day1}', '{$day7}')"); $b = $b ? $b[0] : array("added" => 0, "intrause" => 0, "inflow" => 0, "outflow" => 0, "numMembers" => 0, "totalMemberHours" => 0); if ($i != $row[0]['week']) { $tally_id = $this->insertTally($brand_id, $i, $nBal, $pBal); } $nBal += $b['added'] - $b['intrause'] - $b['inflow']; $pBal += $b['added'] - $b['intrause'] - $b['outflow']; $numUpdated += $this->updateTally($tally_id, $b['added'], $b['intrause'], $b['inflow'], $b['outflow'], $b['numMembers'], $b['totalMemberHours']); } return $numUpdated; }
function get() { $graph = array($this); $tracked = array(); $this->add = "{$this->root}/form/promo-add"; $this->setFilters($_GET); $nestingRef = array("brand_" => array("@id" => "{$this->root}/team/{id}", "@type" => "brand"), "relay_" => array("@id" => "{$this->root}/relay/{id}", "@type" => "relay", "edit" => "/form/relay-edit", "by_all_limit" => "{by_all_limit}")); $sql = "SELECT promo_id AS id, \n\t\t\t\tbrand_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\texpires, \n\t\t\t\trelay_id, \n\t\t\t\tkeyword, \n\t\t\t\tby_all_limit AS relay_by_all_limit, \n\t\t\t\tby_brand_limit AS relay_by_brand_limit, \n\t\t\t\tby_user_limit AS relay_by_user_limit, \n\t\t\t\tby_user_wait AS relay_by_user_wait\n\t\t\tFROM promos p\n\t\t\tJOIN relays r USING (relay_id)\n\t\t\tJOIN brands USING (brand_id)\n\t\t\tWHERE brand_id={$this->brand_id} {$this->filterCond} AND promo_id {$this->ltgt} {$this->limitID}\n\t\t\tORDER BY id ASC\n\t\t\tLIMIT {$this->itemsLimit}"; $items = DBquery::get($sql, $this->filterValArr); foreach ($items as &$r) { $this->nestResources($r, $nestingRef, $graph, $tracked); $r['@id'] = "{$this->root}/promo/" . $r['id']; $r['@type'] = 'promo'; $r['payURL'] = Requester::$ProtDomain . "/for/{$r['keyword']}-{$r['id']}"; $r['code'] = "{$r['keyword']}-{$r['id']}"; $r['promoPage'] = Requester::$ProtDomain . "/ad/{$r['id']}"; if (!$r['infoURL']) { $r['infoURL'] = $r['promoPage']; } $r['edit'] = '/form/promo-edit'; $relayHoldings = array(); if (in_array($r['relay_id'], $relayHoldings) or Requester::isRelayHolder($r['relay_id'])) { $relayHoldings[] = $r['relay_id']; $r['relay-edit'] = '/form/relay-edit'; $r['relay-edit-target'] = "/relay/" . $r['relay_id']; } $r['brand'] = "{$this->root}/brand/{$this->brand_id}"; $this->{$this->collectionOf}[] = $r['@id']; $graph[] = $r; } $this->paginate('promo_id'); return $graph; }
function get() { $forms = array(); if (!isset($_GET['member_id'])) { $graph = array($this); $otherCond = ""; $vals = array($this->user_id); } else { $otherCond = "AND member_id=?"; $vals = array($this->user_id, $_GET['member_id']); } $sql = "SELECT m.brand_id, member_id AS id, m.joined AS joined, role, hours \n\t\t\tFROM members m\n\t\t\tJOIN brands b USING (brand_id)\n\t\t\tWHERE user_id=? AND m.ended IS NULL AND revoked IS NULL AND type_system != 'sim' {$otherCond}"; $items = DBquery::get($sql, $vals); $this->setForms(); $tracked = array(); foreach ($items as &$r) { $graph[] =& $r; $r["team"] = "{$this->root}/team/{$r['brand_id']}"; if ($r['role'] == 'admin') { $r["issuer"] = "{$this->root}/brand/{$r['brand_id']}"; } unset($r['brand_id']); $r['@type'] = 'userMembership'; $r['@id'] = $this->{'@id'} . "?member_id=" . $r['id']; $r['edit'] = "/form/member-edit"; if (!$r['joined']) { $r['accept'] = "/form/member-accept"; } $r['revoke'] = "/form/member-revoke"; if (!isset($_GET['member_id'])) { $this->membership[] = $r['@id']; } } return $graph; }
function verifyAdjustedAmt($amount) { $sql = "SELECT adjusted_amt, txntype FROM reversals WHERE orig_record_id=? ORDER BY rev_record_id DESC LIMIT 1"; $rows = DBquery::get($sql, array($this->orig_record_id)); if ($rows) { $remaining_amount = $rows[0]['adjusted_amt']; $txntype = $rows[0]['txntype']; } else { $sql = "SELECT amount, txntype FROM records WHERE record_id=?"; $rows = DBquery::get($sql, array($this->orig_record_id)); if (!$rows) { Error::http(403, "The transaction record to reverse, #{$this->orig_record_id}, was not found."); } if ($rows[0]['amount'] < 0) { Error::http(403, "Record #{$this->orig_record_id} is already a transaction reversal and cannot be reversed."); } $remaining_amount = $rows[0]['amount']; $txntype = $rows[0]['txntype']; } $this->adjusted_amt = $remaining_amount + $amount; //reversal amount is expressed as a negative amount if ($this->adjusted_amt < 0) { Error::http(403, "The reversal amount ({$amount}) exceeds the previous amount that can be reversed ({$remaining_amount})."); } if ($txntype != $this->txnType) { Error::http(403, "The accounts ({$txntype}) to be used in a reversal must match the account types of those used in the original transaction ({$this->txnType})."); } }
function getByPhoneNum() { if (!($phone = $_REQUEST['From'])) { Error::sms("The SMS sender's phone number was not detected."); } if (!($body = $_REQUEST['Body'])) { Error::sms("Missing email address."); } $sql = "SELECT user_id, email, wallet FROM users WHERE phone=?"; $row = DBquery::get($sql, array($phone)); if ($row) { if ($body != $row[0]['email']) { Error::sms("The email address does not match the one set for phone #{$phone}."); } else { $this->user_id = $row[0]['user_id']; Requester::$consumer_id = $row[0]['wallet']; return $this->setToken(); } } else { require_once "models/UserCollection.php"; $Users = new UserCollection(json_decode('{ "email": "' . $body . '", "name": "' . $body . '", "password": "******", "phone": "' . $phone . '", "login_provider": "phone", "wallet": 2 }')); $arr = $Users->add(); $this->user_id = $arr[0]->user_id; return $this->setToken(); } }
function asApplied($filters) { if (!is_array($filters['brand_id'])) { $filters['brand_id'] = explode(",", $filters['brand_id']); } if (!$filters['brand_id']) { Error::http(400, "An array of brand_id values are required when testing the applicability of throttle #{$this->throttle_id}."); } $currtime = time(); $throttle_id = $filters['throttle_id'] ? $filters['throttle_id'] : $this->throttle_id; $sql = "SELECT a.brand_id, from_user, amount, r.created\n\t\t\tFROM records r\n\t\t\tJOIN accounts a ON a.account_id=from_acct\n\t\t\tWHERE r.throttle_id=? AND r.status>-1 AND r.txntype='pn' AND {$currtime} - UNIX_TIMESTAMP(r.created) < {$this->period};"; $rows = DBquery::get($sql, array($throttle_id)); $used = array('by_all' => 0, 'by_brand' => array("0" => 0), 'by_user' => 0); foreach ($rows as $r) { $used['by_all'] += $r['amount']; if (in_array($r['brand_id'], $filters['brand_id'])) { $used['by_brand'][$r['brand_id']] += $r['amount']; } if (Requester::$user_id == $r['from_user']) { $used['by_user'] += $r['amount']; } } $this->unusedAmt = min(max($this->by_all - $used['by_all'], 0), max($this->by_brand - min($used['by_brand']), 0), max($this->by_user - $used['by_user'], 0)); unset($used['by_brand']["0"]); $this->used = $used; return array($this); }
function getByEmailAddr() { if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) { Error::http(400, "Invalid email value='{$this->email}'. {$this->pwd}"); } $sql = "SELECT user_id, password, login_provider, ver_code, ver_expires FROM users WHERE email=?"; return DBquery::get($sql, array($this->email))[0]; }
function get() { $sql = "SELECT report_id, txntype, from_brand, to_brand, amount, UNIX_TIMESTAMP(max_updated) AS updated, keyword, status\n\t\t\tFROM reports \t\t\t\n\t\t\tWHERE report_id {$this->ltgt} {$this->limitID}\n\t\t\tORDER BY report_id {$this->pageOrder}\n\t\t\tLIMIT {$this->itemsLimit}"; $rows = DBquery::get($sql); $this->data = $rows; $this->paginate('report_id'); return array($this); }
function get() { $sql = "SELECT brand_id FROM members WHERE user_id={$this->user_id} AND ended IS NULL"; $items = DBquery::get($sql, array($this->user_id)); foreach ($items as $i) { $this->brand[] = "{$this->root}/team/{$i['brand_id']}"; } return array($this); }
function get() { //limited public profile information $sql = "SELECT m.user_id, name, m.created, COUNT(DISTINCT(brand_id)) AS numMemberships, SUM(hours) AS totalHours\n\t\tFROM members m\n\t\tJOIN users ON m.user_id=users.user_id\n\t\tWHERE m.user_id IN (?) AND m.ended IS NULL\n\t\tGROUP BY m.user_id"; $rows = DBquery::get($sql, array($this->user_id)); foreach ($rows[0] as $k => $v) { $this->{$k} = $v; } return array($this); }
function get() { if (!Requester::isBrandAdmin($this->brand_id)) { Error::http(403, "Only admins of brand #{$this->brand_id} can view details of its budget issuance records."); } $sql = "SELECT r.record_id, r.created, from_acct, from_user, to_acct, to_user, amount, `note`\n\t\tFROM records r JOIN accounts a ON (r.from_acct = a.account_id)\n\t\tWHERE brand_id=? AND txntype='pn' \n\t\tORDER BY record_id DESC LIMIT 50"; $this->items = DBquery::get($sql, array($this->brand_id)); $this->setForms(); return array($this); }
function get() { $sql = "SELECT brand_id FROM members WHERE user_id={$this->user_id} AND ended IS NULL AND role='admin'"; $items = DBquery::get($sql, array($this->user_id)); foreach ($items as $i) { $this->brand[] = "/brand/{$i['brand_id']}"; } $this->setForms(); $this->add = "{$this->root}/form/brand-registration"; return array($this); }
function setDetails($throttle_id = 0) { $sql = "SELECT * FROM {$this->table} WHERE throttle_id=?"; $row = DBquery::get($sql, array($throttle_id ? $throttle_id : $this->throttle_id)); if (!$row) { Error::http(404, "No details were found for throttle #'{$this->throttle_id}'."); } foreach ($row[0] as $k => $v) { $this->{$k} = $v; } }
function get() { $this->setForms(); $sql = "SELECT COUNT(*) AS numUsers, MIN(created) AS earliest, MAX(created) AS latest FROM users"; $row = DBquery::get($sql); if (!$row) { return array($this); } foreach ($row[0] as $key => $val) { $this->{$key} = $val; } return array($this); }
function getRole() { $sql = "SELECT role, hours, m.created, u.name, m.joined, m.revoked\n\t\t\tFROM members m\n\t\t\tJOIN users u ON u.user_id=m.user_id \n\t\t\tWHERE brand_id=? AND m.user_id=?\n\t\t\tAND m.ended IS NULL AND m.revoked IS NULL \n\t\t\tORDER BY m.created DESC"; $row = DBquery::get($sql, array($this->brand_id, Requester::$user_id)); if ($row) { foreach ($row as $r) { foreach ($r as $k => $v) { $this->{$k} = $v; } } } return array($this); }
function get() { $this->add = "/form/rating-add"; $sql = "SELECT rating_id, r.brand_id AS brand_id, b.name AS brand_name, score, reason, r.created, r.ended\n\t\t\tFROM ratings r\n\t\t\tJOIN brands b ON b.brand_id = r.brand_id \n\t\t\tWHERE r.user_id=? AND rating_id {$this->ltgt} {$this->limitID}\n\t\t\tORDER BY rating_id {$this->pageOrder}\n\t\t\tLIMIT {$this->itemsLimit}"; $items = DBquery::get($sql, array($this->user_id)); foreach ($items as &$item) { $item['@id'] = $this->{"@id"} . "?rating_id=" . $item['rating_id']; $item['edit'] = "{$this->root}/form/rating-edit"; } $this->{$this->collectionOf} = $items; $this->paginate('rating_id'); return array($this); }
function get() { $graph = array($this); $sql = "SELECT member_id AS id, m.user_id, role, hours, m.created, u.name, m.joined, m.revoked\n\t\t\tFROM members m\n\t\t\tJOIN users u ON u.user_id=m.user_id \n\t\t\tWHERE brand_id=? \n\t\t\tAND m.ended IS NULL AND m.revoked IS NULL AND member_id {$this->ltgt} {$this->limitID}\n\t\t\tORDER BY member_id {$this->pageOrder}\n\t\t\tLIMIT {$this->itemsLimit}"; $items = DBquery::get($sql, array($this->brand_id)); foreach ($items as &$r) { $r['@id'] = $this->{"@id"} . "?member_id=" . $r['id']; $r['brand'] = "{$this->root}/team/{$this->brand_id}"; $this->{$this->collectionOf}[] = $r['@id']; $graph[] = $r; } $this->paginate('member_id'); return $graph; }
function get() { $graph = array($this); $sql = "CALL brandAccountsAsc({$this->brand_id}, 0, 100)"; $items = DBquery::get($sql, array($this->brand_id, $this->brand_id, $this->brand_id)); foreach ($items as &$r) { $r['@id'] = $this->{"@id"} . "?account_id=" . $r['id']; $r['brand'] = "{$this->root}/team/{$this->brand_id}"; $this->{$this->collectionOf}[] = $r['@id']; $graph[] = $r; } $this->paginate('account_id'); return $graph; }
function get() { if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR'] or $_SERVER['REMOTE_ADDR'] == '127.0.0.1') { /*allowed*/ } else { Error::http(403, "Requests for the sim/records resource must originate from the server environment."); } $sql = "SELECT record_id FROM records WHERE status=0 AND TIMESTAMPDIFF(SECOND,created,NOW()) > 300"; $rows = DBquery::get($sql); $pending = count($rows); foreach ($rows as $r) { DBquery::get("CALL approveRecord(" . $r['record_id'] . ")"); } return array(array("numApproved" => $pending)); }
function getAggregated() { $sql = "SELECT brand_id, week, n_start_bal, n_start_bal, issued, intrause, inflow, outflow, \n\t\t\tnum_members, member_hours, type_system, type_id, country_code, area_code, tallies.updated\n\t\tFROM tallies\n\t\tJOIN brands USING (brand_id)\n\t\tWHERE 1 {$this->countryCode} {$this->areaCode} {$this->typeSystem}\n\t\tORDER BY brand_id ASC, week ASC"; $rows = DBquery::get($sql, $this->params); if (!$rows) { return array(new stdClass()); } foreach ($rows as $r) { $d["" . $r['brand_id']][] = $r; } foreach ($d as $key => $arr) { $data[] = array("brand_id" => $key, "data" => $arr); } return array(array("@id" => $_SERVER['REQUEST_URI'], "data" => $data)); }
function getInfo() { $sql = "SELECT name, description, mission, created, url, advisor, type_system, type_id, country_code, area_code FROM brands WHERE brand_id=?"; $row = DBquery::get($sql, array($this->brand_id)); if ($row[0]) { foreach ($row[0] as $key => $val) { if ($key == 'url' and !$val) { $val = "https://tatag.cc/{$this->brand_id}"; } if ($key == 'country_code' and !$val) { $val = "USA"; } $this->{$key} = $val; } } }
function get() { $sql = "select b.brand_id, 'approved' AS type,\n\t\t\tCOALESCE(numApproved,0) AS total\n\t\tfrom brands b\n\t\tLEFT JOIN (\n\t\t\tSELECT brand_id, COUNT(*) as numApproved\n\t\t\tFROM records r\n\t\t\tJOIN accounts f ON f.account_id=r.from_acct\n\t\t\tWHERE status=7 and txntype='pn'\n\t\t\tGROUP BY brand_id\n\t\t) approved ON approved.brand_id = b.brand_id\n\t\tUNION ALL\n\t\tselect b.brand_id, 'rejected' AS type, \n\t\t\tCOALESCE(numrejected,0) AS total\n\t\tfrom brands b\n\t\tLEFT JOIN (\n\t\t\tSELECT brand_id, COUNT(*) as numrejected\n\t\t\tFROM records r\n\t\t\tJOIN accounts f ON f.account_id=r.from_acct\n\t\t\tWHERE status=7 and txntype='pn'\n\t\t\tGROUP BY brand_id\n\t\t) rejected ON rejected.brand_id = b.brand_id"; $rows = DBquery::get($sql); $d = []; foreach ($rows as &$r) { $d[$r['brand_id']][$r['type']] = $r['total']; } $data = array(); foreach ($d as $key => &$arr) { $ratios = array(); $ratios[] = array('brand' => $key, 'amount' => $arr['approved'] / (1 + $arr['rejected'])); $data[] = array('brand_id' => $key, "arRatio" => $ratios); } return array(array("@id" => $_SERVER['REQUEST_URI'], "data" => $data)); }
function get() { $sql = "select b.brand_id, week, 'approved' AS type,\n\t\t\tCOALESCE(numApproved,0) AS total\n\t\tfrom brands b\n\t\tLEFT JOIN (\n\t\t\tSELECT brand_id, WEEKOFYEAR(r.updated) AS week, COUNT(*) as numApproved\n\t\t\tFROM records r\n\t\t\tJOIN accounts f ON f.account_id=r.from_acct\n\t\t\tWHERE status=7 and txntype='pn'\n\t\t\tGROUP BY brand_id, week\n\t\t) approved ON approved.brand_id = b.brand_id\n\t\tUNION ALL\n\t\tselect b.brand_id, week, 'rejected' AS type, \n\t\t\tCOALESCE(numrejected,0) AS total\n\t\tfrom brands b\n\t\tLEFT JOIN (\n\t\t\tSELECT brand_id, WEEKOFYEAR(r.updated) AS week, COUNT(*) as numrejected\n\t\t\tFROM records r\n\t\t\tJOIN accounts f ON f.account_id=r.from_acct\n\t\t\tWHERE status=7 and txntype='pn'\n\t\t\tGROUP BY brand_id, week\n\t\t) rejected ON rejected.brand_id = b.brand_id"; $rows = DBquery::get($sql); $d = []; $weekMin = 54; $weekMax = 0; $hasData = array(); foreach ($rows as &$r) { if (!$r['week']) { $r['week'] = $this->week; } if ($r['week'] < $weekMin) { $weekMin = $r['week']; } if ($r['week'] > $weekMax) { $weekMax = $r['week']; } $hasData[$r['brand_id']][] = $r['week']; $d[$r['brand_id']][$r['week']][$r['type']] = $r['total']; } $expectedWeeks = range($weekMin, $weekMax); foreach ($hasData as $brand_id => $hasWeeks) { foreach ($hasWeeks as $wk) { if (!isset($d[$brand_id][$wk]['approved'])) { $d[$brand_id][$wk]['approved'] = 0; } if (!isset($d[$brand_id][$wk]['rejected'])) { $d[$brand_id][$wk]['rejected'] = 0; } } $missingWeeks = array_diff($expectedWeeks, $hasWeeks); foreach ($missingWeeks as $wk) { $d[$brand_id][$wk]['approved'] = 0; $d[$brand_id][$wk]['rejected'] = 0; } } $data = array(); foreach ($d as $key => &$arr) { $ratios = array(); foreach ($arr as $week => $r) { $ratios[] = array('brand' => $key, 'week' => $week, 'amount' => $r['approved'] / (1 + $r['rejected'])); } $data[] = array('brand_id' => $key, "arRatio" => $ratios); } return array(array("@id" => $_SERVER['REQUEST_URI'], "data" => $data)); }
function get() { $graph = array($this); //$this->getRole(); $startDate = "2015-01-01 00:00:00"; $endDate = "2015-12-31 11:59:59"; $tally = DBquery::get("CALL tally({$this->brand_id}, '{$startDate}', '{$endDate}')")[0]; if (!$tally) { return array(null); } foreach ($tally as $k => $v) { $this->{$k} = $v; } //array_merge(array("@type" => "budgetTally"),$tally); $this->brand = "{$this->root}/team/{$this->brand_id}"; return $graph; }
function get() { $graph = array($this); $tracked = array(); $nestingRef = array("promo_" => array("@id" => "{$this->root}/promo/{id}", "@type" => "promo"), "user_" => array("@id" => "{$this->root}/user/{id}/about", "@type" => "user"), "from_" => array("@id" => "{$this->root}/brand/{id}/about")); $sql = "SELECT record_id, \n\t\t\tr.created, \n\t\t\tbf.brand_id AS from_id,\n\t\t\tbf.name AS from_name,\n\t\t\t-- to_acct AS `to`, \n\t\t\tr.amount,\n\t\t\tr.`note`, \n\t\t\tr.order_step, \n\t\t\tr.updated AS updated,\n\t\t\tr.promo_id AS promo_id,\n\t\t\tp.name AS promo_name,\n\t\t\tr.from_user AS user_id\n\t\tFROM records r \n\t\tJOIN accounts af ON r.from_acct = af.account_id \n\t\tJOIN brands bf ON af.brand_id = bf.brand_id\n\t\tJOIN accounts at ON r.to_acct = at.account_id\n\t\tLEFT JOIN promos p USING (promo_id)\n\t\tWHERE promo_id!=0 AND txntype='pn' AND at.brand_id=? AND order_step BETWEEN ? AND ?\n\t\tGROUP BY record_id\n\t\tORDER BY record_id DESC LIMIT 50"; $items = DBquery::get($sql, array($this->brand_id, 0, 9)); foreach ($items as &$o) { $o['@id'] = "{$this->root}/team/{$this->brand_id}/orders?record_id={$o['record_id']}"; $o['update'] = "/form/order-update"; $this->nestResources($o, $nestingRef, $graph, $tracked, $skip); $this->order[] = $o['@id']; $graph[] = $o; } $this->paginate('record_id'); return $graph; }
function initTally() { $sql = "SELECT {$this->from_brand} AS brand_id, \n\t\t\tb.advisor AS advisor, \n\t\t\tCOALESCE(p_start_bal, 0) AS p_start_bal,\n\t\t\tCOALESCE(n_start_bal, 0) AS n_start_bal, \n\t\t\tCOALESCE(issued, 0) AS issued, \n\t\t\tCOALESCE(inflow, 0) AS inflow, \n\t\t\tCOALESCE(outflow, 0) AS outflow, \n\t\t\tCOALESCE(intrause, 0) AS intrause, \n\t\t\tCOALESCE(num_members, 0) AS num_members, \n\t\t\tCOALESCE(member_hours, 0) AS member_hours\n\t\tFROM brands b\n\t\tLEFT JOIN tallies t ON t.brand_id={$this->from_brand}\n\t\t\tAND t.year=2015\n\t\t\tAND week=(SELECT max(week) FROM tallies WHERE brand_id={$this->from_brand}) \n\t\tWHERE b.brand_id={$this->to_brand}"; //echo $sql; $r = DBquery::get($sql)[0]; $this->tally = new stdClass(); foreach ($r as $k => $v) { if ($k == 'advisor') { $this->advisor = $v; } else { $this->tally->{$k} = $v; } } if (!$this->advisor) { $this->advisor = $this->consumer_id ? $this->consumer_id : 0; } }
function get() { $graph = array($this); $this->app = array("/app/trial"); $sql = "SELECT * FROM consumers WHERE user_id=?"; $rows = DBquery::get($sql, array($this->user_id)); foreach ($rows as $r) { if ($r['type'] == 'advisor') { $r['advise'] = "{$this->root}/app/{$r['consumer_id']}/advise"; $r['config'] = "{$this->root}/app/{$r['consumer_id']}/config"; } $r['@id'] = "{$this->root}/app/{$r['consumer_id']}/details"; $this->app[] = $r["@id"]; $graph[] = $r; } $this->paginate('consumer_id'); return $graph; }
function getInfo() { $sql = "SELECT name FROM brands WHERE brand_id=?"; $row = DBquery::get($sql, array($this->brand_id)); if ($row[0]) { foreach ($row[0] as $key => $val) { $this->{$key} = $val; } $this->brand_name = $this->name; $this->members = "{$this->root}/brand/{$this->brand_id}/members"; $this->accounts = "{$this->root}/brand/{$this->brand_id}/accounts"; $this->about = "{$this->root}/brand/{$this->brand_id}/about"; $this->promos = "{$this->root}/brand/{$this->brand_id}/promos"; $this->records = "{$this->root}/budget/{$this->brand_id}/records"; $this->throttles = "{$this->root}/budget/{$this->brand_id}/throttles"; $this->about = "{$this->root}/brand/{$this->brand_id}/about"; } }
function getByOauthID($info) { $tw_id = "" . $info['user_id']; $sql = "SELECT user_id FROM users WHERE tw_id=?"; $row = DBquery::get($sql, array($tw_id)); if ($row) { return $row[0]['user_id']; } require_once "models/UserCollection.php"; $Users = new UserCollection(json_decode('{ "name": "' . $info['screen_name'] . '", "password": "******", "tw_id": "' . $tw_id . '", "login_provider": "tw" }')); $arr = $Users->add(); return $arr[0]->user_id; }