Esempio n. 1
0
 /**
  * @before _secure
  */
 public function details($id)
 {
     $ad = \Ad::first(['_id' => $id, 'org_id' => $this->org->_id]);
     if (!$ad) {
         $this->_404();
     }
     $this->seo(array("title" => $ad->title));
     $view = $this->getActionView();
     $start = RM::get("start", date('Y-m-d', strtotime("-1 day")));
     $end = RM::get("end", date('Y-m-d'));
     if (RM::type() === 'DELETE') {
         $this->_commissionDel($ad, $view);
     }
     switch (RM::post("action")) {
         case 'caccess':
             $meta = $ad->meta;
             $meta["access"] = RM::post("access");
             $ad->meta = $meta;
             $ad->save();
             break;
     }
     switch (RM::get("action")) {
         case 'updateAccess':
             $access = AdAccess::first(["id = ?" => RM::get("access_id")]);
             if ($access) {
                 $access->live = RM::get("live", 0);
                 $access->save();
                 $this->redirect("/campaign/details/" . $ad->id . ".html#permission");
                 $session->set('$flashMessage', 'Access Updated');
             }
             break;
     }
     $comms = Commission::all(["ad_id = ?" => $id]);
     $models = ArrayMethods::arrayKeys($comms, 'model');
     $advertiser = User::first(["id = ?" => $ad->user_id], ['name']);
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $publishers = \User::all(['type' => 'publisher', 'org_id' => $this->org->_id, "live = ?" => true], ["id", "name"]);
     $adaccess = \AdAccess::all(['org_id' => $this->org->_id, "ad_id = ?" => $ad->id]);
     $view->set("ad", $ad)->set("comms", $comms)->set("categories", $categories)->set("advertiser", $advertiser)->set('publishers', \User::objectArr($publishers, ['_id', 'name']))->set('models', $models)->set('adaccess', $adaccess)->set("start", $start)->set("end", $end);
 }
Esempio n. 2
0
 /**
  * @before _secure
  */
 public function campaign($id)
 {
     $ad = \Ad::first(["_id = ?" => $id, 'org_id' => $this->org->_id]);
     if (!$ad) {
         $this->_404();
     }
     $this->seo(array("title" => $ad->title));
     $view = $this->getActionView();
     if (RM::get("action") == "permission" && array_key_exists("permission", $ad->meta)) {
         $search = ["org_id" => $this->org->id, "ad_id" => $id, "user_id" => $this->user->id];
         $access = AdAccess::first($search);
         // Check before saving to prevent duplication of records
         if (!$access) {
             $access = new AdAccess($search);
             $access->save();
         }
     }
     if (RM::post("action")) {
         // action value already checked in _postback func
         $this->_postback('add', ['ad' => $ad]);
     }
     if (RM::type() === 'DELETE') {
         $this->_postback('delete');
     }
     $this->_postback('show', ['ad' => $ad]);
     $start = RM::get("start", date('Y-m-d', strtotime("-7 day")));
     $end = RM::get("end", date('Y-m-d'));
     $limit = RM::get("limit", 10);
     $page = RM::get("page", 1);
     $query = ['adid' => Db::convertType($id), 'created' => Db::dateQuery($start, $end)];
     $clicks = \Click::all($query, [], 'created', 'desc', $limit, $page);
     $count = \Click::count($query);
     $cf = Utils::getConfig('cf', 'cloudflare');
     $view->set("domain", $cf->api->domain)->set("clicks", $clicks)->set("count", $count)->set('advertiser', $this->user);
     $comms = Commission::all(["ad_id = ?" => $id]);
     $models = [];
     foreach ($comms as $comm) {
         $models[] = $comm->model;
     }
     $advertiser = User::first(["id = ?" => $ad->user_id], ['name']);
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $view->set("ad", $ad)->set("comms", $comms)->set("categories", $categories)->set("advertiser", $advertiser)->set('models', $models)->set("start", $start)->set("end", $end)->set('tdomains', \Shared\Services\User::trackingLinks($this->user, $this->org));
 }