Is it possible in Symphony CMS to update Subsection Manager field entries in a frontend member form?

StackOverflow https://stackoverflow.com//questions/22048086

  •  21-12-2019
  •  | 
  •  

문제

Backend:

backend Subsection manager

Frontend:

frontend members section

What I'm trying to accomplish is a front-end form that allows members to update their phone numbers on file. Phone numbers are stored in their own section and attached to a member record via subsection manager in the backend.

c.f., Symphony CMS Discussion


Symphony 2.3.6 Subsection Manager 3.5.1

도움이 되었습니까?

해결책 2

My initial answer sort of worked but it was reinventing the wheel. Symphony's Events can handle the scenario I jotted out above. By using the native event behavior you don't have to recode the user feedback etc.

I highly recommend this article (slightly dated) by @Brendo.

Note: references to self::ROOTELEMENT is deprecated you should use $this->ROOTELEMENT instead.

다른 팁

Pseudocode

1. Identify new phone numbers
2. Create New Entry Objects for each number
3. Create array of entry objects that includes 
    3.1 existent numbers being edited
    3.2 new numbers being added
4. Update all numbers with new/edited values
5. Commit Numbers Entries to the Phone Number Section in DB
6. Update the Member entry to reflect the ID of the new phone number
7. Commit the Member Entry to the Members Section in the DB

I have this bit working which saves new phone numbers to the Phone Number Section (PseudoCode #s 1-5; I'm not worrying about editing existing numbers just yet):

foreach($_POST['fields']['phone-numbers-new'] as $hash => $field)
{
    $data = array();
    $data[$ids['phoneNumbers']['fields']['type']]['handle'] = General::createHandle($field['type']);
    $data[$ids['phoneNumbers']['fields']['type']]['value'] = $field['type'];
    $data[$ids['phoneNumbers']['fields']['number']]['handle'] = General::createHandle($field['number']);
    $data[$ids['phoneNumbers']['fields']['number']]['value'] = $field['number'];
    $data[$ids['phoneNumbers']['fields']['added_by']]['author_id'] = "1";
    $data[$ids['phoneNumbers']['fields']['active']]['value'] = "yes";


    $newPNs = EntryManager::create();
    $newPNs->set('section_id', "{$ids['phoneNumbers']['sectionID']}");
    $newPNs->setDataFromPost($data);
    $newPNs->setData($ids['phoneNumbers']['fields']['type'],$data[$ids['phoneNumbers']['fields']['type']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['number'],$data[$ids['phoneNumbers']['fields']['number']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['added_by'],$data[$ids['phoneNumbers']['fields']['added_by']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['active'],$data[$ids['phoneNumbers']['fields']['active']]);

    $ids['newPNs'][] = $newPNs->get('id');

    $newPNs->commit(); //adds the new phone number to the Phone Number Section

}

I then update the Member Entry with the new phone numbers:

$entries = EntryManager::fetch($ids['entry']);
$member = $entries[0];

$data = array(); // reset data array

$data[$ids['phoneNumbers']['fieldID']] = $member->getData($ids['phoneNumbers']['fieldID']);
for($i = 0; $i < count($ids['newPNs']); $i++)
{
    $index = count($data[$ids['phoneNumbers']['fieldID']]['relation_id']) + $i;
    $data[$ids['phoneNumbers']['fieldID']]['relation_id'][$index] = "{$ids['newPNs'][$i]}";
}
$member->setData($ids['phoneNumbers']['fieldID'],$data[$ids['phoneNumbers']['fieldID']]);
$member->commit();

That worked for adding new phone numbers. Edited numbers should be updated in the Section prior to committing the member Entry and the results are also successful.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top