public function createGrid() { $this->view->headScript()->appendFile(REL_ROOT_URL . "/application/default/views/public/js/jquery/jquery.json.js"); $this->view->headScript()->appendScript($this->getJs()); $table = $this->getDi()->savedFormTable; $ds = new Am_Query($table); $ds->addWhere('`type` in (?a)', array_keys($table->getTypeDefs())); $ds->addOrderRaw("`type`='signup' DESC"); $grid = new Am_Grid_Editable('_s', ___("Forms Editor"), $ds, $this->_request, $this->view); $grid->setForm(array($this, 'createForm')); $grid->setRecordTitle(' '); //$grid->addGridField(new Am_Grid_Field('saved_form_id', '#', true, '', null, '5%')); $grid->addGridField(SavedForm::D_SIGNUP, ___('Default Signup'), false)->setWidth('5%')->setRenderFunction(array($this, 'renderDefault')); $grid->addGridField(SavedForm::D_MEMBER, ___('Default for Members'), false)->setWidth('5%')->setRenderFunction(array($this, 'renderDefault')); $existingTypes = $this->getDi()->savedFormTable->getExistingTypes(); $grid->actionGet('edit')->setTarget('_top'); $grid->actionDelete('insert'); foreach ($this->getDi()->savedFormTable->getTypeDefs() as $type => $typeDef) { if (!empty($typeDef['isSingle']) && in_array($type, $existingTypes)) { continue; } $grid->actionAdd(new Am_Grid_Action_Insert('insert-' . $type))->addUrlParam('type', $type)->setTitle(___('New %s', $typeDef['title'])); } $grid->addCallback(Am_Grid_Editable::CB_BEFORE_SAVE, array($this, 'beforeSave')); $grid->addGridField(new Am_Grid_Field('type', ___('Type'))); $grid->addGridField(new Am_Grid_Field('title', ___('Title'))); $grid->addGridField(new Am_Grid_Field('comment', ___('Comment'))); $grid->addGridField(new Am_Grid_Field('code', ___('Code'))); $grid->addGridField(new Am_Grid_Field('url', ___('URL')))->setRenderFunction(array($this, 'renderUrl')); $grid->actionGet('delete')->setIsAvailableCallback(create_function('$record', 'return $record->canDelete();')); return $grid; }
protected function createAdapter() { $q = new Am_Query(Am_Di::getInstance()->newsletterListTable); $q->leftJoin('?_newsletter_user_subscription', 's', 's.list_id = t.list_id AND s.is_active > 0'); $q->addField('COUNT(s.list_id)', 'subscribed_users'); return $q; }
/** @return Am_Query */ public function getQuery() { $q = new Am_Query($this->getDi()->helpdeskMessageTable, 'hm'); $q->clearFields(); $q->addField('COUNT(message_id)', 'cnt'); $q->addWhere('admin_id IS NULL'); return $q; }
/** * @return Am_Query $query; */ function getMainDataSource() { $ds = new Am_Query($this->getDi()->invoicePaymentTable); $ds->leftJoin('?_user', 'u', 't.user_id = u.user_id')->leftJoin('?_data', 'user_country', 't.invoice_id = user_country.id and `table` = "invoice" and `key`="tax_user_country"')->leftJoin('?_invoice_refund', 'refund', 't.invoice_payment_id = refund.invoice_payment_id')->leftJoin('?_invoice', 'invoice', 't.invoice_id = invoice.invoice_id')->addField('if(user_country.value is null, if(u.country is null, "", u.country), user_country.value)', 'country')->addField('invoice.tax_rate')->addField('round(sum(if(refund.amount, t.amount-refund.amount, t.amount)/t.base_currency_multi),2)', 'sales_amount')->addField('round(sum(if(refund.amount, (t.amount-refund.amount)*if(t.tax, t.tax, 0)/t.amount, if(t.tax, t.tax, 0))/t.base_currency_multi),2)', 'tax_amount')->addField('round(sum(if(refund.amount, (t.amount-refund.amount) - (t.amount-refund.amount)*if(t.tax, t.tax, 0)/t.amount, t.amount-if(t.tax, t.tax, 0))/t.base_currency_multi),2)', 'sales_without_tax_amount')->addField('concat(if(country is null, "", country), "-", if(invoice.tax_rate is null, "", invoice.tax_rate))', 'country_rate'); $ds->groupBy('country_rate', ''); $ds->addOrder('country'); return $ds; }
/** @return Am_Query */ public function getQuery() { $q = new Am_Query(new AffCommissionTable(), 'cl'); $q->clearFields(); $q->addField("SUM(IF(cl.record_type='commission', cl.amount, -cl.amount)) AS commission"); if ($this->aff_id) { $q->addWhere("aff_id = ?d", $this->aff_id); } return $q; }
/** @return Am_Query */ public function getQuery() { $q = new Am_Query(new InvoicePaymentTable(), 'p'); $q->clearFields(); foreach ($this->getPaysystems() as $k => $ps) { $ps = $q->escape($ps); $q->addField("ROUND(SUM(IF(p.paysys_id={$ps}, p.amount/p.base_currency_multi, 0)),2)\n", 'amt_' . $k); } return $q; }
function renderInvoiceCommissions(Invoice $invoice, Am_View $view) { $query = new Am_Query($this->getDi()->affCommissionTable); $query->leftJoin('?_invoice', 'i', 'i.invoice_id=t.invoice_id')->leftJoin('?_user', 'a', 't.aff_id=a.user_id')->leftJoin('?_product', 'p', 't.product_id=p.product_id')->addField('CONCAT(a.login, \' (\', a.name_f, \' \', a.name_l,\') #\', a.user_id)', 'aff_name')->addField('p.title', 'product_title')->addWhere('t.invoice_id=?', $invoice->pk())->leftJoin('?_aff_payout_detail', 'apd', 't.payout_detail_id=apd.payout_detail_id')->leftJoin('?_aff_payout', 'ap', 'ap.payout_id=apd.payout_id')->addField('ap.date', 'payout_date')->addField('ap.payout_id')->addField('apd.is_paid')->setOrder('commission_id', 'desc'); $items = $query->selectAllRecords(); $view->comm_items = $items; $view->invoice = $invoice; $view->has_tiers = $this->getDi()->affCommissionRuleTable->getMaxTier(); return $view->render('blocks/admin-user-invoice-details.phtml'); }
/** @return Am_Query */ public function getQuery() { $q = new Am_Query(new AffCommissionTable(), 'cl'); $q->clearFields(); $q->addField("COUNT(DISTINCT invoice_payment_id) AS sales"); if ($this->aff_id) { $q->addWhere("aff_id = ?d", $this->aff_id); } return $q; }
function createGrid($id, $title) { $ds = new Am_Query($this->getDi()->banTable); $ds->addWhere("`type` = ?", $id); $g = new Am_Grid_Editable('_' . $id, ___("Disallow new Signups by %s", $title), $ds, $this->_request, $this->view); $g->setForm(array($this, 'createForm')); $g->addGridField("value", ___("Locked Value")); $g->addGridField("comment", ___("Comment")); $g->addCallback(Am_Grid_ReadOnly::CB_RENDER_TABLE, array($this, 'renderConfig')); return $g; }
function createGrid($id, $title) { $ds = new Am_Query($this->getDi()->banTable); $ds->addWhere("`type` = ?", $id); $g = new Am_Grid_Editable('_' . $id, ___('Disallow new Signups by %s', $title), $ds, $this->_request, $this->view); $g->setPermissionId(Am_Auth_Admin::PERM_BAN); $g->setForm(array($this, 'createForm')); $g->addField('value', ___('Locked Value')); $g->addField('comment', ___('Comment')); $g->addCallback(Am_Grid_ReadOnly::CB_RENDER_TABLE, array($this, 'renderConfig')); return $g; }
function createGrid() { $query = new Am_Query($this->getDi()->fileDownloadTable); $query->leftJoin('?_file', 'f', 'f.file_id=t.file_id')->addField('f.title', 'title')->addWhere('user_id=?', $this->getParam('user_id')); $grid = new Am_Grid_Editable('_file_download', ___("File Downloads"), $query, $this->_request, $this->view); $grid->setPermissionId(Am_Auth_Admin::PERM_LOGS_DOWNLOAD); $grid->actionsClear(); $grid->actionAdd(new Am_Grid_Action_Delete()); $grid->actionAdd(new Am_Grid_Action_Group_Delete()); $grid->addField(new Am_Grid_Field_Date('dattm', ___('Date/Time'))); $grid->addField('remote_addr', ___('IP')); $grid->addField('title', ___('File')); return $grid; }
public function createGrid() { $ds = new Am_Query($this->getDi()->helpdeskCategoryTable); $ds->leftJoin('?_admin', 'a', 't.owner_id=a.admin_id')->addField("CONCAT(a.login, ' (',a.name_f, ' ', a.name_l, ')')", 'owner'); $ds->setOrder('sort_order'); $grid = new Am_Grid_Editable('_helpdesk_category', ___("Ticket Categories"), $ds, $this->_request, $this->view); $grid->addField(new Am_Grid_Field('title', ___('Title'), true, '', null, '50%')); $grid->addField(new Am_Grid_Field('owner_id', ___('Owner'), true, '', array($this, 'renderOwner'))); $grid->addField(new Am_Grid_Field_IsDisabled()); $grid->setForm('Am_Form_Admin_HelpdeskCategory'); $grid->addCallback(Am_Grid_Editable::CB_BEFORE_SAVE, array($this, 'beforeSave')); $grid->setPermissionId(Bootstrap_Helpdesk::ADMIN_PERM_CATEGORY); $grid->actionAdd(new Am_Grid_Action_Sort_HelpdeskCategory()); return $grid; }
function _getWhere(Am_Query $db) { $a = $db->getAlias(); switch ($this->type) { case 'any': $c = ''; break; case 'paid': $c = 'AND payout_detail_id IS NOT NULL'; break; case 'not-paid': $c = 'AND payout_detail_id IS NULL'; break; } return "EXISTS\n (SELECT * FROM ?_aff_commission\n WHERE aff_id={$a}.user_id\n {$c})"; }
public function renderOut(&$out) { $titles = array(); $this->ds->clearFields()->clearOrder()->toggleAutoGroupBy(false); foreach ($this->fields as $field) { /* @var $field Am_Grid_Field */ $name = $field->getFieldName(); $stm = $this->stms[$name]; $this->ds->addField(sprintf("SUM({$stm})", $name), '_' . $name); $titles['_' . $name] = $field->getFieldTitle(); } $totals = array(); foreach (Am_Di::getInstance()->db->selectRow($this->ds->getSql()) as $key => $val) { $totals[] = sprintf('%s %s: <strong>%s</strong>', ___('Total'), $titles[$key], Am_Currency::render($val)); } $count = count($this->grid->getFields()); $tr = sprintf('<tr><td class="grid-total" colspan="%d">%s</td></td>', $count, implode(',', $totals)); $out = preg_replace('|(<tr>\\s*<th>)|', str_replace('$', '\\$', $tr) . '\\1', $out); }
function viewAction() { // display payouts list date | method | total | paid | $id = $this->getInt('payout_id'); if (!$id) { throw new Am_Exception_InputError("Not payout_id passed"); } $ds = new Am_Query($this->getDi()->affPayoutDetailTable); $ds->leftJoin('?_aff_payout', 'p', 'p.payout_id=t.payout_id'); $ds->leftJoin('?_user', 'u', 't.aff_id=u.user_id'); $ds->addField('u.*'); $ds->addField('p.type', 'type'); $ds->addWhere('t.payout_id=?d', $id); $grid = new Am_Grid_Editable('_d', ___("Payout %d Details", $id), $ds, $this->_request, $this->view); $grid->setPermissionId('affiliates'); $grid->addCallback(Am_Grid_Editable::CB_RENDER_TABLE, array($this, 'addBackLink')); $grid->addField('email', ___('E-Mail')); $grid->addField('name_f', ___('First Name')); $grid->addField('name_l', ___('Last Name')); $grid->addField('type', ___('Payout Method')); $grid->addField('amount', ___('Amount')); // $grid->addField('receipt_id', ___('Receipt Id')); $grid->addField('is_paid', ___('Is Paid?')); $grid->addField(new Am_Grid_Field_Expandable('_details', ___('Payout Details')))->setGetFunction(array($this, 'getPayoutDetails')); $grid->actionsClear(); //$grid->actionAdd(new Am_Grid_Action_LiveEdit('receipt_id')); $grid->actionAdd(new Am_Grid_Action_PayoutMarkPaid('mark_paid', ___("Mark Paid"))); $grid->actionAdd(new Am_Grid_Action_PayoutMarkNotPaid('mark_notpaid', ___("Mark NOT Paid"))); $grid->runWithLayout(); // detail payout records date | method | paid | receipt_id | aff. payout fields }
public function gridAction() { $prefix = $this->getRequest()->getParam('prefix'); if (!$prefix) { throw new Am_Exception_InputError('prefix is undefined'); } if (!$this->getDi()->uploadAcl->checkPermission($prefix, Am_Upload_Acl::ACCESS_LIST, $this->getDi()->authAdmin->getUser())) { throw new Am_Exception_AccessDenied(); } $ds = new Am_Query($this->getDi()->uploadTable); $ds->addWhere('prefix=?', $prefix); $grid = new Am_Grid_Editable_Uploads('_files', 'Files', $ds, $this->getRequest(), $this->view); $grid->setPermissionId('grid_content'); $grid->addField(new Am_Grid_Field('name', 'Name', true))->setRenderFunction(array($this, 'renderName')); $grid->addField(new Am_Grid_Field('desc', 'Description', true)); $grid->actionsClear(); $grid->actionAdd(new Am_Grid_Action_LiveEdit('desc')); $grid->addCallback(Am_Grid_ReadOnly::CB_RENDER_STATIC, array($this, 'addJs')); $grid->isAjax(false); $response = $grid->run(); $response->sendHeaders(); $response->sendResponse(); }
public function createGrid() { $ds = new Am_Query($this->getDi()->countryTable); $ds->addField('ABS(tag)', 'tag_abs'); $ds->setOrderRaw('tag_abs desc, title'); $grid = new Am_Grid_Editable('_c', ___("Browse Countries"), $ds, $this->_request, $this->view); $grid->setPermissionId(Am_Auth_Admin::PERM_COUNTRY_STATE); $grid->addField(new Am_Grid_Field('tag_abs', ___('Sort Order'), true, null, null, '10%')); $grid->addField(new Am_Grid_Field('title', ___('Title'), true)); $grid->addField(new Am_Grid_Field('country', ___('Code'), true)); $grid->setForm(array($this, 'createForm')); $grid->actionAdd(new Am_Grid_Action_Url_Country('states', ___('Edit States'), '__ROOT__/admin-states/?country=__COUNTRY__'))->setTarget('_top'); $grid->actionDelete('delete'); $grid->actionDelete('insert'); $grid->addCallback(Am_Grid_ReadOnly::CB_TR_ATTRIBS, array($this, 'getTrAttribs')); $grid->addCallback(Am_Grid_Editable::CB_VALUES_TO_FORM, array($this, 'valuesToForm')); $grid->addCallback(Am_Grid_Editable::CB_VALUES_FROM_FORM, array($this, 'valuesFromForm')); $grid->actionAdd(new Am_Grid_Action_LiveEdit('title')); $grid->actionAdd(new Am_Grid_Action_Group_CountryEnable(false)); $grid->actionAdd(new Am_Grid_Action_Group_CountryEnable(true)); $grid->setFilter(new Am_Grid_Filter_Text(___('Filter by Counrty Title'), array('title' => 'LIKE'))); return $grid; }
public function getProductsQuery(ProductCategory $category = null) { if (!$this->query) { $scope = false; if ($root = $this->getModule()->getConfig('category_id', null)) { $scope = array_merge($this->getDi()->productCategoryTable->getSubCategoryIds($root), array($root)); } $this->query = $this->getDi()->productTable->createQuery($category ? $category->product_category_id : null, $this->getHiddenCatCodes(), $scope); if ($user = $this->getDi()->auth->getUser()) { $products = $this->getDi()->productTable->getVisible(); $filtered = $this->getDi()->productTable->filterProducts($products, $user->getActiveProductIds(), $user->getExpiredProductIds(), true); $hide_pids = array_diff(array_map(function ($p) { return $p->pk(); }, $products), array_map(function ($p) { return $p->pk(); }, $filtered)); if (!empty($hide_pids)) { $this->query->addWhere('p.product_id not in (?a)', $hide_pids); } } } return $this->query; }
function addDefaultSort(Am_Query $q) { $a = $q->getAlias(); $type = $this->createRecord()->getAccessType(); $q->leftJoin('?_resource_access_sort', "ras", "{$a}.{$this->_key} = ras.resource_id AND ras.resource_type='{$type}'"); $q->addField('ras.sort_order', '_sort_order'); $q->setOrder('_sort_order'); }
public function createGrid() { $ds = new Am_Query($this->getDi()->productTable); $ds->addWhere('t.is_archived = ?', 0); $ds->addOrder('sort_order')->addOrder('title'); $grid = new Am_Grid_Editable('_product', ___("Products"), $ds, $this->_request, $this->view); $grid->setRecordTitle(___('Product')); $grid->actionAdd(new Am_Grid_Action_Group_ProductEnable(false)); $grid->actionAdd(new Am_Grid_Action_Group_ProductEnable(true)); $grid->actionAdd(new Am_Grid_Action_Group_ProductAssignCategory(false)); $grid->actionAdd(new Am_Grid_Action_Group_ProductAssignCategory(true)); $grid->actionAdd(new Am_Grid_Action_Group_ChangeOrder())->setTitle(___('Change Order')); $grid->actionAdd(new Am_Grid_Action_Group_Archive(true)); $grid->addField(new Am_Grid_Field('product_id', '#', true, '', null, '1%')); $grid->addField(new Am_Grid_Field('title', ___('Title'), true, '', null, '50%'))->setGetFunction(function ($r, $g, $f) { return strip_tags($r->{$f}); }); if ($this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_product_product_category")) { $grid->addField(new Am_Grid_Field('pgroup', ___('Product Categories'), false))->setRenderFunction(array($this, 'renderPGroup')); } $grid->addField(new Am_Grid_Field('terms', ___('Billing Terms'), false))->setRenderFunction(array($this, 'renderTerms')); if ($this->getDi()->plugins_tax->getEnabled()) { $grid->addField(new Am_Grid_Field('tax_group', ___('Tax'))); $grid->actionAdd(new Am_Grid_Action_LiveCheckbox('tax_group'))->setValue(IProduct::ALL_TAX)->setEmptyValue(IProduct::NO_TAX); } $grid->actionGet('edit')->setTarget('_top'); $grid->actionDelete('delete'); $grid->actionAdd(new Am_Grid_Action_Archive('delete', 1)); $grid->actionAdd(new Am_Grid_Action_LiveEdit('title')); $grid->actionAdd(new Am_Grid_Action_Sort_Product()); $grid->setFormValueCallback('start_date', array('RECORD', 'getStartDate'), array('RECORD', 'setStartDate')); $grid->setFormValueCallback('require_other', array('RECORD', 'unserializeList'), array('RECORD', 'serializeList')); $grid->setFormValueCallback('prevent_if_other', array('RECORD', 'unserializeList'), array('RECORD', 'serializeList')); $grid->addCallback(Am_Grid_Editable::CB_AFTER_SAVE, array($this, 'afterSave')); $grid->addCallback(Am_Grid_Editable::CB_VALUES_TO_FORM, array($this, 'valuesToForm')); $grid->addCallback(Am_Grid_ReadOnly::CB_TR_ATTRIBS, array($this, 'getTrAttribs')); $grid->setForm(array($this, 'createForm')); $grid->setFilter(new Am_Grid_Filter_Product()); $grid->setEventId('gridProduct'); $grid->actionAdd(new Am_Grid_Action_Url('categories', ___('Edit Categories'), REL_ROOT_URL . '/admin-product-categories'))->setType(Am_Grid_Action_Abstract::NORECORD)->setTarget('_top')->setCssClass('link')->setPrivilegeId('edit'); $grid->actionAdd(new Am_Grid_Action_Url('upgrades', ___('Manage Product Upgrade Paths'), REL_ROOT_URL . '/admin-products/upgrades'))->setType(Am_Grid_Action_Abstract::NORECORD)->setTarget('_top')->setCssClass('link')->setPrivilegeId('edit'); $grid->actionAdd(new Am_Grid_Action_CopyProduct())->setTarget('_top'); $ar_count = $this->getArchivedCount(1); if ($ar_count) { $grid->actionAdd(new Am_Grid_Action_Url('archived', ___("Archived products") . " ({$ar_count})", REL_ROOT_URL . '/admin-products/archived'))->setType(Am_Grid_Action_Abstract::NORECORD)->setTarget('_top')->setCssClass('link')->setPrivilegeId('browse'); } return $grid; }
public function createAdminLog() { $ds = new Am_Query($this->getDi()->adminLogTable); $ds->setOrder('dattm', 'desc'); $g = new Am_Grid_ReadOnly('_admin', ___('Admin Log'), $ds, $this->getRequest(), $this->view); $g->setPermissionId(Am_Auth_Admin::PERM_LOGS_ADMIN); $g->addField(new Am_Grid_Field_Date('dattm', ___('Date/Time'), true)); $g->addField(new Am_Grid_Field('admin_login', ___('Admin'), true))->addDecorator(new Am_Grid_Field_Decorator_Link(REL_ROOT_URL . "/admin-admins?_admin_a=edit&_admin_id={admin_id}", '_top')); $g->addField(new Am_Grid_Field('ip', ___('IP'), true, '', null, '10%')); $g->addField(new Am_Grid_Field('message', ___('Message'))); $g->addField(new Am_Grid_Field('record', ___('Record')))->setRenderFunction(array($this, 'renderRec')); $g->setFilter(new Am_Grid_Filter_AdminLog()); return $g; }
protected function getQuery() { $q = new Am_Query($this->getDi()->uploadTable); $q->addOrder('name'); if ($this->prefix) { $q->addWhere('prefix=?', $this->prefix); } return $q; }
/** * return query object with category filter applied if specified * if parameters === 0, it selects products not assigned to any categories * if parameter === null, it selects products regardless of categories * @param int $product_category_id * @param bool $include_hidden Include products from hidden categories. * @return Am_Query */ function createQuery($product_category_id = null, $include_hidden = true) { $q = new Am_Query($this, 'p'); $q->addOrderRaw('0+p.sort_order')->addOrder('title'); $q->addWhere('p.is_disabled=0'); if ($product_category_id > 0) { $q->innerJoin('?_product_product_category', 'ppc', 'ppc.product_id = p.product_id AND ppc.product_category_id=' . intval($product_category_id)); } elseif ((string) $product_category_id === '0') { $q->leftJoin('?_product_product_category', 'ppc', 'ppc.product_id = p.product_id')->addHaving('count(ppc.product_category_id)=0'); } elseif (!$include_hidden) { $q->leftJoin('?_product_product_category', 'ppc', 'ppc.product_id = p.product_id')->leftJoin('?_product_category', 'pc', 'pc.product_category_id = ppc.product_category_id')->addHaving('sum(if(pc.code>"", 1, 0)) =0'); } return $q; }
public function autocompleteAction() { $term = '%' . $this->getParam('term') . '%'; $exclude = $this->getInt('exclude'); if (!$term) { return null; } $q = new Am_Query($this->getDi()->userTable); $q->addWhere('((t.login LIKE ?) OR (t.email LIKE ?) OR (t.name_f LIKE ?) OR (t.name_l LIKE ?))', $term, $term, $term, $term); if ($exclude) { $q->addWhere('user_id<>?', $exclude); } $q->addWhere('is_affiliate>?', 0); $qq = $q->query(0, 10); $ret = array(); while ($r = $this->getDi()->db->fetchRow($qq)) { $ret[] = array('label' => sprintf('%s / "%s" <%s>', $r['login'], $r['name_f'] . ' ' . $r['name_l'], $r['email']), 'value' => $r['login']); } if ($q->getFoundRows() > 10) { $ret[] = array('label' => sprintf("... %d more rows found ...", $q->getFoundRows() - 10), 'value' => null); } $this->ajaxResponse($ret); }
public function deleteAction() { $this->session->unsetAll(); $this->session->proccessed = 0; $this->session->lastUserId = 0; $query = new Am_Query($this->getDi()->userTable); $this->session->total = $query->getFoundRows(); $this->session->params = array(); $this->session->params['import-id'] = $this->getRequest()->getParam('id'); if (!$this->session->params['import-id']) { throw new Am_Exception_InputError('import-id is undefined'); } $this->sendDelRedirect(); }
protected function createDs() { $query = new Am_Query(Am_Di::getInstance()->affBannerTable); $query->setOrder('sort_order'); return $query; }
protected function createDs() { $query = new Am_Query(Am_Di::getInstance()->affBannerTable); $query->addWhere('type=?', $this->affBannerType); return $query; }
public function createGrid() { $ds = new Am_Query($this->getDi()->notificationTable); $ds->leftJoin('?_notification_click', 'nc', 't.notification_id=nc.notification_id')->addField('COUNT(nc.notification_click_id)', 'cnt')->addOrder('sort_order'); $grid = new Am_Grid_Editable('_notification', ___('Notifications'), $ds, $this->_request, $this->view, $this->getDi()); $grid->setPermissionId(Am_Plugin_Notification::ADMIN_PERM_ID); $grid->addField('content', ___('Content')); $grid->addField('url', ___('Link')); $grid->addField(new Am_Grid_Field_Date('begin', ___('Begin')))->setFormatDate(); $grid->addField(new Am_Grid_Field_Date('expire', ___('Expire')))->setFormatDate(); $grid->addField('cnt', ___('Clicks'), true, null, null, '1%')->setRenderFunction(array($this, 'renderClicks')); $grid->addField(new Am_Grid_Field_IsDisabled()); $grid->setForm(array($this, 'createForm')); $grid->addCallback(Am_Grid_Editable::CB_VALUES_TO_FORM, array($this, 'valuesToForm')); $grid->addCallback(Am_Grid_Editable::CB_VALUES_FROM_FORM, array($this, 'valuesFromForm')); $grid->actionAdd(new Am_Grid_Action_NotificationPreview('preview', ___('Preview')))->setTarget('_top'); $grid->actionAdd(new Am_Grid_Action_Group_Delete()); $grid->actionAdd(new Am_Grid_Action_Sort_Notification()); $grid->addCallback(Am_Grid_ReadOnly::CB_RENDER_STATIC, array($this, 'renderStatic')); $grid->setFilter(new Am_Grid_Filter_Text(___('Filter by Content or Link'), array('content' => 'LIKE', 'url' => 'LIKE'))); $grid->setRecordTitle(___('Notification')); return $grid; }
public function batchProcess(&$context, Am_BatchProcessor $batch) { @(list($step, $start) = explode('-', $context)); $pageCount = 30; switch ($step) { case 0: $q = new Am_Query($this->getTable()); $count = 0; $updated = array(); foreach ($q->selectPageRecords($start / $pageCount, $pageCount) as $r) { $count++; if (!$this->canUpdate($r)) { continue; } /* @var $r Am_Record */ $user = $this->_table->findAmember($r); if (!$user) { // no such records in aMember, disable user record ? $this->_table->disableRecord($r, $this->calculateGroups(null, true)); } else { $updated[] = $user->user_id; $this->getTable()->updateFromAmember($r, $user, $this->calculateGroups($user, true)); $pass = $this->getDi()->savedPassTable->findSaved($user, $this->getPasswordFormat()); if ($pass) { $this->getTable()->updatePassword($r, $pass); } } } if (!$count) { $step++; $context = "{$step}-0"; } else { $store = array(); foreach ($updated as $v) { $store[] = $v; } $this->getDi()->storeRebuild->setArray($this->_rebuildName, $this->_sessionId, $store, '+3 hour'); $start += $count; $context = "{$step}-{$start}"; } break; case 1: /// now select aMember users not exists in plugin db $count = 0; $db = $this->getDi()->db; $r = $db->queryResultOnly("SELECT t.* from ?_user t left join ?_store_rebuild s on s.user_id = t.user_id and s.rebuild_name = ? and s.session_id = ? \n WHERE s.user_id is null LIMIT ?d , ?d", $this->_rebuildName, $this->_sessionId, $start, $pageCount); while ($row = $db->fetchRow($r)) { $records[] = $this->getDi()->userTable->createRecord($row); } foreach ($records as $user) { $count++; /* @var $user User */ $this->onSubscriptionChanged(new Am_Event_SubscriptionChanged($user, array(), array())); } if (!$count) { $context = null; return true; } $start += $count; $context = "{$step}-{$start}"; break; default: throw new Am_Exception_InputError(___('Wrong step')); } }
public function buildQuery(Am_Query $q, $pointField, Am_Report_Date $report) { $f = $this->getSqlExpr($pointField); $q->addField($f, Am_Report_Abstract::POINT_FLD); $q->groupBy(Am_Report_Abstract::POINT_FLD, ""); }