Пример #1
0
 private function setEntryOnCategory(category $category, $entry = null)
 {
     $category->incrementEntriesCount($this->getEntryId());
     $category->incrementDirectEntriesCount($this->getEntryId());
     //if was pending - decrease pending entries count!
     if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) {
         $category->decrementPendingEntriesCount();
     }
     $category->save();
     //only categories with no context are saved on entry - this is only for Backward compatible
     if ($entry && !categoryEntryPeer::getSkipSave() && (trim($category->getPrivacyContexts()) == '' || $category->getPrivacyContexts() == null)) {
         $categories = array();
         if (trim($entry->getCategories()) != '') {
             $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories());
         }
         $categories[] = $category->getFullName();
         $categoriesIds = array();
         if (trim($entry->getCategoriesIds()) != '') {
             $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds());
         }
         $categoriesIds[] = $category->getId();
         $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories));
         $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds));
         $entry->justSave();
     }
     return $entry;
 }
 /**
  * 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);
     }
 }
Пример #3
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);
     }
 }
 private function setEntryOnCategory(category $category, $entry = null)
 {
     if (is_null($this->entryCategoriesAddedIds)) {
         $categoriesEntries = categoryEntryPeer::retrieveActiveByEntryId($this->getEntryId());
         $categoriesIds = array();
         foreach ($categoriesEntries as $categroyEntry) {
             //cannot get directly the full ids - since it might not be updated.
             if ($categroyEntry->getCategoryId() != $this->getCategoryId()) {
                 $categoriesIds[] = $categroyEntry->getCategoryId();
             }
         }
         $categoriesAdded = categoryPeer::retrieveByPKs($categoriesIds);
         $entryCategoriesAddedIds = array();
         foreach ($categoriesAdded as $categoryAdded) {
             $fullIds = explode(categoryPeer::CATEGORY_SEPARATOR, $categoryAdded->getFullIds());
             $entryCategoriesAddedIds = array_merge($entryCategoriesAddedIds, $fullIds);
         }
         $this->entryCategoriesAddedIds = $entryCategoriesAddedIds;
     }
     $category->incrementEntriesCount(1, $this->entryCategoriesAddedIds);
     $category->incrementDirectEntriesCount();
     //if was pending - decrease pending entries count!
     if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) {
         $category->decrementPendingEntriesCount();
     }
     $category->save();
     //only categories with no context are saved on entry - this is only for Backward compatible
     if ($entry && !categoryEntryPeer::getSkipSave() && (trim($category->getPrivacyContexts()) == '' || $category->getPrivacyContexts() == null)) {
         $categories = array();
         if (trim($entry->getCategories()) != '') {
             $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories());
         }
         $categories[] = $category->getFullName();
         $categoriesIds = array();
         if (trim($entry->getCategoriesIds()) != '') {
             $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds());
         }
         $categoriesIds[] = $category->getId();
         $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories));
         $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds));
         $entry->justSave();
     }
     return $entry;
 }