Net.nehmer.branchenbuch
From OpenPSA Wiki
This provides yellow pages functionality and only works in conjunction with a net.nehmer.account Topic which has to be specified in the configuration. Internally, the component uses n.n.account's Datamanager2 Schemas to create main categories. Two levels of subcategories (branchen) can be added.
[edit] Synchronizing with net.nehmer.account
By adding a special callback to the account handlers, account data and branchenbuch entries can be synchronized:
<?php function site_local_callback_account_save ($person) { $_MIDCOM->componentloader->load('net.nehmer.branchenbuch'); $topic = new midcom_db_topic($branchenbuch_topic_guid); $qb = net_nehmer_branchenbuch_entry::new_query_builder(); $qb->add_constraint('account', '=', $person->guid); $qb->set_limit(1); $bb_entries = $qb->execute(); foreach($bb_entries as $key => $bb_entry) { $schemamgr = new net_nehmer_branchenbuch_schemamgr($topic); $type = $bb_entry->type; $schemadb = Array($type => $schemamgr->get_account_schema($type)); $entry_dm = new midcom_helper_datamanager2_datamanager($schemadb); $user = $_MIDCOM->auth->get_user($person->guid); $logo_name = "image_logo"; $avatar = $person->get_attachment('avatar'); $entry_dm->set_schema($type); $entry_dm->set_storage($bb_entry); $defaults = $schemamgr->remote->get_defaults_from_account($user); foreach ($defaults as $field => $value) { $entry_dm->types[$field]->convert_from_storage($value); } // Save if (! $entry_dm->save()) { $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Failed to save the entry, see the debug level log for more information, Dm2 save operation failed'); // This will exit. } // Update the Index $indexer =& $_MIDCOM->get_service('indexer'); $bb_entry->index($entry_dm, $indexer, $topic); if (!$avatar) { continue; } $tmpfile = tempnam('/tmp', 'ac_bb_convert_'); unlink($tmpfile); $dst = fopen($tmpfile, 'w'); $src = mgd_open_attachment($avatar->id, 'r'); while (!feof($src)) { $buffer = fread($src, 131072); // 128 kB fwrite($dst, $buffer, 131072); } fclose($src); fclose($dst); if ( ! $entry_dm->types[$logo_name]->set_image($logo_name, $tmpfile, "") ) { $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Failed to set image: ' . mgd_errstr()); } } } ?>
You get a lot of respect from me for writing these helpful aticrles.
