Skip to content

Instantly share code, notes, and snippets.

@markbalt
Last active August 29, 2015 14:01
Show Gist options
  • Save markbalt/02f664e5a75a9ba4ffab to your computer and use it in GitHub Desktop.
Save markbalt/02f664e5a75a9ba4ffab to your computer and use it in GitHub Desktop.
Applies additional presets before returning the kuWidgetSidebar object.
<?php
/**
* Applies additional presets before returning the kuWidgetSidebar object.
*
* @return kuWidgetSidebar
*/
protected function overrideTemplateIndexSidebar()
{
$sidebar = parent::overrideTemplateIndexSidebar();
// add data center preset filter links
$datacenters = kuWidgetSidebarHeader::factory('Data Center');
$criteria = new Criteria();
$criteria->addAscendingOrderByColumn(QuoteLocationPeer::NAME);
$criteria->innerJoin(QuoteLocationPeer::SMC_LOCATION_ID, LocationPeer::ID);
$criteria->add(LocationPeer::IS_ACTIVE, 1);
foreach (QuoteLocationPeer::doSelect($criteria) as $location)
{
$criteria = new Criteria();
$criteria->add(QuotePeer::QUOTE_LOCATION_ID, $location->getPrimaryKey());
$datacenters->addLinkObject(
kuWidgetSidebarLinkCount::factory($location, $this->generateUriPresetFilter('quote_location_id', $location->getPrimaryKey()))
->setCountByCriteria($this->getPeerClass(), $criteria));
}
// add sales rep preset filter links
$sql = <<<SQL
SELECT salesrep AS `id`
FROM quote
WHERE salesrep IS NOT NULL
UNION
SELECT secondary_salesrep AS `id`
FROM quote
WHERE secondary_salesrep IS NOT NULL
SQL;
$stmt = Propel::getConnection()->prepare($sql);
$stmt->execute();
// this is everybody in both primary and secondary salesmen columns
$ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
$salesreps = kuWidgetSidebarHeader::factory('Sales Rep');
$criteria = new Criteria();
$criteria->innerJoin(sfGuardUserPeer::ID, sfGuardUserProfilePeer::USER_ID);
$criteria->add(sfGuardUserPeer::ID, $ids, Criteria::IN);
$criteria->add(sfGuardUserPeer::IS_ACTIVE, 1);
$criteria->addAscendingOrderByColumn(sfGuardUserPeer::USERNAME);
$criteria->addAscendingOrderByColumn(sfGuardUserProfilePeer::FIRST_NAME);
$criteria->addAscendingOrderByColumn(sfGuardUserProfilePeer::LAST_NAME);
$criteria->setDistinct(true);
foreach (sfGuardUserPeer::doSelect($criteria) as $user)
{
$criteria = new Criteria();
$criteria
->add(QuotePeer::SALESREP, $user->getPrimaryKey())
->addOr(QuotePeer::SECONDARY_SALESREP, $user->getPrimaryKey());
$salesreps->addLinkObject(
kuWidgetSidebarLinkCount::factory($user, $this->generateUriPresetFilter('salesrep', $user->getPrimaryKey()))
->setCountByCriteria($this->getPeerClass(), $criteria));
}
return $sidebar
->addHeaderObject($datacenters)
->addHeaderObject($salesreps);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment