Пример #1
0
 public function copyInheritedFields(category $oldParentCategory)
 {
     $this->setUserJoinPolicy($oldParentCategory->getUserJoinPolicy());
     $this->setDefaultPermissionLevel($oldParentCategory->getDefaultPermissionLevel());
     $this->setKuserId($oldParentCategory->getKuserId());
     $this->setPuserId($oldParentCategory->getPuserId());
     $this->reSetMembersCount();
     //removing all members from this category
     $this->reSetPendingMembersCount();
 }
Пример #2
0
 /**
  * validate category fields
  * 1. category that inherit memebers cannot set values to inherited fields.
  * 2. validate the owner id exists as kuser
  * 
  * @param category $sourceObject
  */
 private function validateCategory(category $sourceObject = null)
 {
     if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT);
     }
     if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) {
         $isInheritedPrivacyContext = true;
         if ($this->parentId != null) {
             $parentCategory = categoryPeer::retrieveByPK($this->parentId);
             if (!$parentCategory) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId);
             }
             if ($parentCategory->getPrivacyContexts() == '') {
                 $isInheritedPrivacyContext = false;
             }
         } else {
             $isInheritedPrivacyContext = false;
         }
         if (!$isInheritedPrivacyContext) {
             if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && !$this->isNull('appearInList')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_APPEAR_IN_LIST_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->inheritanceType != KalturaInheritanceType::MANUAL && !$this->isNull('inheritanceType')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_INHERITANCE_TYPE_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->privacy != KalturaPrivacyType::ALL && !$this->isNull('privacy')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_PRIVACY_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if (!$this->isNull('owner')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && !$this->isNull('userJoinPolicy')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->contributionPolicy != KalturaContributionPolicyType::ALL && !$this->isNull('contributionPolicy')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_CONTIRUBUTION_POLICY_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && !$this->isNull('defaultPermissionLevel')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
         }
     }
     if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) {
         if ($this->owner != null) {
             if (!$sourceObject) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_WHEN_CATEGORY_INHERIT_MEMBERS);
             } elseif ($this->owner != $sourceObject->getKuserId()) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_WHEN_CATEGORY_INHERIT_MEMBERS);
             }
         }
         if ($this->userJoinPolicy != null) {
             if (!$sourceObject) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_WHEN_CATEGORY_INHERIT_MEMBERS);
             } elseif ($this->userJoinPolicy != $sourceObject->getUserJoinPolicy()) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_WHEN_CATEGORY_INHERIT_MEMBERS);
             }
         }
         if ($this->defaultPermissionLevel != null) {
             if (!$sourceObject) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_WHEN_CATEGORY_INHERIT_MEMBERS);
             } elseif ($this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_WHEN_CATEGORY_INHERIT_MEMBERS);
             }
         }
     }
     if (!is_null($sourceObject)) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $partner = PartnerPeer::retrieveByPK($partnerId);
         if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) {
             throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED);
         }
     }
     if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_FIELD_WITH_USER_ID, $this->owner);
         }
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         kuserPeer::createKuserForPartner($partnerId, $this->owner);
     }
 }
 /**
  * validate category fields
  * 1. category that inherit memebers canno set values to inherited fields.
  * 2. validate the owner id exists as kuser
  * 
  * @param category $sourceObject
  */
 private function validateCategory(category $sourceObject = null)
 {
     if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT);
     }
     if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) {
         if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && $this->appearInList != null || $this->moderation != KalturaNullableBoolean::FALSE_VALUE && $this->moderation != null || $this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->privacy != KalturaPrivacyType::ALL && $this->privacy != null || $this->owner != null || $this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && $this->userJoinPolicy != null || $this->contributionPolicy != KalturaContributionPolicyType::ALL && $this->contributionPolicy != null || $this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && $this->defaultPermissionLevel !== null) {
             if ($this->parentId != null) {
                 $parentCategory = categoryPeer::retrieveByPK($this->parentId);
                 if (!$parentCategory) {
                     throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId);
                 }
                 if ($parentCategory->getPrivacyContexts() == '') {
                     throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT);
                 }
             } else {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT);
             }
         }
     }
     if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) {
         if (!$sourceObject && $this->owner != null || $sourceObject && $this->owner != null && $this->owner != $sourceObject->getKuserId() || !$sourceObject && $this->userJoinPolicy != null || $sourceObject && $this->userJoinPolicy != null && $this->userJoinPolicy != $sourceObject->getUserJoinPolicy() || !$sourceObject && $this->defaultPermissionLevel != null || $sourceObject && $this->defaultPermissionLevel != null && $this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS_CANNOT_UPDATE_INHERITED_ATTRIBUTES);
         }
     }
     if (!is_null($sourceObject)) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $partner = PartnerPeer::retrieveByPK($partnerId);
         if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) {
             throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED);
         }
     }
     if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'owner');
         }
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         kuserPeer::createKuserForPartner($partnerId, $this->owner);
     }
 }