Пример #1
0
 /**
  * Allows you to add a new KalturaPermission object
  * 
  * @action add
  * @param KalturaPermission $permission
  * @return KalturaPermission
  * 
  * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
  * @throws KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE
  */
 public function addAction(KalturaPermission $permission)
 {
     $permission->validateForInsert();
     $permission->validatePropertyNotNull('name');
     if (!$permission->friendlyName) {
         $permission->friendlyName = $permission->name;
     }
     if (!$permission->status) {
         $permission->status = KalturaPermissionStatus::ACTIVE;
     }
     $dbPermission = $permission->toInsertableObject();
     $dbPermission->setType(PermissionType::NORMAL);
     // only normal permission types are added through this services
     $dbPermission->setPartnerId($this->getPartnerId());
     try {
         PermissionPeer::addToPartner($dbPermission, $this->getPartnerId());
     } catch (kPermissionException $e) {
         $code = $e->getCode();
         if ($code === kPermissionException::PERMISSION_ALREADY_EXISTS) {
             throw new KalturaAPIException(KalturaErrors::PERMISSION_ALREADY_EXISTS, $permission->getName(), $this->getPartnerId());
         }
         if ($code === kPermissionException::PERMISSION_ITEM_NOT_FOUND) {
             throw new KalturaAPIException(KalturaErrors::PERMISSION_ITEM_NOT_FOUND);
         }
         throw $e;
     }
     $permission = new KalturaPermission();
     $permission->fromObject($dbPermission);
     return $permission;
 }