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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * @return Am_Query
  */
 protected function _getBaseQuery($joinConditions = "")
 {
     if ($joinConditions) {
         $joinConditions = "(" . $joinConditions . ") AND ";
     }
     $q = new Am_Query($this, 'r');
     $q->clearFields();
     $q->addField('DISTINCT r.resource_id', 'resource_id');
     $q->addField('resource_type', 'resource_type');
     $q->addField("fn", 'fn');
     $q->addField("id", 'fn_id');
     $q->leftJoin("?_access_cache", "c", "\n                    {$joinConditions} \n                    (((c.fn = r.fn) AND (c.id = r.id)) OR (r.fn='product_category_id' AND r.id=-1)) \n                    AND (\n                            (c.status='active' AND r.start_days IS NULL AND r.stop_days IS NULL AND r.start_payments = 0) \n                            OR\n                            (c.status='active' AND c.days BETWEEN IFNULL(r.start_days,0) AND IFNULL(r.stop_days, 90000) AND c.payments_count >= IFNULL(r.start_payments,0)) \n                            OR\n                            (c.days >= IFNULL(r.start_days,0) AND r.stop_days = -1 AND c.payments_count >= IFNULL(r.start_payments,0)) \n                       )");
     // is available if free, or if user has equal subscription record in access_cache
     $q->addWhere("(r.fn IN ('free', 'free_without_login') OR c.user_id IS NOT NULL)");
     $q->addOrderRaw("(SELECT ras.sort_order\n                      FROM ?_resource_access_sort ras\n                      WHERE ras.resource_id=r.resource_id AND ras.resource_type=r.resource_type \n                      LIMIT 1), r.resource_id, r.resource_type");
     return $q;
 }