function createPackageList()
{
    $partnerPackages = new PartnerPackages();
    $packages = $partnerPackages->listPackages();
    $partner_package_list = array();
    foreach ($packages as $package) {
        $partner_package_list[$package['id']] = $package['name'];
    }
    return $partner_package_list;
}
Пример #2
0
 private static function validatePartnerMonthlyUsagePerType($partner, $partnerPackage, $usage, $usageType, $report_date, $block_notification_grace, $delete_grace, $email_link_hash)
 {
     if (!array_key_exists($usageType, $partnerPackage)) {
         return;
     }
     $usageGB = $usage / 1024 / 1024;
     // from KB to GB
     $percent = round($usageGB / $partnerPackage[$usageType] * 100, 2);
     $notificationId = 0;
     KalturaLog::debug("percent (" . $partner->getId() . ") is: {$percent} for usage type {$usageType}");
     //check if partner should be deleted
     if ($partner->getStatus() == Partner::PARTNER_STATUS_CONTENT_BLOCK) {
         $warning_100 = $partner->getUsageWarning($usageType, 100);
         if ($warning_100 > 0 && $warning_100 <= $delete_grace) {
             KalturaLog::debug("partner " . $partner->getId() . " reached 100% a month ago - deleting partner");
             /* delete partner */
             $notificationId = myPartnerUtils::KALTURA_DELETE_ACCOUNT;
             $partner->setStatus(Partner::PARTNER_STATUS_DELETED);
         }
     } else {
         self::resetMonthlyUsageWarningIfNotRelevant($partner, $usageType, $percent, $report_date);
         $warning_80 = $partner->getUsageWarning($usageType, 80);
         $warning_100 = $partner->getUsageWarning($usageType, 100);
         if ($percent >= 80 && $percent < 100 && !$warning_80) {
             KalturaLog::debug("partner " . $partner->getId() . " reached 80% - setting first warning for usage " . $usageType);
             $partner->setUsageWarning($usageType, 80, time());
             $partner->resetUsageWarning($usageType, 100);
             $notificationId = myPartnerUtils::KALTURA_MONTHLY_PACKAGE_EIGHTY_PERCENT_WARNING;
         } elseif ($percent >= 80 && $percent < 100 && $warning_80 && !$warning_100) {
             KalturaLog::log("passed the 80%, assume notification sent, nothing to do.");
         } elseif ($percent >= 100 && !$warning_100) {
             KalturaLog::debug("partner " . $partner->getId() . " reached 100% - setting second warning for usage " . $usageType);
             $partner->setUsageWarning($usageType, 100, time());
             $notificationId = myPartnerUtils::KALTURA_MONTHLY_PACKAGE_LIMIT_WARNING_1;
         } elseif ($percent >= 100 && $warning_100 > 0 && $warning_100 <= $block_notification_grace && $warning_100 > $delete_grace) {
             KalturaLog::debug("partner " . $partner->getId() . " reached 100% " . self::BLOCKING_DAYS_GRACE . " days ago - sending block email and blocking partner");
             /* send block email and block partner */
             $notificationId = myPartnerUtils::KALTURA_MONTHLY_PACKAGE_LIMIT_WARNING_2;
             $partner->setStatus(Partner::PARTNER_STATUS_CONTENT_BLOCK);
         }
     }
     if ($notificationId) {
         $body_params = array();
         $usageText = PartnerPackages::getPackageUsageText($usageType);
         switch ($notificationId) {
             case myPartnerUtils::KALTURA_MONTHLY_PACKAGE_EIGHTY_PERCENT_WARNING:
                 $body_params = array($partner->getAdminName(), $partnerPackage[$usageType], $usageText, round($usageGB, 2), $email_link_hash);
                 break;
             case myPartnerUtils::KALTURA_MONTHLY_PACKAGE_LIMIT_WARNING_1:
                 $body_params = array($partner->getAdminName(), $partnerPackage[$usageType], $usageText, round($usageGB, 2), $email_link_hash);
                 break;
             case myPartnerUtils::KALTURA_MONTHLY_PACKAGE_LIMIT_WARNING_2:
                 $body_params = array($partner->getAdminName(), $partnerPackage[$usageType], $usageText, round($usageGB, 2), $email_link_hash);
                 break;
             case myPartnerUtils::KALTURA_DELETE_ACCOUNT:
                 $body_params = array($partner->getAdminName());
                 break;
         }
         myPartnerUtils::notifiyPartner($notificationId, $partner, $body_params);
     }
 }
 public static function doPartnerUsage(Partner $partner)
 {
     if ($partner->getExtendedFreeTrail()) {
         if ($partner->getExtendedFreeTrailExpiryDate() < time()) {
             //ExtendedFreeTrail ended
             $partner->setExtendedFreeTrail(null);
             $partner->setExtendedFreeTrailExpiryDate(null);
             $partner->setExtendedFreeTrailExpiryReason('');
         } else {
             //ExtendedFreeTrail
             if ($partner->getExtendedFreeTrailExpiryDate() < time() + dateUtils::DAY * 7 && !$partner->getExtendedFreeTrailEndsWarning()) {
                 $partner->setExtendedFreeTrailEndsWarning(true);
                 $partner->save();
                 $email_link_hash = 'pid=' . $partner->getId() . '&h=' . self::getEmailLinkHash($partner->getId(), $partner->getSecret());
                 $mail_parmas = array($partner->getAdminName(), $email_link_hash);
                 myPartnerUtils::notifiyPartner(myPartnerUtils::KALTURA_EXTENED_FREE_TRAIL_ENDS_WARNING, $partner, $mail_parmas);
             }
             return;
         }
     }
     $should_block_delete_partner = true;
     $blocking_days_grace = 7;
     $block_notification_grace = time() - dateUtils::DAY * $blocking_days_grace;
     $delete_grace = time() - dateUtils::DAY * 30;
     $packages = new PartnerPackages();
     $partnerPackage = $packages->getPackageDetails($partner->getPartnerPackage());
     $report_date = date('Y-m') . '-01';
     // We are now working with the DWH and a stored-procedure, and not with record type 6 on partner_activity.
     $report_date = dateUtils::todayOffset(-1);
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerStatisticsFromDWH($partner, $partnerPackage, $report_date);
     $totalUsageGB = $totalUsage / 1024 / 1024;
     // from KB to GB
     $percent = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
     KalturaLog::debug("percent (" . $partner->getId() . ") is: {$percent}");
     $email_link_hash = 'pid=' . $partner->getId() . '&h=' . self::getEmailLinkHash($partner->getId(), $partner->getSecret());
     $email_link_hash_adOpt = $email_link_hash . '&type=adOptIn';
     /* mindtouch partners - extra mail parameter */
     $mindtouch_notice = ' ';
     if ($partner->getType() == 103) {
         $mindtouch_notice = '<BR><BR>Note: You must be a MindTouch paying customer to upgrade your video service. If you are not a paying MindTouch customer, contact MindTouch: http://www.mindtouch.com/about_mindtouch/contact_mindtouch to get a quote.<BR><BR>';
     }
     if ($percent >= 80 && $percent < 100 && !$partner->getEightyPercentWarning()) {
         KalturaLog::debug("partner " . $partner->getId() . " reached 80% - setting first warning");
         /* prepare mail job, and set EightyPercentWarning() to true/date */
         $partner->setEightyPercentWarning(time());
         $partner->setUsageLimitWarning(0);
         $body_params = array($partner->getAdminName(), $partnerPackage['cycle_bw'], $mindtouch_notice, round($totalUsageGB, 2), $email_link_hash);
         myPartnerUtils::notifiyPartner(myPartnerUtils::KALTURA_PACKAGE_EIGHTY_PERCENT_WARNING, $partner, $body_params);
     } elseif ($percent >= 80 && $percent < 100 && $partner->getEightyPercentWarning() && !$partner->getUsageLimitWarning()) {
         KalturaLog::debug("passed the 80%, assume notification sent, nothing to do.");
     } elseif ($percent < 80 && $partner->getEightyPercentWarning()) {
         KalturaLog::debug("partner " . $partner->getId() . " was 80%, now not. clearing warnings");
         /* clear getEightyPercentWarning */
         $partner->setEightyPercentWarning(0);
         $partner->setUsageLimitWarning(0);
     } elseif ($percent >= 100 && !$partner->getUsageLimitWarning()) {
         KalturaLog::debug("partner " . $partner->getId() . " reached 100% - setting second warning");
         /* prepare mail job, and set getUsageLimitWarning() date */
         $partner->setUsageLimitWarning(time());
         $body_params = array($partner->getAdminName(), $mindtouch_notice, round($totalUsageGB, 2), $email_link_hash);
         myPartnerUtils::notifiyPartner(myPartnerUtils::KALTURA_PACKAGE_LIMIT_WARNING_1, $partner, $body_params);
     } elseif ($percent >= 100 && $partnerPackage['cycle_fee'] == 0 && $partner->getUsageLimitWarning() > 0 && $partner->getUsageLimitWarning() <= $block_notification_grace && $partner->getUsageLimitWarning() > $delete_grace && $partner->getStatus() != Partner::PARTNER_STATUS_CONTENT_BLOCK) {
         KalturaLog::debug("partner " . $partner->getId() . " reached 100% {$blocking_days_grace} days ago - sending block email and blocking partner");
         /* send block email and block partner */
         $body_params = array($partner->getAdminName(), $mindtouch_notice, round($totalUsageGB, 2), $email_link_hash);
         myPartnerUtils::notifiyPartner(myPartnerUtils::KALTURA_PACKAGE_LIMIT_WARNING_2, $partner, $body_params);
         if ($should_block_delete_partner) {
             $partner->setStatus(Partner::PARTNER_STATUS_CONTENT_BLOCK);
         }
     } elseif ($percent >= 120 && $partnerPackage['cycle_fee'] != 0 && $partner->getUsageLimitWarning() <= $block_notification_grace) {
         $body_params = array($partner->getAdminName(), round($totalUsageGB, 2));
         myPartnerUtils::notifiyPartner(myPartnerUtils::KALTURA_PAID_PACKAGE_SUGGEST_UPGRADE, $partner, $body_params);
     } elseif ($percent >= 100 && $partnerPackage['cycle_fee'] == 0 && $partner->getUsageLimitWarning() > 0 && $partner->getUsageLimitWarning() <= $delete_grace && $partner->getStatus() == Partner::PARTNER_STATUS_CONTENT_BLOCK) {
         KalturaLog::debug("partner " . $partner->getId() . " reached 100% a month ago - deleting partner");
         /* delete partner */
         $body_params = array($partner->getAdminName());
         myPartnerUtils::notifiyPartner(myPartnerUtils::KALTURA_DELETE_ACCOUNT, $partner, $body_params);
         if ($should_block_delete_partner) {
             $partner->setStatus(Partner::PARTNER_STATUS_DELETED);
         }
     } elseif ($percent < 80 && ($partner->getUsageLimitWarning() || $partner->getEightyPercentWarning())) {
         KalturaLog::debug("partner " . $partner->getId() . " OK");
         // PARTNER OK
         // resetting status and warnings should only be done manually
         //$partner->setStatus(1);
         $partner->setEightyPercentWarning(0);
         $partner->setUsageLimitWarning(0);
     }
     $partner->save();
 }
 /**
  * Get usage statistics for a partner
  * Calculation is done according to partner's package
  *
  * @action getStatistics
  * @return KalturaPartnerStatistics
  * 
  * @throws APIErrors::UNKNOWN_PARTNER_ID
  */
 public function getStatisticsAction()
 {
     $dbPartner = PartnerPeer::retrieveByPK($this->getPartnerId());
     if (!$dbPartner) {
         throw new KalturaAPIException(APIErrors::UNKNOWN_PARTNER_ID, $this->getPartnerId());
     }
     $packages = new PartnerPackages();
     $partnerUsage = new KalturaPartnerStatistics();
     $partnerPackage = $packages->getPackageDetails($dbPartner->getPartnerPackage());
     $report_date = date("Y-m-d", time());
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerUsageFromDWH($dbPartner, $partnerPackage, $report_date);
     $partnerUsage->hosting = round($totalStorage / 1024, 2);
     // from MB to GB
     $totalUsageGB = round($totalUsage / 1024 / 1024, 2);
     // from KB to GB
     if ($partnerPackage) {
         $partnerUsage->usagePercent = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
         $partnerUsage->packageBandwidthAndStorage = $partnerPackage['cycle_bw'];
     }
     if ($totalTraffic) {
         $partnerUsage->bandwidth = round($totalTraffic / 1024 / 1024, 2);
         // from KB to GB
     }
     $partnerUsage->usage = $totalUsageGB;
     $partnerUsage->reachedLimitDate = $dbPartner->getUsageLimitWarning();
     return $partnerUsage;
 }
Пример #5
0
 /**
  * Get usage statistics for a partner
  * Calculation is done according to partner's package
  *
  * Additional data returned is a graph points of streaming usage in a timeframe
  * The resolution can be "days" or "months"
  *
  * @link http://docs.kaltura.org/api/partner/usage
  * @action getUsage
  * @param int $year
  * @param int $month
  * @param string $resolution accepted values are "days" or "months"
  * @return KalturaPartnerUsage
  * 
  * @throws APIErrors::UNKNOWN_PARTNER_ID
  */
 function getUsageAction($year = '', $month = 1, $resolution = "days")
 {
     $dbPartner = PartnerPeer::retrieveByPK($this->getPartnerId());
     if (!$dbPartner) {
         throw new KalturaAPIException(APIErrors::UNKNOWN_PARTNER_ID, $this->getPartnerId());
     }
     $packages = new PartnerPackages();
     $partnerUsage = new KalturaPartnerUsage();
     $partnerPackage = $packages->getPackageDetails($dbPartner->getPartnerPackage());
     $report_date = dateUtils::todayOffset(-3);
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerUsageFromDWH($dbPartner, $partnerPackage, $report_date);
     $partnerUsage->hostingGB = round($totalStorage / 1024, 2);
     // from MB to GB
     $totalUsageGB = round($totalUsage / 1024 / 1024, 2);
     // from KB to GB
     if ($partnerPackage) {
         $partnerUsage->Percent = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
         $partnerUsage->packageBW = $partnerPackage['cycle_bw'];
     }
     $partnerUsage->usageGB = $totalUsageGB;
     $partnerUsage->reachedLimitDate = $dbPartner->getUsageLimitWarning();
     if ($year != '' && is_int($year)) {
         $graph_lines = myPartnerUtils::getPartnerUsageGraph($year, $month, $dbPartner, $resolution);
         // currently we provide only one line, output as a string.
         // in the future this could be extended to something like KalturaGraphLines object
         $partnerUsage->usageGraph = $graph_lines['line'];
     }
     return $partnerUsage;
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $packages = new PartnerPackages();
     $this->addMsg("packages", $packages->listPackages());
 }
Пример #7
0
 /**
  * @action getPackages
  * @return KalturaSystemPartnerPackageArray
  */
 public function getPackages()
 {
     $partnerPackages = new PartnerPackages();
     $packages = $partnerPackages->listPackages();
     $partnerPackages = new KalturaSystemPartnerPackageArray();
     $partnerPackages->fromArray($packages);
     return $partnerPackages;
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     // make sure the secret fits the one in the partner's table
     $partner = PartnerPeer::retrieveByPK($partner_id);
     if (!$partner) {
         // CANNOT be because we are already in the service. it would have fallen before...
         $this->addException(APIErrors::UNKNOWN_PARTNER_ID);
     }
     $packages = new PartnerPackages();
     $partnerPackage = $packages->getPackageDetails($partner->getPartnerPackage());
     $report_date = dateUtils::todayOffset(-3);
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerUsageFromDWH($partner, $partnerPackage, $report_date);
     $return['hostingGB'] = round($totalStorage / 1024, 2);
     // from MB to GB
     $totalUsageGB = round($totalUsage / 1024 / 1024, 2);
     // from KB to GB
     $return['Percent'] = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
     $return['package_bw'] = $partnerPackage['cycle_bw'];
     $return['GB'] = $totalUsageGB;
     $return['reached_limit_date'] = $partner->getUsageLimitWarning();
     /* total usage status */
     /*  --- ended total usage status --- */
     /* usage graph */
     $year = $this->getPM("year");
     $month = $this->getP("month");
     $resolution = $this->getP("resolution");
     $graph_points = myPartnerUtils::getPartnerUsageGraph($year, $month, $partner, $resolution);
     /* --- ended usage graph --- */
     $this->addMsg("usage", $return);
     if (isset($debug_data)) {
         $this->addDebug('debug_data', $debug_data);
     }
     $this->addMsg("graph", $graph_points);
     /*
     * ADD ATTRIBUTES TO GRAPH
     
     <graph caption=""
     bgcolor="0xffffff" 
     border="false" 
     bordercolor="0xffffa7" 
     customxaxis="true" 
     minimumx="0"  
     maximumx="10" 
     intervalx="1" 
     xaxisname="Time"
     xtype="Category" 
     dataunits="hours"
     customyaxis="false" 
     minimumy="0" 
     maximumy="100" 
     intervaly="10" 
     yaxisname=""
     showdatatips="true" 
     mousesensitivity="50" 
     datatipmode="multiple"
     gridlinesdirection="both"
     customgridlines="true" 
     lineshadow="false"
     horizontalstrokecolor="0xeeeeee" 
     horizontalstrokesize=".3" 
     horizontalfillcolor="0xffffff" 
     horizontalfillsize=".3" 
     horizontalstrokealpha="0.1"
     horizontalalternatefillcolor="0xffffff" 
     horizontalalternatefillsize=".3"
     verticalstrokecolor="0xcccccc" 
     verticalstrokesize=".5"  
     verticalstrokealpha="0.5"
     verticalfillcolor="0xffffff" 
     verticalfillsize=".3" 
     verticalalternatefillcolor="0xffffff"
     verticalalternatefillsize=".3">
     
     * 
     */
 }