/** * @before _secure */ public function index() { $this->seo(array("title" => "Dashboard", "description" => "Stats for your Data")); $view = $this->getActionView(); $commissions = []; $start = RM::get("start", date("Y-m-d", strtotime('now'))); $end = RM::get("end", date("Y-m-d", strtotime('now'))); $today = date('Y-m-d'); $yesterday = date('Y-m-d', strtotime("-1 day")); $perf = Shared\Services\User::livePerf($this->user, $today, $today); $yestPerf = Shared\Services\User::livePerf($this->user, $yesterday, $yesterday); $notifications = Notification::all(["org_id = ?" => $this->org->id, "meta = ?" => ['$in' => ['all', $this->user->_id]]], [], "created", "desc", 5, 1); $total = Performance::total(['start' => date("Y-m-d", strtotime('-365 day')), 'end' => date("Y-m-d", strtotime('-2 day'))], $this->user); $view->set("start", date("Y-m-d", strtotime('-7 day')))->set("end", date("Y-m-d", strtotime('now')))->set("notifications", $notifications)->set("total", $total)->set("yestPerf", $yestPerf)->set("performance", $perf); }
/** * @before _verified */ public function createLink() { $this->JSONView(); $view = $this->getActionView(); $adid = RM::post("adid"); if (!$adid) { return $view->set('message', "Invalid Request"); } $ad = \Ad::first(["_id = ?" => $adid, "live = ?" => true], ['_id', 'title']); if (!$ad) { return $view->set('message', "Invalid Request"); } $user = User::first(["id = ?" => RM::post("aff_id")]) ?? $this->user; $tdomains = Shared\Services\User::trackingLinks($user, $this->org); if (RM::post("domain")) { $domain = RM::post("domain"); } else { $domain = $this->array_random($tdomains); } $link = Link::first(["ad_id = ?" => $ad->_id, "user_id = ?" => $user->_id], ['domain', '_id']); if (!$link) { $link = new Link(['user_id' => $user->_id, 'ad_id' => $ad->_id, 'domain' => $domain, 'live' => true]); $link->save(); } $view->set('message', $ad->title)->set('link', $link->getUrl($domain)); }
protected function _reports($table) { $view = $this->getActionView(); $fields = Shared\Services\User::fields($table); $table = "\\{$table}"; $ads = \Ad::all(['org_id' => $this->org->_id], ['_id', 'title'], 'created', 'desc'); $affs = \User::all(['org_id' => $this->org->_id, 'type = ?' => 'publisher'], ['_id', 'name']); $adIds = array_keys($ads); $pIds = array_keys($affs); $searchData = $this->_searchQuery($fields, $adIds, $pIds); $query = $searchData['query']; $searching = $searchData['searching']; $adIds = Db::convertType($adIds); $pIds = Db::convertType($pIds); $query['adid'] = ['$in' => $adIds]; $query['pid'] = ['$in' => $pIds]; $query['created'] = Db::dateQuery($this->start, $this->end); $records = $table::all($query, [], 'created', 'desc', $this->limit, $this->page); $count = $table::count($query); $view->set(['clicks' => $records, 'fields' => $fields, 'count' => $count, 'ads' => $ads, 'query' => $searching, 'affs' => $affs]); }
protected function _publisherRegister($org, $view) { $platformUrl = RM::post("platform", ''); try { $platform = new \Platform(['url' => $platformUrl]); } catch (\Exception $e) { return $view->set('message', $e->getMessage()); } $user = User::addNew('publisher', $org, $view); if ($user === false) { return; } $pass = $user->password; $user->password = sha1($pass); $output = Shared\Services\User::customFields($user, $org); if (!$output['success']) { return $view->set($output); } $user->save(); Mail::send(['user' => $user, 'org' => $this->org, 'template' => 'pubRegister', 'pass' => $pass, 'subject' => $this->org->name . ' Support']); $platform->user_id = $user->_id; $platform->save(); $view->set('message', "Registered Successfully"); }