Example #1
0
 protected function beforeStoreStatement(array &$response, array &$params, \GO\Base\Data\AbstractStore &$store, \GO\Base\Db\FindParams $storeParams)
 {
     if (!empty($params['filters'])) {
         $abMultiSel = new \GO\Base\Component\MultiSelectGrid('books', "GO\\Addressbook\\Model\\Addressbook", $store, $params, true);
         $abMultiSel->addSelectedToFindCriteria($storeParams, 'addressbook_id');
         //		$abMultiSel->setButtonParams($response);
         //		$abMultiSel->setStoreTitle();
         $addresslistMultiSel = new \GO\Base\Component\MultiSelectGrid('addresslist_filter', "GO\\Addressbook\\Model\\Addresslist", $store, $params, false);
         if (!empty($params['addresslist_filters'])) {
             $addresslistMultiSel->addSelectedToFindCriteria($storeParams, 'addresslist_id', 'ac');
             if (count($addresslistMultiSel->selectedIds)) {
                 //we need to join the addresslist link model if a filter for the addresslist is enabled.
                 $storeParams->join(\GO\Addressbook\Model\AddresslistContact::model()->tableName(), \GO\Base\Db\FindCriteria::newInstance()->addCondition('id', 'ac.contact_id', '=', 't', true, true), 'ac');
                 $storeParams->group('t.id');
             }
         }
         if (!empty($params['onlyCurrentActions'])) {
             $storeParams->getCriteria()->addCondition('action_date', 0, '>', 't')->addCondition('action_date', time(), '<=', 't');
         }
     }
     return parent::beforeStoreStatement($response, $params, $store, $storeParams);
 }
Example #2
0
 protected function actionContact()
 {
     //GOS::site()->config->contact_addressbook_id;
     if (\GO\Base\Util\Http::isPostRequest()) {
         if (isset($_POST['Addressbook']['name'])) {
             $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findSingleByAttribute('name', $_POST['Addressbook']['name']);
         } else {
             $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findByPk($_POST['Addressbook']['id']);
         }
         if (!$addressbookModel) {
             throw new \Exception(sprintf(\GO::t('addressbookNotFound', 'defaultsite'), $_POST['Addressbook']['name']));
         }
         $contactModel = \GO\Addressbook\Model\Contact::model()->findSingleByAttributes(array('email' => $_POST['Contact']['email'], 'addressbook_id' => $addressbookModel->id));
         if (!$contactModel) {
             $contactModel = new \GO\Addressbook\Model\Contact();
             $contactModel->addressbook_id = $addressbookModel->id;
         }
         $contactModel->setValidationRule('first_name', 'required', true);
         $contactModel->setValidationRule('last_name', 'required', true);
         $contactModel->setValidationRule('email', 'required', true);
         $companyModel = \GO\Addressbook\Model\Company::model()->findSingleByAttributes(array('name' => $_POST['Company']['name'], 'addressbook_id' => $addressbookModel->id));
         if (!$companyModel) {
             $companyModel = new \GO\Addressbook\Model\Company();
             $companyModel->addressbook_id = $addressbookModel->id;
         }
         $companyModel->setValidationRule('name', 'required', true);
         $companyModel->setAttributes($_POST['Company']);
         if ($companyModel->validate()) {
             $companyModel->save();
             $contactModel->company_id = $companyModel->id;
         }
         $contactModel->setAttributes($_POST['Contact']);
         if ($contactModel->validate()) {
             $saveSuccess = $contactModel->save();
             if ($saveSuccess) {
                 // Add to mailings.
                 $addresslists = !empty($_POST['Addresslist']) ? $_POST['Addresslist'] : array();
                 foreach ($addresslists as $addresslistName => $checked) {
                     if (!empty($checked)) {
                         $addresslistModel = \GO\Addressbook\Model\Addresslist::model()->findSingleByAttribute('name', $addresslistName);
                         if ($addresslistModel) {
                             $addresslistContactModel = \GO\Addressbook\Model\AddresslistContact::model()->findSingleByAttributes(array('contact_id' => $contactModel->id, 'addresslist_id' => $addresslistModel->id));
                             if (!$addresslistContactModel) {
                                 $addresslistContactModel = new \GO\Addressbook\Model\AddresslistContact();
                                 $addresslistContactModel->contact_id = $contactModel->id;
                                 $addresslistContactModel->addresslist_id = $addresslistModel->id;
                                 $addresslistContactModel->save();
                             }
                         }
                     }
                 }
                 echo $this->render('contactform_done');
             } else {
                 echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel));
             }
         } else {
             $validationErrors = $contactModel->getValidationErrors();
             foreach ($validationErrors as $valError) {
                 echo $valError;
             }
             echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel));
         }
     } else {
         $addressbookModel = new \GO\Addressbook\Model\Addressbook();
         $contactModel = new \GO\Addressbook\Model\Contact();
         $companyModel = new \GO\Addressbook\Model\Company();
         echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel));
     }
 }