public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     //No need to add objectId to result with status ERROR
     if ($this->status != KalturaBulkUploadResultStatus::ERROR) {
         $kuser = kuserPeer::getKuserByPartnerAndUid($this->partnerId, $this->userId);
         if (!$kuser) {
             throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
         }
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->categoryId, $kuser->getId());
         if ($categoryKuser) {
             $this->objectId = $categoryKuser->getId();
         }
     }
     return parent::toObject($object_to_fill, $props_to_skip);
 }
Example #2
0
 /**
  * reject CategoryUser
  * 
  * @action deactivate
  * @param int $categoryId
  * @param string $userId
  * @return KalturaCategoryUser
  */
 function deactivateAction($categoryId, $userId)
 {
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $userId);
     if (!$kuser) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID, $userId);
     }
     $dbCategoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($categoryId, $kuser->getId());
     if (!$dbCategoryKuser) {
         throw new KalturaAPIException(KalturaErrors::INVALID_CATEGORY_USER_ID, $categoryId, $userId);
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($dbCategoryKuser->getCategoryId(), kCurrentContext::getCurrentKsKuserId());
     if (kEntitlementUtils::getEntitlementEnforcement() && (!$currentKuserCategoryKuser || $currentKuserCategoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && kCurrentContext::$ks_uid != $userId)) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER);
     }
     $dbCategoryKuser->setStatus(CategoryKuserStatus::NOT_ACTIVE);
     $dbCategoryKuser->save();
     $categoryUser = new KalturaCategoryUser();
     $categoryUser->fromObject($dbCategoryKuser, $this->getResponseProfile());
     return $categoryUser;
 }
Example #3
0
 public function save(PropelPDO $con = null)
 {
     if ($this->isNew()) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
         $c->add(categoryPeer::STATUS, CategoryStatus::DELETED, Criteria::NOT_EQUAL);
         $c->add(categoryPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $numOfCatsForPartner = categoryPeer::doCount($c);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $chunkedCategoryLoadThreshold = kConf::get('kmc_chunked_category_load_threshold');
         if ($numOfCatsForPartner >= $chunkedCategoryLoadThreshold) {
             PermissionPeer::enableForPartner(PermissionName::DYNAMIC_FLAG_KMC_CHUNKED_CATEGORY_LOAD, PermissionType::SPECIAL_FEATURE);
         }
         if ($this->getParentId() && ($this->getPrivacyContext() == '' || $this->getPrivacyContext() == null)) {
             $parentCategory = $this->getParentCategory();
             $this->setPrivacyContexts($parentCategory->getPrivacyContexts());
         }
     }
     if (!$this->getIsIndex() && ($this->isColumnModified(categoryPeer::NAME) || $this->isColumnModified(categoryPeer::PARENT_ID))) {
         $this->updateFullName();
     }
     if (trim($this->getPrivacyContexts()) == '') {
         $this->setDefaultUnEntitlmenetCategory();
     }
     // set the depth of the parent category + 1
     if (!$this->getIsIndex() && ($this->isNew() || $this->isColumnModified(categoryPeer::PARENT_ID))) {
         $this->reSetDepth();
     }
     if (!$this->isNew() && $this->isColumnModified(categoryPeer::PARENT_ID)) {
         $this->resetFullIds();
     }
     //index + update categoryEntry
     if (!$this->isNew() && ($this->isColumnModified(categoryPeer::FULL_IDS) || $this->isColumnModified(categoryPeer::PARENT_ID))) {
         $this->addIndexCategoryEntryJob($this->getId());
         $this->addIndexCategoryKuserJob($this->getId());
     }
     if (!$this->isNew() && $this->getInheritanceType() !== InheritanceType::INHERIT && $this->isColumnModified(categoryPeer::PRIVACY_CONTEXTS)) {
         if ($this->getPrivacyContexts() == '') {
             $this->addDeleteCategoryKuserJob($this->getId());
         }
     }
     if (!$this->isNew() && $this->isColumnModified(categoryPeer::PRIVACY_CONTEXTS)) {
         $this->addSyncCategoryPrivacyContextJob();
     }
     // save the childs for action category->delete - delete category is not done by async batch.
     foreach ($this->childs_for_save as $child) {
         $child->save();
     }
     $this->childs_for_save = array();
     if ($this->isColumnModified(categoryPeer::DELETED_AT) && $this->getDeletedAt() !== null) {
         // delete all categoryKuser objects for this category
         if ($this->getInheritanceType() == InheritanceType::MANUAL) {
             $this->addDeleteCategoryKuserJob($this->getId());
         }
         if ($this->move_entries_to_parent_category) {
             $this->addMoveEntriesToCategoryJob($this->move_entries_to_parent_category);
         } elseif ($this->move_entries_to_parent_category === 0) {
             $this->addDeleteCategoryEntryJob($this->getId());
         }
     }
     $kuserChanged = false;
     if (!$this->isNew() && $this->isColumnModified(categoryPeer::INHERITANCE_TYPE)) {
         if ($this->inheritance_type == InheritanceType::MANUAL && $this->old_inheritance_type == InheritanceType::INHERIT) {
             if ($this->parent_id) {
                 $categoryToCopyInheritedFields = $this->getInheritParent();
             }
             if ($categoryToCopyInheritedFields) {
                 $this->copyInheritedFields($categoryToCopyInheritedFields);
                 $kuserChanged = true;
             }
             $this->reSetMembersCount();
         } elseif ($this->inheritance_type == InheritanceType::INHERIT && $this->old_inheritance_type == InheritanceType::MANUAL) {
             $this->addDeleteCategoryKuserJob($this->getId(), true);
         }
     }
     if ($this->isColumnModified(categoryPeer::KUSER_ID)) {
         $kuserChanged = true;
     }
     if (!$this->isNew() && $this->isColumnModified(categoryPeer::PRIVACY) && $this->getPrivacy() == PrivacyType::MEMBERS_ONLY) {
         $this->removeNonMemberKusers();
     }
     parent::save($con);
     if ($kuserChanged && $this->inheritance_type != InheritanceType::INHERIT && $this->getKuserId()) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->getId(), $this->getKuserId());
         if (!$categoryKuser) {
             $categoryKuser = new categoryKuser();
             $categoryKuser->setCategoryId($this->getId());
             $categoryKuser->setCategoryFullIds($this->getFullIds());
             $categoryKuser->setKuserId($this->getKuserId());
         }
         $categoryKuser->setPermissionLevel(CategoryKuserPermissionLevel::MANAGER);
         $permissionNamesArr = array();
         if ($categoryKuser->getPermissionNames()) {
             $permissionNamesArr = explode(",", $categoryKuser->getPermissionNames());
         }
         $permissionNamesArr = categoryKuser::removeCategoryPermissions($permissionNamesArr);
         $permissionNamesArr[] = PermissionName::CATEGORY_CONTRIBUTE;
         $permissionNamesArr[] = PermissionName::CATEGORY_EDIT;
         $permissionNamesArr[] = PermissionName::CATEGORY_MODERATE;
         $permissionNamesArr[] = PermissionName::CATEGORY_VIEW;
         $categoryKuser->setPermissionNames(implode(",", $permissionNamesArr));
         $categoryKuser->setStatus(CategoryKuserStatus::ACTIVE);
         $categoryKuser->setPartnerId($this->getPartnerId());
         $categoryKuser->setUpdateMethod(UpdateMethodType::MANUAL);
         $categoryKuser->save();
         $this->indexToSearchIndex();
     }
 }
Example #4
0
 public function validateForInsert($propertiesToSkip = array())
 {
     $category = categoryPeer::retrieveByPK($this->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryId);
     }
     if ($category->getInheritanceType() == InheritanceType::INHERIT) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS, $this->categoryId);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $this->userId);
     if ($kuser) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->categoryId, $kuser->getId());
         if ($categoryKuser) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_ALREADY_EXISTS);
         }
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($this->categoryId, kCurrentContext::getCurrentKsKuserId());
     if ((!$currentKuserCategoryKuser || $currentKuserCategoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER) && $category->getUserJoinPolicy() == UserJoinPolicyType::NOT_ALLOWED && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_JOIN_NOT_ALLOWED, $this->categoryId);
     }
     //if user doesn't exists - create it
     if (!$kuser) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->userId)) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'userId');
         }
         kuserPeer::createKuserForPartner($partnerId, $this->userId);
     }
     return parent::validateForInsert($propertiesToSkip);
 }