Пример #1
0
 public function formatStoreRecord($record, $model, $store)
 {
     $r = new \GO\Base\Mail\EmailRecipients();
     $r->addRecipient($model->email, $model->name);
     $record['from'] = (string) $r;
     $record['html_signature'] = \GO\Base\Util\String::text_to_html($model->signature);
     $record['plain_signature'] = $model->signature;
     $record['signature_below_reply'] = $model->account->signature_below_reply;
     $record['template_id'] = 0;
     if (\GO::modules()->addressbook) {
         $defaultAccountTemplateModel = \GO\Addressbook\Model\DefaultTemplateForAccount::model()->findByPk($model->account_id);
         if ($defaultAccountTemplateModel) {
             $record['template_id'] = $defaultAccountTemplateModel->template_id;
         } else {
             $defaultUserTemplateModel = \GO\Addressbook\Model\DefaultTemplate::model()->findByPk(\GO::user()->id);
             if (!$defaultUserTemplateModel) {
                 $defaultUserTemplateModel = new \GO\Addressbook\Model\DefaultTemplateForAccount();
                 $defaultUserTemplateModel->account_id = $model->account_id;
                 $defaultUserTemplateModel->save();
             }
             $record['template_id'] = $defaultUserTemplateModel->template_id;
         }
     }
     unset($record['signature']);
     return parent::formatStoreRecord($record, $model, $store);
 }
Пример #2
0
 public function actionEmailSelection($params)
 {
     // 'type' is only set by the client if a template should be selected as default.
     // The user can choose to set the default template for an email account or
     // for himself (current user).
     if (!empty($params['type']) && $params['type'] == 'default_for_account' || !empty($params['account_id']) && isset($params['default_template_id'])) {
         $defTempForAccount = \GO\Addressbook\Model\DefaultTemplateForAccount::model()->findByPk($params['account_id']);
         if (!$defTempForAccount) {
             $defTempForAccount = new \GO\Addressbook\Model\DefaultTemplateForAccount();
             $defTempForAccount->account_id = $params['account_id'];
             $defTempForAccount->save();
         }
     } else {
         $defTempForUser = \GO\Addressbook\Model\DefaultTemplate::model()->findByPk(\GO::user()->id);
         if (!$defTempForUser) {
             $defTempForUser = new \GO\Addressbook\Model\DefaultTemplate();
             $defTempForUser->user_id = \GO::user()->id;
             $defTempForUser->save();
         }
     }
     $this->_defaultTemplate = !empty($defTempForAccount) ? $defTempForAccount : $defTempForUser;
     if (isset($params['default_template_id'])) {
         $this->_defaultTemplate->template_id = $params['default_template_id'];
         $this->_defaultTemplate->save();
     }
     $findParams = \GO\Base\Db\FindParams::newInstance()->order('name');
     $findParams->getCriteria()->addCondition('type', \GO\Addressbook\Model\Template::TYPE_EMAIL);
     $stmt = \GO\Addressbook\Model\Template::model()->find($findParams);
     $store = \GO\Base\Data\Store::newInstance(\GO\Addressbook\Model\Template::model());
     $store->getColumnModel()->setFormatRecordFunction(array($this, 'formatEmailSelectionRecord'));
     $store->setStatement($stmt);
     $store->addRecord(array('group' => 'templates', 'checked' => isset($this->_defaultTemplate->template_id) && $this->_defaultTemplate->template_id == 0, 'text' => \GO::t('none'), 'template_id' => 0));
     $response = $store->getData();
     if ($response['total'] > 0) {
         $response['results'][] = '-';
         $record = array('text' => \GO::t('setCurrentTemplateAsDefault', 'addressbook'), 'template_id' => 'default');
         $response['results'][] = $record;
         $record = array('text' => \GO::t('setCurrentTemplateAsDefaultEAccount', 'addressbook'), 'template_id' => 'default_for_account');
         $response['results'][] = $record;
     }
     return $response;
 }