protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); echo "Running sfReviewStatsTask ... \n"; $query = "SELECT r.entity_id, r.sf_review_type_id, r.value, SUM(r.value) sum " . "FROM %s r " . "INNER JOIN %s s ON s.id = r.sf_review_status_id " . "WHERE r.is_active = 1 " . "AND r.sf_review_type_id is not null " . "group by entity_id, sf_review_type_id, value "; $query = sprintf($query, SfReviewPeer::TABLE_NAME, SfReviewStatusPeer::TABLE_NAME); $connection = Propel::getConnection(); $statement = $connection->prepare($query); //$statement->bindValue(1, 0); $statement->execute(); while ($row = $statement->fetch()) { $isNew = false; $yesterday = strtotime("yesterday"); $sfReviewTypeEntity = SfReviewTypeEntityPeer::retrieveByPK($row['sf_review_type_id'], $row['entity_id'], $yesterday, $row['value']); if (!$sfReviewTypeEntity) { $isNew = true; $sfReviewTypeEntity = new SfReviewTypeEntity(); $sfReviewTypeEntity->setSfReviewTypeId($row['sf_review_type_id']); $sfReviewTypeEntity->setEntityId($row['entity_id']); $sfReviewTypeEntity->setValue($row['value']); $sfReviewTypeEntity->setDate($yesterday); $sfReviewTypeEntity->setSum($row['sum']); SfReviewTypeEntityPeer::doInsert($sfReviewTypeEntity); } } }
public static function paintPolitico($id) { $c = new Criteria(); $c->add(SfReviewTypeEntityPeer::ENTITY_ID, $id); $c->add(SfReviewTypeEntityPeer::VALUE, 1); $c->addAscendingOrderByColumn(SfReviewTypeEntityPeer::DATE); $elements = SfReviewTypeEntityPeer::doSelect($c); $sparkline = new Sparkline_Line(); $sparkline->SetDebugLevel(DEBUG_NONE); $sparkline->SetColorHtml('background', '#e0e0e0'); $sparkline->SetColorBackground('background'); $i = 0; foreach ($elements as $element) { $i++; $sparkline->SetData($i, $element->getSum()); } $sparkline->SetYMin(0); $sparkline->SetLineSize(4); $sparkline->RenderResampled(100, 15); $sparkline->Output(); }
/** * Returns the number of related SfReviewTypeEntity objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related SfReviewTypeEntity objects. * @throws PropelException */ public function countSfReviewTypeEntitys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(SfReviewTypePeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collSfReviewTypeEntitys === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(SfReviewTypeEntityPeer::SF_REVIEW_TYPE_ID, $this->id); $count = SfReviewTypeEntityPeer::doCount($criteria, false, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(SfReviewTypeEntityPeer::SF_REVIEW_TYPE_ID, $this->id); if (!isset($this->lastSfReviewTypeEntityCriteria) || !$this->lastSfReviewTypeEntityCriteria->equals($criteria)) { $count = SfReviewTypeEntityPeer::doCount($criteria, false, $con); } else { $count = count($this->collSfReviewTypeEntitys); } } else { $count = count($this->collSfReviewTypeEntitys); } } return $count; }
/** * Retrieve object using using composite pkey values. * @param int $sf_review_type_id * @param int $entity_id * @param string $date * @param int $value * @param PropelPDO $con * @return SfReviewTypeEntity */ public static function retrieveByPK($sf_review_type_id, $entity_id, $date, $value, PropelPDO $con = null) { $key = serialize(array((string) $sf_review_type_id, (string) $entity_id, (string) $date, (string) $value)); if (null !== ($obj = SfReviewTypeEntityPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(SfReviewTypeEntityPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(SfReviewTypeEntityPeer::DATABASE_NAME); $criteria->add(SfReviewTypeEntityPeer::SF_REVIEW_TYPE_ID, $sf_review_type_id); $criteria->add(SfReviewTypeEntityPeer::ENTITY_ID, $entity_id); $criteria->add(SfReviewTypeEntityPeer::DATE, $date); $criteria->add(SfReviewTypeEntityPeer::VALUE, $value); $v = SfReviewTypeEntityPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = SfReviewTypeEntityPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setSfReviewTypeId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setEntityId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDate($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setValue($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setSum($arr[$keys[4]]); } }