Override Visibility Strategy while initializing Sugar Bean

Hello Folks,

I wanted to override visibility strategy defined in module bean class definition while initializing that bean.

For eg: I have a module called Test and I have defined following visibility in bean class.

class Test extends SugarBean

{

    public function __construct()

    {

         $this->addVisibilityStrategy("OwnerVisibility");

         parent::__construct();

    }

}

Now, while initializing bean, I wanted to override this strategy in some scenarios.

$testBean = BeanFactory::newBean("Test");

$testBean->addVisibilityStrategy("OwnerOrAdminVisibility");

But the above line is not working. I am not sure how to override the visibility already defined in bean definition.

Any help or idea would be greatly appreciated.

Regards.

Hats

Parents
  • Hi hats 

    I believe the best way is to create a custom visibility which adds either OwnerVisibility or OwnerOrAdminVisibility depends on $this->bean/user attributes.

    We have done that very frequently without big deal.

    Kind regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André Lopes,

    Thank you so much for the suggestion. There is little complexity in my scenario. I want this visibility to change only when instantiating bean to fetch some rows. With owner visibility, I am not able to fetch records of other users even with admin user and if I set owner or admin visibility, it shows all records even in Sugar UI (which I don't want).

    I hope you have understood my scenario. Please let me know if there is any possible way to achieve this or final solution would be to fetch these records using raw SQL queries (which I don't prefer much).

    Thank you in advance.

    Regards.

    Hats

Reply
  • Hi André Lopes,

    Thank you so much for the suggestion. There is little complexity in my scenario. I want this visibility to change only when instantiating bean to fetch some rows. With owner visibility, I am not able to fetch records of other users even with admin user and if I set owner or admin visibility, it shows all records even in Sugar UI (which I don't want).

    I hope you have understood my scenario. Please let me know if there is any possible way to achieve this or final solution would be to fetch these records using raw SQL queries (which I don't prefer much).

    Thank you in advance.

    Regards.

    Hats

Children