Beispiel #1
0
 public static function incrementActivity($partner_id, $activity, $sub_activity, $amount = 1, $day = null, $field = null)
 {
     if (!$day) {
         $day = date("Y-m-d");
     }
     $field_name = $field ? PartnerActivityPeer::AMOUNT . $field : PartnerActivityPeer::AMOUNT;
     /*		
     		$query = "INSERT INTO ".PartnerActivityPeer::TABLE_NAME." (".
     			PartnerActivityPeer::PARTNER_ID.",".
     			PartnerActivityPeer::ACTIVITY_DATE.",".
     			PartnerActivityPeer::ACTIVITY.",".
     			PartnerActivityPeer::SUB_ACTIVITY.",".
     			$field_name.") VALUES ".
     			"($partner_id,'$day',$activity,$sub_activity,$amount) ON DUPLICATE KEY UPDATE ".
     			"$field_name=$field_name+$amount";
     
     		$connection = Propel::getConnection();
     
     		$statement = $connection->prepareStatement($query);
     	    $resultset = $statement->executeQuery();
     */
     $connection = Propel::getConnection();
     $crit = new Criteria();
     $crit->addAnd(PartnerActivityPeer::PARTNER_ID, $partner_id);
     $crit->addAnd(PartnerActivityPeer::ACTIVITY_DATE, $day);
     $crit->addAnd(PartnerActivityPeer::ACTIVITY, $activity);
     $crit->addAnd(PartnerActivityPeer::SUB_ACTIVITY, $sub_activity);
     $crit->addSelectColumn(PartnerActivityPeer::ID);
     $resultset = PartnerActivityPeer::doSelectOne($crit, $connection);
     /*
     		$query = "SELECT ID FROM ".PartnerActivityPeer::TABLE_NAME." WHERE ".
     			PartnerActivityPeer::PARTNER_ID."=$partner_id AND ".
     			PartnerActivityPeer::ACTIVITY_DATE."='$day' AND ".
     			PartnerActivityPeer::ACTIVITY."=$activity AND ".
     			PartnerActivityPeer::SUB_ACTIVITY."=$sub_activity";
     		
     		$statement = $connection->prepare($query);
     	    $resultset = $statement->execute();
     */
     // if the key exists do an update command
     if ($resultset) {
         $id = $resultset->getInt('ID');
         $updateCommand = "UPDATE " . PartnerActivityPeer::TABLE_NAME . " SET {$field_name}={$field_name}+{$amount} WHERE " . PartnerActivityPeer::ID . "={$id}";
     } else {
         $updateCommand = "INSERT INTO " . PartnerActivityPeer::TABLE_NAME . " (" . PartnerActivityPeer::PARTNER_ID . "," . PartnerActivityPeer::ACTIVITY_DATE . "," . PartnerActivityPeer::ACTIVITY . "," . PartnerActivityPeer::SUB_ACTIVITY . "," . $field_name . ") VALUES " . "({$partner_id},'{$day}',{$activity},{$sub_activity},{$amount})";
     }
     $statement = $connection->prepare($updateCommand);
     $resultset = $statement->execute();
 }
 /**
  * deprecated - data moved to DWH
  */
 public static function collectPartnerUsage($partner, $partnerPackage, $report_date)
 {
     $c = new Criteria();
     $c->addAnd(PartnerActivityPeer::ACTIVITY, PartnerActivity::PARTNER_ACTIVITY_MONTHLY_AGGREGATION);
     $c->addAnd(PartnerActivityPeer::PARTNER_ID, $partner->getId());
     if ($partnerPackage['id'] != 1) {
         $c->addAnd(PartnerActivityPeer::ACTIVITY_DATE, $report_date);
     }
     $activities = PartnerActivityPeer::doSelect($c);
     $totalUsage = 0;
     $totalStorage = 0;
     $totalTraffic = 0;
     if ($partnerPackage['id'] == 1) {
         foreach ($activities as $activity) {
             $totalStorage += $activity->getAmount1();
             $totalTraffic += $activity->getAmount2();
             $totalUsage += $activity->getAmount();
         }
     } else {
         if (count($activities)) {
             $totalStorage = $activities[0]->getAmount1();
             // MB value
             $totalTraffic = $activities[0]->getAmount2();
             // KB value
             $totalUsage = $activities[0]->getAmount();
             // KB value
         } else {
             $totalStorage = $totalTraffic = $totalUsage = 0;
             // probably 04/Month/year, and batch didn't get to that partner yet
         }
     }
     return array($totalStorage, $totalUsage, $totalTraffic);
 }
 private function getTrafficFor($partnerId, $date)
 {
     $partnerActivityCriteria = new Criteria();
     $partnerActivityCriteria->addAnd(PartnerActivityPeer::ACTIVITY_DATE, $date);
     $partnerActivityCriteria->addAnd(PartnerActivityPeer::ACTIVITY, PartnerActivity::PARTNER_ACTIVITY_TRAFFIC);
     $partnerActivityCriteria->addAnd(PartnerActivityPeer::SUB_ACTIVITY, array(PartnerActivity::PARTNER_SUB_ACTIVITY_WWW, PartnerActivity::PARTNER_SUB_ACTIVITY_LIMELIGHT), Criteria::IN);
     $partnerActivityCriteria->addAnd(PartnerActivityPeer::PARTNER_ID, $partnerId);
     $activity = PartnerActivityPeer::doSelect($partnerActivityCriteria);
     //KalturaLog::debug("traffic ! $partnerId and $date resulted in ".count($activity). " rows");
     $_traffic = 0;
     if (count($activity) == 2) {
         $_traffic = $activity[0]->getAmount();
         //KalturaLog::debug("DB value (act[0]) = ".$activity[0]->getAmount().' my value = '.$_traffic);
         $_traffic += $activity[1]->getAmount();
         //KalturaLog::debug("DB value (act[1]) = ".$activity[1]->getAmount().' my value = '.$_traffic);
     } elseif (count($activity) == 1) {
         $_traffic = $activity[0]->getAmount();
         //KalturaLog::debug("DB value (act[0] only) = ".$activity[0]->getAmount().' my value = '.$_traffic);
     }
     return $_traffic;
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PartnerActivityPeer::DATABASE_NAME);
         $criteria->add(PartnerActivityPeer::ID, $pks, Criteria::IN);
         $objs = PartnerActivityPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * 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 = PartnerActivityPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setPartnerId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setActivityDate($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setActivity($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setSubActivity($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setAmount($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setAmount1($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setAmount2($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setAmount3($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setAmount4($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setAmount5($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setAmount6($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setAmount7($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setAmount9($arr[$keys[13]]);
     }
 }