/** * @before _secure */ public function postbacks() { $this->seo(["title" => "Network: PostBacks"]); $view = $this->getActionView(); $postbacks = \PostBack::all(['org_id = ?' => $this->org->id]); $view->set('postbacks', $postbacks); }
protected function _postback($case, $extra = []) { $view = $this->getActionView(); switch ($case) { case 'add': $search = ["org_id" => $this->org->_id, "user_id" => $this->user->_id, "event" => RM::post("event")]; if (isset($extra['ad'])) { $search["ad_id"] = $extra['ad']->_id; } $foundPostback = PostBack::first($search); if (RM::post('action') === 'addCallback' && !$foundPostback) { $postback = new PostBack(array_merge($search, ["data" => RM::post("data"), "type" => RM::post("type")])); $postback->save(); $view->set('message', 'Postback Saved Successfully'); } else { $view->set('message', 'Postback already added'); } break; case 'delete': $postback = PostBack::first(["_id" => RM::get("postback_id"), "user_id" => $this->user->_id, "org_id" => $this->org->_id]); // check for valid request as a fallback if (RM::type() === 'DELETE' && RM::get('removeCallback') && $postback) { $postback->delete(); $view->set('message', "Postback removed!!"); } else { $view->set('message', "Invalid Request!!"); } break; case 'show': $query = ['user_id' => $this->user->_id, 'org_id' => $this->org->_id]; if (isset($extra['ad'])) { $query["ad_id"] = $extra['ad']->_id; $postbacks = PostBack::all($query); } else { $postbacks = PostBack::all($query); $ans = []; foreach ($postbacks as $p) { if (!$p->ad_id) { $ans[$p->_id] = $p; } } $postbacks = $ans; } $view->set('postbacks', $postbacks); break; } }