Пример #1
0
 /**
  * @before _secure
  */
 public function campaign($id)
 {
     $ad = \Ad::first(['_id' => $id, 'org_id' => $this->org->_id]);
     if (!$ad) {
         $this->_404();
     }
     $this->seo(["title" => $ad->title]);
     $view = $this->getActionView();
     if (RM::post("action")) {
         // action value already checked in _postback func
         $this->_postback('add', ['ad' => $ad]);
     }
     if (RM::type() === 'DELETE') {
         $this->_postback('delete');
     }
     $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], ['model', 'coverage', 'revenue', 'description']);
     $models = ArrayMethods::arrayKeys($comms, 'model');
     $advertiser = User::first(["id = ?" => $ad->user_id], ['name']);
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $this->_postback('show', ['ad' => $ad]);
     $view->set("ad", $ad)->set("comms", $comms)->set("categories", $categories)->set("advertiser", $advertiser)->set('models', $models)->set("start", $start)->set("end", $end);
 }
Пример #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));
 }
Пример #3
0
 public function delete()
 {
     $deleteList = ['Link', 'Platform', 'Ad', 'Performance', 'Invoice', 'Adaccess'];
     $query = ['user_id' => $this->_id];
     $delete = false;
     switch ($this->_type) {
         case 'publisher':
             $clicks = Click::count(['pid' => $this->_id]);
             if ($clicks !== 0) {
                 return false;
             }
             $delete = true;
             $this->removeFields();
             break;
         case 'advertiser':
             $ads = Ad::all(['user_id' => $this->_id], ['_id']);
             if (count($ads) === 0) {
                 $delete = true;
             } else {
                 $in = array_keys($ads);
                 $in = Db::convertType($in, 'id');
                 $clickCount = Click::count(['adid' => ['$in' => $in]]);
                 if ($clickCount === 0) {
                     Commission::deleteAll(['ad_id' => ['$in' => $in]]);
                     $delete = true;
                 }
             }
             break;
     }
     if ($delete) {
         parent::delete();
         foreach ($deleteList as $table) {
             $table::deleteAll($query);
         }
     }
     return $delete;
 }
Пример #4
0
 /**
  * Overrides the parent delete method to check for clicks on the
  * ad before deleting it
  */
 public function delete()
 {
     $id = Utils::mongoObjectId($this->_id);
     $count = \Click::count(['adid' => $id]);
     if ($count !== 0) {
         return ['message' => 'Can not delete!! Campaign contain clicks', 'success' => false];
     }
     $this->_removeMedia();
     parent::delete();
     \Commission::deleteAll(['ad_id' => $id]);
     \Link::deleteAll(['ad_id' => $id]);
     return ['message' => 'Campaign removed successfully!!', 'success' => true];
 }