Source of file Vision6.php
Size: 2,881 Bytes - Last Modified: 2021-12-23T10:38:15+00:00
/var/www/docs.ssmods.com/process/src/code/Vision6.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | <?php /** * Class Vision6 */ class Vision6 extends Object { /** * @param Vision6List|int $listOrId * @return FieldList|Object */ public function getFieldsForList($listOrId) { $factory = Vision6FieldFactory::create(); return $factory->setList($listOrId)->build(); } /** * Checks to see if the email is already in the Vision6 List * @param $listId * @param $emailAddress * * @return bool */ public function isEmailInList($listId, $emailAddress) { $api = Vision6Api::create(); $contacts = $api->callMethod( 'searchContacts', $listId, array( array( 'Email', 'exactly', $emailAddress ) ) ); return (!empty($contacts)); } /** * Gets the session container or creates it if it doesn't exist. * * @return array|mixed|null|\Session */ public function getSession() { return \Session::get('Vision6') ?: (\Session::set('Vision6', array())) ?: \Session::get('Vision6'); } /** * Sets the session container * * @param array $data * * @return void */ public function setSession(array $data) { Session::set('Vision6', $data); Session::save(); } /** * @param $listId * @param TextField|EmailField|string $fieldOrEmail * @return bool */ public static function subscribeEmail($listId, $fieldOrEmail) { $email = null; if ($fieldOrEmail instanceof TextField) { $email = $fieldOrEmail->Value(); } if (is_string($fieldOrEmail)) { $email = $fieldOrEmail; } if (!$email) { user_error( 'An email address was not provided', E_USER_ERROR ); } /** @var Vision6List $list */ $list = Vision6List::get()->filter('ListID', $listId)->first(); $api = Vision6Api::create(); $api->callMethod("subscribeContact", (int)$listId, array('Email' => $email)); if ($api->hasError()) { user_error( _t( 'Vision6.SUBSCRIBE_DEV_ERROR', 'An error occurred when attempting to subscribe {email} to {list_title}: {error}', 'The message that is logged when an error occurs while attempting to subscribe a user to a mailing list', array( 'email' => $email, 'list_title' => $list->Name, 'error' => $api->getErrorMessage() ) ), E_USER_WARNING ); } return (!$api->hasError()); } } |