From 080c3ec9449e4181915423af8023ebcc335de833 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 5 Nov 2012 15:38:35 -0500 Subject: [PATCH] CC-4661: Listener Statistics -factor out mountname into it's own table --- .../application/models/ListenerStat.php | 39 +- .../airtime/map/CcListenerCountTableMap.php | 3 +- .../models/airtime/om/BaseCcListenerCount.php | 171 +++++--- .../airtime/om/BaseCcListenerCountPeer.php | 365 +++++++++++++++++- .../airtime/om/BaseCcListenerCountQuery.php | 113 +++++- airtime_mvc/build/schema.xml | 9 +- airtime_mvc/build/sql/schema.sql | 22 +- 7 files changed, 634 insertions(+), 88 deletions(-) diff --git a/airtime_mvc/application/models/ListenerStat.php b/airtime_mvc/application/models/ListenerStat.php index 903aa647c..8964bc726 100644 --- a/airtime_mvc/application/models/ListenerStat.php +++ b/airtime_mvc/application/models/ListenerStat.php @@ -39,17 +39,44 @@ SQL; public static function insertDataPoints($p_dataPoints) { - $timestamp_sql = "INSERT INTO cc_timestamp (timestamp) VALUES (:ts::TIMESTAMP) RETURNING id;"; - $stats_sql = "INSERT INTO cc_listener_count (timestamp_id, listener_count, mount_name) - VALUES (:timestamp_id, :listener_count, :mount_name)"; + $timestamp_sql = "INSERT INTO cc_timestamp (timestamp) VALUES + (:ts::TIMESTAMP) RETURNING id;"; + + $mount_name_check_sql = "SELECT id from cc_mount_name WHERE + mount_name = :mn;"; + + $mount_name_insert_sql = "INSERT INTO cc_mount_name (mount_name) VALUES + (:mn) RETURNING id;"; + + $stats_sql = "INSERT INTO cc_listener_count (timestamp_id, + listener_count, mount_name_id) VALUES (:timestamp_id, + :listener_count, :mount_name_id)"; + foreach ($p_dataPoints as $dp) { - $timestamp_id = Application_Common_Database::prepareAndExecute($timestamp_sql, - array('ts'=> $dp['timestamp']), "column"); + $timestamp_id = Application_Common_Database::prepareAndExecute( + $timestamp_sql, + array('ts'=> $dp['timestamp']), + "column"); + + $mount_name_id = Application_Common_Database::prepareAndExecute( + $mount_name_check_sql, + array('mn' => $dp['mount_name']), + "column"); + + if (strlen($mount_name_id) == 0) { + //there is a race condition here where theoretically the row + //with value "mount_name" could appear, but this is *very* + //unlikely and won't break anything even if it happens. + $mount_name_id = Application_Common_Database::prepareAndExecute( + $mount_name_insert_sql, + array('mn' => $dp['mount_name']), + "column"); + } Application_Common_Database::prepareAndExecute($stats_sql, array('timestamp_id' => $timestamp_id, 'listener_count' => $dp["num_listeners"], - 'mount_name' => $dp["mount_name"], + 'mount_name_id' => $mount_name_id, ) ); } diff --git a/airtime_mvc/application/models/airtime/map/CcListenerCountTableMap.php b/airtime_mvc/application/models/airtime/map/CcListenerCountTableMap.php index 40efa51fe..ec7a5165b 100644 --- a/airtime_mvc/application/models/airtime/map/CcListenerCountTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcListenerCountTableMap.php @@ -40,8 +40,8 @@ class CcListenerCountTableMap extends TableMap { // columns $this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null); $this->addForeignKey('TIMESTAMP_ID', 'DbTimestampId', 'INTEGER', 'cc_timestamp', 'ID', true, null, null); + $this->addForeignKey('MOUNT_NAME_ID', 'DbMountNameId', 'INTEGER', 'cc_mount_name', 'ID', true, null, null); $this->addColumn('LISTENER_COUNT', 'DbListenerCount', 'INTEGER', true, null, null); - $this->addColumn('MOUNT_NAME', 'DbMountName', 'VARCHAR', true, 255, null); // validators } // initialize() @@ -51,6 +51,7 @@ class CcListenerCountTableMap extends TableMap { public function buildRelations() { $this->addRelation('CcTimestamp', 'CcTimestamp', RelationMap::MANY_TO_ONE, array('timestamp_id' => 'id', ), 'CASCADE', null); + $this->addRelation('CcTimestamp', 'CcTimestamp', RelationMap::MANY_TO_ONE, array('mount_name_id' => 'id', ), 'CASCADE', null); } // buildRelations() } // CcListenerCountTableMap diff --git a/airtime_mvc/application/models/airtime/om/BaseCcListenerCount.php b/airtime_mvc/application/models/airtime/om/BaseCcListenerCount.php index f831ccce6..04d4b60f3 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcListenerCount.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcListenerCount.php @@ -36,6 +36,12 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent */ protected $timestamp_id; + /** + * The value for the mount_name_id field. + * @var int + */ + protected $mount_name_id; + /** * The value for the listener_count field. * @var int @@ -43,10 +49,9 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent protected $listener_count; /** - * The value for the mount_name field. - * @var string + * @var CcTimestamp */ - protected $mount_name; + protected $aCcTimestamp; /** * @var CcTimestamp @@ -87,6 +92,16 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent return $this->timestamp_id; } + /** + * Get the [mount_name_id] column value. + * + * @return int + */ + public function getDbMountNameId() + { + return $this->mount_name_id; + } + /** * Get the [listener_count] column value. * @@ -97,16 +112,6 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent return $this->listener_count; } - /** - * Get the [mount_name] column value. - * - * @return string - */ - public function getDbMountName() - { - return $this->mount_name; - } - /** * Set the value of [id] column. * @@ -151,6 +156,30 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent return $this; } // setDbTimestampId() + /** + * Set the value of [mount_name_id] column. + * + * @param int $v new value + * @return CcListenerCount The current object (for fluent API support) + */ + public function setDbMountNameId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->mount_name_id !== $v) { + $this->mount_name_id = $v; + $this->modifiedColumns[] = CcListenerCountPeer::MOUNT_NAME_ID; + } + + if ($this->aCcTimestamp !== null && $this->aCcTimestamp->getDbId() !== $v) { + $this->aCcTimestamp = null; + } + + return $this; + } // setDbMountNameId() + /** * Set the value of [listener_count] column. * @@ -171,26 +200,6 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent return $this; } // setDbListenerCount() - /** - * Set the value of [mount_name] column. - * - * @param string $v new value - * @return CcListenerCount The current object (for fluent API support) - */ - public function setDbMountName($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->mount_name !== $v) { - $this->mount_name = $v; - $this->modifiedColumns[] = CcListenerCountPeer::MOUNT_NAME; - } - - return $this; - } // setDbMountName() - /** * Indicates whether the columns in this object are only set to default values. * @@ -225,8 +234,8 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null; $this->timestamp_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null; - $this->listener_count = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null; - $this->mount_name = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null; + $this->mount_name_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null; + $this->listener_count = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null; $this->resetModified(); $this->setNew(false); @@ -261,6 +270,9 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent if ($this->aCcTimestamp !== null && $this->timestamp_id !== $this->aCcTimestamp->getDbId()) { $this->aCcTimestamp = null; } + if ($this->aCcTimestamp !== null && $this->mount_name_id !== $this->aCcTimestamp->getDbId()) { + $this->aCcTimestamp = null; + } } // ensureConsistency /** @@ -301,6 +313,7 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent if ($deep) { // also de-associate any related objects? $this->aCcTimestamp = null; + $this->aCcTimestamp = null; } // if (deep) } @@ -423,6 +436,13 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent $this->setCcTimestamp($this->aCcTimestamp); } + if ($this->aCcTimestamp !== null) { + if ($this->aCcTimestamp->isModified() || $this->aCcTimestamp->isNew()) { + $affectedRows += $this->aCcTimestamp->save($con); + } + $this->setCcTimestamp($this->aCcTimestamp); + } + if ($this->isNew() ) { $this->modifiedColumns[] = CcListenerCountPeer::ID; } @@ -523,6 +543,12 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent } } + if ($this->aCcTimestamp !== null) { + if (!$this->aCcTimestamp->validate($columns)) { + $failureMap = array_merge($failureMap, $this->aCcTimestamp->getValidationFailures()); + } + } + if (($retval = CcListenerCountPeer::doValidate($this, $columns)) !== true) { $failureMap = array_merge($failureMap, $retval); @@ -569,10 +595,10 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent return $this->getDbTimestampId(); break; case 2: - return $this->getDbListenerCount(); + return $this->getDbMountNameId(); break; case 3: - return $this->getDbMountName(); + return $this->getDbListenerCount(); break; default: return null; @@ -600,13 +626,16 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent $result = array( $keys[0] => $this->getDbId(), $keys[1] => $this->getDbTimestampId(), - $keys[2] => $this->getDbListenerCount(), - $keys[3] => $this->getDbMountName(), + $keys[2] => $this->getDbMountNameId(), + $keys[3] => $this->getDbListenerCount(), ); if ($includeForeignObjects) { if (null !== $this->aCcTimestamp) { $result['CcTimestamp'] = $this->aCcTimestamp->toArray($keyType, $includeLazyLoadColumns, true); } + if (null !== $this->aCcTimestamp) { + $result['CcTimestamp'] = $this->aCcTimestamp->toArray($keyType, $includeLazyLoadColumns, true); + } } return $result; } @@ -645,10 +674,10 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent $this->setDbTimestampId($value); break; case 2: - $this->setDbListenerCount($value); + $this->setDbMountNameId($value); break; case 3: - $this->setDbMountName($value); + $this->setDbListenerCount($value); break; } // switch() } @@ -676,8 +705,8 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setDbTimestampId($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setDbListenerCount($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setDbMountName($arr[$keys[3]]); + if (array_key_exists($keys[2], $arr)) $this->setDbMountNameId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setDbListenerCount($arr[$keys[3]]); } /** @@ -691,8 +720,8 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent if ($this->isColumnModified(CcListenerCountPeer::ID)) $criteria->add(CcListenerCountPeer::ID, $this->id); if ($this->isColumnModified(CcListenerCountPeer::TIMESTAMP_ID)) $criteria->add(CcListenerCountPeer::TIMESTAMP_ID, $this->timestamp_id); + if ($this->isColumnModified(CcListenerCountPeer::MOUNT_NAME_ID)) $criteria->add(CcListenerCountPeer::MOUNT_NAME_ID, $this->mount_name_id); if ($this->isColumnModified(CcListenerCountPeer::LISTENER_COUNT)) $criteria->add(CcListenerCountPeer::LISTENER_COUNT, $this->listener_count); - if ($this->isColumnModified(CcListenerCountPeer::MOUNT_NAME)) $criteria->add(CcListenerCountPeer::MOUNT_NAME, $this->mount_name); return $criteria; } @@ -755,8 +784,8 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent public function copyInto($copyObj, $deepCopy = false) { $copyObj->setDbTimestampId($this->timestamp_id); + $copyObj->setDbMountNameId($this->mount_name_id); $copyObj->setDbListenerCount($this->listener_count); - $copyObj->setDbMountName($this->mount_name); $copyObj->setNew(true); $copyObj->setDbId(NULL); // this is a auto-increment column, so set to default value @@ -849,6 +878,55 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent return $this->aCcTimestamp; } + /** + * Declares an association between this object and a CcTimestamp object. + * + * @param CcTimestamp $v + * @return CcListenerCount The current object (for fluent API support) + * @throws PropelException + */ + public function setCcTimestamp(CcTimestamp $v = null) + { + if ($v === null) { + $this->setDbMountNameId(NULL); + } else { + $this->setDbMountNameId($v->getDbId()); + } + + $this->aCcTimestamp = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the CcTimestamp object, it will not be re-added. + if ($v !== null) { + $v->addCcListenerCount($this); + } + + return $this; + } + + + /** + * Get the associated CcTimestamp object + * + * @param PropelPDO Optional Connection object. + * @return CcTimestamp The associated CcTimestamp object. + * @throws PropelException + */ + public function getCcTimestamp(PropelPDO $con = null) + { + if ($this->aCcTimestamp === null && ($this->mount_name_id !== null)) { + $this->aCcTimestamp = CcTimestampQuery::create()->findPk($this->mount_name_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCcTimestamp->addCcListenerCounts($this); + */ + } + return $this->aCcTimestamp; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -856,8 +934,8 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent { $this->id = null; $this->timestamp_id = null; + $this->mount_name_id = null; $this->listener_count = null; - $this->mount_name = null; $this->alreadyInSave = false; $this->alreadyInValidation = false; $this->clearAllReferences(); @@ -881,6 +959,7 @@ abstract class BaseCcListenerCount extends BaseObject implements Persistent } // if ($deep) $this->aCcTimestamp = null; + $this->aCcTimestamp = null; } /** diff --git a/airtime_mvc/application/models/airtime/om/BaseCcListenerCountPeer.php b/airtime_mvc/application/models/airtime/om/BaseCcListenerCountPeer.php index ce9336bcb..9e3a7cb87 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcListenerCountPeer.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcListenerCountPeer.php @@ -37,12 +37,12 @@ abstract class BaseCcListenerCountPeer { /** the column name for the TIMESTAMP_ID field */ const TIMESTAMP_ID = 'cc_listener_count.TIMESTAMP_ID'; + /** the column name for the MOUNT_NAME_ID field */ + const MOUNT_NAME_ID = 'cc_listener_count.MOUNT_NAME_ID'; + /** the column name for the LISTENER_COUNT field */ const LISTENER_COUNT = 'cc_listener_count.LISTENER_COUNT'; - /** the column name for the MOUNT_NAME field */ - const MOUNT_NAME = 'cc_listener_count.MOUNT_NAME'; - /** * An identiy map to hold any loaded instances of CcListenerCount objects. * This must be public so that other peer classes can access this when hydrating from JOIN @@ -59,11 +59,11 @@ abstract class BaseCcListenerCountPeer { * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('DbId', 'DbTimestampId', 'DbListenerCount', 'DbMountName', ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbTimestampId', 'dbListenerCount', 'dbMountName', ), - BasePeer::TYPE_COLNAME => array (self::ID, self::TIMESTAMP_ID, self::LISTENER_COUNT, self::MOUNT_NAME, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID', 'TIMESTAMP_ID', 'LISTENER_COUNT', 'MOUNT_NAME', ), - BasePeer::TYPE_FIELDNAME => array ('id', 'timestamp_id', 'listener_count', 'mount_name', ), + BasePeer::TYPE_PHPNAME => array ('DbId', 'DbTimestampId', 'DbMountNameId', 'DbListenerCount', ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbTimestampId', 'dbMountNameId', 'dbListenerCount', ), + BasePeer::TYPE_COLNAME => array (self::ID, self::TIMESTAMP_ID, self::MOUNT_NAME_ID, self::LISTENER_COUNT, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID', 'TIMESTAMP_ID', 'MOUNT_NAME_ID', 'LISTENER_COUNT', ), + BasePeer::TYPE_FIELDNAME => array ('id', 'timestamp_id', 'mount_name_id', 'listener_count', ), BasePeer::TYPE_NUM => array (0, 1, 2, 3, ) ); @@ -74,11 +74,11 @@ abstract class BaseCcListenerCountPeer { * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbTimestampId' => 1, 'DbListenerCount' => 2, 'DbMountName' => 3, ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbTimestampId' => 1, 'dbListenerCount' => 2, 'dbMountName' => 3, ), - BasePeer::TYPE_COLNAME => array (self::ID => 0, self::TIMESTAMP_ID => 1, self::LISTENER_COUNT => 2, self::MOUNT_NAME => 3, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'TIMESTAMP_ID' => 1, 'LISTENER_COUNT' => 2, 'MOUNT_NAME' => 3, ), - BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'timestamp_id' => 1, 'listener_count' => 2, 'mount_name' => 3, ), + BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbTimestampId' => 1, 'DbMountNameId' => 2, 'DbListenerCount' => 3, ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbTimestampId' => 1, 'dbMountNameId' => 2, 'dbListenerCount' => 3, ), + BasePeer::TYPE_COLNAME => array (self::ID => 0, self::TIMESTAMP_ID => 1, self::MOUNT_NAME_ID => 2, self::LISTENER_COUNT => 3, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'TIMESTAMP_ID' => 1, 'MOUNT_NAME_ID' => 2, 'LISTENER_COUNT' => 3, ), + BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'timestamp_id' => 1, 'mount_name_id' => 2, 'listener_count' => 3, ), BasePeer::TYPE_NUM => array (0, 1, 2, 3, ) ); @@ -153,13 +153,13 @@ abstract class BaseCcListenerCountPeer { if (null === $alias) { $criteria->addSelectColumn(CcListenerCountPeer::ID); $criteria->addSelectColumn(CcListenerCountPeer::TIMESTAMP_ID); + $criteria->addSelectColumn(CcListenerCountPeer::MOUNT_NAME_ID); $criteria->addSelectColumn(CcListenerCountPeer::LISTENER_COUNT); - $criteria->addSelectColumn(CcListenerCountPeer::MOUNT_NAME); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.TIMESTAMP_ID'); + $criteria->addSelectColumn($alias . '.MOUNT_NAME_ID'); $criteria->addSelectColumn($alias . '.LISTENER_COUNT'); - $criteria->addSelectColumn($alias . '.MOUNT_NAME'); } } @@ -495,6 +495,56 @@ abstract class BaseCcListenerCountPeer { } + /** + * Returns the number of rows matching criteria, joining the related CcTimestamp table + * + * @param Criteria $criteria + * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead. + * @param PropelPDO $con + * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN + * @return int Number of matching rows. + */ + public static function doCountJoinCcTimestamp(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN) + { + // we're going to modify criteria, so copy it first + $criteria = clone $criteria; + + // We need to set the primary table name, since in the case that there are no WHERE columns + // it will be impossible for the BasePeer::createSelectSql() method to determine which + // tables go into the FROM clause. + $criteria->setPrimaryTableName(CcListenerCountPeer::TABLE_NAME); + + if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { + $criteria->setDistinct(); + } + + if (!$criteria->hasSelectClause()) { + CcListenerCountPeer::addSelectColumns($criteria); + } + + $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + if ($con === null) { + $con = Propel::getConnection(CcListenerCountPeer::DATABASE_NAME, Propel::CONNECTION_READ); + } + + $criteria->addJoin(CcListenerCountPeer::MOUNT_NAME_ID, CcTimestampPeer::ID, $join_behavior); + + $stmt = BasePeer::doCount($criteria, $con); + + if ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $count = (int) $row[0]; + } else { + $count = 0; // no rows returned; we infer that means 0 matches. + } + $stmt->closeCursor(); + return $count; + } + + /** * Selects a collection of CcListenerCount objects pre-filled with their CcTimestamp objects. * @param Criteria $criteria @@ -561,6 +611,72 @@ abstract class BaseCcListenerCountPeer { } + /** + * Selects a collection of CcListenerCount objects pre-filled with their CcTimestamp objects. + * @param Criteria $criteria + * @param PropelPDO $con + * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN + * @return array Array of CcListenerCount objects. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelectJoinCcTimestamp(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) + { + $criteria = clone $criteria; + + // Set the correct dbName if it has not been overridden + if ($criteria->getDbName() == Propel::getDefaultDB()) { + $criteria->setDbName(self::DATABASE_NAME); + } + + CcListenerCountPeer::addSelectColumns($criteria); + $startcol = (CcListenerCountPeer::NUM_COLUMNS - CcListenerCountPeer::NUM_LAZY_LOAD_COLUMNS); + CcTimestampPeer::addSelectColumns($criteria); + + $criteria->addJoin(CcListenerCountPeer::MOUNT_NAME_ID, CcTimestampPeer::ID, $join_behavior); + + $stmt = BasePeer::doSelect($criteria, $con); + $results = array(); + + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $key1 = CcListenerCountPeer::getPrimaryKeyHashFromRow($row, 0); + if (null !== ($obj1 = CcListenerCountPeer::getInstanceFromPool($key1))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj1->hydrate($row, 0, true); // rehydrate + } else { + + $cls = CcListenerCountPeer::getOMClass(false); + + $obj1 = new $cls(); + $obj1->hydrate($row); + CcListenerCountPeer::addInstanceToPool($obj1, $key1); + } // if $obj1 already loaded + + $key2 = CcTimestampPeer::getPrimaryKeyHashFromRow($row, $startcol); + if ($key2 !== null) { + $obj2 = CcTimestampPeer::getInstanceFromPool($key2); + if (!$obj2) { + + $cls = CcTimestampPeer::getOMClass(false); + + $obj2 = new $cls(); + $obj2->hydrate($row, $startcol); + CcTimestampPeer::addInstanceToPool($obj2, $key2); + } // if obj2 already loaded + + // Add the $obj1 (CcListenerCount) to $obj2 (CcTimestamp) + $obj2->addCcListenerCount($obj1); + + } // if joined row was not null + + $results[] = $obj1; + } + $stmt->closeCursor(); + return $results; + } + + /** * Returns the number of rows matching criteria, joining all related tables * @@ -599,6 +715,8 @@ abstract class BaseCcListenerCountPeer { $criteria->addJoin(CcListenerCountPeer::TIMESTAMP_ID, CcTimestampPeer::ID, $join_behavior); + $criteria->addJoin(CcListenerCountPeer::MOUNT_NAME_ID, CcTimestampPeer::ID, $join_behavior); + $stmt = BasePeer::doCount($criteria, $con); if ($row = $stmt->fetch(PDO::FETCH_NUM)) { @@ -635,8 +753,13 @@ abstract class BaseCcListenerCountPeer { CcTimestampPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (CcTimestampPeer::NUM_COLUMNS - CcTimestampPeer::NUM_LAZY_LOAD_COLUMNS); + CcTimestampPeer::addSelectColumns($criteria); + $startcol4 = $startcol3 + (CcTimestampPeer::NUM_COLUMNS - CcTimestampPeer::NUM_LAZY_LOAD_COLUMNS); + $criteria->addJoin(CcListenerCountPeer::TIMESTAMP_ID, CcTimestampPeer::ID, $join_behavior); + $criteria->addJoin(CcListenerCountPeer::MOUNT_NAME_ID, CcTimestampPeer::ID, $join_behavior); + $stmt = BasePeer::doSelect($criteria, $con); $results = array(); @@ -672,6 +795,218 @@ abstract class BaseCcListenerCountPeer { $obj2->addCcListenerCount($obj1); } // if joined row not null + // Add objects for joined CcTimestamp rows + + $key3 = CcTimestampPeer::getPrimaryKeyHashFromRow($row, $startcol3); + if ($key3 !== null) { + $obj3 = CcTimestampPeer::getInstanceFromPool($key3); + if (!$obj3) { + + $cls = CcTimestampPeer::getOMClass(false); + + $obj3 = new $cls(); + $obj3->hydrate($row, $startcol3); + CcTimestampPeer::addInstanceToPool($obj3, $key3); + } // if obj3 loaded + + // Add the $obj1 (CcListenerCount) to the collection in $obj3 (CcTimestamp) + $obj3->addCcListenerCount($obj1); + } // if joined row not null + + $results[] = $obj1; + } + $stmt->closeCursor(); + return $results; + } + + + /** + * Returns the number of rows matching criteria, joining the related CcTimestamp table + * + * @param Criteria $criteria + * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead. + * @param PropelPDO $con + * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN + * @return int Number of matching rows. + */ + public static function doCountJoinAllExceptCcTimestamp(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN) + { + // we're going to modify criteria, so copy it first + $criteria = clone $criteria; + + // We need to set the primary table name, since in the case that there are no WHERE columns + // it will be impossible for the BasePeer::createSelectSql() method to determine which + // tables go into the FROM clause. + $criteria->setPrimaryTableName(CcListenerCountPeer::TABLE_NAME); + + if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { + $criteria->setDistinct(); + } + + if (!$criteria->hasSelectClause()) { + CcListenerCountPeer::addSelectColumns($criteria); + } + + $criteria->clearOrderByColumns(); // ORDER BY should not affect count + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + if ($con === null) { + $con = Propel::getConnection(CcListenerCountPeer::DATABASE_NAME, Propel::CONNECTION_READ); + } + + $stmt = BasePeer::doCount($criteria, $con); + + if ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $count = (int) $row[0]; + } else { + $count = 0; // no rows returned; we infer that means 0 matches. + } + $stmt->closeCursor(); + return $count; + } + + + /** + * Returns the number of rows matching criteria, joining the related CcTimestamp table + * + * @param Criteria $criteria + * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead. + * @param PropelPDO $con + * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN + * @return int Number of matching rows. + */ + public static function doCountJoinAllExceptCcTimestamp(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN) + { + // we're going to modify criteria, so copy it first + $criteria = clone $criteria; + + // We need to set the primary table name, since in the case that there are no WHERE columns + // it will be impossible for the BasePeer::createSelectSql() method to determine which + // tables go into the FROM clause. + $criteria->setPrimaryTableName(CcListenerCountPeer::TABLE_NAME); + + if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { + $criteria->setDistinct(); + } + + if (!$criteria->hasSelectClause()) { + CcListenerCountPeer::addSelectColumns($criteria); + } + + $criteria->clearOrderByColumns(); // ORDER BY should not affect count + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + if ($con === null) { + $con = Propel::getConnection(CcListenerCountPeer::DATABASE_NAME, Propel::CONNECTION_READ); + } + + $stmt = BasePeer::doCount($criteria, $con); + + if ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $count = (int) $row[0]; + } else { + $count = 0; // no rows returned; we infer that means 0 matches. + } + $stmt->closeCursor(); + return $count; + } + + + /** + * Selects a collection of CcListenerCount objects pre-filled with all related objects except CcTimestamp. + * + * @param Criteria $criteria + * @param PropelPDO $con + * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN + * @return array Array of CcListenerCount objects. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelectJoinAllExceptCcTimestamp(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) + { + $criteria = clone $criteria; + + // Set the correct dbName if it has not been overridden + // $criteria->getDbName() will return the same object if not set to another value + // so == check is okay and faster + if ($criteria->getDbName() == Propel::getDefaultDB()) { + $criteria->setDbName(self::DATABASE_NAME); + } + + CcListenerCountPeer::addSelectColumns($criteria); + $startcol2 = (CcListenerCountPeer::NUM_COLUMNS - CcListenerCountPeer::NUM_LAZY_LOAD_COLUMNS); + + + $stmt = BasePeer::doSelect($criteria, $con); + $results = array(); + + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $key1 = CcListenerCountPeer::getPrimaryKeyHashFromRow($row, 0); + if (null !== ($obj1 = CcListenerCountPeer::getInstanceFromPool($key1))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj1->hydrate($row, 0, true); // rehydrate + } else { + $cls = CcListenerCountPeer::getOMClass(false); + + $obj1 = new $cls(); + $obj1->hydrate($row); + CcListenerCountPeer::addInstanceToPool($obj1, $key1); + } // if obj1 already loaded + + $results[] = $obj1; + } + $stmt->closeCursor(); + return $results; + } + + + /** + * Selects a collection of CcListenerCount objects pre-filled with all related objects except CcTimestamp. + * + * @param Criteria $criteria + * @param PropelPDO $con + * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN + * @return array Array of CcListenerCount objects. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelectJoinAllExceptCcTimestamp(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) + { + $criteria = clone $criteria; + + // Set the correct dbName if it has not been overridden + // $criteria->getDbName() will return the same object if not set to another value + // so == check is okay and faster + if ($criteria->getDbName() == Propel::getDefaultDB()) { + $criteria->setDbName(self::DATABASE_NAME); + } + + CcListenerCountPeer::addSelectColumns($criteria); + $startcol2 = (CcListenerCountPeer::NUM_COLUMNS - CcListenerCountPeer::NUM_LAZY_LOAD_COLUMNS); + + + $stmt = BasePeer::doSelect($criteria, $con); + $results = array(); + + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $key1 = CcListenerCountPeer::getPrimaryKeyHashFromRow($row, 0); + if (null !== ($obj1 = CcListenerCountPeer::getInstanceFromPool($key1))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj1->hydrate($row, 0, true); // rehydrate + } else { + $cls = CcListenerCountPeer::getOMClass(false); + + $obj1 = new $cls(); + $obj1->hydrate($row); + CcListenerCountPeer::addInstanceToPool($obj1, $key1); + } // if obj1 already loaded + $results[] = $obj1; } $stmt->closeCursor(); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcListenerCountQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcListenerCountQuery.php index 44f235115..ed04cd146 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcListenerCountQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcListenerCountQuery.php @@ -8,13 +8,13 @@ * * @method CcListenerCountQuery orderByDbId($order = Criteria::ASC) Order by the id column * @method CcListenerCountQuery orderByDbTimestampId($order = Criteria::ASC) Order by the timestamp_id column + * @method CcListenerCountQuery orderByDbMountNameId($order = Criteria::ASC) Order by the mount_name_id column * @method CcListenerCountQuery orderByDbListenerCount($order = Criteria::ASC) Order by the listener_count column - * @method CcListenerCountQuery orderByDbMountName($order = Criteria::ASC) Order by the mount_name column * * @method CcListenerCountQuery groupByDbId() Group by the id column * @method CcListenerCountQuery groupByDbTimestampId() Group by the timestamp_id column + * @method CcListenerCountQuery groupByDbMountNameId() Group by the mount_name_id column * @method CcListenerCountQuery groupByDbListenerCount() Group by the listener_count column - * @method CcListenerCountQuery groupByDbMountName() Group by the mount_name column * * @method CcListenerCountQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method CcListenerCountQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query @@ -24,18 +24,22 @@ * @method CcListenerCountQuery rightJoinCcTimestamp($relationAlias = '') Adds a RIGHT JOIN clause to the query using the CcTimestamp relation * @method CcListenerCountQuery innerJoinCcTimestamp($relationAlias = '') Adds a INNER JOIN clause to the query using the CcTimestamp relation * + * @method CcListenerCountQuery leftJoinCcTimestamp($relationAlias = '') Adds a LEFT JOIN clause to the query using the CcTimestamp relation + * @method CcListenerCountQuery rightJoinCcTimestamp($relationAlias = '') Adds a RIGHT JOIN clause to the query using the CcTimestamp relation + * @method CcListenerCountQuery innerJoinCcTimestamp($relationAlias = '') Adds a INNER JOIN clause to the query using the CcTimestamp relation + * * @method CcListenerCount findOne(PropelPDO $con = null) Return the first CcListenerCount matching the query * @method CcListenerCount findOneOrCreate(PropelPDO $con = null) Return the first CcListenerCount matching the query, or a new CcListenerCount object populated from the query conditions when no match is found * * @method CcListenerCount findOneByDbId(int $id) Return the first CcListenerCount filtered by the id column * @method CcListenerCount findOneByDbTimestampId(int $timestamp_id) Return the first CcListenerCount filtered by the timestamp_id column + * @method CcListenerCount findOneByDbMountNameId(int $mount_name_id) Return the first CcListenerCount filtered by the mount_name_id column * @method CcListenerCount findOneByDbListenerCount(int $listener_count) Return the first CcListenerCount filtered by the listener_count column - * @method CcListenerCount findOneByDbMountName(string $mount_name) Return the first CcListenerCount filtered by the mount_name column * * @method array findByDbId(int $id) Return CcListenerCount objects filtered by the id column * @method array findByDbTimestampId(int $timestamp_id) Return CcListenerCount objects filtered by the timestamp_id column + * @method array findByDbMountNameId(int $mount_name_id) Return CcListenerCount objects filtered by the mount_name_id column * @method array findByDbListenerCount(int $listener_count) Return CcListenerCount objects filtered by the listener_count column - * @method array findByDbMountName(string $mount_name) Return CcListenerCount objects filtered by the mount_name column * * @package propel.generator.airtime.om */ @@ -193,6 +197,37 @@ abstract class BaseCcListenerCountQuery extends ModelCriteria return $this->addUsingAlias(CcListenerCountPeer::TIMESTAMP_ID, $dbTimestampId, $comparison); } + /** + * Filter the query on the mount_name_id column + * + * @param int|array $dbMountNameId The value to use as filter. + * Accepts an associative array('min' => $minValue, 'max' => $maxValue) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CcListenerCountQuery The current query, for fluid interface + */ + public function filterByDbMountNameId($dbMountNameId = null, $comparison = null) + { + if (is_array($dbMountNameId)) { + $useMinMax = false; + if (isset($dbMountNameId['min'])) { + $this->addUsingAlias(CcListenerCountPeer::MOUNT_NAME_ID, $dbMountNameId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($dbMountNameId['max'])) { + $this->addUsingAlias(CcListenerCountPeer::MOUNT_NAME_ID, $dbMountNameId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + return $this->addUsingAlias(CcListenerCountPeer::MOUNT_NAME_ID, $dbMountNameId, $comparison); + } + /** * Filter the query on the listener_count column * @@ -225,25 +260,67 @@ abstract class BaseCcListenerCountQuery extends ModelCriteria } /** - * Filter the query on the mount_name column - * - * @param string $dbMountName The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) + * Filter the query by a related CcTimestamp object + * + * @param CcTimestamp $ccTimestamp the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return CcListenerCountQuery The current query, for fluid interface */ - public function filterByDbMountName($dbMountName = null, $comparison = null) + public function filterByCcTimestamp($ccTimestamp, $comparison = null) { - if (null === $comparison) { - if (is_array($dbMountName)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $dbMountName)) { - $dbMountName = str_replace('*', '%', $dbMountName); - $comparison = Criteria::LIKE; - } + return $this + ->addUsingAlias(CcListenerCountPeer::TIMESTAMP_ID, $ccTimestamp->getDbId(), $comparison); + } + + /** + * Adds a JOIN clause to the query using the CcTimestamp relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return CcListenerCountQuery The current query, for fluid interface + */ + public function joinCcTimestamp($relationAlias = '', $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CcTimestamp'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); } - return $this->addUsingAlias(CcListenerCountPeer::MOUNT_NAME, $dbMountName, $comparison); + + // add the ModelJoin to the current object + if($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CcTimestamp'); + } + + return $this; + } + + /** + * Use the CcTimestamp relation CcTimestamp object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return CcTimestampQuery A secondary query class using the current class as primary query + */ + public function useCcTimestampQuery($relationAlias = '', $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCcTimestamp($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CcTimestamp', 'CcTimestampQuery'); } /** @@ -257,7 +334,7 @@ abstract class BaseCcListenerCountQuery extends ModelCriteria public function filterByCcTimestamp($ccTimestamp, $comparison = null) { return $this - ->addUsingAlias(CcListenerCountPeer::TIMESTAMP_ID, $ccTimestamp->getDbId(), $comparison); + ->addUsingAlias(CcListenerCountPeer::MOUNT_NAME_ID, $ccTimestamp->getDbId(), $comparison); } /** diff --git a/airtime_mvc/build/schema.xml b/airtime_mvc/build/schema.xml index de3f6481c..d633fb299 100644 --- a/airtime_mvc/build/schema.xml +++ b/airtime_mvc/build/schema.xml @@ -437,6 +437,10 @@ + + + +
@@ -444,10 +448,13 @@
+ - + + +
diff --git a/airtime_mvc/build/sql/schema.sql b/airtime_mvc/build/sql/schema.sql index 6d3b061cf..2fc3e30ad 100644 --- a/airtime_mvc/build/sql/schema.sql +++ b/airtime_mvc/build/sql/schema.sql @@ -666,6 +666,24 @@ CREATE TABLE "cc_webstream_metadata" COMMENT ON TABLE "cc_webstream_metadata" IS ''; +SET search_path TO public; +----------------------------------------------------------------------------- +-- cc_mount_name +----------------------------------------------------------------------------- + +DROP TABLE "cc_mount_name" CASCADE; + + +CREATE TABLE "cc_mount_name" +( + "id" serial NOT NULL, + "mount_name" VARCHAR(255) NOT NULL, + PRIMARY KEY ("id") +); + +COMMENT ON TABLE "cc_mount_name" IS ''; + + SET search_path TO public; ----------------------------------------------------------------------------- -- cc_timestamp @@ -696,8 +714,8 @@ CREATE TABLE "cc_listener_count" ( "id" serial NOT NULL, "timestamp_id" INTEGER NOT NULL, + "mount_name_id" INTEGER NOT NULL, "listener_count" INTEGER NOT NULL, - "mount_name" VARCHAR(255) NOT NULL, PRIMARY KEY ("id") ); @@ -758,3 +776,5 @@ ALTER TABLE "cc_subjs_token" ADD CONSTRAINT "cc_subjs_token_userid_fkey" FOREIGN ALTER TABLE "cc_webstream_metadata" ADD CONSTRAINT "cc_schedule_inst_fkey" FOREIGN KEY ("instance_id") REFERENCES "cc_schedule" ("id") ON DELETE CASCADE; ALTER TABLE "cc_listener_count" ADD CONSTRAINT "cc_timestamp_inst_fkey" FOREIGN KEY ("timestamp_id") REFERENCES "cc_timestamp" ("id") ON DELETE CASCADE; + +ALTER TABLE "cc_listener_count" ADD CONSTRAINT "cc_mount_name_inst_fkey" FOREIGN KEY ("mount_name_id") REFERENCES "cc_mount_name" ("id") ON DELETE CASCADE;