本文整理汇总了PHP中Zend_Db_Select::columns方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Select::columns方法的具体用法?PHP Zend_Db_Select::columns怎么用?PHP Zend_Db_Select::columns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Select
的用法示例。
在下文中一共展示了Zend_Db_Select::columns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCollection
/**
* Retrieve cms page collection array
*
* @param unknown_type $storeId
* @return Zend_Db_Statement_Interface
*/
public function getCollection($storeId, $includeEEHierarchy = false)
{
$this->_select = $this->_getWriteAdapter()->select();
$this->_select->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName(), 'DATE(main_table.update_time) as updated_at'))->join(array('store_table' => $this->getTable('cms/page_store')), 'main_table.page_id=store_table.page_id', array())->where('main_table.is_active=1')->where('store_table.store_id IN(?)', array(0, $storeId));
if ($includeEEHierarchy) {
$this->_addHierarchy();
} else {
$this->_select->columns('main_table.identifier as url');
}
// die((string)$this->_select);
$query = $this->_getWriteAdapter()->query($this->_select);
return $query;
}
示例2: _saveCustomerInfo
/**
* Saving information about customer
*
* @param Mage_Log_Model_Visitor $visitor
*
* @return Mage_Log_Model_Resource_Visitor
*/
protected function _saveCustomerInfo($visitor)
{
$adapter = $this->_getWriteAdapter();
if ($visitor->getDoCustomerLogout() && ($logId = $visitor->getCustomerLogId())) {
$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_read');
$select = new Zend_Db_Select($connection);
$select->from($resource->getTableName('log/customer'));
$select->reset(Zend_Db_Select::COLUMNS);
$select->columns('login_at');
$select->where('log_id = ?', $logId);
$loginAt = $connection->fetchOne($select);
if (!$loginAt) {
return parent::_saveCustomerInfo($visitor);
}
$data = new Varien_Object(array('login_at' => $loginAt, 'logout_at' => Mage::getSingleton('core/date')->gmtDate(), 'store_id' => (int) Mage::app()->getStore()->getId()));
$bind = $this->_prepareDataForTable($data, $this->getTable('log/customer'));
$condition = array('log_id = ?' => (int) $logId);
$adapter->update($this->getTable('log/customer'), $bind, $condition);
$visitor->setDoCustomerLogout(false);
$visitor->setCustomerId(null);
$visitor->setCustomerLogId(null);
} else {
return parent::_saveCustomerInfo($visitor);
}
return $this;
}
示例3: getCollection
/**
* Get category collection array
*
* @param null|string|bool|int|\Magento\Store\Model\Store $storeId
* @return array|bool
*/
public function getCollection($storeId)
{
$products = [];
/* @var $store \Magento\Store\Model\Store */
$store = $this->_storeManager->getStore($storeId);
if (!$store) {
return false;
}
$adapter = $this->_getWriteAdapter();
$this->_select = $adapter->select()->from(['e' => $this->getMainTable()], [$this->getIdFieldName(), 'updated_at'])->joinInner(['w' => $this->getTable('catalog_product_website')], 'e.entity_id = w.product_id', [])->joinLeft(['url_rewrite' => $this->getTable('url_rewrite')], 'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1' . $adapter->quoteInto(' AND url_rewrite.store_id = ?', $store->getId()) . $adapter->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE), ['url' => 'request_path'])->where('w.website_id = ?', $store->getWebsiteId());
$this->_addFilter($store->getId(), 'visibility', $this->_productVisibility->getVisibleInSiteIds(), 'in');
$this->_addFilter($store->getId(), 'status', $this->_productStatus->getVisibleStatusIds(), 'in');
// Join product images required attributes
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'name');
$this->_select->columns(['name' => $this->getReadConnection()->getIfNullSql('t2_name.value', 't1_name.value')]);
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'thumbnail');
$this->_select->columns(['thumbnail' => $this->getReadConnection()->getIfNullSql('t2_thumbnail.value', 't1_thumbnail.value')]);
} elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'image');
$this->_select->columns(['image' => $this->getReadConnection()->getIfNullSql('t2_image.value', 't1_image.value')]);
}
}
$query = $adapter->query($this->_select);
while ($row = $query->fetch()) {
$product = $this->_prepareProduct($row, $store->getId());
$products[$product->getId()] = $product;
}
return $products;
}
示例4: getCollection
/**
* Get category collection array
*
* @param null|string|bool|int|\Magento\Store\Model\Store $storeId
* @return array|bool
*/
public function getCollection($storeId)
{
$products = array();
/* @var $store \Magento\Store\Model\Store */
$store = $this->_storeManager->getStore($storeId);
if (!$store) {
return false;
}
$urConditions = array('e.entity_id = ur.product_id', 'ur.category_id IS NULL', $this->_getWriteAdapter()->quoteInto('ur.store_id = ?', $store->getId()), $this->_getWriteAdapter()->quoteInto('ur.is_system = ?', 1));
$this->_select = $this->_getWriteAdapter()->select()->from(array('e' => $this->getMainTable()), array($this->getIdFieldName(), 'updated_at'))->joinInner(array('w' => $this->getTable('catalog_product_website')), 'e.entity_id = w.product_id', array())->joinLeft(array('ur' => $this->getTable('core_url_rewrite')), join(' AND ', $urConditions), array('url' => 'request_path'))->where('w.website_id = ?', $store->getWebsiteId());
$this->_addFilter($store->getId(), 'visibility', $this->_productVisibility->getVisibleInSiteIds(), 'in');
$this->_addFilter($store->getId(), 'status', $this->_productStatus->getVisibleStatusIds(), 'in');
// Join product images required attributes
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'name');
$this->_select->columns(array('name' => $this->getReadConnection()->getIfNullSql('t2_name.value', 't1_name.value')));
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'thumbnail');
$this->_select->columns(array('thumbnail' => $this->getReadConnection()->getIfNullSql('t2_thumbnail.value', 't1_thumbnail.value')));
} elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'image');
$this->_select->columns(array('image' => $this->getReadConnection()->getIfNullSql('t2_image.value', 't1_image.value')));
}
}
$query = $this->_getWriteAdapter()->query($this->_select);
while ($row = $query->fetch()) {
$product = $this->_prepareProduct($row, $store->getId());
$products[$product->getId()] = $product;
}
return $products;
}
示例5: columns
/**
* Columns
*
* @param unknown_type $name
* @param unknown_type $cond
* @return WeFlex_Db_Model
*/
public function columns($cols)
{
$this->_selector->reset(Zend_Db_Select::COLUMNS);
foreach ($cols as $col) {
$this->_selector->columns($col, null);
}
return $this;
}
示例6: _prepareExecute
protected function _prepareExecute()
{
if ($this->_server == 'mysql') {
$ghostColumn = $this->getColumns();
$this->_select->reset('columns');
$this->_select->columns(array('ZFG_GHOST' => new Zend_Db_Expr("SQL_CALC_FOUND_ROWS 1+1")));
foreach ($ghostColumn as $value) {
if ($value[2] == 'ZFG_GHOST') {
continue;
}
if (is_object($value[1])) {
$this->_select->columns(array($value[2] => $value[1]), $value[0]);
} elseif ($value[2] != '') {
$this->_select->columns(array($value[2] => $value[1]), $value[0]);
} else {
$this->_select->columns($value[1], $value[0]);
}
}
}
$where = $this->_select->getPart('where');
$replaced = false;
if (count($where) > count($this->_where)) {
foreach ($this->_where as $value) {
$key = array_search($value, $where);
if ($key !== false) {
unset($where[$key]);
$replaced = true;
}
}
if ($replaced === true) {
$where = array_values($where);
$where[0] = substr($where[0], strpos(trim($where[0]), ' ') + 1);
}
if (count($where) > 0) {
$this->_select->reset('where');
$this->_select->where(new Zend_Db_Expr(implode(' ', $where)));
}
if (count($this->_where) > 0) {
$this->_select->where(new Zend_Db_Expr(implode(' ', $this->_where)));
}
}
}
示例7: _prepareExecute
protected function _prepareExecute()
{
if ($this->_server == 'mysql') {
$ghostColumn = $this->getColumns();
$this->_select->reset('columns');
$this->_select->columns(array('ZFG_GHOST' => new Zend_Db_Expr("SQL_CALC_FOUND_ROWS 1+1")));
foreach ($ghostColumn as $value) {
if ($value[2] == 'ZFG_GHOST') {
continue;
}
if (is_object($value[1])) {
$this->_select->columns(array($value[2] => $value[1]), $value[0]);
} elseif ($value[2] != '') {
$this->_select->columns(array($value[2] => $value[1]), $value[0]);
} else {
$this->_select->columns($value[1], $value[0]);
}
}
}
}
示例8: _prepareSelect
protected function _prepareSelect(Zend_Db_Select $select)
{
$fromPart = $select->getPart(Zend_Db_Select::FROM);
// the recipient table is required!
if (!isset($fromPart['recipient'])) {
return false;
}
foreach ($this->_where as $where) {
$select->where($where);
}
$select->columns($this->_columns, 'recipient');
return true;
}
示例9: _addLabelConcat
protected function _addLabelConcat(Zend_Db_Select $sql, $alias = null)
{
$alias = $alias ?: $this->getTableName();
// have to have array() as the last param or issue_id will get
// overwritten with a 0 if there are no issues to join
$sql->joinLeft(array('ill' => 'issue_label_linker'), "{$alias}.issue_id = ill.issue_id", array());
$sql->columns(array('labels' => 'GROUP_CONCAT(DISTINCT ill.label_id SEPARATOR \' \')'));
$sql->group($alias . '.issue_id');
return $sql;
}
示例10: _appendForeignSort
/**
* (non-PHPdoc)
* @see Tinebase_Backend_Sql_Abstract::_appendForeignSort()
*
* @todo generalize this: find a place (in model config?) for foreign record sorting information
* @todo maybe we can use a temp table with joins here
* @todo allow to to use it with keyfields, too (and/or switch those settings to keyfield configs)
*/
protected function _appendForeignSort(Tinebase_Model_Pagination $pagination, Zend_Db_Select $select)
{
$virtualSortColumns = array('leadstate_id' => Crm_Config::LEAD_STATES, 'leadsource_id' => Crm_Config::LEAD_SOURCES, 'leadtype_id' => Crm_Config::LEAD_TYPES);
$col = $pagination->sort;
if (isset($virtualSortColumns[$col])) {
$config = Crm_Config::getInstance()->get($virtualSortColumns[$col]);
// create cases (when => then) for sql switch (CASE) command
$cases = array();
foreach ($config['records'] as $settingRecord) {
$cases[$settingRecord['id']] = $settingRecord['value'];
}
$foreignSortCase = $this->_dbCommand->getSwitch($col, $cases);
$select->columns(array('foreignSortCol' => $foreignSortCase));
$pagination->sort = 'foreignSortCol';
}
}
示例11: getCollection
/**
* Get category collection array
*
* @return array
*/
public function getCollection($storeId, $onlyCount = false, $limit = 4000000000, $from = 0)
{
$products = array();
$store = Mage::app()->getStore($storeId);
/* @var $store Mage_Core_Model_Store */
if (!$store) {
return false;
}
if (self::FILTER_PRODUCT == 1) {
$fpstring = " AND product_id IN (" . implode(',', $this->_getStoreProductIds($storeId)) . ")";
} else {
$fpstring = '';
}
$read = $this->_getReadAdapter();
$this->_select = $read->select()->distinct()->from(array('e' => $this->getMainTable()), array($onlyCount ? 'COUNT(*)' : $this->getIdFieldName()))->join(array('w' => $this->getTable('catalog/product_website')), "e.entity_id=w.product_id {$fpstring}", array())->where('w.website_id=?', $store->getWebsiteId())->limit($limit, $from);
$excludeAttr = Mage::getModel('catalog/product')->getResource()->getAttribute('exclude_from_sitemap');
if ($excludeAttr) {
$this->_select->joinLeft(array('exclude_tbl' => $excludeAttr->getBackend()->getTable()), 'exclude_tbl.entity_id = e.entity_id AND exclude_tbl.attribute_id = ' . $excludeAttr->getAttributeId() . new Zend_Db_Expr(" AND store_id =\n IF(\n\t\t\t\t\t\t(SELECT `exclude`.`value` FROM `{$excludeAttr->getBackend()->getTable()}` AS `exclude` WHERE `exclude`.`entity_id` = `e`.`entity_id` AND `attribute_id` = {$excludeAttr->getAttributeId()} AND `store_id` = {$storeId}) ,\n\t\t\t\t\t\t(SELECT {$storeId}),\n\t\t\t\t\t\t(SELECT 0)\n\t\t\t\t\t)"), array())->where('exclude_tbl.value=0 OR exclude_tbl.value IS NULL');
}
if (Mage::helper('xsitemap')->isExcludeFromXMLOutOfStockProduct($storeId)) {
$cond = 'e.entity_id = csi.product_id';
if (Mage::getStoreConfig('cataloginventory/item_options/manage_stock', $storeId)) {
$cond .= ' AND IF (csi.use_config_manage_stock = 1, csi.is_in_stock = 1, (csi.manage_stock = 0 OR (csi.manage_stock = 1 AND csi.is_in_stock = 1)))';
} else {
$cond .= ' AND IF (csi.use_config_manage_stock = 1, TRUE, (csi.manage_stock = 0 OR (csi.manage_stock = 1 AND csi.is_in_stock = 1)))';
}
$this->_select->join(array('csi' => $this->getTable('cataloginventory/stock_item')), $cond, array('is_in_stock', 'manage_stock', 'use_config_manage_stock'));
}
$this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in');
$this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in');
if ($onlyCount) {
return $read->fetchOne($this->_select);
}
$sort = '';
if (Mage::helper('xsitemap')->isSeosuiteUltimateAvailable() && Mage::helper('xsitemap')->isSeosuiteCanonicalUrlEnabled($storeId) && Mage::helper('xsitemap')->getSeosuiteProductCanonicalType($storeId)) {
$productCanonicalType = Mage::helper('xsitemap')->getSeosuiteProductCanonicalType($storeId);
if ($productCanonicalType == 3) {
//$suffix = "AND canonical_url_rewrite.category_id IS NULL";
$suffix = '';
$suffix2 = "AND category_id IS NULL";
} else {
//$suffix = "AND canonical_url_rewrite.category_id IS NOT NULL";
$suffix = '';
$suffix2 = "AND category_id IS NOT NULL";
}
if ($productCanonicalType == 1 || $productCanonicalType == 4) {
$sort = 'DESC';
} else {
if ($productCanonicalType == 2 || $productCanonicalType == 5) {
$sort = 'ASC';
} else {
}
}
} else {
$length = Mage::helper('xsitemap')->getXmlSitemapUrlLength();
if ($length == 'short') {
$sort = 'ASC';
} elseif ($length == 'long') {
$sort = 'DESC';
}
if (Mage::getStoreConfigFlag('catalog/seo/product_use_categories', $storeId)) {
$suffix3 = '';
} else {
$suffix3 = 'AND `category_id` IS NULL';
}
}
$canonicalAttr = Mage::getModel('catalog/product')->getResource()->getAttribute('canonical_url');
$urlPathAttr = Mage::getModel('catalog/product')->getResource()->getAttribute('url_path');
/*
if (Mage::helper('xsitemap')->isEnterpriseSince113()) {
$this->_select->columns(array('url' => new Zend_Db_Expr("(
SELECT `eur`.`request_path`
FROM `" . Mage::getSingleton('core/resource')->getTableName('enterprise_url_rewrite') . "` AS `eur`
INNER JOIN `" . Mage::getSingleton('core/resource')->getTableName('enterprise_catalog_product_rewrite') . "` AS `ecpr`
ON `eur`.`url_rewrite_id` = `ecpr`.`url_rewrite_id`
WHERE `product_id`=`e`.`entity_id` AND `ecpr`.`store_id` IN(" . intval(Mage::app()->isSingleStoreMode()
? 0 : 0, $storeId) . ") AND `is_system`=1 AND `request_path` IS NOT NULL " .
($sort ? " ORDER BY LENGTH(`request_path`) " . $sort : "") .
" LIMIT 1)")));
}
*
*/
if (Mage::helper('xsitemap')->isEnterpriseSince113()) {
$urlSuffix = Mage::helper('catalog/product')->getProductUrlSuffix($storeId);
if ($urlSuffix) {
$urlSuffix = '.' . $urlSuffix;
} else {
$urlSuffix = '';
}
$this->_select->joinLeft(array('ecp' => $this->getTable('enterprise_catalog/product')), 'ecp.product_id = e.entity_id ' . 'AND ecp.store_id = ' . $storeId, array())->joinLeft(array('euur' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'ecp.url_rewrite_id = euur.url_rewrite_id AND euur.is_system = 1', array())->joinLeft(array('ecp2' => $this->getTable('enterprise_catalog/product')), 'ecp2.product_id = e.entity_id AND ecp2.store_id = 0', array())->joinLeft(array('euur2' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'ecp2.url_rewrite_id = euur2.url_rewrite_id', array('url' => 'concat( ' . $this->_getWriteAdapter()->getIfNullSql('euur.request_path', 'euur2.request_path') . ',"' . $urlSuffix . '")'));
} elseif (!empty($productCanonicalType) && $canonicalAttr) {
$this->_select->columns(array('url' => new Zend_Db_Expr("\n IFNULL(\n (IFNULL(\n (SELECT canonical_url_rewrite.`request_path`\n FROM `" . $canonicalAttr->getBackend()->getTable() . "` AS canonical_path\n LEFT JOIN `" . $this->getTable('core/url_rewrite') . "` AS canonical_url_rewrite ON canonical_url_rewrite.`id_path` = canonical_path.`value`\n WHERE canonical_path.`entity_id` = e.`entity_id` AND canonical_path.`attribute_id` = " . $canonicalAttr->getAttributeId() . " AND canonical_url_rewrite.`store_id` IN (0," . $storeId . ") {$suffix}" . ($sort ? " ORDER BY LENGTH(canonical_url_rewrite.`request_path`) " . $sort : "") . " LIMIT 1),\n (SELECT `request_path`\n FROM `" . $this->getTable('core/url_rewrite') . "`\n WHERE `product_id`=e.`entity_id` AND `store_id` IN (0," . $storeId . ") AND `is_system`=1 AND `request_path` IS NOT NULL {$suffix2}" . ($sort ? " ORDER BY LENGTH(`request_path`) " . $sort : "") . " LIMIT 1)\n )),\n (SELECT p.`value` FROM `" . $urlPathAttr->getBackend()->getTable() . "` AS p\n WHERE p.`entity_id` = e.`entity_id` AND p.`attribute_id` = " . $urlPathAttr->getAttributeId() . " AND p.`store_id` IN (0," . $storeId . ") ORDER BY p.`store_id` DESC LIMIT 1\n )\n )")));
} else {
$this->_select->columns(array('url' => new Zend_Db_Expr("(\n SELECT `request_path`\n FROM `" . $this->getTable('core/url_rewrite') . "`\n WHERE `product_id`=e.`entity_id` AND `store_id`=" . intval($storeId) . " AND `is_system`=1 AND `request_path` IS NOT NULL {$suffix3}" . ($sort ? " ORDER BY LENGTH(`request_path`) " . $sort : "") . " LIMIT 1)")));
//.........这里部分代码省略.........
示例12: _appendEffectiveGrantCalculationSql
/**
* appends effective grant calculation to select object
*
* @param Zend_Db_Select $_select
*/
protected function _appendEffectiveGrantCalculationSql($_select, $_attendeeFilters = NULL)
{
// groupmemberships of current user, needed to compute phys and inherited grants
$_select->joinLeft(array('groupmemberships' => $this->_tablePrefix . 'group_members'), $this->_db->quoteInto($this->_db->quoteIdentifier('groupmemberships.account_id') . ' = ?', Tinebase_Core::getUser()->getId()), array());
// attendee joins the attendee we need to compute the curr users effective grants
// NOTE: 2010-04 the behaviour changed. Now, only the attendee the client filters for are
// taken into account for grants calculation
$attendeeWhere = FALSE;
if (is_array($_attendeeFilters) && !empty($_attendeeFilters)) {
$attendeeSelect = $this->_db->select();
foreach ((array) $_attendeeFilters as $attendeeFilter) {
if ($attendeeFilter instanceof Calendar_Model_AttenderFilter) {
$attendeeFilter->appendFilterSql($attendeeSelect, $this);
}
}
$whereArray = $attendeeSelect->getPart(Zend_Db_Select::SQL_WHERE);
if (!empty($whereArray)) {
$attendeeWhere = ' AND ' . Tinebase_Helper::array_value(0, $whereArray);
}
}
$_select->joinLeft(array('attendee' => $this->_tablePrefix . 'cal_attendee'), $this->_db->quoteIdentifier('attendee.cal_event_id') . ' = ' . $this->_db->quoteIdentifier('cal_events.id') . $attendeeWhere, array());
$_select->joinLeft(array('attendeeaccounts' => $this->_tablePrefix . 'accounts'), $this->_db->quoteIdentifier('attendeeaccounts.contact_id') . ' = ' . $this->_db->quoteIdentifier('attendee.user_id') . ' AND (' . $this->_db->quoteInto($this->_db->quoteIdentifier('attendee.user_type') . '= ?', Calendar_Model_Attender::USERTYPE_USER) . ' OR ' . $this->_db->quoteInto($this->_db->quoteIdentifier('attendee.user_type') . '= ?', Calendar_Model_Attender::USERTYPE_GROUPMEMBER) . ')', array());
$_select->joinLeft(array('attendeegroupmemberships' => $this->_tablePrefix . 'group_members'), $this->_db->quoteIdentifier('attendeegroupmemberships.account_id') . ' = ' . $this->_db->quoteIdentifier('attendeeaccounts.contact_id'), array());
$_select->joinLeft(array('dispgrants' => $this->_tablePrefix . 'container_acl'), $this->_db->quoteIdentifier('dispgrants.container_id') . ' = ' . $this->_db->quoteIdentifier('attendee.displaycontainer_id') . ' AND ' . $this->_getContainGrantCondition('dispgrants', 'groupmemberships'), array());
$_select->joinLeft(array('physgrants' => $this->_tablePrefix . 'container_acl'), $this->_db->quoteIdentifier('physgrants.container_id') . ' = ' . $this->_db->quoteIdentifier('cal_events.container_id'), array());
$allGrants = Tinebase_Model_Grants::getAllGrants();
foreach ($allGrants as $grant) {
if (in_array($grant, $this->_recordBasedGrants)) {
$_select->columns(array($grant => "\n MAX( CASE WHEN ( \n" . ' /* physgrant */' . $this->_getContainGrantCondition('physgrants', 'groupmemberships', $grant) . " OR \n" . ' /* implicit */' . $this->_getImplicitGrantCondition($grant) . " OR \n" . ' /* inherited */' . $this->_getInheritedGrantCondition($grant) . " \n" . ") THEN 1 ELSE 0 END ) "));
} else {
$_select->columns(array($grant => "\n MAX( CASE WHEN ( \n" . ' /* physgrant */' . $this->_getContainGrantCondition('physgrants', 'groupmemberships', $grant) . "\n" . ") THEN 1 ELSE 0 END ) "));
}
}
}
示例13: _columnsDefault
/**
* Padrão de Colunas para o relatório de Beneficiários
*
* @access protected
* @param Zend_Db_Select $select
* @return void
*/
protected function _columnsDefault(Zend_Db_Select $select)
{
$select->reset(Zend_Db_Select::COLUMNS);
$select->columns(array('FEFOP_Contract.id_fefop_contract', 'FEFOP_Contract.num_district', 'FEFOP_Contract.num_program', 'FEFOP_Contract.num_module', 'AddDistrict.id_adddistrict', 'AddDistrict.District', 's.status_description', 'id_perdata' => 'b.id', 'b.code', 'b.name', 'target' => new Zend_Db_Expr("CASE WHEN b.target = 1 THEN 'Sin' ELSE 'Lae' END"), 'module' => new Zend_Db_Expr("CONCAT(FEFOP_Modules.acronym, ' - ', FEFOP_Modules.description)"), 'program' => new Zend_Db_Expr("CONCAT(FEFOP_Programs.acronym, ' - ', FEFOP_Programs.description)"), 'cod_contract' => new Zend_Db_Expr("CONCAT(FEFOP_Contract.num_program, '-', FEFOP_Contract.num_module, '-', FEFOP_Contract.num_district, '-', FEFOP_Contract.num_year, '-', FEFOP_Contract.num_sequence)"), 'disability' => new Zend_Db_Expr('(' . $this->_columnDisability() . ')'), 'gender' => new Zend_Db_Expr('(' . $this->_columnGender() . ')'), 'amount_contracted' => new Zend_Db_Expr('(' . $this->_columnAmountContracted() . ')'), 'amount_payment' => new Zend_Db_Expr('(' . $this->_columnAmouontPayment() . ')'), 'amount_real' => new Zend_Db_Expr('(' . $this->_columnAmountReal() . ')'), 'amount_addcosts' => new Zend_Db_Expr('(' . $this->_columnAdditional() . ')')));
$select->group(array('FEFOP_Contract.id_fefop_contract'));
}
示例14: _appendForeignSort
/**
* (non-PHPdoc)
* @see Tinebase_Backend_Sql_Abstract::_appendForeignSort()
*
* @todo generalize this: find a place (in model config?) for foreign record sorting information
* @todo maybe we can use a temp table with joins here
* @todo allow to to use it with keyfields, too (and/or switch those settings to keyfield configs)
*/
protected function _appendForeignSort(Tinebase_Model_Pagination $pagination, Zend_Db_Select $select)
{
$virtualSortColumns = array('leadstate_id' => Crm_Model_Config::LEADSTATES, 'leadsource_id' => Crm_Model_Config::LEADSOURCES, 'leadtype_id' => Crm_Model_Config::LEADTYPES);
$col = $pagination->sort;
if (isset($virtualSortColumns[$col])) {
$settings = Crm_Controller::getInstance()->getConfigSettings();
$setting = $settings->{$virtualSortColumns[$col]};
// create cases (when => then) for sql switch (CASE) command
$cases = array();
foreach ($setting as $settingRecord) {
$cases[$settingRecord['id']] = $settingRecord[str_replace('_id', '', $col)];
}
$foreignSortCase = $this->_dbCommand->getSwitch($col, $cases);
$select->columns(array('foreignSortCol' => $foreignSortCase));
$pagination->sort = 'foreignSortCol';
}
}
示例15: find
//.........这里部分代码省略.........
case Condition::MODE_AND:
default:
$this->_select->where($statement);
break;
}
}
// Adjust query based on returnCount
if ($returnCount) {
if (is_array($returnCount)) {
if ($subOp) {
} else {
// return count on grouped columns
foreach ($returnCount as $key => $property) {
$fieldmodifier = null;
if ($this->_mapper) {
$class = $property->getParent() ? $property->getParent()->getId() : $collection->getDataObject()->getClass();
$field = $this->_mapper->propertyToDatastoreName($class, $property->getId());
} else {
$field = $property->getId();
}
if ($property instanceof ObjectProperty) {
// join with $key if necessary
if (strstr($key, '.') !== false) {
$leftPart = substr($key, 0, strpos($key, '.'));
$intermediateProp = $collection->getDataObject()->getProperty($leftPart);
$fieldmodifier = $this->_join($intermediateProp, $table) . '.' . $field;
}
}
// limit date grouping to date part, omitting possible hour part
if ($property instanceof DateProperty) {
$fieldmodifier = "DATE({$field})";
}
$this->_select->group($fieldmodifier ? $fieldmodifier : $field);
$this->_select->columns(array($field => $fieldmodifier ? $fieldmodifier : $field));
}
}
} else {
$this->_select->reset('group');
}
} else {
$this->_select->limit($collection->getBoundaryBatch() != -1 ? $collection->getBoundaryBatch() : null, $collection->getBoundaryOffset());
/**
* Sorting part
*/
foreach ($collection->getSortings() as $sorting) {
$slUniqext = $slTable = null;
// Specific cases first
// @todo find a better way to sort on meta properties
if ($sorting[0]->getId() == ObjectUri::IDENTIFIER || $sorting[0] instanceof MetaProperty) {
$id = Backend::DEFAULT_PKEY;
$this->_select->order(new \Zend_Db_Expr($table . '.' . $id . ' ' . $sorting[1]));
continue;
} else {
if ($sorting[0] instanceof Property\CollectionProperty) {
// handling of conditions based on collection limited to withMembers() and withoutMembers()
$leftkey = $sorting[0]->getParameter('keyprop');
//$field = $property->getId();
$subSelect = $this->_ressource->select();
$subseltbl = $this->_mapper ? $this->_mapper->getDatastore($sorting[0]->getParameter('instanceof')) : $this->_getTableFromClass($sorting[0]->getParameter('instanceof'));
$subSelect->from($subseltbl, new \Zend_Db_Expr(sprintf("COUNT(%s)", $leftkey)));
$join = sprintf("%s.%s = %s", $subseltbl, $leftkey, $pkey);
$subSelect->where($join);
// $statement = $this->_buildConditionStatement(new \Zend_Db_Expr(sprintf("(%s)", $subSelect)), $condition->getClauses(), $conditionArray[1]);
$this->_select->order(new \Zend_Db_Expr('(' . $subSelect->__toString() . ') ' . $sorting[1]));
continue;
} else {