Announcement

Collapse
No announcement yet.

7.0x about value-objects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 7.0x about value-objects

    https://docs.espocrm.com/development...#value-objects

    Hi,
    i try .. but no luck (certainly because my english)
    how i can "insert" phoneNumber in back-end

    i have try many .. no luck
    nothing is saved in entity

    HTML Code:
    $group = $entity->getPhoneNumberGroup();
    
    if ($data->phone_office && !$group->hasNumber($data->phone_office))
    {
    $phone = PhoneNumber::create($data->phone_office);
    $phone->withType('Office');
    $group->withAdded($phone);
    
    }elseif($data->phone_alternate && !$group->hasNumber($data->phone_alternate))
    {
    $phone = PhoneNumber::create($data->phone_alternate);
    $phone->withType('Home');
    $group->withAdded($phone);
    
    }elseif($data->dio_phone_mobile && !$group->hasNumber($data->dio_phone_mobile))
    {
    $phone = PhoneNumber::create($data->dio_phone_mobile);
    $phone->withType('Mobile');
    $group->withAdded($phone);
    }
    
    
    $valueMap = (new PhoneNumberGroupAttributeExtractor())->extract($group, 'phoneNumberData');
    $GLOBALS['log']->warning('valueMap => ' .json_encode( $valueMap ));
    $GLOBALS['log']->warning('group => ' .json_encode( $group ));
    $GLOBALS['log']->warning('phone => ' .json_encode( $phone ));
    //$entity->setPhoneNumberGroup($group);
    //$entity->setValueObject($group);
    
    $GLOBALS['log']->warning('group => ' .json_encode( $phoneNumberData ));
    $entity->setPhoneNumberGroup($phoneNumberData);
    $em->saveEntity($entity, $options);
    Last edited by item; 11-06-2021, 12:03 AM.

  • #2
    Value objects are immutable. https://en.wikipedia.org/wiki/Value_object.

    Wrong:

    PHP Code:
    $valueObject->withSomething($something); 

    Right:

    PHP Code:
    $valueObject $valueObject->withSomething($something); 

    https://docs.espocrm.com/development...#value-objects

    Comment


    • #3
      Thanks Yuri,
      i don't undertand all but with your guidance..

      PHP Code:
      if ($data->dio_phone_mobile)
      {
              
      $phoneNumberGroup $entity->getPhoneNumberGroup();
              if (!
      $phoneNumberGroup->hasNumber($data->dio_phone_mobile))
             {
                     
      $modifiedPhoneNumberGroup $phoneNumberGroup
                           
      ->withAddedPhoneNumber::create($data->dio_phone_mobile)->withType('Mobile'));
                     
      $entity->setPhoneNumberGroup($modifiedPhoneNumberGroup);
                     
      $em->saveEntity($entity);
             }

      Last edited by item; 11-06-2021, 09:04 PM.

      Comment


      • #4
        Hello item ,
        Trying to educate myself on what are "value objects" and how they work, ran into this article that might help
        If you already have heard about DDD (Domain-Driven Design), you probably also may have heard about...

        Comment


        • item
          item commented
          Editing a comment
          Hello telecastg,
          as you know.. my english is like a Penguin in Sahara

          i think on what i have understand.. it's for "multi-users/multi-threatding" (for simple explanation).. i can not say more, it's out of my scope

        • telecastg
          telecastg commented
          Editing a comment
          like a Penguin in Sahara
          that's how I feel sometimes, specially if dealing with server issues or git
      Working...
      X