Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
0
 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);
 }
Example #4
0
    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();
        }
    }
Example #5
0
 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;
 }
Example #6
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);
 }
Example #7
0
 public static function run()
 {
     self::renameGETparams();
     self::parseURL();
     self::setMethod();
     $output = self::getResource(self::getData());
     DBquery::$conn = NULL;
     PhlatMedia::write($output);
 }
Example #8
0
 function get()
 {
     $graph = array($this);
     $sql = "INSERT INTO reports \n\t\t\t(txntype, from_brand, to_brand, amount, max_id, max_updated, keyword, status)\n\t\t\tSELECT txntype, \n\t\t\t\tf.brand_id AS from_brand, \n\t\t\t\tt.brand_id AS to_brand, \n\t\t\t\tSUM(r.amount) AS amount, \n\t\t\t\tMAX(record_id) AS max_id,\n\t\t\t\tMAX(r.updated) AS max_updated,\n\t\t\t\tp.keyword AS keyword,\n\t\t\t\tr.status AS status\n\t\t\tFROM records r\n\t\t\tINNER JOIN accounts f ON f.account_id = r.from_acct\n\t\t\tINNER JOIN accounts t ON t.account_id = r.to_acct\n\t\t\tLEFT JOIN promos p ON p.promo_id = r.promo_id\n\t\t\tWHERE record_id > (SELECT COALESCE(MAX(max_id),0) AS max_id FROM reports)\n\t\t\t\tAND (status < 0 OR status > 6) \n\t\t\t\tAND txntype IN ('np','pn') \n\t\t\tGROUP BY txntype, from_brand, to_brand, keyword";
     $numInserted = DBquery::set($sql);
     //$this->sql = $sql;
     $this->numInserted = $success;
     return $graph;
 }
Example #9
0
 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);
 }
Example #10
0
 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);
 }
Example #11
0
 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;
     }
 }
Example #12
0
 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);
 }
Example #13
0
 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);
 }
Example #14
0
 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);
 }
Example #15
0
 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);
 }
Example #16
0
 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;
 }
Example #17
0
 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;
 }
Example #18
0
 function catchError($balErr, $authErr = '')
 {
     $mssg = $balErr . $authErr;
     if ($this->record_id and $mssg) {
         $sql = "UPDATE records SET status=-1 WHERE record_id={$this->record_id}";
         $rowCount = DBquery::update($sql);
         if (!$rowCount) {
             Error::http(403, "Affected rows=0.");
         }
     }
     if ($mssg) {
         Error::http(403, $mssg);
     }
 }
Example #19
0
 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));
 }
Example #20
0
 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));
 }
Example #21
0
 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));
 }
Example #22
0
 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;
         }
     }
 }
Example #23
0
 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));
 }
Example #24
0
 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;
 }
Example #25
0
 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;
 }
Example #26
0
 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;
     }
 }
Example #27
0
 function updateTally($tally_id, $issued, $intrause, $inflow, $outflow, $num_members, $member_hours)
 {
     if (!$issued) {
         $issued = 0;
     }
     if (!$intrause) {
         $intrause = 0;
     }
     if (!$inflow) {
         $inflow = 0;
     }
     if (!$outflow) {
         $outflow = 0;
     }
     $sql = "UPDATE tallies SET updated=NOW(), issued={$issued}, intrause={$intrause}, inflow={$inflow}, outflow={$outflow}, num_members={$num_members}, member_hours={$member_hours}\n\t\t\tWHERE tally_id={$tally_id}";
     return DBquery::set($sql);
 }
Example #28
0
 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";
     }
 }
Example #29
0
    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;
    }
Example #30
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;
 }