/**
  * Add new CategoryEntry
  * 
  * @action add
  * @param KalturaCategoryEntry $categoryEntry
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY
  * @throws KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS
  * @return KalturaCategoryEntry
  */
 function addAction(KalturaCategoryEntry $categoryEntry)
 {
     $categoryEntry->validateForInsert();
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $categoryEntry->entryId);
     }
     $category = categoryPeer::retrieveByPK($categoryEntry->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryEntry->categoryId);
     }
     $categoryEntries = categoryEntryPeer::retrieveActiveAndPendingByEntryId($categoryEntry->entryId);
     if (count($categoryEntries) >= entry::MAX_CATEGORIES_PER_ENTRY) {
         throw new KalturaAPIException(KalturaErrors::MAX_CATEGORIES_FOR_ENTRY_REACHED, entry::MAX_CATEGORIES_PER_ENTRY);
     }
     //validate user is entiteld to assign entry to this category
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntry->categoryId, kCurrentContext::$ks_kuser_id);
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
         if ($categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $entry->getKuserId() != kCurrentContext::$ks_kuser_id && $entry->getCreatorKuserId() != kCurrentContext::$ks_kuser_id) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
     }
     $categoryEntryExists = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryEntry->categoryId, $categoryEntry->entryId);
     if ($categoryEntryExists && $categoryEntryExists->getStatus() == CategoryEntryStatus::ACTIVE) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS);
     }
     if (!$categoryEntryExists) {
         $dbCategoryEntry = new categoryEntry();
     } else {
         $dbCategoryEntry = $categoryEntryExists;
     }
     $categoryEntry->toInsertableObject($dbCategoryEntry);
     $dbCategoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getModeration()) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntry->categoryId, kCurrentContext::$ks_kuser_id);
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) {
             $dbCategoryEntry->setStatus(CategoryEntryStatus::PENDING);
         }
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $dbCategoryEntry->setPartnerId($partnerId);
     $dbCategoryEntry->save();
     //need to select the entry again - after update
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
     $categoryEntry = new KalturaCategoryEntry();
     $categoryEntry->fromObject($dbCategoryEntry);
     return $categoryEntry;
 }
예제 #2
0
 /**
  * Add new CategoryEntry
  * 
  * @action add
  * @param KalturaCategoryEntry $categoryEntry
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY
  * @throws KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS
  * @return KalturaCategoryEntry
  */
 function addAction(KalturaCategoryEntry $categoryEntry)
 {
     $categoryEntry->validateForInsert();
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $categoryEntry->entryId);
     }
     $category = categoryPeer::retrieveByPK($categoryEntry->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryEntry->categoryId);
     }
     $categoryEntries = categoryEntryPeer::retrieveActiveAndPendingByEntryId($categoryEntry->entryId);
     $maxCategoriesPerEntry = $entry->getMaxCategoriesPerEntry();
     if (count($categoryEntries) >= $maxCategoriesPerEntry) {
         throw new KalturaAPIException(KalturaErrors::MAX_CATEGORIES_FOR_ENTRY_REACHED, $maxCategoriesPerEntry);
     }
     //validate user is entiteld to assign entry to this category
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL) {
         $categoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryEntry->categoryId, kCurrentContext::getCurrentKsKuserId());
         if (!$categoryKuser) {
             KalturaLog::err("User [" . kCurrentContext::getCurrentKsKuserId() . "] is not a member of the category [{$categoryEntry->categoryId}]");
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
         if ($categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER) {
             KalturaLog::err("User [" . kCurrentContext::getCurrentKsKuserId() . "] permission level [" . $categoryKuser->getPermissionLevel() . "] on category [{$categoryEntry->categoryId}] is not member [" . CategoryKuserPermissionLevel::MEMBER . "]");
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
         if (!$categoryKuser->hasPermission(PermissionName::CATEGORY_EDIT) && !$categoryKuser->hasPermission(PermissionName::CATEGORY_CONTRIBUTE) && $entry->getKuserId() != kCurrentContext::getCurrentKsKuserId() && $entry->getCreatorKuserId() != kCurrentContext::getCurrentKsKuserId()) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
     }
     $categoryEntryExists = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryEntry->categoryId, $categoryEntry->entryId);
     if ($categoryEntryExists && $categoryEntryExists->getStatus() == CategoryEntryStatus::ACTIVE) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS);
     }
     if (!$categoryEntryExists) {
         $dbCategoryEntry = new categoryEntry();
     } else {
         $dbCategoryEntry = $categoryEntryExists;
     }
     $categoryEntry->toInsertableObject($dbCategoryEntry);
     $dbCategoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getModeration()) {
         $categoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryEntry->categoryId, kCurrentContext::getCurrentKsKuserId());
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) {
             $dbCategoryEntry->setStatus(CategoryEntryStatus::PENDING);
         }
     }
     if (kEntitlementUtils::getCategoryModeration() && $category->getModeration()) {
         $dbCategoryEntry->setStatus(CategoryEntryStatus::PENDING);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $dbCategoryEntry->setPartnerId($partnerId);
     $dbCategoryEntry->save();
     //need to select the entry again - after update
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
     $categoryEntry = new KalturaCategoryEntry();
     $categoryEntry->fromObject($dbCategoryEntry, $this->getResponseProfile());
     return $categoryEntry;
 }