Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REACH2-1246: Search for partner IDs that a catalog item is configured on #12907

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package deployment
* @subpackage scorpius.roles_and_permissions
* @subpackage tucana.roles_and_permissions
*/

$script = realpath(dirname(__FILE__) . '/../../../../') . '/alpha/scripts/utils/permissions/addPermissionsAndItems.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ protected function createObjects()
case KalturaBulkUploadAction::ADD:
$bulkUploadResultChunk[] = $bulkUploadResult;
$vendorCatalogItem = $this->createVendorCatalogItemFromResult($bulkUploadResult);
$vendorCatalogItem->lastBulkUpdateId = $this->job->id;
KBatchBase::$kClient->vendorCatalogItem->add($vendorCatalogItem);
break;

Expand All @@ -258,6 +259,7 @@ protected function createObjects()

case KalturaBulkUploadAction::UPDATE_STATUS:
$bulkUploadResultChunk[] = $bulkUploadResult;
$vendorCatalogItem->lastBulkUpdateId = $this->job->id;
KBatchBase::$kClient->vendorCatalogItem->updateStatus($bulkUploadResult->vendorCatalogItemId, KalturaVendorCatalogItemStatus::DEPRECATED);
break;

Expand Down
20 changes: 18 additions & 2 deletions plugins/reach/admin/PartnerCatalogItemListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ public function doAction(Zend_Controller_Action $action)
$request = $action->getRequest();
$page = $this->_getParam('page', 1);
$pageSize = $this->_getParam('pageSize', 10);
$partnerId = $this->_getParam('filter_input') ? $this->_getParam('filter_input') : $request->getParam('partnerId');

$partnerId = null;
$catalogItemId = null;
if ($this->_getParam('filter_input'))
{
$filterType = $this->_getParam('filter_type');
if ($filterType === 'partnerIdEqual')
{
$partnerId = $this->_getParam('filter_input');
}
elseif ($filterType === 'catalogItemIdEqual')
{
$catalogItemId = $this->_getParam('filter_input');
}
}

$serviceFeature = $this->_getParam('filterServiceFeature') != "" ? $this->_getParam('filterServiceFeature') : null;
$serviceType = $this->_getParam('filterServiceType') != "" ? $this->_getParam('filterServiceType') : null;
$turnAroundTime = $this->_getParam('filterTurnAroundTime') != "" ? $this->_getParam('filterTurnAroundTime') : null;
Expand All @@ -36,7 +51,7 @@ public function doAction(Zend_Controller_Action $action)
$vendorPartnerId = $this->_getParam('vendorPartnerId') != "" ? $this->_getParam('vendorPartnerId') : null;

$action->view->allowed = $this->isAllowedForPartner($partnerId);
if ($partnerId)
if ($partnerId || $catalogItemId)
{
$vendorCatalogItemFilter = $this->getCatalogItemFilter($serviceFeature);
$vendorCatalogItemFilter->orderBy = "-createdAt";
Expand All @@ -45,6 +60,7 @@ public function doAction(Zend_Controller_Action $action)
$vendorCatalogItemFilter->partnerIdEqual = $partnerId;
$vendorCatalogItemFilter->sourceLanguageEqual = $sourceLanguage;
$vendorCatalogItemFilter->vendorPartnerIdEqual = $vendorPartnerId;
$vendorCatalogItemFilter->catalogItemIdEqual = $catalogItemId;

if(in_array($serviceFeature, array(Kaltura_Client_Reach_Enum_VendorServiceFeature::TRANSLATION, Kaltura_Client_Reach_Enum_VendorServiceFeature::DUBBING)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function init()
$filterType = $this->getElement('filter_type');
$filterType->setMultiOptions(array(
'partnerIdEqual' => 'Partner ID',
'catalogItemIdEqual' => 'Catalog Item ID',
));

// filter by vendor partner id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<td><?php echo $this->enumTranslate('Kaltura_Client_Reach_Enum_VendorCatalogItemStatus', $catalogItem->status); ?></td>
<td><?php echo $catalogItem->name; ?></td>
<td><?php echo $catalogItem->systemName; ?></td>
<td><?php echo $this->partnerId != null ? $this->partnerId : ' '; ?></td>
<td><?php echo $catalogItem->partnerId; ?></td>
<td><?php echo $catalogItem->vendorPartnerId; ?></td>
<td><?php echo $this->enumTranslate('Kaltura_Client_Reach_Enum_VendorServiceFeature', $catalogItem->serviceFeature); ?></td>
<td><?php echo $this->enumTranslate('Kaltura_Client_Reach_Enum_VendorServiceType', $catalogItem->serviceType); ?></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ abstract class KalturaVendorCatalogItem extends KalturaObject implements IRelate
*/
public $notes;

/**
* @var int
*/
public $partnerId;

private static $map_between_objects = array
(
'id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class KalturaVendorCatalogItemFilter extends KalturaVendorCatalogItemBaseFilter
* @var int
*/
public $partnerIdEqual;

/**
* @var int
*/
public $catalogItemIdEqual;

protected function getCoreFilter()
{
Expand All @@ -23,15 +28,17 @@ public function getTypeListResponse(KalturaFilterPager $pager, KalturaDetachedRe
public function doGetListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null, $type = null)
{
$c = new Criteria();
if($type)
if ($type)
{
$c->add(VendorCatalogItemPeer::SERVICE_FEATURE, $type);

}

$filter = $this->toObject();
$filter->attachToCriteria($c);
$pager->attachToCriteria($c);

$partnerIdEqual = null;
if($this->partnerIdEqual && !in_array(kCurrentContext::$ks_partner_id, array(Partner::ADMIN_CONSOLE_PARTNER_ID, $this->partnerIdEqual)))
if ($this->partnerIdEqual && !in_array(kCurrentContext::$ks_partner_id, array(Partner::ADMIN_CONSOLE_PARTNER_ID, $this->partnerIdEqual)))
{
//Add Id that does not exist to break list
$c->add(VendorCatalogItemPeer::ID, -1);
Expand All @@ -46,26 +53,32 @@ public function doGetListResponse(KalturaFilterPager $pager, KalturaDetachedResp
$partnerIdEqual = kCurrentContext::$ks_partner_id;
}

if($partnerIdEqual)
if ($partnerIdEqual)
{
$c->add(PartnerCatalogItemPeer::PARTNER_ID, $partnerIdEqual);
$c->add(PartnerCatalogItemPeer::STATUS, VendorCatalogItemStatus::ACTIVE);
$c->addJoin(PartnerCatalogItemPeer::CATALOG_ITEM_ID, VendorCatalogItemPeer::ID, Criteria::INNER_JOIN);
}

elseif ($this->catalogItemIdEqual)
{
return $this->listPartnersWithVendorCatalogItem($pager, $c);
}

$list = VendorCatalogItemPeer::doSelect($c);
$resultCount = count($list);
if ($resultCount && $resultCount < $pager->pageSize)
$totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount;
else

$totalCount = $this->countResultsFromListAndCriteria($list, $c, $pager);

$responseObjects = KalturaVendorCatalogItemArray::fromDbArray($list, $responseProfile);
if ($this->partnerIdEqual && kCurrentContext::$ks_partner_id == Partner::ADMIN_CONSOLE_PARTNER_ID)
{
KalturaFilterPager::detachFromCriteria($c);
$totalCount = VendorCatalogItemPeer::doCount($c);
foreach ($responseObjects as $responseObject)
{
$responseObject->partnerId = $partnerIdEqual;
}
}

$response = new KalturaVendorCatalogItemListResponse();
$response->objects = KalturaVendorCatalogItemArray::fromDbArray($list, $responseProfile);
$response->objects = $responseObjects;
$response->totalCount = $totalCount;
return $response;
}
Expand All @@ -77,4 +90,46 @@ public function getListResponse(KalturaFilterPager $pager, KalturaDetachedRespon
{
return $this->getTypeListResponse($pager, $responseProfile);
}

protected function listPartnersWithVendorCatalogItem($pager, $vendorCatalogItemCriteria)
{
$partnerCatalogItemCriteria = new Criteria();
$partnerCatalogItemCriteria->add(PartnerCatalogItemPeer::CATALOG_ITEM_ID, $this->catalogItemIdEqual);
$partnerCatalogItemCriteria->add(PartnerCatalogItemPeer::STATUS, VendorCatalogItemStatus::ACTIVE);
$pager->attachToCriteria($partnerCatalogItemCriteria);
$partnerCatalogItemList = PartnerCatalogItemPeer::doSelect($partnerCatalogItemCriteria);

$totalCount = $this->countResultsFromListAndCriteria($partnerCatalogItemList, $partnerCatalogItemCriteria, $pager);

$vendorCatalogItemCriteria->add(VendorCatalogItemPeer::ID, $this->catalogItemIdEqual);
$catalogItem = VendorCatalogItemPeer::doSelectOne($vendorCatalogItemCriteria);

$catalogItemsList = new KalturaVendorCatalogItemArray();
foreach ($partnerCatalogItemList as $partnerCatalogItem)
{
$catalogItemWithPartnerId = KalturaVendorCatalogItem::getInstance($catalogItem);
$catalogItemWithPartnerId->partnerId = $partnerCatalogItem->getPartnerId();
$catalogItemsList[] = $catalogItemWithPartnerId;
}

$response = new KalturaVendorCatalogItemListResponse();
$response->objects = $catalogItemsList;
$response->totalCount = $totalCount;
return $response;
}

protected function countResultsFromListAndCriteria($resultsList, $criteria, $pager)
{
$resultCount = count($resultsList);
if ($resultCount && $resultCount < $pager->pageSize)
{
$totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount;
}
else
{
KalturaFilterPager::detachFromCriteria($criteria);
$totalCount = PartnerCatalogItemPeer::doCount($criteria);
}
return $totalCount;
}
}