Exemplo n.º 1
0
 public function inUse()
 {
     $count = Ad::count(['org_id' => $this->org_id, 'category' => ['$elemMatch' => ['$eq' => Utils::mongoObjectId($this->_id)]]]);
     if ($count === 0) {
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 2
0
 /**
  * @before _secure
  */
 public function campaigns()
 {
     $this->seo(array("title" => "Campaigns"));
     $view = $this->getActionView();
     $limit = RM::get("limit", 20);
     $page = RM::get("page", 1);
     $category = RM::get("category", []);
     $keyword = RM::get("keyword", '');
     $query = ["live = ?" => true, "org_id = ?" => $this->org->_id];
     $query["meta.private"] = ['$ne' => true];
     $today = date('Y-m-d');
     if (count($category) > 0) {
         // if you want AND query instead of OR query then replace '$in' --> '$all'
         $query["category"] = ['$in' => Ad::setCategories($category)];
     }
     if ($keyword) {
         $query["title"] = Utils::mongoRegex($keyword);
     }
     switch (RM::get("action")) {
         case 'trending':
             $ads = \Ad::all($query, [], 'modified', 'desc');
             $fields = Shared\Services\User::fields('Ad');
             $ids = array_keys($ads);
             $ads = Ad::objectArr($ads, $fields);
             $limit = $count = 30;
             $clickCol = Registry::get("MongoDB")->clicks;
             $results = $clickCol->aggregate([['$match' => ['adid' => ['$in' => Db::convertType($ids, 'id')], 'is_bot' => false, 'created' => Db::dateQuery(RM::get("start", $today), RM::get("end", $today))]], ['$project' => ['adid' => 1, '_id' => 1]], ['$group' => ['_id' => '$adid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => $limit]]);
             $ans = [];
             foreach ($results as $r) {
                 $a = (object) $r;
                 $key = Utils::getMongoID($a->_id);
                 $ans[$key] = $ads[$key];
             }
             $ads = $ans;
             break;
         default:
             $count = \Ad::count($query);
             $ads = \Ad::all($query, [], 'modified', 'desc', $limit, $page);
             break;
     }
     //private campaigns
     $query["meta.private"] = true;
     $query["meta.access"] = ['$in' => [$this->user->id]];
     $pads = \Ad::all($query, [], 'modified', 'desc');
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $user = $this->user;
     $model = null;
     $rate = null;
     if (array_key_exists("campaign", $user->meta)) {
         $model = $user->meta["campaign"]["model"];
         $rate = $user->meta["campaign"]["rate"];
     }
     $view->set(['limit' => $limit, 'page' => $page, 'count' => $count, 'ads' => $ads, 'model' => $model, 'rate' => $rate, 'categories' => $categories, 'coverage' => $category, 'tdomains' => \Shared\Services\User::trackingLinks($this->user, $this->org), 'keyword' => $keyword, 'pads' => $pads]);
 }
Exemplo n.º 3
0
 /**
  * @before _secure
  */
 public function campaigns()
 {
     $this->seo(array("title" => "Campaigns"));
     $view = $this->getActionView();
     $start = RM::get("start", strftime("%Y-%m-%d", strtotime('-7 day')));
     $end = RM::get("end", strftime("%Y-%m-%d", strtotime('now')));
     $limit = RM::get("limit", 20);
     $page = RM::get("page", 1);
     $query = ["user_id" => $this->user->id];
     $ads = \Ad::all($query, ['title', 'image', 'category', '_id', 'live', 'created'], 'created', 'desc', $limit, $page);
     $count = \Ad::count($query);
     $in = Db::convertType(array_keys($ads));
     $query["created"] = Db::dateQuery($start, $end);
     $records = Db::query('Click', ['adid' => ['$in' => $in], 'is_bot' => false, 'created' => $query["created"]], ['adid']);
     $view->set("ads", $ads);
     $view->set("start", $start);
     $view->set("end", $end);
     $view->set(['count' => $count, 'page' => $page, 'limit' => $limit, 'dateQuery' => $query['created'], 'clicks' => Click::classify($records, 'adid')]);
 }
Exemplo n.º 4
0
 public function run()
 {
     $model = new Ad();
     //条件
     $criteria = new CDbCriteria();
     $title = trim(Yii::app()->request->getParam('title'));
     $position_id = intval(Yii::app()->request->getParam('position_id'));
     $title && $criteria->addColumnCondition(array('title' => $title));
     $position_id && $criteria->addColumnCondition(array('position_id', $position_id));
     $criteria->order = 't.id ASC';
     $count = $model->count($criteria);
     //分页
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     //查询
     $result = $model->findAll($criteria);
     $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages));
 }
Exemplo n.º 5
0
 /**
  * 广告管理
  *
  */
 public function actionIndex()
 {
     $model = new Ad();
     $criteria = new CDbCriteria();
     $condition = '1';
     $title = $this->_request->getParam('title');
     $position_id = $this->_request->getParam('positionID');
     $position_id && ($condition .= ' AND position_id =' . $position_id);
     $title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
     $criteria->condition = $condition;
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 13;
     $pageParams = $this->buildCondition($_GET, array('title'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     $this->render('ad_index', array('datalist' => $result, 'pagebar' => $pages));
 }
Exemplo n.º 6
0
        $or_filter .= " OR id LIKE '{$gs_description}'";
    }
    if ($or_filter != '') {
        $filter .= " AND (1=2 {$or_filter})";
    }
    if ($g_category != "any" && $g_category != '0') {
        $filter .= " AND (category=(SELECT r.id FROM category r WHERE r.slug='{$g_category}' LIMIT 1) OR category IN (SELECT r.id FROM category r WHERE r.parent=(SELECT s.id FROM category s WHERE s.slug='{$g_category}' LIMIT 1)))";
    }
    if ($g_region != "any" && $g_region != '0') {
        $filter .= " AND (region=(SELECT r.id FROM region r WHERE r.slug='{$g_region}' LIMIT 1) OR region IN (SELECT r.id FROM region r WHERE r.parent=(SELECT s.id FROM region s WHERE s.slug='{$g_region}' LIMIT 1)))";
    }
    if ($g_min_price != "") {
        $filter .= " AND ar>={$g_min_price}";
    }
    if ($g_max_price != "") {
        $filter .= " AND ar<={$g_max_price}";
    }
    if ($g_id > 0) {
        $filter .= " AND id='{$g_id}'";
    }
}
$rpp = 15;
//row per page
$tct = Ad::count(array(), $filter);
//total count
$pager_options = array('mode' => 'Sliding', 'perPage' => $rpp, 'delta' => 2, 'totalItems' => $tct);
$pager = @Pager::factory($pager_options);
list($from, $to) = $pager->getOffsetByPageId();
$ads = Ad::get_all(array(), $filter, $from - 1 . ", {$rpp}");
$curr_page = "home";
include "./templates/ad-list.php";
Exemplo n.º 7
0
 /**
  * 广告管理
  *
  */
 public function actionAd()
 {
     parent::_acl('ad_index');
     $model = new Ad();
     $criteria = new CDbCriteria();
     $condition = '1';
     $title = $this->_gets->getParam('title');
     $title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
     $criteria->condition = $condition;
     //$criteria->params = '';
     $criteria->order = 't.id DESC';
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 13;
     $pageParams = XUtils::buildCondition($_GET, array('title'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     $this->render('ad_index', array('datalist' => $result, 'pagebar' => $pages));
 }
Exemplo n.º 8
0
<?php

require_once '../bootstrap.php';
// require_once '../views/partials/header.php';
if (!Auth::checkUser()) {
    header("Location: /auth.login.php");
    exit;
}
$limit = 6;
$count = Ad::count();
$numPages = ceil($count / $limit);
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($page - 1) * 4;
$nextPage = $page + 1;
$prevPage = $page - 1;
$errors = [];
$items = Ad::paginate($limit, $offset);
?>
<html>
<head>
	<title>WoW Lister</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">	
<link rel="stylesheet" href="/css/main.css">

	<style>

	body {
		background-image: url("/img/auction.jpg");
		background-attachment: fixed;
	}
Exemplo n.º 9
0
<?php

require_once 'ads.index.php';
require_once '../bootstrap.php';
$ads = [];
$ads = Ad::all();
if (Input::has('id') && Input::get('id') >= 0) {
    $id = Input::get('id');
} else {
    $id = 0;
}
$idUp = $id + 1;
$idDown = $id - 1;
$lastId = Ad::count() - 1;
?>

<html>
<head>
    <title>Instrument Exchange</title>
    <!-- Bootstrap styling -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <!-- Custom styling for site -->
    <link rel="stylesheet" type="text/css" href="../css/main.css">
</head>
<body>
    <? include "../views/partials/navbar.php"; ?>


    <div class="container">

        <div class="row listing-wrapper">
Exemplo n.º 10
0
    $d = (int) $_GET['d'];
    if ($d > 0) {
        Ad::delete($d);
    }
}
if (isset($_GET['o'])) {
    $o = (int) $_GET['o'];
    $r = (int) $_GET['r'];
    if ($r != 0) {
        $r = 1;
    }
    $a['sponsored'] = $r;
    $a['sponsoredon'] = $r = 0 ? '' : date('Y-m-d', time());
    Ad::update($o, $a);
}
$tct = Ad::count();
//total count
$rpp = 10;
//row per page
$pager_options = array('mode' => 'Sliding', 'perPage' => $rpp, 'delta' => 2, 'totalItems' => $tct, 'excludeVars' => array('o', 'r', 'd', 't', 'e'));
$pager = @Pager::factory($pager_options);
list($from, $to) = $pager->getOffsetByPageId();
$ads = Ad::get_all(array(), '', $from - 1 . ", {$rpp}");
include "page-header.php";
?>

<div id="wrapper">
	
	<?php 
include "page-left.php";
?>
 /**
  * Returns the count of the user's favourite ads 
  *
  * @param 	int 	$user_id	The user's id.
  * @return 	int					Count of the favourite ads.
  */
 public static function count($user_id)
 {
     global $db;
     $filter = sprintf("active=1 AND id IN (SELECT f.ad_id FROM " . static::$table_name . " f WHERE f.user_id=%d)", $user_id);
     return Ad::count(array(), $filter);
 }
Exemplo n.º 12
0
include "{$docroot}/db-ad-review.php";
include "{$docroot}/db-favourite.php";
include "{$docroot}/db-user-review.php";
include "{$docroot}/db-report.php";
$db = new db();
if (!$db->connect()) {
    exit(mysql_error());
}
$categories = Category::get_tree();
$regions = Region::get_tree();
$statics = StaticContent::get_all(array(), 'id>6');
//counters
$today = date("Y-m-d", time());
$ct_fresh = Ad::count(array('active' => 1), "lastmodified>='{$today}'");
$ct_all = Ad::count(array('active' => 1));
$ct_expirys = Ad::count(array('active' => 1, "DATEDIFF(expiry,'{$today}')" => 0));
//menu and breadcumb
$menu = User::get_menu();
$current_script_name = basename($_SERVER['SCRIPT_NAME']);
if (strpos($current_script_name, '-') > 0) {
    $current_page = explode('-', $current_script_name, 2);
    if (isset($current_page[2])) {
        $current_page[1] .= '-' . $current_page[2];
    }
    //php 5.3.5 bug?? workaround
    $subpage_name = explode('.', $current_page[1]);
    $subpage_name = str_replace('-', ' ', $subpage_name[0]);
    if ($current_page[0] == 'static') {
        $current_page[0] = 'static content';
    }
    $current_group_page = array('name' => ucwords($current_page[0]), 'script' => $menu[ucwords($current_page[0])][reset(array_keys($menu[ucwords($current_page[0])]))]);
Exemplo n.º 13
0
 /**
  * @before _secure
  */
 public function manage()
 {
     $this->seo(['title' => 'Campaign: List', 'description' => 'Manage campaigns']);
     $view = $this->getActionView();
     $campaigns = [];
     $page = RM::get("page", 1);
     $limit = RM::get("limit", 10);
     $property = RM::get("property");
     $value = RM::get("value");
     switch (RM::get("sort")) {
         case 'trending':
             $start = RM::get("start", date("Y-m-d", strtotime('now')));
             $end = RM::get("end", date("Y-m-d", strtotime('now')));
             $q = ['start' => $start, 'end' => $end];
             $view->set($q);
             // Only find the ads for this organizations
             $allAds = \Ad::all(['org_id' => $this->org->_id], ['_id']);
             $in = Db::convertType(array_keys($allAds));
             $clickCol = Db::collection('Click');
             $match = ['created' => Db::dateQuery($start, $end), 'is_bot' => false, 'adid' => ['$in' => $in]];
             $records = $clickCol->aggregate([['$match' => $match], ['$project' => ['adid' => 1, '_id' => 0]], ['$group' => ['_id' => '$adid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => (int) $limit]]);
             foreach ($records as $r) {
                 $arr = Utils::toArray($r);
                 $id = Utils::getMongoID($arr['_id']);
                 $campaigns[] = Ad::first(["id = ?" => $id]);
             }
             $count = $limit;
             break;
         default:
             $query = ["org_id = ?" => $this->org->id];
             if (in_array($property, ["user_id", "live", "id"])) {
                 $query[$property] = $value;
             } else {
                 if (in_array($property, ["url", "title"])) {
                     $query[$property] = Utils::mongoRegex(preg_quote($value));
                 }
             }
             $campaigns = \Ad::all($query, [], 'created', 'desc', $limit, $page);
             $count = \Ad::count($query);
             break;
     }
     $categories = \Category::all(['org_id' => $this->org->_id], ['_id', 'name']);
     $active = \Ad::count(["org_id = ?" => $this->org->id, "live = ?" => 1]);
     $inactive = \Ad::count(["org_id = ?" => $this->org->id, "live = ?" => 0]);
     $view->set("campaigns", $campaigns)->set("count", $count)->set("active", $active)->set("inactive", $inactive)->set("limit", $limit)->set("page", $page)->set("property", $property)->set("value", $value)->set("categories", $categories);
 }
Exemplo n.º 14
0
            $type = 10;
            break;
    }
} else {
    $type = 'all';
}
if (Input::has('page')) {
    $page = Input::get('page');
} else {
    $page = 1;
}
$items_per_page = 4;
if (isset($catString)) {
    $totalListings = Ad::countPerCat($type);
} else {
    $totalListings = Ad::count();
}
$lastPage = ceil($totalListings / $items_per_page);
if ($page > $lastPage) {
    $page = $lastPage;
}
if ($page < 1) {
    $page = 1;
}
$offset = ($page - 1) * $items_per_page;
if (isset($type) && $type != 'all') {
    $ads = Ad::pagerWithCat($offset, $items_per_page, $type);
} else {
    $ads = Ad::pager($offset, $items_per_page);
}
// var_dump($ads);