Esempio n. 1
0
 public function actionRestrictionCheck()
 {
     $this->response->result = false;
     if (!empty($this->request->details->plan)) {
         $plan = new SubscriptionPlan();
         $plan->load($this->request->details->plan);
         if ($plan->id != $this->request->details->plan) {
             $this->error = 'could not find plan to check restrictions for';
             return;
         }
         $restrictions = $plan->getRestrictionsArray();
         if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) {
             if (!ItemGroupHandler::checkParentRestrictions($plan, 'item', $this->metaUser)) {
                 $this->error = 'user is denied permission - plans parent group is restricted from this user';
             }
         } else {
             $this->error = 'user is denied permission - plan is restricted from this user';
         }
         unset($this->request->details->plan);
     }
     if (!empty($this->request->details->group)) {
         $group = new ItemGroup();
         $group->load($this->request->details->group);
         if ($group->id != $this->request->details->group) {
             $this->error = 'could not find group to check restrictions for';
             return;
         }
         $restrictions = $group->getRestrictionsArray();
         if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) {
             if (!ItemGroupHandler::checkParentRestrictions($group, 'group', $this->metaUser)) {
                 $this->error = 'user is denied permission - groups parent group is restricted from this user';
             }
         } else {
             $this->error = 'user is denied permission - group is restricted from this user';
         }
         unset($this->request->details->group);
     }
     if (!empty($this->request->details)) {
         $re = get_object_vars($this->request->details);
         $restrictions = aecRestrictionHelper::getRestrictionsArray($re);
         if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) === false) {
             $this->error = 'user is denied permission - at least one restriction result was negative';
         }
     }
     if (empty($this->error)) {
         $this->response->result = true;
     }
 }
Esempio n. 2
0
 public function getRestrictionsArray()
 {
     return aecRestrictionHelper::getRestrictionsArray($this->restrictions);
 }
Esempio n. 3
0
 public function checkRestrictions($metaUser, $terms = null, $usage = null)
 {
     if (empty($metaUser)) {
         return false;
     }
     $restrictionHelper = new aecRestrictionHelper();
     // Load Restrictions and resulting Permissions
     $restrictions = $restrictionHelper->getRestrictionsArray($this->restrictions);
     $permissions = $metaUser->permissionResponse($restrictions);
     // Check for a set usage
     if (!empty($this->restrictions['usage_plans_enabled']) && !is_null($usage)) {
         if (!empty($this->restrictions['usage_plans'])) {
             // Check whether this usage is restricted
             $plans = $this->restrictions['usage_plans'];
             if (in_array($usage, $plans)) {
                 $permissions['usage'] = true;
             } else {
                 $permissions['usage'] = false;
             }
         }
     }
     // Check for Trial only
     if ($this->discount['useon_trial'] && !$this->discount['useon_full'] && is_object($terms)) {
         $permissions['trial_only'] = false;
         if ($terms->nextterm->type == 'trial') {
             $permissions['trial_only'] = true;
         }
     }
     // Check for max reuse per user
     if (!empty($this->restrictions['has_max_peruser_reuse']) && !empty($this->restrictions['max_peruser_reuse'])) {
         $used = $metaUser->usedCoupon($this->coupon->id, $this->type);
         if ($used == false) {
             $permissions['max_peruser_reuse'] = true;
         } elseif ((int) $used <= (int) $this->restrictions['max_peruser_reuse']) {
             // use count was set immediately before, so <= is accurate
             $permissions['max_peruser_reuse'] = true;
         } else {
             $permissions['max_peruser_reuse'] = false;
         }
     }
     // Plot out error messages
     if (count($permissions)) {
         foreach ($permissions as $name => $status) {
             if (!$status) {
                 $errors = array('fixgid' => 'permission', 'mingid' => 'permission', 'maxgid' => 'permission', 'setgid' => 'permission', 'usage' => 'wrong_usage', 'trial_only' => 'trial_only', 'plan_previous' => 'wrong_plan_previous', 'plan_present' => 'wrong_plan', 'plan_overall' => 'wrong_plans_overall', 'plan_amount_min' => 'wrong_plan', 'plan_amount_max' => 'wrong_plans_overall', 'max_reuse' => 'max_reuse', 'max_peruser_reuse' => 'max_reuse');
                 if (isset($errors[$name])) {
                     $this->setError(JText::_(strtoupper('coupon_error_' . $errors[$name])));
                 } else {
                     $this->status = false;
                 }
                 return false;
             }
         }
     }
     return true;
 }