本文整理汇总了PHP中ARSelectFilter::createString方法的典型用法代码示例。如果您正苦于以下问题:PHP ARSelectFilter::createString方法的具体用法?PHP ARSelectFilter::createString怎么用?PHP ARSelectFilter::createString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARSelectFilter
的用法示例。
在下文中一共展示了ARSelectFilter::createString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
// get filter to select manufacturers of active products only
$rootCat = Category::getRootNode();
$f = new ARSelectFilter();
$productFilter = new ProductFilter($rootCat, $f);
$ids = $counts = array();
foreach (ActiveRecordModel::getDataBySQL('SELECT DISTINCT(manufacturerID), COUNT(*) AS cnt FROM Product ' . $f->createString() . ' GROUP BY manufacturerID') as $row) {
$ids[] = $row['manufacturerID'];
$counts[$row['manufacturerID']] = $row['cnt'];
}
$f = new ARSelectFilter(new InCond(new ARFieldHandle('Manufacturer', 'ID'), $ids));
$f->mergeCondition(new NotEqualsCond(new ARFieldHandle('Manufacturer', 'name'), ''));
$f->setOrder(new ARFieldHandle('Manufacturer', 'name'));
$manufacturers = ActiveRecordModel::getRecordSetArray('Manufacturer', $f);
foreach ($manufacturers as &$manufacturer) {
$manufacturer['url'] = $this->getManufacturerFilterUrl($manufacturer);
}
$this->addBreadCrumb($this->translate('_manufacturers'), '');
$response = new ActionResponse();
$response->setReference('manufacturers', $manufacturers);
$response->set('counts', $counts);
$response->set('rootCat', $rootCat->toArray());
return $response;
}
示例2: createString
public function createString()
{
$sql = $this->createStatementBody();
if ($this->filter != null) {
$sql .= $this->filter->createString();
}
return $sql;
}
示例3: mergeFields
/**
* @todo Rewrite this to use ARUpdateFilter or simply an SQL query to update all values
As in the original bug report:
The update query for merging value 799 into 808 would look something like this:
UPDATE SpecificationItem
LEFT JOIN SpecificationItem AS SecondItem ON SpecificationItem.productID=SecondItem.productID AND SecondItem.specFieldValueID=808
SET SpecificationItem.specFieldValueID=808
WHERE SpecificationItem.specFieldValueID=799 AND SecondItem.specFieldValueID IS NULL
- it would only update products that do not have value 808 already set (otherwise the query would error because of duplicate SpecificationItem records).
The remaining records with value 799 will be automatically removed (cascade) when SpecFieldValue 799 is deleted.
*/
private function mergeFields()
{
if (empty($this->mergedFields)) {
return true;
}
$itemClass = call_user_func(array($this->getFieldClass(), 'getSelectValueClass'));
$valueColumn = call_user_func(array($itemClass, 'getValueIDColumnName'));
$specificationItemSchema = self::getSchemaInstance($itemClass);
$foreignKeys = $specificationItemSchema->getForeignKeyList();
$specFieldReferenceFieldName = '';
foreach ($foreignKeys as $foreignKey) {
if ($foreignKey->getForeignClassName() == get_class($this)) {
$specFieldReferenceFieldName = $foreignKey->getName();
break;
}
}
$thisSchema = self::getSchemaInstance(get_class($this));
$primaryKeyList = $thisSchema->getPrimaryKeyList();
$promaryKey = array_shift($primaryKeyList);
$mergedFieldsIDs = array();
foreach ($this->mergedFields as $mergedField) {
$mergedFieldsIDs[] = $mergedField->getID();
}
$inAllItemsExceptThisCondition = new INCond(new ARFieldHandle(get_class($this), $promaryKey->getName()), $mergedFieldsIDs);
$mergedFieldsIDs[] = $this->getID();
$inAllItemsCondition = new INCond(new ARFieldHandle($itemClass, $specFieldReferenceFieldName), $mergedFieldsIDs);
// Create filters
$mergedSpecificationItemsFilter = new ARSelectFilter();
$mergedSpecificationItemsFilter->setCondition($inAllItemsCondition);
// Using IGNORE I'm ignoring duplicate primary keys. Those rows that violate the uniqueness of the primary key are simply not saved
// Then later I just delete these records and the merge is complete.
$sql = 'UPDATE IGNORE ' . $itemClass . ' SET ' . $valueColumn . ' = ' . $this->getID() . ' ' . $mergedSpecificationItemsFilter->createString();
self::getLogger()->logQuery($sql);
self::executeUpdate($sql);
$mergedSpecFieldValuesDeleteFilter = new ARDeleteFilter();
$mergedSpecFieldValuesDeleteFilter->setCondition($inAllItemsExceptThisCondition);
ActiveRecord::deleteRecordSet(get_class($this), $mergedSpecFieldValuesDeleteFilter);
}
示例4: getActiveProductManufacturerFirstLetters
public static function getActiveProductManufacturerFirstLetters()
{
$letters = $ids = array();
$f = new ARSelectFilter();
$sql = !self::getApplication()->getConfig()->get('MANUFACTURER_PAGE_DISPLAY_ACTIVE') ? 'SELECT DISTINCT(ID) as manufacturerID FROM Manufacturer ' . $f->createString() . ' GROUP BY manufacturerID' : 'SELECT DISTINCT(manufacturerID) FROM Product ' . $f->createString() . ' GROUP BY manufacturerID';
foreach (ActiveRecordModel::getDataBySQL($sql) as $row) {
$ids[] = $row['manufacturerID'];
}
$f = new ARSelectFilter(new InCond(new ARFieldHandle('Manufacturer', 'ID'), $ids));
$f->addField('UPPER(LEFT(TRIM(Manufacturer.name),1))', '', 'FirstLetter');
$f->mergeCondition(new NotEqualsCond(new ARFieldHandle('Manufacturer', 'name'), ''));
$f->setOrder(new ARFieldHandle('Manufacturer', 'name'));
$manufacturers = ActiveRecordModel::getRecordSetArray('Manufacturer', $f);
foreach ($manufacturers as $item) {
$letters[$item['FirstLetter']] = $item['FirstLetter'];
}
return $letters;
}