public static function getPlanLimitsForResource($resourceType, $advertiserId) { if ($resourceType == '') { return array(); } $planType = PlanResourceType::getPlanType($resourceType); if ($planType == PlanType::ADVERTISER_PLAN) { if ($advertiserId == '') { $advertiserId = Yii::app()->user->getAdvertiserId(); } } // get some payment plan $sql = "SELECT plan_id, type, duration, expired FROM p_purchased_plans" . " WHERE wlabel_id=" . Yii::app()->user->getWhiteLabelId() . " AND expired=0"; if ($planType == PlanType::ADVERTISER_PLAN && $advertiserId != '') { $sql .= " AND advertiser_id=" . $advertiserId; } $sql .= " AND pplan_id in (" . " SELECT pplan_id from p_purchased_plans_payments" . " WHERE date_expire>='" . date("Y-m-d 00:00:00") . "'" . " )"; $dbCommand = Yii::app()->db->createCommand($sql); $results = $dbCommand->queryAll(); if ($results == null) { // it is still possible that the plan is paid by authorize.net and lastpayment expired, check its status $results = PlanRestriction::checkAuthorizeNetPlans($planType, $advertiserId); } if ($results == null) { return 0; } $planIds = array(); foreach ($results as $result) { $planIds[] = $result['plan_id']; } // now check for planlimits with this resource type $criteria = new CDbCriteria(); $criteria->compare('t.plan_id', $planIds); $criteria->compare('t.resource_type', $resourceType); $result = PlanLimit::model()->find($criteria); if ($result == false) { return -1; } return $result->limit_amount; }