public function createAction()
 {
     $request = $this->getRequest();
     $client = Infra_ClientHelper::getClient();
     $systemPartnerPlugin = Kaltura_Client_SystemPartner_Plugin::get($client);
     $form = new Form_PartnerCreate();
     $partner = Zend_Registry::get('config')->partner;
     $allowNonePackage = isset($partner->enableNonePackage) ? $partner->enableNonePackage : false;
     $packages = $systemPartnerPlugin->systemPartner->getPackages();
     if (!Infra_AclHelper::isAllowed('partner', 'configure-account-packages-service-paid')) {
         foreach ($packages as $index => $package) {
             if (intval($package->id) != PartnerController::PARTNER_PACKAGE_FREE) {
                 unset($packages[$index]);
             }
         }
     }
     //		Form_PackageHelper::addPackagesToForm($form, $packages, 'partner_package', $allowNonePackage);
     //		Form_PackageHelper::addPackagesToForm($form, $systemPartnerPlugin->systemPartner->getPackagesClassOfService(), 'partner_package_class_of_service');
     //		Form_PackageHelper::addPackagesToForm($form, $systemPartnerPlugin->systemPartner->getPackagesVertical(), 'vertical_clasiffication');
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $partner = $form->getObject("Kaltura_Client_Type_Partner", $request->getPost());
             if (is_array($partner->contentCategories)) {
                 $partner->contentCategories = implode(',', $partner->contentCategories);
             }
             $partner->adminName = $partner->name;
             $partner->description = "Admin Console";
             $partner->type = Kaltura_Client_Enum_PartnerType::ADMIN_CONSOLE;
             $client->startMultiRequest();
             $client->partner->register($partner);
             $config = new Kaltura_Client_SystemPartner_Type_SystemPartnerConfiguration();
             $config->partnerPackage = $form->getValue('partner_package');
             $config->partnerPackageClassOfService = $form->getValue('partner_package_class_of_service');
             $config->verticalClasiffication = $form->getValue('vertical_clasiffication');
             $config->storageDeleteFromKaltura = true;
             $config->storageServePriority = Kaltura_Client_Enum_StorageServePriority::EXTERNAL_FIRST;
             $systemPartnerPlugin->systemPartner->updateConfiguration('{1:result:id}', $config);
             // set request timeout
             $clientConfig = $client->getConfig();
             $clientConfig->curlTimeout = 300;
             $client->setConfig($clientConfig);
             // do multirequest
             $result = $client->doMultiRequest();
             // check for errors in partner.register
             if ($client->isError($result[0])) {
                 if (strpos($result[0]['message'], 'already exists in system') !== false) {
                     $form->getElement('admin_email')->addError('Email already exists');
                 } else {
                     throw new Kaltura_Client_Exception($result[0]['message'], $result[0]['code']);
                 }
             } else {
                 Infra_AclHelper::refreshCurrentUserAllowrdPartners();
                 $this->_helper->redirector('list');
             }
         } else {
             $form->populate($request->getPost());
         }
     }
     $this->view->form = $form;
 }
 public function createAction()
 {
     $request = $this->getRequest();
     $client = Infra_ClientHelper::getClient();
     $form = new Form_PartnerCreate();
     $partner = Zend_Registry::get('config')->partner;
     $this->view->errorDescription = "";
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $partner = $form->getObject("Kaltura_Client_Type_Partner", $request->getPost());
             $templatePartnerId = $form->getValue("copyPartner");
             /* @var $partner Kaltura_Client_Type_Partner */
             if (is_array($partner->contentCategories)) {
                 $partner->contentCategories = implode(',', $partner->contentCategories);
             }
             $partner->description = "Multi-publishers console";
             $partner->type = Kaltura_Client_Enum_PartnerType::ADMIN_CONSOLE;
             try {
                 $result = $client->partner->register($partner, null, $templatePartnerId);
                 // check for errors in partner.register
                 if ($client->isError($result)) {
                     if (strpos($result[0]['message'], 'already exists in system') !== false) {
                         $form->getElement('admin_email')->addError('Email already exists');
                     } else {
                         $this->view->errorDescription = 'An error occured: ' . $e->getMessage();
                     }
                 } else {
                     Infra_AclHelper::refreshCurrentUserAllowrdPartners();
                     $this->_helper->redirector('list');
                 }
             } catch (Exception $e) {
                 $this->view->errorDescription = 'An error occured: ' . $e->getMessage();
             }
         } else {
             $form->populate($request->getPost());
         }
     }
     $varConsoleFilter = new Kaltura_Client_VarConsole_Type_VarConsolePartnerFilter();
     $varConsoleFilter->groupTypeEq = Kaltura_Client_Enum_PartnerGroupType::TEMPLATE;
     $varConsoleFilter->statusEqual = Kaltura_Client_Enum_PartnerStatus::ACTIVE;
     $pager = new Kaltura_Client_Type_FilterPager();
     $templatePartnerList = $client->partner->listAction($varConsoleFilter, $pager);
     $providers = array();
     $providers[0] = $this->view->translate('partner-create default copy partner');
     foreach ($templatePartnerList->objects as $templatePartner) {
         /* @var $templatePartner Kaltura_Client_Type_Partner */
         $providers[$templatePartner->id] = $templatePartner->name;
     }
     $form->setProviders($providers);
     //If available sub-publisher quota was reached, submit button should be disabled.
     //Exclude publisher iteself, template sub-publisher and deleted sub-publisher
     $currentPartner = $client->partner->getInfo();
     $filter = new Kaltura_Client_VarConsole_Type_VarConsolePartnerFilter();
     $filter->idNotIn = $currentPartner->id;
     $filter->statusIn = implode(",", array(Kaltura_Client_Enum_PartnerStatus::ACTIVE, Kaltura_Client_Enum_PartnerStatus::BLOCKED));
     $filter->groupTypeEq = Kaltura_Client_Enum_PartnerGroupType::PUBLISHER;
     $subPublisherCount = $client->partner->count($filter);
     /* @var $currentPartner Kaltura_Client_Type_Partner */
     if ($currentPartner->publishersQuota - $subPublisherCount <= 0) {
         $submitBtn = $form->getElement('submit');
         $submitBtn->setOptions(array('disable' => array(1, 2)));
     }
     $this->view->usedPublishers = $subPublisherCount;
     $this->view->remainingPublishers = $currentPartner->publishersQuota - $subPublisherCount > 0 ? $currentPartner->publishersQuota - $subPublisherCount : 0;
     $this->view->form = $form;
 }