0

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

Community
  • 1
  • 1
Will Nielsen
  • 542
  • 1
  • 5
  • 16
  • I suppose you have a good reason for having the phone numbers in their own section as opposed to simple text fields in the members section? – David Oliver Feb 26 '14 at 19:15
  • This allows for members to have multiple phone numbers with a variety of types. Multiple mobile or work numbers for example. It also allows us to keep a core principle of entering a datum once and using it in a variety of instantiations. This format works well within the backend control panel but I'm having a difficult time (not being completely familiar with the underlying code) replicating the functionality on the frontend. – Will Nielsen Feb 26 '14 at 23:01
  • Ok. I think you have your answer now (and I'm not sure of the specifics myself, anyway) but I don't think SSM is going to be supported by its author long-term; if you can get away with using vanilla Symphony CMS fields, like SBL, that might be worth considering. Related, if I remember correctly from when I converted a field from SSM to SBL, SSM uses the same database structure as SBL. Maybe this is relevant to using a core event, too? – David Oliver Feb 27 '14 at 08:35
  • Ah, the author has just said that you can use core events with SSM: http://www.getsymphony.com/discuss/thread/105441/1/#position-9 – David Oliver Feb 27 '14 at 08:36

2 Answers2

0

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.

Will Nielsen
  • 542
  • 1
  • 5
  • 16
0

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.

Will Nielsen
  • 542
  • 1
  • 5
  • 16