Author: david
Date: 2008-11-26 15:03:30 -0800 (Wed, 26 Nov 2008)
New Revision: 1620
Modified:
trunk/qubit/lib/QubitCultureFallback.class.php
trunk/qubit/lib/QubitPager.class.php
Log:
Update culture QubitCultureFallback and QubitPager classes to work with symfony
1.2 and PDO DBA layer. Also update code to conform with pre-commit formatting
validator.
Modified: trunk/qubit/lib/QubitCultureFallback.class.php
===================================================================
--- trunk/qubit/lib/QubitCultureFallback.class.php 2008-11-26 22:57:13 UTC
(rev 1619)
+++ trunk/qubit/lib/QubitCultureFallback.class.php 2008-11-26 23:03:30 UTC
(rev 1620)
@@ -37,27 +37,26 @@
*/
public static function addFallbackColumns($criteria, $fallbackClassName)
{
-
// Get array of column names by getting a table map via MapBuilder class
// for passed fallback table
- $mapBuilderClassName = substr($fallbackClassName, 5).'MapBuilder';
+ $mapBuilderClassName = substr($fallbackClassName, 5).'MapBuilder';
$objectMapBuilder = eval ('return new '.$mapBuilderClassName.';');
$tableName = eval('return '.$fallbackClassName.'::TABLE_NAME;');
-
+
// Build the database and table map, and then get tableMap
call_user_func(array($objectMapBuilder, 'doBuild'));
$tableMap = $objectMapBuilder->getDatabaseMap()->getTable($tableName);
-
+
// Loop through table columns and add fallback calculated fields to
criteria
- foreach ($tableMap->getColumns() as $col)
+ foreach ($tableMap->getColumns() as $col)
{
- $criteria->addAsColumn($col->getColumnName(),
self::getfallbackCaseStmt($col->getColumnName()));
+ $criteria->addAsColumn($col->getColumnName(),
self::getfallbackCaseStmt($col->getColumnName()));
}
-
+
return $criteria;
}
-
-
+
+
/**
* Build SQL 'case' statement to get the most relevant value for $column
*
@@ -68,11 +67,11 @@
{
$fallbackCaseStmt = '(CASE WHEN current.'.$column.' IS NOT NULL THEN
current.'.$column;
$fallbackCaseStmt .= ' ELSE source.'.$column.' END)';
-
+
return $fallbackCaseStmt;
}
-
-
+
+
/**
* Add fallback query criteria to $criteria
*
@@ -81,31 +80,34 @@
* @return QubitQuery array of objects
*/
public static function addFallbackCriteria($criteria, $fallbackClassName,
$culture, $options = array())
- {
-
+ {
// Expose class constants so we can call them using a dynamic class name
$fallbackClass = new ReflectionClass($fallbackClassName);
$fallbackClassI18n = new ReflectionClass($fallbackClassName.'I18n');
-
+
// Add fallback columns (calculated)
$criteria = self::addFallbackColumns($criteria,
$fallbackClassI18n->getName());
-
+
// Get i18n "CULTURE" column name, with "<tablename>." stripped off the
front
$cultureColName =
str_replace($fallbackClassI18n->getConstant('TABLE_NAME').'.', '',
$fallbackClassI18n->getConstant('CULTURE'));
-
+
// Build join strings
$currentJoinString = 'current.id AND current.'.$cultureColName.' =
\''.$culture.'\'';
-
+
$sourceJoinString = 'source.id AND source.'.$cultureColName.' =
'.$fallbackClass->getConstant('SOURCE_CULTURE');
$sourceJoinString .= ' AND source.'.$cultureColName.' <> \''.$culture.'\'';
-
+
// Build fancy criteria to get fallback values
$criteria->addAlias('current',
$fallbackClassI18n->getConstant('TABLE_NAME'));
$criteria->addAlias('source',
$fallbackClassI18n->getConstant('TABLE_NAME'));
- $criteria->addJoin($fallbackClass->getConstant('ID'), $currentJoinString,
Criteria::LEFT_JOIN);
- $criteria->addJoin($fallbackClass->getConstant('ID'), $sourceJoinString,
Criteria::LEFT_JOIN);
-
+
+ $criteria->addJoin(array($fallbackClass->getConstant('ID'),
'current.'.$cultureColName), array('current.id', '\''.$culture.'\''),
Criteria::LEFT_JOIN);
+ $criteria->addJoin(
+ array($fallbackClass->getConstant('ID'), 'source.'.$cultureColName),
+ array('source.id', $fallbackClass->getConstant('SOURCE_CULTURE').' AND
source.'.$cultureColName.' <> \''.$culture.'\''),
+ Criteria::LEFT_JOIN);
+
return $criteria;
}
-
+
}
\ No newline at end of file
Modified: trunk/qubit/lib/QubitPager.class.php
===================================================================
--- trunk/qubit/lib/QubitPager.class.php 2008-11-26 22:57:13 UTC (rev
1619)
+++ trunk/qubit/lib/QubitPager.class.php 2008-11-26 23:03:30 UTC (rev
1620)
@@ -20,8 +20,8 @@
*/
/**
- * Qubit specifc extension to the sfPropelPager
- *
+ * Qubit specifc extension to the sfPropelPager
+ *
* @package Qubit
* @author David Juhasz <[EMAIL PROTECTED]>
* @version svn:$Id$
@@ -29,40 +29,40 @@
class QubitPager extends sfPropelPager
{
protected
- $criteria = null,
- $base_peer_class = 'BasePeer',
- $peer_method_name = 'doSelect',
- $select_method_name = 'get',
- $clear_group_by = true,
- $peer_count_method_name = null, // Qubit BasePeer has no "doCount()"
method
- $offset = 0,
- $limit = 0,
- $firstPageLink = null,
- $lastPageLink = null,
- $totalRecordCount = null;
-
-
-
+ $criteria = null,
+ $base_peer_class = 'BasePeer',
+ $peer_method_name = 'doSelect',
+ $select_method_name = 'get',
+ $clear_group_by = true,
+ $peer_count_method_name = null, // Qubit BasePeer has no "doCount()" method
+ $offset = 0,
+ $limit = 0,
+ $firstPageLink = null,
+ $lastPageLink = null,
+ $totalRecordCount = null;
+
+
+
/**
* Class constructor
*
* @param string $class Qubit class name for database mapping
* @param integer $maxPerPage results to show per page
- */
+ */
public function __construct($class, $maxPerPage=null)
{
$this->setClass($class);
-
+
// If maxPerPage not set explicitly, then grab from app_hits_per_page
Qubit setting
$maxPerPage = ($maxPerPage !== null) ? $maxPerPage :
sfConfig::get('app_hits_per_page', 10);
-
+
$this->setMaxPerPage($maxPerPage);
$this->parameterHolder = new sfParameterHolder();
-
+
$this->setCriteria(new Criteria());
$this->tableName = constant($class.'::TABLE_NAME');
}
-
+
/**
* Initialize Pager
*/
@@ -70,7 +70,7 @@
{
$hasMaxRecordLimit = ($this->getMaxRecordLimit() !== false);
$maxRecordLimit = $this->getMaxRecordLimit();
-
+
if (!isset($this->totalRecordCount))
{
$this->totalRecordCount = $this->getTotalRecordCount($this->criteria);
@@ -105,15 +105,15 @@
{
$this->setLimit($this->getMaxPerPage());
}
-
+
$this->criteria->setOffset($this->offset);
$this->criteria->setLimit($this->limit);
}
}
-
+
/**
* Return current object
- *
+ *
* @param integer $offset from start of foundset
* @return object Propel representation of requested row
*/
@@ -126,7 +126,7 @@
return $this->resultSet->offsetGet($offset - 1);
}
-
+
/**
* Query database for current page of results
*
@@ -138,7 +138,7 @@
$this->resultSet = call_user_func(array($this->getClass(),
$this->getSelectMethod()), $c);
return $this->resultSet;
}
-
+
/**
* Overwrite sfPager::getLinks() so we can set the $firstPageLink
* and $lastPageLink
@@ -153,31 +153,30 @@
$check = $this->lastPage - $nb_links + 1;
$limit = ($check > 0) ? $check : 1;
$begin = ($tmp > 0) ? (($tmp > $limit) ? $limit : $tmp) : 1;
-
$i = $begin;
while (($i < $begin + $nb_links) && ($i <= $this->lastPage))
{
$links[] = $i++;
}
-
+
$this->firstPageLink = $begin;
$this->lastPageLink = $i;
$this->currentMaxLink = $links[count($links) - 1];
return $links;
}
-
+
/**
* Get index of first page in link set
*
* @return integer first link page number
*/
- public function getFirstPageLink()
+ public function getFirstPageLink()
{
return $this->firstPageLink;
}
-
+
/**
* Get index of last page in link set
*
@@ -187,7 +186,7 @@
{
return $this->lastPageLink;
}
-
+
/**
* For Qubit we only have the BasePeer peer class.
*
@@ -197,12 +196,12 @@
{
return $this->base_peer_class;
}
-
+
public function getSelectMethod()
{
return $this->select_method_name;
}
-
+
/**
* Get the offset for the first record in the paginated hitlist
*
@@ -212,7 +211,7 @@
{
return $this->offset;
}
-
+
/**
* Set the offset for the first record in the paginated hitlist
*
@@ -222,7 +221,7 @@
{
$this->offset = $offset;
}
-
+
/**
* Get the max. number of rows to return for the current page
*
@@ -232,7 +231,7 @@
{
return $this->limit;
}
-
+
/**
* Set the max. number of rows to return for the current page
*
@@ -240,9 +239,9 @@
*/
public function setLimit($limit)
{
- $this->limit = $limit;
+ $this->limit = intval($limit);
}
-
+
/**
* Set flag to clear "GROUP BY" column when getting a count of Total records
found
*
@@ -253,17 +252,17 @@
{
$this->clear_group_by = ($clearGroupBy == false) ? false : true;
}
-
+
/**
* Get clearGroupBy flag
*
- * @return boolean clear_group_by value
+ * @return boolean clear_group_by value
*/
public function clearGroupBy()
{
return $this->clear_group_by;
}
-
+
/**
* Set the total number of rows returned from the database
* with no offset or limit criteria.
@@ -274,27 +273,20 @@
{
$this->totalRecordCount = $count;
}
-
+
/**
* Get the total records that are returned from the database
* with no offset or limit criteria.
- *
+ *
* @param criteria $criteria original search criteria
* @return integer number of rows returned
*/
public function getTotalRecordCount($criteria)
{
$countCriteria = clone $criteria;
-
- // Clear criteria that we don't want for counting records
- $countCriteria->setOffset(0);
- $countCriteria->setLimit(0);
- $countCriteria->clearOrderByColumns();
- $countCriteria->clearGroupByColumns();
-
$stmt = BasePeer::doCount($countCriteria);
$count = $stmt->fetchColumn(0);
-
+
return $count;
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---