示例#1
0
 function onUserForm(Am_Event_UserForm $event)
 {
     switch ($event->getAction()) {
         case Am_Event_UserForm::INIT:
             $form = $event->getForm()->getElementById('general');
             $el = $form->addMagicSelect('_newsletter')->setLabel(___('Newsletter Subscriptions'));
             $el->loadOptions($this->getDi()->newsletterListTable->getAdminOptions());
             if ($event->getUser()->isLoaded()) {
                 $el->setValue($ids = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($event->getUser()->pk()));
             }
             $form->addHidden('_newsletter_hidden')->setValue(1);
             break;
         case Am_Event_UserForm::VALUES_TO_FORM:
             // todo
             if ($event->getUser()->isLoaded()) {
                 $event->_newsletter = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($event->getUser()->pk());
             } else {
                 $event->_newsletter = array();
             }
             break;
         case Am_Event_UserForm::AFTER_SAVE:
             if ($event->_newsletter_hidden) {
                 $vals = $event->_newsletter;
                 $this->getDi()->newsletterUserSubscriptionTable->adminSetIds($event->getUser()->pk(), (array) $event->_newsletter);
             }
             break;
     }
 }
示例#2
0
    public function onUserForm(Am_Event_UserForm $event)
    {
        if ($event->getAction() == Am_Event_UserForm::BEFORE_SAVE) {
            $input = $event->getForm()->getValue();
            if (!empty($input['_aff'])) {
                $aff = $this->getDi()->userTable->findFirstByLogin($input['_aff'], false);
                if ($aff) {
                    if ($aff->pk() == $event->getUser()->pk()) {
                        throw new Am_Exception_InputError("Cannot assign affiliate to himself");
                    }
                    $event->getUser()->aff_id = $aff->pk();
                } else {
                    throw new Am_Exception_InputError("Affiliate not found, username specified: " . Am_Controller::escape($input['_aff']));
                }
            }
        }
        if ($event->getAction() != Am_Event_UserForm::INIT) {
            return;
        }
        $fieldSet = $event->getForm()->addFieldset('affiliate')->setLabel(___('Affiliate Program'));
        $user = $event->getUser();
        $affHtml = "";
        if (!empty($user->aff_id)) {
            try {
                $aff = $this->getDi()->userTable->load($user->aff_id);
                $url = new Am_View_Helper_UserUrl();
                $affHtml = sprintf('<a target="_blank" href="%s">"%s %s" &lt;%s&gt;</a>', Am_Controller::escape($url->userUrl($user->aff_id)), $aff->name_f, $aff->name_l, $aff->email);
                $fieldSet->addElement('static', '_aff')->setLabel(___('Referred Affiliate'))->setContent($affHtml);
            } catch (Am_Exception $e) {
                // ignore if affiliate was deleted
            }
        } else {
            $fieldSet->addElement('text', '_aff', array('placeholder' => 'Type username or e-mail'))->setLabel(___('Referred Affiliate'));
            $fieldSet->addScript()->setScript(<<<CUT
    \$("input#_aff-0").autocomplete({
        minLength: 2,
        source: window.rootUrl + "/admin-users/autocomplete"
    });
CUT
);
        }
        $fieldSet->addElement('advradio', 'is_affiliate')->setLabel(array(___('Is Affiliate?'), ___('customer / affiliate status')))->loadOptions(array('0' => ___('No'), '1' => ___('Both Affiliate and member'), '2' => ___('Only Affiliate %s(rarely used)%s', '<i>', '</i>')));
        $this->addPayoutInputs($fieldSet);
    }