/** * @before _secure */ public function index() { $this->seo(array("title" => "Dashboard")); $view = $this->getActionView(); $d = 1; $publishers = User::all(["org_id = ?" => $this->org->_id, "type = ?" => "publisher"], ["_id"]); $in = array_keys($publishers); $start = RM::get("start", date('Y-m-d', strtotime('-4 day'))); $end = RM::get("end", date('Y-m-d', strtotime('now'))); $dq = ['start' => date('Y-m-d', strtotime("-365 day")), 'end' => $end]; $pubPerf = (object) Performance::total($dq, $publishers); $advPerf = (object) Performance::total($dq, $this->org->users('advertiser', 'users'), ['revenue']); $topusers = $this->widgets(); if (array_key_exists("widgets", $this->org->meta)) { $d = in_array("top10ads", $this->org->meta["widgets"]) + in_array("top10pubs", $this->org->meta["widgets"]); } $view->set("start", $start)->set("end", $end)->set("d", 12 / $d)->set("topusers", $topusers)->set("links", \Link::count(['user_id' => ['$in' => $in]]))->set("platforms", \Platform::count(['user_id' => ['$in' => $in]]))->set("performance", Performance::calProfit($pubPerf, $advPerf)); }