diff --git a/Classes/API/PaypalApiCredentials.php b/Classes/API/PaypalApiCredentials.php deleted file mode 100755 index 4f724df..0000000 --- a/Classes/API/PaypalApiCredentials.php +++ /dev/null @@ -1,130 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Classes\API; - -use Paypal\Paypal; -use Thelia\Core\Translation\Translator; - -class PaypalApiCredentials -{ - - /** @var string PayPal API username */ - protected $apiUsername = null; - - /** @var string PayPal API password */ - protected $apiPassword = null; - - /** @var string PayPal API signature (Three Token Authentication) */ - protected $apiSignature = null; - - /** - * Create a NVP Credentials - * - * @param string $user PayPal API username - * @param string $password PayPal API password - * @param string $signature PayPal API signature (3T) - * - * @throws \InvalidArgumentException - */ - public function __construct($user = null, $password = null, $signature = null) - { - if ($user === null && $password === null && $signature === null) { - $this->setDefaultCredentials(); - } else { - if (empty($user) || empty($password) || empty($signature)) { - throw new \InvalidArgumentException( - 'PaypalApiCredentials : Missing Argument' - ); - } - $this->apiPassword = $password; - $this->apiSignature = $signature; - $this->apiUsername = $user; - - } - } - - /** - * Set credentials from database according to SandBox Mode - * - * @throws \InvalidArgumentException - */ - protected function setDefaultCredentials() - { - $paypalApiManager = new PaypalApiManager(); - - if ($paypalApiManager->isModeSandbox()) { - $username = Paypal::getConfigValue('sandbox_login', ''); - $password = Paypal::getConfigValue('sandbox_password', ''); - $signature = Paypal::getConfigValue('sandbox_signature', ''); - } else { - $username = Paypal::getConfigValue('login', ''); - $password = Paypal::getConfigValue('password', ''); - $signature = Paypal::getConfigValue('signature', ''); - } - - if (empty($username)) { - throw new \InvalidArgumentException(Translator::getInstance()->trans('The username option must be set.')); - } - if (empty($password)) { - throw new \InvalidArgumentException(Translator::getInstance()->trans('The password option must be set.')); - } - if (empty($signature)) { - throw new \InvalidArgumentException(Translator::getInstance()->trans('The signature option must be set.')); - } - - $this->apiUsername = $username; - $this->apiPassword = $password; - $this->apiSignature = $signature; - } - - /** - * Return API password - * - * @return string - */ - public function getApiPassword() - { - return $this->apiPassword; - } - - /** - * Return API signature - * - * @return string - */ - public function getApiSignature() - { - return $this->apiSignature; - } - - /** - * Return API username - * - * @return string - */ - public function getApiUsername() - { - return $this->apiUsername; - } -} diff --git a/Classes/API/PaypalApiLogManager.php b/Classes/API/PaypalApiLogManager.php deleted file mode 100755 index dad6323..0000000 --- a/Classes/API/PaypalApiLogManager.php +++ /dev/null @@ -1,92 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Classes\API; - -use Thelia\Log\Tlog; - -/** - * Class PaypalApiLogManager - * This class is the Paypal logger - * Logged actions: transaction - */ -class PaypalApiLogManager -{ - /** @var Tlog $log */ - protected static $logger; - - /** - * Parse and log the return of the Paypal NVP API - * - * @param string $transaction A special string returned by the NVP API - */ - public function logTransaction($parsedTransaction) - { - if ($parsedTransaction) { - /* - * Then write - */ - $logLine = ''; - $date = new \DateTime($parsedTransaction['TIMESTAMP']); - - $logLine .= $date->format('Y-m-d H:i:s') . ' '; - $logLine .= 'Transaction ' . $parsedTransaction['ACK'] . ' '; - $logLine .= 'correlationId: ' . $parsedTransaction['CORRELATIONID'] . ' '; - - if ($parsedTransaction !== null && array_key_exists('L_ERRORCODE0', $parsedTransaction)) { - $logLine .= 'error: '; - $logLine .= '[' . $parsedTransaction['L_ERRORCODE0'] . '] '; - $logLine .= '<' . $parsedTransaction['L_SHORTMESSAGE0'] . '> '; - $logLine .= $parsedTransaction['L_LONGMESSAGE0'] . ' '; - } - - $this->getLogger()->info($logLine); - } else { - $this->getLogger()->info('No transaction was created.'); - } - } - - public static function getLogFilePath() - { - return THELIA_LOG_DIR . DS . "log-paypal.txt"; - } - - /** - * @return Tlog - */ - public function getLogger() - { - if (self::$logger == null) { - self::$logger = Tlog::getNewInstance(); - - $logFilePath = self::getLogFilePath(); - - self::$logger->setPrefix("#LEVEL: #DATE #HOUR: "); - self::$logger->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile"); - self::$logger->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile", 0, $logFilePath); - self::$logger->setLevel(Tlog::INFO); - } - - return self::$logger; - } -} diff --git a/Classes/API/PaypalApiManager.php b/Classes/API/PaypalApiManager.php deleted file mode 100755 index 28b5392..0000000 --- a/Classes/API/PaypalApiManager.php +++ /dev/null @@ -1,199 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Classes\API; - -use Paypal\Classes\PaypalResources; -use Paypal\Classes\vendor\MobileDetect\MobileDetect; -use Paypal\Paypal; - -/** - * Class PaypalApiManager - * Assist in helping managing API - */ -class PaypalApiManager -{ - /** Live API */ - const DEFAULT_NVP_3T_API_URL_LIVE = 'https://api-3t.paypal.com/nvp'; - - /** SandBox API */ - const DEFAULT_NVP_3T_API_URL_SANDBOX = 'https://api-3t.sandbox.paypal.com/nvp'; - - /** Button Source - Identification code for third-party applications */ - const BUTTON_SOURCE = 'Thelia_Cart'; - - /** API Version */ - const API_VERSION = '108.0'; - - const PAYMENT_TYPE_ORDER = 'Order'; - const PAYMENT_TYPE_SALE = 'Sale'; - const PAYMENT_TYPE_AUTHORIZATION = 'Authorization'; - - /** @var bool if SandBox mode is enabled or not */ - protected $isModeSandbox = true; - - protected $config=null; - - public function __construct() - { - $this->isModeSandbox = Paypal::isSandboxMode(); - } - - /** - * Get if SandBox is enabled or not - * - * @return bool - */ - public function isModeSandbox() - { - return $this->isModeSandbox; - } - - /** - * Convert NVP string to array - * - * @param string $nvpstr NVP string - * - * @return array parameters - */ - public static function nvpToArray($nvpstr) - { - $paypalResponse = array(); - parse_str($nvpstr, $paypalResponse); - - $cleanedArray = array(); - $previousKey = reset($paypalResponse); - foreach ($paypalResponse as $key => $value) { - if (1 === preg_match('#^([A-Z0-9_]+)$#', $key)) { - $cleanedArray[$key] = $value; - $previousKey = $key; - } else { - $cleanedArray[$previousKey] .= '&' . $key . '=' . $value; - } - } - - return $cleanedArray; - } - - /** - * Convert array to NVP string - * - * @param $data - * @param \stdClass|null $ret - * @param null $construct_scheme - * - * @return string - */ - public static function arrayToNvp($data, \stdClass $ret = null, $construct_scheme = null) - { - if ($ret===null) { - $ret = new \stdClass(); - $ret->value=""; - } - if (is_array($data)) { - foreach ($data as $key => $value) { - self::arrayToNvp($value, $ret, $construct_scheme===null?$key:$construct_scheme."_".$key); - } - } else { - $ret->value .= $construct_scheme."=".$data."&"; - } - - return substr($ret->value, 0, strlen($ret->value)-1); - } - - /** - * Detect if user is using a mobile - * Used in Express Checkout Mobile - * - * @return bool - */ - public function isMobile() - { - $detect = new MobileDetect(); - - return $detect->isMobile(); - } - - /** - * Return Express checkout URL - * Check itself if mobile or not - * - * @param string $token Paypal API token - * - * @return string - */ - public function getExpressCheckoutUrl($token) - { - if ($this->isMobile()) { - $cmd = PaypalResources::CMD_EXPRESS_CHECKOUT_MOBILE_KEY; - } else { - $cmd = PaypalResources::CMD_EXPRESS_CHECKOUT_KEY; - } - - return $this->getPaypalUrl() .'?cmd=' . $cmd . '&token=' . $token; - } - - /** - * Return relevant PayPal redirect URL - * According to SandBox Mode on or not - * - * @return string URL - */ - public function getPaypalUrl() - { - $url = PaypalResources::PAYPAL_REDIRECT_SANDBOX_URL; - - if (!$this->isModeSandbox()) { - $url = PaypalResources::PAYPAL_REDIRECT_NORMAL_URL; - } - - return $url; - } - - /** - * Convert float into NVP number - * - * @param string $number number - * - * @return string - */ - public static function convertFloatToNvpFormat($number) - { - return number_format($number, 2, '.', ''); - } - - /** - * Return API Url (sandbox or live) - * - * @return string - */ - public function getApiUrl() - { - $url = self::DEFAULT_NVP_3T_API_URL_SANDBOX; - if (!$this->isModeSandbox) { - $url = self::DEFAULT_NVP_3T_API_URL_LIVE; - } - - return $url; - } -} diff --git a/Classes/NVP/Operations/.DS_Store b/Classes/NVP/Operations/.DS_Store deleted file mode 100755 index 5008ddf..0000000 Binary files a/Classes/NVP/Operations/.DS_Store and /dev/null differ diff --git a/Classes/NVP/Operations/PaypalNvpOperationsBase.php b/Classes/NVP/Operations/PaypalNvpOperationsBase.php deleted file mode 100755 index 8d00507..0000000 --- a/Classes/NVP/Operations/PaypalNvpOperationsBase.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -namespace Paypal\Classes\NVP\Operations; - -use Paypal\Classes\API\PaypalApiManager; - -abstract class PaypalNvpOperationsBase implements PaypalNvpOperationInterface -{ - /** @var \Paypal\Classes\API\PaypalApiCredentials API Credentials (3T) */ - protected $credentials = null; - - /** @var string operation name */ - protected $operationName = null; - - /** @var array Payload with optional parameters */ - protected $payload = null; - - /** - * Generate NVP request message - * - * @return string NVP string - */ - public function getRequest() - { - $request = 'METHOD=' . $this->operationName; - $request .= '&VERSION=' . PaypalApiManager::API_VERSION; - $request .= '&USER=' . urlencode($this->credentials->getApiUsername()); - $request .= '&PWD=' . urlencode($this->credentials->getApiPassword()); - $request .= '&SIGNATURE=' . urlencode($this->credentials->getApiSignature()); - - return $request; - } - - /** - * Get Operation Name - * - * @return string Operation name - */ - public function getOperationName() - { - return $this->operationName; - } -} diff --git a/Classes/NVP/Operations/PaypalNvpOperationsDoExpressCheckoutPayment.php b/Classes/NVP/Operations/PaypalNvpOperationsDoExpressCheckoutPayment.php deleted file mode 100755 index 3b9338a..0000000 --- a/Classes/NVP/Operations/PaypalNvpOperationsDoExpressCheckoutPayment.php +++ /dev/null @@ -1,108 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Classes\NVP\Operations; - -use Paypal\Classes\API\PaypalApiCredentials; - -/** - * Class PaypalNvpOperationsDoExpressCheckoutPayment - * Manage NVP DoExpressCheckoutPayment Operation - */ -class PaypalNvpOperationsDoExpressCheckoutPayment extends PaypalNvpOperationsBase -{ - /** @var string Payer ID returned by PayPal when it redirects the buyer's browser to your site */ - protected $payerId = null; - - /** @var string SetExpressCheckout API Token */ - protected $token = null; - - /** @var string Transaction amount - * Must be specified as 2000.00 or 2,000.00. - * The specified amount cannot exceed USD $10,000.00, regardless of the currency used. - */ - protected $amount = null; - - /** @var string Currency id ex: EUR */ - protected $currencyId = null; - - /** @var string Payment action ex: sale/order */ - protected $paymentAction = null; - - /** @var string URL IPN listener */ - protected $ipnListenerUrl = null; - - /** @var string Button Source for Thelia_Cart */ - protected $buttonSource; - - /** - * Constructor - * - * @param PaypalApiCredentials $credentials API Credentials (3T) - * @param string $amount Transaction amount. Must be specified as 2000.00 or 2,000.00. The specified amount cannot exceed USD $10,000.00, regardless of the currency used. - * @param string $currencyId Currency id ex: EUR - * @param string $payerId Payer ID returned by PayPal when it redirects the buyer's browser to your site - * @param string $paymentAction Payment action ex: sale/order - * @param string $token Token returned by PayPal SetExpressCheckout API when it redirects the buyer's browser to your site. - * @param string $ipnListenerUrl Url Paypal will call in order to confirm payment - * @param $buttonSource - */ - public function __construct( - PaypalApiCredentials $credentials, - $amount, - $currencyId, - $payerId, - $paymentAction, - $token, - $ipnListenerUrl, - $buttonSource = null - ) { - $this->operationName = 'DoExpressCheckoutPayment'; - $this->token = $token; - $this->amount = $amount; - $this->payerId = $payerId; - $this->credentials = $credentials; - $this->currencyId = $currencyId; - $this->paymentAction = $paymentAction; - $this->ipnListenerUrl = $ipnListenerUrl; - $this->buttonSource = $buttonSource; - } - - /** - * {@inheritdoc} - */ - public function getRequest() - { - $request = parent::getRequest(); - $request .= '&TOKEN=' . $this->token; - $request .= '&PAYERID=' . $this->payerId; - $request .= '&PAYMENTREQUEST_0_AMT=' . $this->amount; - $request .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . $this->currencyId; - $request .= '&PAYMENTREQUEST_0_PAYMENTACTION=' . $this->paymentAction; - if (null !== $this->buttonSource) { - $request .='&BUTTONSOURCE=' . $this->buttonSource; - } - - return $request; - } -} diff --git a/Classes/NVP/Operations/PaypalNvpOperationsSetExpressCheckout.php b/Classes/NVP/Operations/PaypalNvpOperationsSetExpressCheckout.php deleted file mode 100755 index c218db7..0000000 --- a/Classes/NVP/Operations/PaypalNvpOperationsSetExpressCheckout.php +++ /dev/null @@ -1,163 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Classes\NVP\Operations; - -use Paypal\Classes\API\PaypalApiCredentials; -use Paypal\Classes\API\PaypalApiManager; - -/** - * Class PaypalNvpOperationsSetExpressCheckout - * Manage NVP SetExpressCheckout Operation - */ -class PaypalNvpOperationsSetExpressCheckout extends PaypalNvpOperationsBase -{ - /** @var string Transaction amount - * Must be specified as 2000.00 or 2,000.00. - * The specified amount cannot exceed USD $10,000.00, regardless of the currency used. - */ - protected $amount = null; - - /** @var string Currency id ex: EUR */ - protected $currencyId = null; - - /** @var string URL when operation is successful */ - protected $returnUrl = null; - - /** @var string URL when operation is cancelled */ - protected $cancelUrl = null; - - /** @var string allowing the shortcut transaction */ - protected $billingAgreement = null; - - /** @var bool If Paypal has to use Thelia Customer Address */ - protected $isPaypalAddressOverrided = false; - - /** @var string Delivery Address */ - protected $name = null; - /** @var string Delivery Address */ - protected $street = null; - /** @var string Delivery Address */ - protected $street2 = null; - /** @var string Delivery Address */ - protected $city = null; - /** @var string Delivery Address */ - protected $state = null; - /** @var string Delivery Address */ - protected $zip = null; - /** @var string Delivery Address */ - protected $countryCode = null; - - /** - * Constructor - * - * @param PaypalApiCredentials $credentials API Credentials (3T) - * @param string $amount Transaction amount (operationName = 'SetExpressCheckout'; - $this->credentials = $credentials; - - $this->amount = $amount; - $this->cancelUrl = $cancelUrl; - $this->currencyId = $currencyId; - $this->returnUrl = $returnUrl; - - $this->billingAgreement = $billingAgreement; - - $this->payload = $payload; - } - - /** - * Set customer delivery address - * - * @param string $name Name - * @param string $street Street - * @param string $street2 Street 2 - * @param string $city City - * @param string $state State - * @param string $zip Zip - * @param string $countryCode CountryCode FR|US|UK - * - * @return $this - */ - public function setCustomerDeliveryAddress($name, $street, $street2, $city, $state, $zip, $countryCode) - { - $this->isPaypalAddressOverrided = true; - $this->name = $name; - $this->street = $street; - $this->street2 = $street2; - $this->city = $city; - $this->state = $state; - $this->zip = $zip; - $this->countryCode = $countryCode; - - return $this; - } - - /** - * {@inheritdoc } - */ - public function getRequest() - { - $request = parent::getRequest(); - $request .= '&PAYMENTREQUEST_0_AMT=' . urlencode(PaypalApiManager::convertFloatToNvpFormat($this->amount)); - $request .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($this->currencyId); - $request .= '&RETURNURL=' . urlencode($this->returnUrl); - $request .= '&CANCELURL=' . urlencode($this->cancelUrl); - - if ($this->isPaypalAddressOverrided) { - $request .= '&ADDROVERRIDE=1'; - $request .= '&PAYMENTREQUEST_0_SHIPTONAME=' . urlencode($this->name); - $request .= '&PAYMENTREQUEST_0_SHIPTOSTREET=' . urlencode($this->street); - $request .= '&PAYMENTREQUEST_0_SHIPTOSTREET2=' . urlencode($this->street2); - $request .= '&PAYMENTREQUEST_0_SHIPTOCITY=' . urlencode($this->city); - $request .= '&PAYMENTREQUEST_0_SHIPTOSTATE=' . urlencode($this->state); - $request .= '&PAYMENTREQUEST_0_SHIPTOZIP=' . urlencode($this->zip); - $request .= '&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=' . urlencode($this->countryCode); - } - - if ($this->billingAgreement != 0) { - $request .= '&L_BILLINGTYPE0=MerchantInitiatedBillingSingleAgreement'; - } - - if (!empty($this->payload)) { - $request .= '&' . PaypalApiManager::arrayToNvp($this->payload); - } - - return $request; - } -} diff --git a/Classes/vendor/MobileDetect/MobileDetect.php b/Classes/vendor/MobileDetect/MobileDetect.php deleted file mode 100755 index a14e3d2..0000000 --- a/Classes/vendor/MobileDetect/MobileDetect.php +++ /dev/null @@ -1,1024 +0,0 @@ - - * Victor Stanciu (until v. 1.0) - * @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt - * @link Official page: http://mobiledetect.net - * GitHub Repository: https://github.com/serbanghita/Mobile-Detect - * Google Code Old Page: http://code.google.com/p/php-mobile-detect/ - * @version 2.6.6 - */ - -namespace Paypal\Classes\vendor\MobileDetect; - -class MobileDetect -{ - /** - * Mobile detection type. - */ - const DETECTION_TYPE_MOBILE = 'mobile'; - - /** - * Extended detection type. - */ - const DETECTION_TYPE_EXTENDED = 'extended'; - - /** - * A frequently used regular expression to extract version #s. - */ - const VER = '([\w._\+]+)'; - - /** - * Top-level device. - */ - const MOBILE_GRADE_A = 'A'; - - /** - * Mid-level device. - */ - const MOBILE_GRADE_B = 'B'; - - /** - * Low-level device. - */ - const MOBILE_GRADE_C = 'C'; - - /** - * Stores the version number of the current release. - * @var array - */ - protected $scriptVersion = '2.6.6'; - - /** - * The User-Agent HTTP header is stored in here. - * @var string - */ - protected $userAgent = null; - - /** - * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE. - * @var array - */ - protected $httpHeaders = array(); - - /** - * All the rules combined. - * @var array - */ - protected $mobileDetectionRules = null; - - /** - * The rules, but extended. - * @var array - */ - protected $mobileDetectionRulesExtended = null; - - /** - * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED. - * - * @var string - */ - protected $detectionType = self::DETECTION_TYPE_MOBILE; - - /** - * List of mobile devices (phones). - * - * @var array - */ - protected $phoneDevices = array( - 'iPhone' => '\biPhone.*Mobile|\biPod', // |\biTunes - 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+', - 'HTC' => 'HTC|HTC.*(Sensation|Evo|Vision|Explorer|6800|8100|8900|A7272|S510e|C110e|Legend|Desire|T8282)|APX515CKT|Qtek9090|APA9292KT|HD_mini|Sensation.*Z710e|PG86100|Z715e|Desire.*(A8181|HD)|ADR6200|ADR6400L|ADR6425|001HT|Inspire 4G|Android.*\bEVO\b', - 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile', - // @todo: Is 'Dell Streak' a tablet or a phone? ;) - 'Dell' => 'Dell.*Streak|Dell.*Aero|Dell.*Venue|DELL.*Venue Pro|Dell Flash|Dell Smoke|Dell Mini 3iX|XCD28|XCD35|\b001DL\b|\b101DL\b|\bGS01\b', - 'Motorola' => 'Motorola|\bDroid\b.*Build|DROIDX|Android.*Xoom|HRI39|MOT-|A1260|A1680|A555|A853|A855|A953|A955|A956|Motorola.*ELECTRIFY|Motorola.*i1|i867|i940|MB200|MB300|MB501|MB502|MB508|MB511|MB520|MB525|MB526|MB611|MB612|MB632|MB810|MB855|MB860|MB861|MB865|MB870|ME501|ME502|ME511|ME525|ME600|ME632|ME722|ME811|ME860|ME863|ME865|MT620|MT710|MT716|MT720|MT810|MT870|MT917|Motorola.*TITANIUM|WX435|WX445|XT300|XT301|XT311|XT316|XT317|XT319|XT320|XT390|XT502|XT530|XT531|XT532|XT535|XT603|XT610|XT611|XT615|XT681|XT701|XT702|XT711|XT720|XT800|XT806|XT860|XT862|XT875|XT882|XT883|XT894|XT909|XT910|XT912|XT928', - 'Samsung' => 'Samsung|SGH-I337|BGT-S5230|GT-B2100|GT-B2700|GT-B2710|GT-B3210|GT-B3310|GT-B3410|GT-B3730|GT-B3740|GT-B5510|GT-B5512|GT-B5722|GT-B6520|GT-B7300|GT-B7320|GT-B7330|GT-B7350|GT-B7510|GT-B7722|GT-B7800|GT-C3010|GT-C3011|GT-C3060|GT-C3200|GT-C3212|GT-C3212I|GT-C3262|GT-C3222|GT-C3300|GT-C3300K|GT-C3303|GT-C3303K|GT-C3310|GT-C3322|GT-C3330|GT-C3350|GT-C3500|GT-C3510|GT-C3530|GT-C3630|GT-C3780|GT-C5010|GT-C5212|GT-C6620|GT-C6625|GT-C6712|GT-E1050|GT-E1070|GT-E1075|GT-E1080|GT-E1081|GT-E1085|GT-E1087|GT-E1100|GT-E1107|GT-E1110|GT-E1120|GT-E1125|GT-E1130|GT-E1160|GT-E1170|GT-E1175|GT-E1180|GT-E1182|GT-E1200|GT-E1210|GT-E1225|GT-E1230|GT-E1390|GT-E2100|GT-E2120|GT-E2121|GT-E2152|GT-E2220|GT-E2222|GT-E2230|GT-E2232|GT-E2250|GT-E2370|GT-E2550|GT-E2652|GT-E3210|GT-E3213|GT-I5500|GT-I5503|GT-I5700|GT-I5800|GT-I5801|GT-I6410|GT-I6420|GT-I7110|GT-I7410|GT-I7500|GT-I8000|GT-I8150|GT-I8160|GT-I8190|GT-I8320|GT-I8330|GT-I8350|GT-I8530|GT-I8700|GT-I8703|GT-I8910|GT-I9000|GT-I9001|GT-I9003|GT-I9010|GT-I9020|GT-I9023|GT-I9070|GT-I9100|GT-I9103|GT-I9220|GT-I9250|GT-I9300|GT-I9305|GT-I9500|GT-I9505|GT-M3510|GT-M5650|GT-M7500|GT-M7600|GT-M7603|GT-M8800|GT-M8910|GT-N7000|GT-S3110|GT-S3310|GT-S3350|GT-S3353|GT-S3370|GT-S3650|GT-S3653|GT-S3770|GT-S3850|GT-S5210|GT-S5220|GT-S5229|GT-S5230|GT-S5233|GT-S5250|GT-S5253|GT-S5260|GT-S5263|GT-S5270|GT-S5300|GT-S5330|GT-S5350|GT-S5360|GT-S5363|GT-S5369|GT-S5380|GT-S5380D|GT-S5560|GT-S5570|GT-S5600|GT-S5603|GT-S5610|GT-S5620|GT-S5660|GT-S5670|GT-S5690|GT-S5750|GT-S5780|GT-S5830|GT-S5839|GT-S6102|GT-S6500|GT-S7070|GT-S7200|GT-S7220|GT-S7230|GT-S7233|GT-S7250|GT-S7500|GT-S7530|GT-S7550|GT-S7562|GT-S8000|GT-S8003|GT-S8500|GT-S8530|GT-S8600|SCH-A310|SCH-A530|SCH-A570|SCH-A610|SCH-A630|SCH-A650|SCH-A790|SCH-A795|SCH-A850|SCH-A870|SCH-A890|SCH-A930|SCH-A950|SCH-A970|SCH-A990|SCH-I100|SCH-I110|SCH-I400|SCH-I405|SCH-I500|SCH-I510|SCH-I515|SCH-I600|SCH-I730|SCH-I760|SCH-I770|SCH-I830|SCH-I910|SCH-I920|SCH-LC11|SCH-N150|SCH-N300|SCH-R100|SCH-R300|SCH-R351|SCH-R400|SCH-R410|SCH-T300|SCH-U310|SCH-U320|SCH-U350|SCH-U360|SCH-U365|SCH-U370|SCH-U380|SCH-U410|SCH-U430|SCH-U450|SCH-U460|SCH-U470|SCH-U490|SCH-U540|SCH-U550|SCH-U620|SCH-U640|SCH-U650|SCH-U660|SCH-U700|SCH-U740|SCH-U750|SCH-U810|SCH-U820|SCH-U900|SCH-U940|SCH-U960|SCS-26UC|SGH-A107|SGH-A117|SGH-A127|SGH-A137|SGH-A157|SGH-A167|SGH-A177|SGH-A187|SGH-A197|SGH-A227|SGH-A237|SGH-A257|SGH-A437|SGH-A517|SGH-A597|SGH-A637|SGH-A657|SGH-A667|SGH-A687|SGH-A697|SGH-A707|SGH-A717|SGH-A727|SGH-A737|SGH-A747|SGH-A767|SGH-A777|SGH-A797|SGH-A817|SGH-A827|SGH-A837|SGH-A847|SGH-A867|SGH-A877|SGH-A887|SGH-A897|SGH-A927|SGH-B100|SGH-B130|SGH-B200|SGH-B220|SGH-C100|SGH-C110|SGH-C120|SGH-C130|SGH-C140|SGH-C160|SGH-C170|SGH-C180|SGH-C200|SGH-C207|SGH-C210|SGH-C225|SGH-C230|SGH-C417|SGH-C450|SGH-D307|SGH-D347|SGH-D357|SGH-D407|SGH-D415|SGH-D780|SGH-D807|SGH-D980|SGH-E105|SGH-E200|SGH-E315|SGH-E316|SGH-E317|SGH-E335|SGH-E590|SGH-E635|SGH-E715|SGH-E890|SGH-F300|SGH-F480|SGH-I200|SGH-I300|SGH-I320|SGH-I550|SGH-I577|SGH-I600|SGH-I607|SGH-I617|SGH-I627|SGH-I637|SGH-I677|SGH-I700|SGH-I717|SGH-I727|SGH-i747M|SGH-I777|SGH-I780|SGH-I827|SGH-I847|SGH-I857|SGH-I896|SGH-I897|SGH-I900|SGH-I907|SGH-I917|SGH-I927|SGH-I937|SGH-I997|SGH-J150|SGH-J200|SGH-L170|SGH-L700|SGH-M110|SGH-M150|SGH-M200|SGH-N105|SGH-N500|SGH-N600|SGH-N620|SGH-N625|SGH-N700|SGH-N710|SGH-P107|SGH-P207|SGH-P300|SGH-P310|SGH-P520|SGH-P735|SGH-P777|SGH-Q105|SGH-R210|SGH-R220|SGH-R225|SGH-S105|SGH-S307|SGH-T109|SGH-T119|SGH-T139|SGH-T209|SGH-T219|SGH-T229|SGH-T239|SGH-T249|SGH-T259|SGH-T309|SGH-T319|SGH-T329|SGH-T339|SGH-T349|SGH-T359|SGH-T369|SGH-T379|SGH-T409|SGH-T429|SGH-T439|SGH-T459|SGH-T469|SGH-T479|SGH-T499|SGH-T509|SGH-T519|SGH-T539|SGH-T559|SGH-T589|SGH-T609|SGH-T619|SGH-T629|SGH-T639|SGH-T659|SGH-T669|SGH-T679|SGH-T709|SGH-T719|SGH-T729|SGH-T739|SGH-T746|SGH-T749|SGH-T759|SGH-T769|SGH-T809|SGH-T819|SGH-T839|SGH-T919|SGH-T929|SGH-T939|SGH-T959|SGH-T989|SGH-U100|SGH-U200|SGH-U800|SGH-V205|SGH-V206|SGH-X100|SGH-X105|SGH-X120|SGH-X140|SGH-X426|SGH-X427|SGH-X475|SGH-X495|SGH-X497|SGH-X507|SGH-X600|SGH-X610|SGH-X620|SGH-X630|SGH-X700|SGH-X820|SGH-X890|SGH-Z130|SGH-Z150|SGH-Z170|SGH-ZX10|SGH-ZX20|SHW-M110|SPH-A120|SPH-A400|SPH-A420|SPH-A460|SPH-A500|SPH-A560|SPH-A600|SPH-A620|SPH-A660|SPH-A700|SPH-A740|SPH-A760|SPH-A790|SPH-A800|SPH-A820|SPH-A840|SPH-A880|SPH-A900|SPH-A940|SPH-A960|SPH-D600|SPH-D700|SPH-D710|SPH-D720|SPH-I300|SPH-I325|SPH-I330|SPH-I350|SPH-I500|SPH-I600|SPH-I700|SPH-L700|SPH-M100|SPH-M220|SPH-M240|SPH-M300|SPH-M305|SPH-M320|SPH-M330|SPH-M350|SPH-M360|SPH-M370|SPH-M380|SPH-M510|SPH-M540|SPH-M550|SPH-M560|SPH-M570|SPH-M580|SPH-M610|SPH-M620|SPH-M630|SPH-M800|SPH-M810|SPH-M850|SPH-M900|SPH-M910|SPH-M920|SPH-M930|SPH-N100|SPH-N200|SPH-N240|SPH-N300|SPH-N400|SPH-Z400|SWC-E100|SCH-i909|GT-N7100|GT-N7105|SCH-I535', - 'LG' => '\bLG\b;|(LG|LG-)?(C800|C900|E400|E610|E900|E-900|F160|F180K|F180L|F180S|730|855|L160|LS840|LS970|LU6200|MS690|MS695|MS770|MS840|MS870|MS910|P500|P700|P705|VM696|AS680|AS695|AX840|C729|E970|GS505|272|C395|E739BK|E960|L55C|L75C|LS696|LS860|P769BK|P350|P870|UN272|US730|VS840|VS950|LN272|LN510|LS670|LS855|LW690|MN270|MN510|P509|P769|P930|UN200|UN270|UN510|UN610|US670|US740|US760|UX265|UX840|VN271|VN530|VS660|VS700|VS740|VS750|VS910|VS920|VS930|VX9200|VX11000|AX840A|LW770|P506|P925|P999)', - 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h', - 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile', - // @ref: http://www.micromaxinfo.com/mobiles/smartphones - // Added because the codes might conflict with Acer Tablets. - 'Micromax' => 'Micromax.*\b(A210|A92|A88|A72|A111|A110Q|A115|A116|A110|A90S|A26|A51|A35|A54|A25|A27|A89|A68|A65|A57|A90)\b', - 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ; @todo - complete the regex. - 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;) - // @ref: http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH) - // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android. - 'Pantech' => 'PANTECH|IM-A850S|IM-A840S|IM-A830L|IM-A830K|IM-A830S|IM-A820L|IM-A810K|IM-A810S|IM-A800S|IM-T100K|IM-A725L|IM-A780L|IM-A775C|IM-A770K|IM-A760S|IM-A750K|IM-A740S|IM-A730S|IM-A720L|IM-A710K|IM-A690L|IM-A690S|IM-A650S|IM-A630K|IM-A600S|VEGA PTL21|PT003|P8010|ADR910L|P6030|P6020|P9070|P4100|P9060|P5000|CDM8992|TXT8045|ADR8995|IS11PT|P2030|P6010|P8000|PT002|IS06|CDM8999|P9050|PT001|TXT8040|P2020|P9020|P2000|P7040|P7000|C790', - // @ref: http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones. - 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250', - // Added simvalley mobile just for fun. They have some interesting devices. - // @ref: http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html - 'SimValley' => '\b(SP-80|XT-930|SX-340|XT-930|SX-310|SP-360|SP60|SPT-800|SP-120|SPT-800|SP-140|SPX-5|SPX-8|SP-100|SPX-8|SPX-12)\b', - // @Tapatalk is a mobile app; @ref: http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039 - 'GenericPhone' => 'Tapatalk|PDA;|SAGEM|mmp|pocket|psp|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|wap|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser|LG-P500' - ); - - /** - * List of tablet devices. - * - * @var array - */ - protected $tabletDevices = array( - 'iPad' => 'iPad|iPad.*Mobile', // @todo: check for mobile friendly emails topic. - 'NexusTablet' => '^.*Android.*Nexus(((?:(?!Mobile))|(?:(\s(7|10).+))).)*$', - 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P1000|GT-P1003|GT-P1010|GT-P3105|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3108|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P7501|GT-N5100|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-I9205|GT-P5200|GT-P5210|SM-T311|SM-T310|SM-T210|SM-T211|SM-P900', - // @reference: http://www.labnol.org/software/kindle-user-agent-string/20378/ - 'Kindle' => 'Kindle|Silk.*Accelerated|Android.*\b(KFTT|KFOTE)\b', - // Only the Surface tablets with Windows RT are considered mobile. - // @ref: http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx - 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;', - // @note: watch out for PadFone, see #132 - 'AsusTablet' => 'Transformer|TF101|^.*PadFone((?!Mobile).)*$|ME301T|ME371MG', - 'BlackBerryTablet' => 'PlayBook|RIM Tablet', - 'HTCtablet' => 'HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200', - 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617', - 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|LogicPD Zoom2', - // @ref: http://www.acer.ro/ac/ro/RO/content/drivers - // @ref: http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer) - // @note: Can conflict with Micromax phones codes. - 'AcerTablet' => 'Android.*; \b(A100|A101|A110|A200|A210|A211|A500|A501|A510|A511|A700|A701|W500|W500P|W501|W501P|W510|W511|W700|G100|G100W|B1-A71)\b', - // @ref: http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/ - // @ref: http://us.toshiba.com/tablets/tablet-finder - // @ref: http://www.toshiba.co.jp/regza/tablet/ - 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO', - // @ref: http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html - 'LGTablet' => '\bL-06C|LG-V900|LG-V909\b', - 'FujitsuTablet' => 'Android.*\b(F-01D|F-05E|F-10D|M532|Q572)\b', - // Prestigio Tablets http://www.prestigio.com/support - 'PrestigioTablet' => 'PMP3170B|PMP3270B|PMP3470B|PMP7170B|PMP3370B|PMP3570C|PMP5870C|PMP3670B|PMP5570C|PMP5770D|PMP3970B|PMP3870C|PMP5580C|PMP5880D|PMP5780D|PMP5588C|PMP7280C|PMP7280|PMP7880D|PMP5597D|PMP5597|PMP7100D|PER3464|PER3274|PER3574|PER3884|PER5274|PER5474|PMP5097CPRO|PMP5097|PMP7380D', - // @ref: http://support.lenovo.com/en_GB/downloads/default.page?# - 'LenovoTablet' => 'IdeaTab|S2110|S6000|K3011|A3000|A1000|A2107|A2109|A1107', - 'YarvikTablet' => 'Android.*(TAB210|TAB211|TAB224|TAB250|TAB260|TAB264|TAB310|TAB360|TAB364|TAB410|TAB411|TAB420|TAB424|TAB450|TAB460|TAB461|TAB464|TAB465|TAB467|TAB468)', - 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB', - 'ArnovaTablet' => 'AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT', - // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/ - 'IRUTablet' => 'M702pro', - 'MegafonTablet' => 'MegaFon V9|ZTE V9', - // @ref: http://www.allview.ro/produse/droseries/lista-tablete-pc/ - 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)', - // @reference: http://wiki.archosfans.com/index.php?title=Main_Page - 'ArchosTablet' => 'Android.*ARCHOS|\b101G9\b|\b80G9\b', - // @reference: http://en.wikipedia.org/wiki/NOVO7 - 'AinolTablet' => 'NOVO7|Novo7Aurora|Novo7Basic|NOVO7PALADIN', - // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER - // @ref: Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser - // @ref: http://www.sony.jp/support/tablet/ - 'SonyTablet' => 'Sony.*Tablet|Xperia Tablet|Sony Tablet S|SO-03E|SGPT12|SGPT121|SGPT122|SGPT123|SGPT111|SGPT112|SGPT113|SGPT211|SGPT213|SGP311|SGP312|SGP321|EBRD1101|EBRD1102|EBRD1201', - // @ref: db + http://www.cube-tablet.com/buy-products.html - 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT', - // @ref: http://www.cobyusa.com/?p=pcat&pcat_id=3001 - 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010', - // @ref: http://www.match.net.cn/products.asp - 'MIDTablet' => 'M9701|M9000|M9100|M806|M1052|M806|T703|MID701|MID713|MID710|MID727|MID760|MID830|MID728|MID933|MID125|MID810|MID732|MID120|MID930|MID800|MID731|MID900|MID100|MID820|MID735|MID980|MID130|MID833|MID737|MID960|MID135|MID860|MID736|MID140|MID930|MID835|MID733', - // @ref: http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets) - // @ref: http://www.imp3.net/14/show.php?itemid=20454 - 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)', - // @ref: http://www.rock-chips.com/index.php?do=prod&pid=2 - 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A', - // @ref: http://www.telstra.com.au/home-phone/thub-2/ - 'TelstraTablet' => 'T-Hub2', - // @ref: http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/ - 'FlyTablet' => 'IQ310|Fly Vision', - // @ref: http://www.bqreaders.com/gb/tablets-prices-sale.html - 'bqTablet' => 'bq.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant)', - // @ref: http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290 - // @ref: http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets) - 'HuaweiTablet' => 'MediaPad|IDEOS S7|S7-201c|S7-202u|S7-101|S7-103|S7-104|S7-105|S7-106|S7-201|S7-Slim', - // Nec or Medias Tab - 'NecTablet' => '\bN-06D|\bN-08D', - // Pantech Tablets: http://www.pantechusa.com/phones/ - 'PantechTablet' => 'Pantech.*P4100', - // Broncho Tablets: http://www.broncho.cn/ (hard to find) - 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)', - // @ref: http://versusuk.com/support.html - 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b', - // @ref: http://www.zync.in/index.php/our-products/tablet-phablets - 'ZyncTablet' => 'z1000|Z99 2G|z99|z930|z999|z990|z909|Z919|z900', - // @ref: http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/ - 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA', - // @ref: https://www.nabitablet.com/ - 'NabiTablet' => 'Android.*\bNabi', - 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build', - // French Danew Tablets http://www.danew.com/produits-tablette.php - 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b', - // Texet Tablets and Readers http://www.texet.ru/tablet/ - 'TexetTablet' => 'NaviPad|TB-772A|TM-7045|TM-7055|TM-9750|TM-7016|TM-7024|TM-7026|TM-7041|TM-7043|TM-7047|TM-8041|TM-9741|TM-9747|TM-9748|TM-9751|TM-7022|TM-7021|TM-7020|TM-7011|TM-7010|TM-7023|TM-7025|TM-7037W|TM-7038W|TM-7027W|TM-9720|TM-9725|TM-9737W|TM-1020|TM-9738W|TM-9740|TM-9743W|TB-807A|TB-771A|TB-727A|TB-725A|TB-719A|TB-823A|TB-805A|TB-723A|TB-715A|TB-707A|TB-705A|TB-709A|TB-711A|TB-890HD|TB-880HD|TB-790HD|TB-780HD|TB-770HD|TB-721HD|TB-710HD|TB-434HD|TB-860HD|TB-840HD|TB-760HD|TB-750HD|TB-740HD|TB-730HD|TB-722HD|TB-720HD|TB-700HD|TB-500HD|TB-470HD|TB-431HD|TB-430HD|TB-506|TB-504|TB-446|TB-436|TB-416|TB-146SE|TB-126SE', - // @note: Avoid detecting 'PLAYSTATION 3' as mobile. - 'PlaystationTablet' => 'Playstation.*(Portable|Vita)', - // @ref: http://www.galapad.net/product.html - 'GalapadTablet' => 'Android.*\bG1\b', - // @ref: http://www.micromaxinfo.com/tablet/funbook - 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b', - // http://www.karbonnmobiles.com/products_tablet.php - 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b', - // @ref: http://www.gloryunion.cn/products.asp - // @ref: http://www.allwinnertech.com/en/apply/mobile.html - // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions. - 'GUTablet' => 'TX-A1301|TX-M9002|Q702', // A12R|D75A|D77|D79|R83|A95|A106C|R15|A75|A76|D71|D72|R71|R73|R77|D82|R85|D92|A97|D92|R91|A10F|A77F|W71F|A78F|W78F|W81F|A97F|W91F|W97F|R16G|C72|C73E|K72|K73|R96G - 'GenericTablet' => 'Android.*\b97D\b|Tablet(?!.*PC)|ViewPad7|BNTV250A|MID-WCDMA|LogicPD Zoom2|\bA7EB\b|CatNova8|A1_07|CT704|CT1002|\bM721\b|hp-tablet|rk30sdk', - ); - - /** - * List of mobile Operating Systems. - * - * @var array - */ - protected $operatingSystems = array( - 'AndroidOS' => 'Android', - 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os', - 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino', - 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b', - // @reference: http://en.wikipedia.org/wiki/Windows_Mobile - 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;', - // @reference: http://en.wikipedia.org/wiki/Windows_Phone - // http://wifeng.cn/?r=blog&a=view&id=106 - // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx - 'WindowsPhoneOS' => 'Windows Phone OS|XBLWP7|ZuneWP7', - 'iOS' => '\biPhone.*Mobile|\biPod|\biPad', - // http://en.wikipedia.org/wiki/MeeGo - // @todo: research MeeGo in UAs - 'MeeGoOS' => 'MeeGo', - // http://en.wikipedia.org/wiki/Maemo - // @todo: research Maemo in UAs - 'MaemoOS' => 'Maemo', - 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135 - 'webOS' => 'webOS|hpwOS', - 'badaOS' => '\bBada\b', - 'BREWOS' => 'BREW', - ); - - /** - * List of mobile User Agents. - * - * @var array - */ - protected $userAgents = array( - // @reference: https://developers.google.com/chrome/mobile/docs/user-agent - 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?', - 'Dolfin' => '\bDolfin\b', - 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+', - 'Skyfire' => 'Skyfire', - 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+ - 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile', - 'Bolt' => 'bolt', - 'TeaShark' => 'teashark', - 'Blazer' => 'Blazer', - // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3 - 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile', - // @ref: http://en.wikipedia.org/wiki/Midori_(web_browser) - //'Midori' => 'midori', - 'Tizen' => 'Tizen', - 'UCBrowser' => 'UC.*Browser|UCWEB', - // @ref: https://github.com/serbanghita/Mobile-Detect/issues/7 - 'DiigoBrowser' => 'DiigoBrowser', - // http://www.puffinbrowser.com/index.php - 'Puffin' => 'Puffin', - // @ref: http://mercury-browser.com/index.html - 'Mercury' => '\bMercury\b', - // @reference: http://en.wikipedia.org/wiki/Minimo - // http://en.wikipedia.org/wiki/Vision_Mobile_Browser - 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision' - ); - - /** - * Utilities. - * - * @var array - */ - protected $utilities = array( - // Experimental. When a mobile device wants to switch to 'Desktop Mode'. - // @ref: http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/ - // @ref: https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011 - 'DesktopMode' => 'WPDesktop', - 'TV' => 'SonyDTV|HbbTV', // experimental - 'WebKit' => '(webkit)[ /]([\w.]+)', - 'Bot' => 'Googlebot|DoCoMo|YandexBot|bingbot|ia_archiver|AhrefsBot|Ezooms|GSLFbot|WBSearchBot|Twitterbot|TweetmemeBot|Twikle|PaperLiBot|Wotbox|UnwindFetchor|facebookexternalhit', - 'MobileBot' => 'Googlebot-Mobile|DoCoMo|YahooSeeker/M1A1-R2D2', - 'Watch' => 'SM-V700', - ); - - /** - * The individual segments that could exist in a User-Agent string. VER refers to the regular - * expression defined in the constant self::VER. - * - * @var array - */ - protected $properties = array( - - // Build - 'Mobile' => 'Mobile/[VER]', - 'Build' => 'Build/[VER]', - 'Version' => 'Version/[VER]', - 'VendorID' => 'VendorID/[VER]', - - // Devices - 'iPad' => 'iPad.*CPU[a-z ]+[VER]', - 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]', - 'iPod' => 'iPod.*CPU[a-z ]+[VER]', - //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'), - 'Kindle' => 'Kindle/[VER]', - - // Browser - 'Chrome' => array('Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'), - 'Dolfin' => 'Dolfin/[VER]', - // @reference: https://developer.mozilla.org/en-US/docs/User_Agent_Strings_Reference - 'Firefox' => 'Firefox/[VER]', - 'Fennec' => 'Fennec/[VER]', - // @reference: http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx - 'IE' => array('IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];'), - // http://en.wikipedia.org/wiki/NetFront - 'NetFront' => 'NetFront/[VER]', - 'NokiaBrowser' => 'NokiaBrowser/[VER]', - 'Opera' => array( ' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]' ), - 'Opera Mini' => 'Opera Mini/[VER]', - 'Opera Mobi' => 'Version/[VER]', - 'UC Browser' => 'UC Browser[VER]', - // @note: Safari 7534.48.3 is actually Version 5.1. - // @note: On BlackBerry the Version is overwriten by the OS. - 'Safari' => array( 'Version/[VER]', 'Safari/[VER]' ), - 'Skyfire' => 'Skyfire/[VER]', - 'Tizen' => 'Tizen/[VER]', - 'Webkit' => 'webkit[ /][VER]', - - // Engine - 'Gecko' => 'Gecko/[VER]', - 'Trident' => 'Trident/[VER]', - 'Presto' => 'Presto/[VER]', - - // OS - 'iOS' => ' \bOS\b [VER] ', - 'Android' => 'Android [VER]', - 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'), - 'BREW' => 'BREW [VER]', - 'Java' => 'Java/[VER]', - // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx - // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases - 'Windows Phone OS' => array( 'Windows Phone OS [VER]', 'Windows Phone [VER]'), - 'Windows Phone' => 'Windows Phone [VER]', - 'Windows CE' => 'Windows CE/[VER]', - // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd - 'Windows NT' => 'Windows NT [VER]', - 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'), - 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'), - ); - - /** - * Construct an instance of this class. - * - * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored. - * If left empty, will use the global _SERVER['HTTP_*'] vars instead. - * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT - * from the $headers array instead. - */ - public function __construct( - array $headers = null, - $userAgent = null - ){ - $this->setHttpHeaders($headers); - $this->setUserAgent($userAgent); - - $this->setMobileDetectionRules(); - $this->setMobileDetectionRulesExtended(); - } - - /** - * Get the current script version. - * This is useful for the demo.php file, - * so people can check on what version they are testing - * for mobile devices. - * - * @return string The version number in "X.Y.Z" format. - */ - public function getScriptVersion() - { - return $this->scriptVersion; - } - - /** - * Set the HTTP Headers. Must be PHP-flavored. - * - * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract - * the headers. The default null is left for backwards compatibilty. - */ - public function setHttpHeaders($httpHeaders = null) - { - //use global _SERVER if $httpHeaders aren't defined - if (!is_array($httpHeaders) || !count($httpHeaders)) { - $httpHeaders = $_SERVER; - } - - //Only save HTTP headers. In PHP land, that means only _SERVER vars that - //start with HTTP_. - foreach ($httpHeaders as $key => $value) { - if (substr($key,0,5) == 'HTTP_') { - $this->httpHeaders[$key] = $value; - } - } - } - - /** - * Retrieves the HTTP headers. - * - * @return array - */ - public function getHttpHeaders() - { - return $this->httpHeaders; - } - - /** - * Retrieves a particular header. If it doesn't exist, no exception/error is caused. - * Simply null is returned. - * - * @param string $header The name of the header to retrieve. Can be HTTP compliant such as - * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the - * all-caps, HTTP_ prefixed, underscore seperated awesomeness. - * - * @return string|null The value of the header. - */ - public function getHttpHeader($header) - { - //are we using PHP-flavored headers? - if (strpos($header, '_') === false) { - $header = str_replace('-', '_', $header); - $header = strtoupper($header); - } - - //test the alternate, too - $altHeader = 'HTTP_' . $header; - - //Test both the regular and the HTTP_ prefix - if (isset($this->httpHeaders[$header])) { - return $this->httpHeaders[$header]; - } elseif (isset($this->httpHeaders[$altHeader])) { - return $this->httpHeaders[$altHeader]; - } - } - - /** - * Set the User-Agent to be used. - * - * @param string $userAgent The user agent string to set. - */ - public function setUserAgent($userAgent = null) - { - if (!empty($userAgent)) { - $this->userAgent = $userAgent; - } else { - $this->userAgent = $this->getHttpHeader('User-Agent'); - - if (empty($this->userAgent)) { - $this->userAgent = $this->getHttpHeader('X-Device-User-Agent'); - } - - //Header can occur on devices using Opera Mini (can expose the real device type). - //Let's concatenate it (we need this extra info in the regexes). - if ($operaMiniUa = $this->getHttpHeader('X-OperaMini-Phone-UA')) { - $this->userAgent .= ' ' . $operaMiniUa; - } - } - } - - /** - * Retrieve the User-Agent. - * - * @return string|null The user agent if it's set. - */ - public function getUserAgent() - { - return $this->userAgent; - } - - /** - * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or - * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set. - * - * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default - * parameter is null which will default to self::DETECTION_TYPE_MOBILE. - */ - public function setDetectionType($type = null) - { - if ($type === null) { - $type = self::DETECTION_TYPE_MOBILE; - } - - if ($type != self::DETECTION_TYPE_MOBILE && $type != self::DETECTION_TYPE_EXTENDED) { - return; - } - - $this->detectionType = $type; - } - - /** - * Retrieve the list of known phone devices. - * - * @return array List of phone devices. - */ - public function getPhoneDevices() - { - return $this->phoneDevices; - } - - /** - * Retrieve the list of known tablet devices. - * - * @return array List of tablet devices. - */ - public function getTabletDevices() - { - return $this->tabletDevices; - } - - /** - * Method sets the mobile detection rules. This method is used for the magic methods $detect->is*(). - */ - public function setMobileDetectionRules() - { - // Merge all rules together. - $this->mobileDetectionRules = array_merge( - $this->phoneDevices, - $this->tabletDevices, - $this->operatingSystems, - $this->userAgents - ); - - } - - /** - * Method sets the mobile detection rules + utilities. - * The reason this is separate is because utilities rules - * don't necessary imply mobile. This method is used inside - * the new $detect->is('stuff') method. - */ - public function setMobileDetectionRulesExtended() - { - // Merge all rules together. - $this->mobileDetectionRulesExtended = array_merge( - $this->phoneDevices, - $this->tabletDevices, - $this->operatingSystems, - $this->userAgents, - $this->utilities - ); - - } - - /** - * Retrieve the current set of rules. - * - * @return array - */ - public function getRules() - { - if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) { - return $this->mobileDetectionRulesExtended; - } else { - return $this->mobileDetectionRules; - } - } - - /** - * Check the HTTP headers for signs of mobile. - * This is the fastest mobile check possible; it's used - * inside isMobile() method. - * - * @return bool - */ - public function checkHttpHeadersForMobile() - { - return( - isset($this->httpHeaders['HTTP_ACCEPT']) && - (strpos($this->httpHeaders['HTTP_ACCEPT'], 'application/x-obml2d') !== false || // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/ - strpos($this->httpHeaders['HTTP_ACCEPT'], 'application/vnd.rim.html') !== false || // BlackBerry devices. - strpos($this->httpHeaders['HTTP_ACCEPT'], 'text/vnd.wap.wml') !== false || - strpos($this->httpHeaders['HTTP_ACCEPT'], 'application/vnd.wap.xhtml+xml') !== false) || - isset($this->httpHeaders['HTTP_X_WAP_PROFILE']) || // @todo: validate - isset($this->httpHeaders['HTTP_X_WAP_CLIENTID']) || - isset($this->httpHeaders['HTTP_WAP_CONNECTION']) || - isset($this->httpHeaders['HTTP_PROFILE']) || - isset($this->httpHeaders['HTTP_X_OPERAMINI_PHONE_UA']) || // Reported by Nokia devices (eg. C3) - isset($this->httpHeaders['HTTP_X_NOKIA_IPADDRESS']) || - isset($this->httpHeaders['HTTP_X_NOKIA_GATEWAY_ID']) || - isset($this->httpHeaders['HTTP_X_ORANGE_ID']) || - isset($this->httpHeaders['HTTP_X_VODAFONE_3GPDPCONTEXT']) || - isset($this->httpHeaders['HTTP_X_HUAWEI_USERID']) || - isset($this->httpHeaders['HTTP_UA_OS']) || // Reported by Windows Smartphones. - isset($this->httpHeaders['HTTP_X_MOBILE_GATEWAY']) || // Reported by Verizon, Vodafone proxy system. - isset($this->httpHeaders['HTTP_X_ATT_DEVICEID']) || // Seen this on HTC Sensation. @ref: SensationXE_Beats_Z715e - //HTTP_X_NETWORK_TYPE = WIFI - ( isset($this->httpHeaders['HTTP_UA_CPU']) && - $this->httpHeaders['HTTP_UA_CPU'] == 'ARM' // Seen this on a HTC. - ) - ); - } - - /** - * Magic overloading method. - * - * @method boolean is[...]() - * @param string $name - * @param array $arguments - * @return mixed - * @throws \BadMethodCallException when the method doesn't exist and doesn't start with 'is' - */ - public function __call($name, $arguments) - { - //make sure the name starts with 'is', otherwise - if (substr($name, 0, 2) != 'is') { - throw new \BadMethodCallException("No such method exists: $name"); - } - - $this->setDetectionType(self::DETECTION_TYPE_MOBILE); - - $key = substr($name, 2); - - return $this->matchUAAgainstKey($key); - } - - /** - * Find a detection rule that matches the current User-agent. - * - * @param null $userAgent deprecated - * @return boolean - */ - private function matchDetectionRulesAgainstUA($userAgent = null) - { - // Begin general search. - foreach ($this->getRules() as $_regex) { - if (empty($_regex)) { - continue; - } - if ($this->match($_regex, $userAgent)) { - return true; - } - } - - return false; - } - - /** - * Search for a certain key in the rules array. - * If the key is found the try to match the corresponding - * regex agains the User-Agent. - * - * @param string $key - * @param null $userAgent deprecated - * @return mixed - */ - private function matchUAAgainstKey($key, $userAgent = null) - { - // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc. - $key = strtolower($key); - - //change the keys to lower case - $_rules = array_change_key_case($this->getRules()); - - if (array_key_exists($key, $_rules)) { - if (empty($_rules[$key])) { - return null; - } - - return $this->match($_rules[$key], $userAgent); - } - - return false; - } - - /** - * Check if the device is mobile. - * Returns true if any type of mobile device detected, including special ones - * @param null $userAgent deprecated - * @param null $httpHeaders deprecated - * @return bool - */ - public function isMobile($userAgent = null, $httpHeaders = null) - { - - if ($httpHeaders) { - $this->setHttpHeaders($httpHeaders); - } - - if ($userAgent) { - $this->setUserAgent($userAgent); - } - - $this->setDetectionType(self::DETECTION_TYPE_MOBILE); - - if ($this->checkHttpHeadersForMobile()) { - return true; - } else { - return $this->matchDetectionRulesAgainstUA(); - } - - } - - /** - * Check if the device is a tablet. - * Return true if any type of tablet device is detected. - * - * @param string $userAgent deprecated - * @param array $httpHeaders deprecated - * @return bool - */ - public function isTablet($userAgent = null, $httpHeaders = null) - { - $this->setDetectionType(self::DETECTION_TYPE_MOBILE); - - foreach ($this->tabletDevices as $_regex) { - if ($this->match($_regex, $userAgent)) { - return true; - } - } - - return false; - } - - /** - * This method checks for a certain property in the - * userAgent. - * @todo: The httpHeaders part is not yet used. - * - * @param $key - * @param string $userAgent deprecated - * @param string $httpHeaders deprecated - * @return bool|int|null - */ - public function is($key, $userAgent = null, $httpHeaders = null) - { - // Set the UA and HTTP headers only if needed (eg. batch mode). - if ($httpHeaders) { - $this->setHttpHeaders($httpHeaders); - } - - if ($userAgent) { - $this->setUserAgent($userAgent); - } - - $this->setDetectionType(self::DETECTION_TYPE_EXTENDED); - - return $this->matchUAAgainstKey($key); - } - - /** - * Retrieve the list of mobile operating systems. - * - * @return array The list of mobile operating systems. - */ - public function getOperatingSystems() - { - return $this->operatingSystems; - } - - /** - * Some detection rules are relative (not standard), - * because of the diversity of devices, vendors and - * their conventions in representing the User-Agent or - * the HTTP headers. - * - * This method will be used to check custom regexes against - * the User-Agent string. - * - * @param $regex - * @param string $userAgent - * @return bool - * - * @todo: search in the HTTP headers too. - */ - public function match($regex, $userAgent = null) - { - // Escape the special character which is the delimiter. - $regex = str_replace('/', '\/', $regex); - - return (bool) preg_match('/'.$regex.'/is', (!empty($userAgent) ? $userAgent : $this->userAgent)); - } - - /** - * Get the properties array. - * - * @return array - */ - public function getProperties() - { - return $this->properties; - } - - /** - * Prepare the version number. - * - * @todo Remove the error supression from str_replace() call. - * - * @param string $ver The string version, like "2.6.21.2152"; - * - * @return float - */ - public function prepareVersionNo($ver) - { - $ver = str_replace(array('_', ' ', '/'), array('.', '.', '.'), $ver); - $arrVer = explode('.', $ver, 2); - - if (isset($arrVer[1])) { - $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions. - } - - return (float) implode('.', $arrVer); - } - - /** - * Check the version of the given property in the User-Agent. - * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31) - * - * @param string $propertyName - * @param string $type - * @return mixed $version - */ - public function version($propertyName, $type = 'text') - { - if (empty($propertyName)) { - return false; - } - - if (!in_array($type, array('text', 'float'))) { - $type = 'text'; - } - - $properties = $this->getProperties(); - - // Check if the property exists in the properties array. - if (array_key_exists($propertyName, $properties)) { - - // Prepare the pattern to be matched. - // Make sure we always deal with an array (string is converted). - $properties[$propertyName] = (array) $properties[$propertyName]; - - foreach ($properties[$propertyName] as $propertyMatchString) { - - $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString); - - // Escape the special character which is the delimiter. - $propertyPattern = str_replace('/', '\/', $propertyPattern); - - // Identify and extract the version. - preg_match('/'.$propertyPattern.'/is', $this->userAgent, $match); - - if (!empty($match[1])) { - $version = ( $type == 'float' ? $this->prepareVersionNo($match[1]) : $match[1] ); - - return $version; - } - - } - - } - - return false; - } - - /** - * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants. - * - * @return string One of the self::MOBILE_GRADE_* constants. - */ - public function mobileGrade() - { - $isMobile = $this->isMobile(); - - if ( - // Apple iOS 3.2-5.1 - Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3), iPad 3 (5.1), original iPhone (3.1), iPhone 3 (3.2), 3GS (4.3), 4 (4.3 / 5.0), and 4S (5.1) - $this->version('iPad', 'float')>=4.3 || - $this->version('iPhone', 'float')>=3.1 || - $this->version('iPod', 'float')>=3.1 || - - // Android 2.1-2.3 - Tested on the HTC Incredible (2.2), original Droid (2.2), HTC Aria (2.1), Google Nexus S (2.3). Functional on 1.5 & 1.6 but performance may be sluggish, tested on Google G1 (1.5) - // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM - // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices - // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7 - ( $this->version('Android', 'float')>2.1 && $this->is('Webkit') ) || - - // Windows Phone 7-7.5 - Tested on the HTC Surround (7.0) HTC Trophy (7.5), LG-E900 (7.5), Nokia Lumia 800 - $this->version('Windows Phone OS', 'float')>=7.0 || - - // Blackberry 7 - Tested on BlackBerry® Torch 9810 - // Blackberry 6.0 - Tested on the Torch 9800 and Style 9670 - $this->is('BlackBerry') && $this->version('BlackBerry', 'float')>=6.0 || - // Blackberry Playbook (1.0-2.0) - Tested on PlayBook - $this->match('Playbook.*Tablet') || - - // Palm WebOS (1.4-2.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0) - ( $this->version('webOS', 'float')>=1.4 && $this->match('Palm|Pre|Pixi') ) || - // Palm WebOS 3.0 - Tested on HP TouchPad - $this->match('hp.*TouchPad') || - - // Firefox Mobile (12 Beta) - Tested on Android 2.3 device - ( $this->is('Firefox') && $this->version('Firefox', 'float')>=12 ) || - - // Chrome for Android - Tested on Android 4.0, 4.1 device - ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', 'float')>=4.0 ) || - - // Skyfire 4.1 - Tested on Android 2.3 device - ( $this->is('Skyfire') && $this->version('Skyfire', 'float')>=4.1 && $this->is('AndroidOS') && $this->version('Android', 'float')>=2.3 ) || - - // Opera Mobile 11.5-12: Tested on Android 2.3 - ( $this->is('Opera') && $this->version('Opera Mobi', 'float')>11 && $this->is('AndroidOS') ) || - - // Meego 1.2 - Tested on Nokia 950 and N9 - $this->is('MeeGoOS') || - - // Tizen (pre-release) - Tested on early hardware - $this->is('Tizen') || - - // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser - // @todo: more tests here! - $this->is('Dolfin') && $this->version('Bada', 'float')>=2.0 || - - // UC Browser - Tested on Android 2.3 device - ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', 'float')>=2.3 ) || - - // Kindle 3 and Fire - Tested on the built-in WebKit browser for each - ( $this->match('Kindle Fire') || - $this->is('Kindle') && $this->version('Kindle', 'float')>=3.0 ) || - - // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet - $this->is('AndroidOS') && $this->is('NookTablet') || - - // Chrome Desktop 11-21 - Tested on OS X 10.7 and Windows 7 - $this->version('Chrome', 'float')>=11 && !$isMobile || - - // Safari Desktop 4-5 - Tested on OS X 10.7 and Windows 7 - $this->version('Safari', 'float')>=5.0 && !$isMobile || - - // Firefox Desktop 4-13 - Tested on OS X 10.7 and Windows 7 - $this->version('Firefox', 'float')>=4.0 && !$isMobile || - - // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7 - $this->version('MSIE', 'float')>=7.0 && !$isMobile || - - // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7 - // @reference: http://my.opera.com/community/openweb/idopera/ - $this->version('Opera', 'float')>=10 && !$isMobile - - - ){ - return self::MOBILE_GRADE_A; - } - - if ( - $this->version('iPad', 'float')<4.3 || - $this->version('iPhone', 'float')<3.1 || - $this->version('iPod', 'float')<3.1 || - - // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770 - $this->is('Blackberry') && $this->version('BlackBerry', 'float')>=5 && $this->version('BlackBerry', 'float')<6 || - - //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3 - ( $this->version('Opera Mini', 'float')>=5.0 && $this->version('Opera Mini', 'float')<=6.5 && - ($this->version('Android', 'float')>=2.3 || $this->is('iOS')) ) || - - // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1) - $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') || - - // @todo: report this (tested on Nokia N71) - $this->version('Opera Mobi', 'float')>=11 && $this->is('SymbianOS') - ){ - return self::MOBILE_GRADE_B; - } - - if ( - // Blackberry 4.x - Tested on the Curve 8330 - $this->version('BlackBerry', 'float')<5.0 || - // Windows Mobile - Tested on the HTC Leo (WinMo 5.2) - $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', 'float')<=5.2 - - - ){ - return self::MOBILE_GRADE_C; - } - - //All older smartphone platforms and featurephones - Any device that doesn't support media queries - //will receive the basic, C grade experience. - return self::MOBILE_GRADE_C; - } -} diff --git a/Config/Update/3.0.sql b/Config/Update/3.0.sql new file mode 100644 index 0000000..7a8ed7a --- /dev/null +++ b/Config/Update/3.0.sql @@ -0,0 +1,171 @@ +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- paypal_customer +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_customer` +( + `id` INTEGER NOT NULL, + `paypal_user_id` INTEGER NOT NULL, + `credit_card_id` VARCHAR(40), + `name` VARCHAR(255), + `given_name` VARCHAR(255), + `family_name` VARCHAR(255), + `middle_name` VARCHAR(255), + `picture` VARCHAR(255), + `email_verified` TINYINT, + `gender` VARCHAR(255), + `birthday` VARCHAR(255), + `zoneinfo` VARCHAR(255), + `locale` VARCHAR(255), + `language` VARCHAR(255), + `verified` TINYINT, + `phone_number` VARCHAR(255), + `verified_account` VARCHAR(255), + `account_type` VARCHAR(255), + `age_range` VARCHAR(255), + `payer_id` VARCHAR(255), + `postal_code` VARCHAR(255), + `locality` VARCHAR(255), + `region` VARCHAR(255), + `country` VARCHAR(255), + `street_address` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`,`paypal_user_id`), + CONSTRAINT `fk_paypal_payer_customer_id` + FOREIGN KEY (`id`) + REFERENCES `customer` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_cart +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_cart` +( + `id` INTEGER NOT NULL, + `credit_card_id` VARCHAR(40), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + CONSTRAINT `fk_paypal_cart_cart_id` + FOREIGN KEY (`id`) + REFERENCES `cart` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_order +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_order` +( + `id` INTEGER NOT NULL, + `payment_id` VARCHAR(50), + `agreement_id` VARCHAR(255), + `credit_card_id` VARCHAR(40), + `state` VARCHAR(20), + `amount` DECIMAL(16,6) DEFAULT 0.000000, + `description` LONGTEXT, + `payer_id` VARCHAR(255), + `token` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + PRIMARY KEY (`id`), + CONSTRAINT `fk_paypal_order_order_id` + FOREIGN KEY (`id`) + REFERENCES `order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_plan +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_plan` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `paypal_order_id` INTEGER NOT NULL, + `plan_id` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_plan_paypal_order_id` (`paypal_order_id`), + CONSTRAINT `fk_paypal_plan_paypal_order_id` + FOREIGN KEY (`paypal_order_id`) + REFERENCES `paypal_order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_log +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_log` +( + `id` INTEGER NOT NULL, + `customer_id` INTEGER, + `order_id` INTEGER, + `channel` VARCHAR(255), + `level` INTEGER, + `message` LONGTEXT, + `time` INTEGER, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_log_customer_id` (`customer_id`), + INDEX `FI_paypal_log_order_id` (`order_id`), + CONSTRAINT `fk_paypal_log_customer_id` + FOREIGN KEY (`customer_id`) + REFERENCES `customer` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE, + CONSTRAINT `fk_paypal_log_order_id` + FOREIGN KEY (`order_id`) + REFERENCES `order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_order_version +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_order_version` +( + `id` INTEGER NOT NULL, + `payment_id` VARCHAR(50), + `agreement_id` VARCHAR(255), + `credit_card_id` VARCHAR(40), + `state` VARCHAR(20), + `amount` DECIMAL(16,6) DEFAULT 0.000000, + `description` LONGTEXT, + `payer_id` VARCHAR(255), + `token` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0 NOT NULL, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + `id_version` INTEGER DEFAULT 0, + PRIMARY KEY (`id`,`version`), + CONSTRAINT `paypal_order_version_FK_1` + FOREIGN KEY (`id`) + REFERENCES `paypal_order` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/Config/config.xml b/Config/config.xml old mode 100755 new mode 100644 index abffb4b..46b08c6 --- a/Config/config.xml +++ b/Config/config.xml @@ -4,20 +4,142 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd"> + + + + + + + -
+ + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Config/create.sql b/Config/create.sql new file mode 100644 index 0000000..c3df234 --- /dev/null +++ b/Config/create.sql @@ -0,0 +1,234 @@ +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- paypal_customer +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_customer` +( + `id` INTEGER NOT NULL, + `paypal_user_id` INTEGER NOT NULL, + `credit_card_id` VARCHAR(40), + `name` VARCHAR(255), + `given_name` VARCHAR(255), + `family_name` VARCHAR(255), + `middle_name` VARCHAR(255), + `picture` VARCHAR(255), + `email_verified` TINYINT, + `gender` VARCHAR(255), + `birthday` VARCHAR(255), + `zoneinfo` VARCHAR(255), + `locale` VARCHAR(255), + `language` VARCHAR(255), + `verified` TINYINT, + `phone_number` VARCHAR(255), + `verified_account` VARCHAR(255), + `account_type` VARCHAR(255), + `age_range` VARCHAR(255), + `payer_id` VARCHAR(255), + `postal_code` VARCHAR(255), + `locality` VARCHAR(255), + `region` VARCHAR(255), + `country` VARCHAR(255), + `street_address` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`,`paypal_user_id`), + CONSTRAINT `fk_paypal_payer_customer_id` + FOREIGN KEY (`id`) + REFERENCES `customer` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_planified_payment +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_planified_payment` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `frequency` VARCHAR(255) NOT NULL, + `frequency_interval` INTEGER NOT NULL, + `cycle` INTEGER NOT NULL, + `min_amount` DECIMAL(16,6) DEFAULT 0.000000, + `max_amount` DECIMAL(16,6) DEFAULT 0.000000, + `position` INTEGER DEFAULT 0 NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_cart +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_cart` +( + `id` INTEGER NOT NULL, + `credit_card_id` VARCHAR(40), + `planified_payment_id` INTEGER, + `express_payment_id` VARCHAR(255), + `express_payer_id` VARCHAR(255), + `express_token` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_cart_planified_payment_id` (`planified_payment_id`), + CONSTRAINT `fk_paypal_cart_cart_id` + FOREIGN KEY (`id`) + REFERENCES `cart` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE, + CONSTRAINT `fk_paypal_cart_planified_payment_id` + FOREIGN KEY (`planified_payment_id`) + REFERENCES `paypal_planified_payment` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_order +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_order` +( + `id` INTEGER NOT NULL, + `payment_id` VARCHAR(50), + `agreement_id` VARCHAR(255), + `credit_card_id` VARCHAR(40), + `state` VARCHAR(20), + `amount` DECIMAL(16,6) DEFAULT 0.000000, + `description` LONGTEXT, + `payer_id` VARCHAR(255), + `token` VARCHAR(255), + `planified_title` VARCHAR(255) NOT NULL, + `planified_description` LONGTEXT, + `planified_frequency` VARCHAR(255) NOT NULL, + `planified_frequency_interval` INTEGER NOT NULL, + `planified_cycle` INTEGER NOT NULL, + `planified_actual_cycle` INTEGER DEFAULT 0 NOT NULL, + `planified_min_amount` DECIMAL(16,6) DEFAULT 0.000000, + `planified_max_amount` DECIMAL(16,6) DEFAULT 0.000000, + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + PRIMARY KEY (`id`), + CONSTRAINT `fk_paypal_order_order_id` + FOREIGN KEY (`id`) + REFERENCES `order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_plan +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_plan` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `paypal_order_id` INTEGER NOT NULL, + `plan_id` VARCHAR(255), + `state` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_plan_paypal_order_id` (`paypal_order_id`), + CONSTRAINT `fk_paypal_plan_paypal_order_id` + FOREIGN KEY (`paypal_order_id`) + REFERENCES `paypal_order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_log +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_log` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `customer_id` INTEGER, + `order_id` INTEGER, + `hook` VARCHAR(255), + `channel` VARCHAR(255), + `level` INTEGER, + `message` LONGTEXT, + `time` INTEGER, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_log_customer_id` (`customer_id`), + INDEX `FI_paypal_log_order_id` (`order_id`), + CONSTRAINT `fk_paypal_log_customer_id` + FOREIGN KEY (`customer_id`) + REFERENCES `customer` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE, + CONSTRAINT `fk_paypal_log_order_id` + FOREIGN KEY (`order_id`) + REFERENCES `order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_planified_payment_i18n +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_planified_payment_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255) NOT NULL, + `description` LONGTEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `paypal_planified_payment_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `paypal_planified_payment` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_order_version +-- --------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `paypal_order_version` +( + `id` INTEGER NOT NULL, + `payment_id` VARCHAR(50), + `agreement_id` VARCHAR(255), + `credit_card_id` VARCHAR(40), + `state` VARCHAR(20), + `amount` DECIMAL(16,6) DEFAULT 0.000000, + `description` LONGTEXT, + `payer_id` VARCHAR(255), + `token` VARCHAR(255), + `planified_title` VARCHAR(255) NOT NULL, + `planified_description` LONGTEXT, + `planified_frequency` VARCHAR(255) NOT NULL, + `planified_frequency_interval` INTEGER NOT NULL, + `planified_cycle` INTEGER NOT NULL, + `planified_actual_cycle` INTEGER DEFAULT 0 NOT NULL, + `planified_min_amount` DECIMAL(16,6) DEFAULT 0.000000, + `planified_max_amount` DECIMAL(16,6) DEFAULT 0.000000, + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0 NOT NULL, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + `id_version` INTEGER DEFAULT 0, + PRIMARY KEY (`id`,`version`), + CONSTRAINT `paypal_order_version_FK_1` + FOREIGN KEY (`id`) + REFERENCES `paypal_order` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/Config/module.xml b/Config/module.xml old mode 100755 new mode 100644 index b33f56c..713e5eb --- a/Config/module.xml +++ b/Config/module.xml @@ -1,24 +1,41 @@ - Paypal\Paypal + xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd"> + PayPal\PayPal - Pay with Paypal + PayPal + - Paiement avec Paypal + PayPal + + en_US fr_FR - 2.1.2 - - Thelia - info@thelia.net - - payment - 2.1.0 - prod + 3.0 + + + gbarral + gbarral@openstudio.fr + + + classic + + 2.2.0 + other diff --git a/Config/routing.xml b/Config/routing.xml old mode 100755 new mode 100644 index 6442fa2..a99e80c --- a/Config/routing.xml +++ b/Config/routing.xml @@ -1,22 +1,108 @@ + + - - Paypal\Controller\ConfigurationController::configure - + + PayPal:Configuration:configure + + + + PayPal:Configuration:log + + + + PayPal:Configuration:configure + + + + PayPal:PayPalPlanifiedPayment:default + + + + PayPal:PayPalPlanifiedPayment:create + + + + PayPal:PayPalPlanifiedPayment:delete + + + + PayPal:PayPalPlanifiedPayment:update + \d+ + + + + PayPal:PayPalPlanifiedPayment:processUpdate + \d+ + + + + PayPal:PayPalResponse:cancel + \d+ + + + + PayPal:PayPalResponse:ok + \d+ + - - Paypal\Controller\ConfigurationController::downloadLog + + PayPal:PayPalResponse:expressCheckout - - Paypal\Controller\PaypalResponse::cancel - \d+ + + PayPal:PayPalResponse:expressCheckoutOk + \d+ - - Paypal\Controller\PaypalResponse::ok - \d+ + + PayPal:PayPalResponse:expressCheckoutKo + \d+ + + + PayPal:PayPalResponse:invoiceExpressCheckout + + + + PayPal:PayPalResponse:invoiceExpressCheckoutOk + \d+ + + + + PayPal:PayPalResponse:invoiceExpressCheckoutKo + \d+ + + + + + PayPal:PayPalResponse:executeExpressCheckout + order-delivery + + + + PayPal:PayPalResponse:loginOk + + + + PayPal:PayPalResponse:agreementOk + \d+ + + + + PayPal:PayPalResponse:agreementKo + \d+ + + + + PayPal:PayPalResponse:ipn + \d+ + + + + PayPal:PayPalWebHook:all + + diff --git a/Config/schema.xml b/Config/schema.xml new file mode 100644 index 0000000..8f9c920 --- /dev/null +++ b/Config/schema.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + +
diff --git a/Config/sqldb.map b/Config/sqldb.map new file mode 100644 index 0000000..63a93ba --- /dev/null +++ b/Config/sqldb.map @@ -0,0 +1,2 @@ +# Sqlfile -> Database map +thelia.sql=thelia diff --git a/Config/thelia.sql b/Config/thelia.sql new file mode 100644 index 0000000..1946eab --- /dev/null +++ b/Config/thelia.sql @@ -0,0 +1,251 @@ + +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- paypal_customer +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_customer`; + +CREATE TABLE `paypal_customer` +( + `id` INTEGER NOT NULL, + `paypal_user_id` INTEGER NOT NULL, + `credit_card_id` VARCHAR(40), + `name` VARCHAR(255), + `given_name` VARCHAR(255), + `family_name` VARCHAR(255), + `middle_name` VARCHAR(255), + `picture` VARCHAR(255), + `email_verified` TINYINT, + `gender` VARCHAR(255), + `birthday` VARCHAR(255), + `zoneinfo` VARCHAR(255), + `locale` VARCHAR(255), + `language` VARCHAR(255), + `verified` TINYINT, + `phone_number` VARCHAR(255), + `verified_account` VARCHAR(255), + `account_type` VARCHAR(255), + `age_range` VARCHAR(255), + `payer_id` VARCHAR(255), + `postal_code` VARCHAR(255), + `locality` VARCHAR(255), + `region` VARCHAR(255), + `country` VARCHAR(255), + `street_address` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`,`paypal_user_id`), + CONSTRAINT `fk_paypal_payer_customer_id` + FOREIGN KEY (`id`) + REFERENCES `customer` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_planified_payment +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_planified_payment`; + +CREATE TABLE `paypal_planified_payment` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `frequency` VARCHAR(255) NOT NULL, + `frequency_interval` INTEGER NOT NULL, + `cycle` INTEGER NOT NULL, + `min_amount` DECIMAL(16,6) DEFAULT 0.000000, + `max_amount` DECIMAL(16,6) DEFAULT 0.000000, + `position` INTEGER DEFAULT 0 NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_cart +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_cart`; + +CREATE TABLE `paypal_cart` +( + `id` INTEGER NOT NULL, + `credit_card_id` VARCHAR(40), + `planified_payment_id` INTEGER, + `express_payment_id` VARCHAR(255), + `express_payer_id` VARCHAR(255), + `express_token` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_cart_planified_payment_id` (`planified_payment_id`), + CONSTRAINT `fk_paypal_cart_cart_id` + FOREIGN KEY (`id`) + REFERENCES `cart` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE, + CONSTRAINT `fk_paypal_cart_planified_payment_id` + FOREIGN KEY (`planified_payment_id`) + REFERENCES `paypal_planified_payment` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_order +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_order`; + +CREATE TABLE `paypal_order` +( + `id` INTEGER NOT NULL, + `payment_id` VARCHAR(50), + `agreement_id` VARCHAR(255), + `credit_card_id` VARCHAR(40), + `state` VARCHAR(20), + `amount` DECIMAL(16,6) DEFAULT 0.000000, + `description` LONGTEXT, + `payer_id` VARCHAR(255), + `token` VARCHAR(255), + `planified_title` VARCHAR(255) NOT NULL, + `planified_description` LONGTEXT, + `planified_frequency` VARCHAR(255) NOT NULL, + `planified_frequency_interval` INTEGER NOT NULL, + `planified_cycle` INTEGER NOT NULL, + `planified_actual_cycle` INTEGER DEFAULT 0 NOT NULL, + `planified_min_amount` DECIMAL(16,6) DEFAULT 0.000000, + `planified_max_amount` DECIMAL(16,6) DEFAULT 0.000000, + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + PRIMARY KEY (`id`), + CONSTRAINT `fk_paypal_order_order_id` + FOREIGN KEY (`id`) + REFERENCES `order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_plan +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_plan`; + +CREATE TABLE `paypal_plan` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `paypal_order_id` INTEGER NOT NULL, + `plan_id` VARCHAR(255), + `state` VARCHAR(255), + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_plan_paypal_order_id` (`paypal_order_id`), + CONSTRAINT `fk_paypal_plan_paypal_order_id` + FOREIGN KEY (`paypal_order_id`) + REFERENCES `paypal_order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_log +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_log`; + +CREATE TABLE `paypal_log` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `customer_id` INTEGER, + `order_id` INTEGER, + `hook` VARCHAR(255), + `channel` VARCHAR(255), + `level` INTEGER, + `message` LONGTEXT, + `time` INTEGER, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `FI_paypal_log_customer_id` (`customer_id`), + INDEX `FI_paypal_log_order_id` (`order_id`), + CONSTRAINT `fk_paypal_log_customer_id` + FOREIGN KEY (`customer_id`) + REFERENCES `customer` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE, + CONSTRAINT `fk_paypal_log_order_id` + FOREIGN KEY (`order_id`) + REFERENCES `order` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_planified_payment_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_planified_payment_i18n`; + +CREATE TABLE `paypal_planified_payment_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255) NOT NULL, + `description` LONGTEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `paypal_planified_payment_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `paypal_planified_payment` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- paypal_order_version +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `paypal_order_version`; + +CREATE TABLE `paypal_order_version` +( + `id` INTEGER NOT NULL, + `payment_id` VARCHAR(50), + `agreement_id` VARCHAR(255), + `credit_card_id` VARCHAR(40), + `state` VARCHAR(20), + `amount` DECIMAL(16,6) DEFAULT 0.000000, + `description` LONGTEXT, + `payer_id` VARCHAR(255), + `token` VARCHAR(255), + `planified_title` VARCHAR(255) NOT NULL, + `planified_description` LONGTEXT, + `planified_frequency` VARCHAR(255) NOT NULL, + `planified_frequency_interval` INTEGER NOT NULL, + `planified_cycle` INTEGER NOT NULL, + `planified_actual_cycle` INTEGER DEFAULT 0 NOT NULL, + `planified_min_amount` DECIMAL(16,6) DEFAULT 0.000000, + `planified_max_amount` DECIMAL(16,6) DEFAULT 0.000000, + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0 NOT NULL, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + `id_version` INTEGER DEFAULT 0, + PRIMARY KEY (`id`,`version`), + CONSTRAINT `paypal_order_version_FK_1` + FOREIGN KEY (`id`) + REFERENCES `paypal_order` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/Controller/ConfigurationController.php b/Controller/ConfigurationController.php old mode 100644 new mode 100755 index 45279ff..83ae12f --- a/Controller/ConfigurationController.php +++ b/Controller/ConfigurationController.php @@ -21,12 +21,10 @@ /* */ /*************************************************************************************/ -namespace Paypal\Controller; +namespace PayPal\Controller; -use Paypal\Classes\API\PaypalApiLogManager; -use Paypal\Paypal; +use PayPal\PayPal; use Thelia\Controller\Admin\BaseAdminController; -use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Thelia; @@ -37,39 +35,22 @@ /** * Class ConfigurePaypal * @package Paypal\Controller - * @author Thelia */ class ConfigurationController extends BaseAdminController { - - public function downloadLog() - { - if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'atos', AccessManager::UPDATE)) { - return $response; - } - - $logFilePath = PaypalApiLogManager::getLogFilePath(); - - return Response::create( - @file_get_contents($logFilePath), - 200, - array( - 'Content-type' => "text/plain", - 'Content-Disposition' => sprintf('Attachment;filename=paypal-log.txt') - ) - ); - } - /* * Checks paypal.configure || paypal.configure.sandbox form and save config into json file */ - public function configure() + /** + * @return mixed|\Symfony\Component\HttpFoundation\Response|\Thelia\Core\HttpFoundation\Response + */ + public function configureAction() { if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'Paypal', AccessManager::UPDATE)) { return $response; } - $configurationForm = $this->createForm('paypal.form.configure'); + $configurationForm = $this->createForm('paypal_form_configure'); try { $form = $this->validateForm($configurationForm, "POST"); @@ -107,7 +88,7 @@ public function configure() } $this->setupFormErrorContext( - $this->getTranslator()->trans("Paypal configuration", [], Paypal::DOMAIN), + $this->getTranslator()->trans("Paypal configuration", [], PayPal::DOMAIN_NAME), $error_msg, $configurationForm, $ex @@ -115,9 +96,17 @@ public function configure() // Before 2.2, the errored form is not stored in session if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { - return $this->render('module-configure', [ 'module_code' => 'Paypal' ]); + return $this->render('module-configure', [ 'module_code' => PayPal::getModuleCode()]); } else { - return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Paypal')); + return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/PayPal')); } } + + /** + * @return \Thelia\Core\HttpFoundation\Response + */ + public function logAction() + { + return $this->render('paypal/paypal-log'); + } } diff --git a/Controller/PayPalPlanifiedPaymentController.php b/Controller/PayPalPlanifiedPaymentController.php new file mode 100644 index 0000000..c84ce1d --- /dev/null +++ b/Controller/PayPalPlanifiedPaymentController.php @@ -0,0 +1,315 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Controller; + +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalPlanifiedPaymentEvent; +use PayPal\Form\PayPalFormFields; +use PayPal\Form\PayPalPlanifiedPaymentCreateForm; +use PayPal\Form\PayPalPlanifiedPaymentUpdateForm; +use PayPal\Model\PaypalPlanifiedPayment; +use PayPal\Model\PaypalPlanifiedPaymentQuery; +use PayPal\PayPal; +use Symfony\Component\HttpFoundation\Response; +use Thelia\Controller\Admin\AbstractCrudController; +use Thelia\Core\Security\AccessManager; + +/** + * Class PayPalPlanifiedPaymentController + * @package PayPal\Controller + */ +class PayPalPlanifiedPaymentController extends AbstractCrudController +{ + /** @var string */ + protected $currentRouter = PayPal::ROUTER; + + /** + * PayPalPlanifiedPaymentController constructor. + */ + public function __construct() + { + parent::__construct( + 'team', + 'id', + 'order', + 'paypal.back.planified.payment', + PayPalEvents::PAYPAL_PLANIFIED_PAYMENT_CREATE, + PayPalEvents::PAYPAL_PLANIFIED_PAYMENT_UPDATE, + PayPalEvents::PAYPAL_PLANIFIED_PAYMENT_DELETE + ); + } + + /** + * The default action is displaying the list. + * + * @return Response + */ + public function defaultAction() + { + // Check current user authorization + if (null !== $response = $this->checkAuth($this->resourceCode, $this->getModuleCode(), AccessManager::VIEW)) { + return $response; + } + + return $this->renderList(); + } + + /** + * Return the creation form for this object + * @return PayPalPlanifiedPaymentCreateForm + */ + protected function getCreationForm() + { + return $this->createForm(PayPalPlanifiedPaymentCreateForm::FORM_NAME); + } + + /** + * Return the update form for this object + * @return PayPalPlanifiedPaymentUpdateForm + */ + protected function getUpdateForm() + { + return $this->createForm(PayPalPlanifiedPaymentUpdateForm::FORM_NAME); + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param PaypalPlanifiedPayment $object + * @return PayPalPlanifiedPaymentUpdateForm + */ + protected function hydrateObjectForm($object) + { + /** @var \Thelia\Model\Lang $lang */ + $lang = $this->getRequest()->getSession()->get('thelia.current.lang'); + $object->getTranslation($lang->getLocale()); + + $data = [ + PayPalFormFields::FIELD_PP_ID => $object->getId(), + PayPalFormFields::FIELD_PP_TITLE => $object->getTitle(), + PayPalFormFields::FIELD_PP_DESCRIPTION => $object->getDescription(), + PayPalFormFields::FIELD_PP_FREQUENCY => $object->getFrequency(), + PayPalFormFields::FIELD_PP_FREQUENCY_INTERVAL => $object->getFrequencyInterval(), + PayPalFormFields::FIELD_PP_CYCLE => $object->getCycle(), + PayPalFormFields::FIELD_PP_MIN_AMOUNT => $object->getMinAmount(), + PayPalFormFields::FIELD_PP_MAX_AMOUNT => $object->getMaxAmount(), + PayPalFormFields::FIELD_PP_POSITION => $object->getPosition() + ]; + + return $this->createForm(PayPalPlanifiedPaymentUpdateForm::FORM_NAME, 'form', $data); + } + + /** + * Creates the creation event with the provided form data + * + * @param mixed $formData + * @return PayPalPlanifiedPaymentEvent + */ + protected function getCreationEvent($formData) + { + $planifiedPayment = new PaypalPlanifiedPayment(); + + $planifiedPayment = $this->fillObjectWithDataForm($planifiedPayment, $formData); + + $planifiedPaymentEvent = new PayPalPlanifiedPaymentEvent($planifiedPayment); + + return $planifiedPaymentEvent; + } + + /** + * Creates the update event with the provided form data + * + * @param mixed $formData + * @return PayPalPlanifiedPaymentEvent + */ + protected function getUpdateEvent($formData) + { + if (null === $planifiedPayment = PaypalPlanifiedPaymentQuery::create()->findOneById($formData[PayPalFormFields::FIELD_PP_ID])) { + throw new \InvalidArgumentException( + $this->getTranslator()->trans( + 'Invalid planified payment id : %id', + ['%id' => $formData[PayPalFormFields::FIELD_PP_ID]], + PayPal::DOMAIN_NAME + ) + ); + } + + $planifiedPayment = $this->fillObjectWithDataForm($planifiedPayment, $formData); + + $planifiedPaymentEvent = new PayPalPlanifiedPaymentEvent($planifiedPayment); + + return $planifiedPaymentEvent; + } + + /** + * @param PaypalPlanifiedPayment $planifiedPayment + * @param $formData + * @return PaypalPlanifiedPayment + */ + protected function fillObjectWithDataForm(PaypalPlanifiedPayment $planifiedPayment, $formData) + { + $planifiedPayment + ->setFrequency($formData[PayPalFormFields::FIELD_PP_FREQUENCY]) + ->setFrequencyInterval($formData[PayPalFormFields::FIELD_PP_FREQUENCY_INTERVAL]) + ->setCycle($formData[PayPalFormFields::FIELD_PP_CYCLE]) + ->setMinAmount($formData[PayPalFormFields::FIELD_PP_MIN_AMOUNT]) + ->setMaxAmount($formData[PayPalFormFields::FIELD_PP_MAX_AMOUNT]) + ->setLocale($formData[PayPalFormFields::FIELD_PP_LOCALE]) + ->setTitle($formData[PayPalFormFields::FIELD_PP_TITLE]) + ->setDescription($formData[PayPalFormFields::FIELD_PP_DESCRIPTION]) + ; + + return $planifiedPayment; + } + + /** + * Creates the delete event with the provided form data + * @return PayPalPlanifiedPaymentEvent + */ + protected function getDeleteEvent() + { + return new PayPalPlanifiedPaymentEvent( + $this->getExistingObject() + ); + } + + /** + * Return true if the event contains the object, e.g. the action has updated the object in the event. + * + * @param PayPalPlanifiedPaymentEvent $event + * @return bool + */ + protected function eventContainsObject($event) + { + return $event->getPayPalPlanifiedPayment() ? true : false; + } + + /** + * Get the created object from an event. + * @param PayPalPlanifiedPaymentEvent $event + * @return PaypalPlanifiedPayment + */ + protected function getObjectFromEvent($event) + { + return $event->getPayPalPlanifiedPayment(); + } + + /** + * Load an existing object from the database + * @return PaypalPlanifiedPayment + */ + protected function getExistingObject() + { + if (null === $planifiedPayment = PaypalPlanifiedPaymentQuery::create()->findOneById((int)$this->getRequest()->get('planifiedPaymentId'))) { + throw new \InvalidArgumentException( + $this->getTranslator()->trans('Invalid planified payment id : %id', + ['%id' => (int)$this->getRequest()->get('planifiedPaymentId')], PayPal::DOMAIN_NAME) + ); + } + + return $planifiedPayment; + } + + /** + * Returns the object label form the object event (name, title, etc.) + * + * @param PaypalPlanifiedPayment $object + * @return string + */ + protected function getObjectLabel($object) + { + return $object->getTitle(); + } + + /** + * Returns the object ID from the object + * + * @param PaypalPlanifiedPayment $object + * @return int + */ + protected function getObjectId($object) + { + return $object->getId(); + } + + /** + * Render the main list template + * + * @param mixed $currentOrder , if any, null otherwise. + * @return Response + */ + protected function renderListTemplate($currentOrder) + { + $this->getListOrderFromSession('planified_payment', 'order', 'manual'); + + return $this->render( + 'paypal/planified-payment', + [ + 'order' => $currentOrder, + 'selected_menu' => 'planified' + ] + ); + } + + /** + * Render the edition template + * @return Response + */ + protected function renderEditionTemplate() + { + return $this->render('paypal/planified-payment-edit', $this->getEditionArguments()); + } + + /** + * Must return a RedirectResponse instance + * @return Response + */ + protected function redirectToEditionTemplate() + { + return $this->generateRedirectFromRoute( + 'paypal.admin.configuration.planified.update', + [], + $this->getEditionArguments() + ); + } + + /** + * Must return a RedirectResponse instance + * @return Response + */ + protected function redirectToListTemplate() + { + return $this->generateRedirectFromRoute('paypal.admin.configuration.planified'); + } + + /** + * @return array + */ + private function getEditionArguments() + { + return [ + 'planifiedPaymentId' => (int)$this->getRequest()->get('planifiedPaymentId') + ]; + } +} diff --git a/Controller/PayPalResponseController.php b/Controller/PayPalResponseController.php new file mode 100644 index 0000000..ca5589a --- /dev/null +++ b/Controller/PayPalResponseController.php @@ -0,0 +1,936 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Controller; + +use Front\Controller\OrderController; +use Monolog\Logger; +use PayPal\Api\Details; +use PayPal\Api\PayerInfo; +use PayPal\Event\PayPalCartEvent; +use PayPal\Event\PayPalCustomerEvent; +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalOrderEvent; +use PayPal\Exception\PayPalConnectionException; +use PayPal\Model\PaypalCart; +use PayPal\Model\PaypalCartQuery; +use PayPal\Model\PaypalCustomer; +use PayPal\Model\PaypalCustomerQuery; +use PayPal\Model\PaypalOrder; +use PayPal\Model\PaypalOrderQuery; +use PayPal\PayPal; +use PayPal\Service\PayPalAgreementService; +use PayPal\Service\PayPalCustomerService; +use PayPal\Service\PayPalLoggerService; +use PayPal\Service\PayPalPaymentService; +use Propel\Runtime\Propel; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\Routing\Router; +use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; +use Thelia\Core\Event\Customer\CustomerLoginEvent; +use Thelia\Core\Event\Delivery\DeliveryPostageEvent; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Core\Event\Order\OrderManualEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Translation\Translator; +use Thelia\Model\AddressQuery; +use Thelia\Model\CartQuery; +use Thelia\Model\Country; +use Thelia\Model\CountryQuery; +use Thelia\Model\CustomerQuery; +use Thelia\Model\CustomerTitleQuery; +use Thelia\Model\ModuleQuery; +use Thelia\Model\Order; +use Thelia\Model\OrderQuery; +use Thelia\Model\OrderStatusQuery; +use Thelia\Module\Exception\DeliveryException; +use Thelia\Tools\URL; + + +/** + * Class PayPalResponseController + * @package PayPal\Controller + */ +class PayPalResponseController extends OrderController +{ + /** + * @param $orderId + */ + public function cancelAction($orderId) + { + if (null !== $order = OrderQuery::create()->findOneById($orderId)) { + $event = new OrderEvent($order); + $event->setStatus(OrderStatusQuery::getCancelledStatus()->getId()); + $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + } + } + + /** + * @param $orderId + * @return RedirectResponse + */ + public function okAction($orderId) + { + $con = Propel::getConnection(); + $con->beginTransaction(); + + try { + $payerId = $this->getRequest()->query->get('PayerID'); + $token = $this->getRequest()->query->get('token'); + $payPalOrder = PaypalOrderQuery::create()->findOneById($orderId); + + if (null !== $payPalOrder && null !== $payerId) { + + $response = $this->executePayment($payPalOrder, $payPalOrder->getPaymentId(), $payerId, $token); + } else { + $con->rollBack(); + $message = Translator::getInstance()->trans( + 'Method okAction => One of this parameter is invalid : $payerId = %payer_id, $orderId = %order_id', + [ + '%payer_id' => $payerId, + '%order_id' => $orderId + ], + PayPal::DOMAIN_NAME + ); + + PayPalLoggerService::log( + $message, + [ + 'order_id' => $orderId + ], + Logger::CRITICAL + ); + + $response = $this->getPaymentFailurePageUrl($orderId, $message); + } + } catch (PayPalConnectionException $e) { + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [ + 'order_id' => $orderId + ], + Logger::CRITICAL + ); + $response = $this->getPaymentFailurePageUrl($orderId, $e->getMessage()); + } catch (\Exception $e) { + PayPalLoggerService::log( + $e->getMessage(), + [ + 'order_id' => $orderId + ], + Logger::CRITICAL + ); + + $response = $this->getPaymentFailurePageUrl($orderId, $e->getMessage()); + } + + $con->commit(); + return $response; + } + + + /** + * @param string $routeId + * @return RedirectResponse + */ + public function expressCheckoutAction($routeId = 'cart.view', $fromCartView = true) + { + $session = $this->getRequest()->getSession(); + $cart = $session->getSessionCart($this->getDispatcher()); + + if (null !== $cart) { + /** @var PayPalPaymentService $payPalService */ + $payPalService = $this->getContainer()->get(PayPal::PAYPAL_PAYMENT_SERVICE_ID); + + $payment = $payPalService->makePaymentFromCart( + $cart, + null, + false, + $fromCartView + ); + $response = new RedirectResponse($payment->getApprovalLink()); + + return $response; + } + + return $this->getUrlFromRouteId('cart.view'); + } + + public function invoiceExpressCheckoutAction() + { + return $this->expressCheckoutAction('order.invoice', false); + } + + /** + * @param int $cartId + * @return RedirectResponse + * @throws PayPalConnectionException + * @throws \Exception + */ + public function invoiceExpressCheckoutOkAction($cartId) + { + $con = Propel::getConnection(); + $con->beginTransaction(); + + try { + $this->fillCartWithExpressCheckout(); + + $response = $this->executeExpressCheckoutAction(false); + + } catch (PayPalConnectionException $e) { + $con->rollBack(); + + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + $customerId = null; + if (isset($customer)) { + $customerId = $customer->getId(); + } + + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $customerId + ], + Logger::CRITICAL + ); + throw $e; + } catch(\Exception $e) { + $con->rollBack(); + + $customerId = null; + if (isset($customer)) { + $customerId = $customer->getId(); + } + + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $customerId + ], + Logger::CRITICAL + ); + throw $e; + } + + $con->commit(); + return $response; + } + + public function invoiceExpressCheckoutKoAction($cartId) + { + return $this->getUrlFromRouteId('order.invoice'); + } + + /** + * @return RedirectResponse + * @throws PayPalConnectionException + * @throws \Exception + */ + public function expressCheckoutOkAction() + { + $con = Propel::getConnection(); + $con->beginTransaction(); + + try { + $this->fillCartWithExpressCheckout(); + + $response = $this->getUrlFromRouteId('order.delivery'); + + + } catch (PayPalConnectionException $e) { + $con->rollBack(); + + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + $customerId = null; + if (isset($customer)) { + $customerId = $customer->getId(); + } + + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $customerId + ], + Logger::CRITICAL + ); + throw $e; + } catch(\Exception $e) { + $con->rollBack(); + + $customerId = null; + if (isset($customer)) { + $customerId = $customer->getId(); + } + + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $customerId + ], + Logger::CRITICAL + ); + throw $e; + } + + $con->commit(); + return $response; + } + + /** + * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response + */ + public function executeExpressCheckoutAction($fromCartView = true) + { + if (null === $responseParent = parent::deliver()) { + + if ($fromCartView) { + return $responseParent; + } + } + + $con = Propel::getConnection(); + $con->beginTransaction(); + + try { + $session = $this->getRequest()->getSession(); + $cart = $session->getSessionCart($this->getDispatcher()); + + if (null === $payPalCart = PaypalCartQuery::create()->findOneById($cart->getId())) { + $con->rollBack(); + return $responseParent; + } + + if (null === $payPalCart->getExpressPaymentId() || null === $payPalCart->getExpressPayerId() || null === $payPalCart->getExpressToken()) { + $con->rollBack(); + return $responseParent; + } + + /** @var PayPalPaymentService $payPalPaymentService */ + $payPalPaymentService = $this->container->get(PayPal::PAYPAL_PAYMENT_SERVICE_ID); + $payment = $payPalPaymentService->getPaymentDetails($payPalCart->getExpressPaymentId()); + + $payerInfo = $payment->getPayer()->getPayerInfo(); + + //Check if invoice adresse already exist + if (null === $payerInfo->getBillingAddress()) { + $line1 = $payerInfo->getShippingAddress()->getLine1(); + $zipCode = $payerInfo->getShippingAddress()->getPostalCode(); + } else { + $line1 = $payerInfo->getBillingAddress()->getLine1(); + $zipCode = $payerInfo->getBillingAddress()->getPostalCode(); + } + + /** @var \Thelia\Model\Address $invoiceAddress */ + if (null === $invoiceAddress = AddressQuery::create() + ->filterByCustomerId($cart->getCustomerId()) + ->filterByIsDefault(0) + ->filterByAddress1($line1) + ->filterByZipcode($zipCode) + ->findOne()) { + + $event = $this->createAddressEvent($payerInfo); + $event->setCustomer($cart->getCustomer()); + + $this->dispatch(TheliaEvents::ADDRESS_CREATE, $event); + $invoiceAddress = $event->getAddress(); + } + + if (null === $payPalCustomer = PaypalCustomerQuery::create()->findOneById($cart->getCustomerId())) { + $payPalCustomer = new PaypalCustomer(); + $payPalCustomer->setId($cart->getCustomerId()); + } + + $payPalCustomer + ->setPaypalUserId($payerInfo->getPayerId()) + ->setName($payerInfo->getFirstName()) + ->setGivenName($payerInfo->getFirstName() . ' ' . $payerInfo->getLastName()) + ->setFamilyName($payerInfo->getLastName()) + ->setMiddleName($payerInfo->getMiddleName()) + ->setBirthday($payerInfo->getBirthDate()) + ->setLocale($this->getRequest()->getSession()->getLang()->getLocale()) + ->setPhoneNumber($payerInfo->getPhone()) + ->setPayerId($payerInfo->getPayerId()) + ->setPostalCode($payerInfo->getShippingAddress()->getPostalCode()) + ->setCountry($payerInfo->getShippingAddress()->getCountryCode()) + ->setStreetAddress($payerInfo->getShippingAddress()->getLine1() . $payerInfo->getShippingAddress()->getLine2()) + ; + + $payPalCustomerEvent = new PayPalCustomerEvent($payPalCustomer); + $this->dispatch(PayPalEvents::PAYPAL_CUSTOMER_UPDATE, $payPalCustomerEvent); + + /** @var \Thelia\Model\Address $deliveryAddress */ + $deliveryAddress = $cart->getCustomer()->getDefaultAddress(); + + /** @var \Thelia\Model\Module $deliveryModule */ + $deliveryModule = ModuleQuery::create()->filterByActivate(1)->findOne(); + /** @var \Thelia\Model\Module $paymentModule */ + $paymentModule = ModuleQuery::create()->findPk(PayPal::getModuleId()); + + /** @var \Thelia\Model\Currency $currency */ + $currency = $cart->getCurrency(); + $lang = $this->getRequest()->getSession()->getLang(); + + $order = new Order(); + $order + ->setCustomerId($cart->getCustomerId()) + ->setCurrencyId($currency->getId()) + ->setCurrencyRate($currency->getRate()) + ->setStatusId(OrderStatusQuery::getNotPaidStatus()->getId()) + ->setLangId($lang->getDefaultLanguage()->getId()) + ->setChoosenDeliveryAddress($deliveryAddress) + ->setChoosenInvoiceAddress($invoiceAddress) + ; + + $orderEvent = new OrderEvent($order); + + /* get postage amount */ + $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container); + $deliveryPostageEvent = new DeliveryPostageEvent($moduleInstance, $cart, $deliveryAddress); + + $this->getDispatcher()->dispatch( + TheliaEvents::MODULE_DELIVERY_GET_POSTAGE, + $deliveryPostageEvent + ); + + if (!$deliveryPostageEvent->isValidModule() || null === $deliveryPostageEvent->getPostage()) { + throw new DeliveryException( + $this->getTranslator()->trans('The delivery module is not valid.', [], PayPal::DOMAIN_NAME) + ); + } + + $postage = $deliveryPostageEvent->getPostage(); + + $orderEvent->setPostage($postage->getAmount()); + $orderEvent->setPostageTax($postage->getAmountTax()); + $orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle()); + $orderEvent->setDeliveryAddress($deliveryAddress->getId()); + $orderEvent->setInvoiceAddress($invoiceAddress->getId()); + $orderEvent->setDeliveryModule($deliveryModule->getId()); + $orderEvent->setPaymentModule($paymentModule->getId()); + + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_INVOICE_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_PAYMENT_MODULE, $orderEvent); + + $orderManualEvent = new OrderManualEvent( + $orderEvent->getOrder(), + $orderEvent->getOrder()->getCurrency(), + $orderEvent->getOrder()->getLang(), + $cart, + $cart->getCustomer() + ); + + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_CREATE_MANUAL, $orderManualEvent); + $order = $orderManualEvent->getPlacedOrder(); + + $payPalOrderEvent = $payPalPaymentService->generatePayPalOrder($order); + $payPalPaymentService->updatePayPalOrder($payPalOrderEvent->getPayPalOrder(), $payment->getState(), $payment->getId()); + + $response = $this->executePayment( + $payPalOrderEvent->getPayPalOrder(), + $payPalCart->getExpressPaymentId(), + $payPalCart->getExpressPayerId(), + $payPalCart->getExpressToken(), + PayPal::PAYPAL_METHOD_EXPRESS_CHECKOUT, + $payPalPaymentService->createDetails( + $order->getPostage(), + $order->getPostageTax(), + $order->getTotalAmount($tax, false) + ) + ); + + $con->commit(); + } catch (PayPalConnectionException $e) { + $con->rollBack(); + + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + $customerId = null; + if (isset($customer)) { + $customerId = $customer->getId(); + } + + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $customerId + ], + Logger::CRITICAL + ); + $response = $responseParent; + } catch(\Exception $e) { + $con->rollBack(); + + $customerId = null; + if (isset($customer)) { + $customerId = $customer->getId(); + } + + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $customerId + ], + Logger::CRITICAL + ); + $response = $responseParent; + } + + $con->commit(); + return $response; + } + + /** + * + */ + public function expressCheckoutKoAction() + { + PayPalLoggerService::log( + Translator::getInstance()->trans('Express Checkout login failed', [], PayPal::DOMAIN_NAME), + [], + Logger::WARNING + ); + return $this->getUrlFromRouteId('cart.view'); + } + + /** + * Method called when a customer log in with PayPal. + * @return RedirectResponse + * @throws \Exception + */ + public function loginOkAction() + { + if (null !== $authorizationCode = $this->getRequest()->query->get('code')) { + + /** @var PayPalCustomerService $payPalCustomerService */ + $payPalCustomerService = $this->container->get(PayPal::PAYPAL_CUSTOMER_SERVICE_ID); + $openIdUserinfo = $payPalCustomerService->getUserInfoWithAuthorizationCode($authorizationCode); + + $payPalCustomer = $payPalCustomerService->getCurrentPayPalCustomer(); + $payPalCustomer + ->setPaypalUserId($openIdUserinfo->getUserId()) + ->setName($openIdUserinfo->getName()) + ->setGivenName($openIdUserinfo->getGivenName()) + ->setFamilyName($openIdUserinfo->getFamilyName()) + ->setMiddleName($openIdUserinfo->getMiddleName()) + ->setPicture($openIdUserinfo->getPicture()) + ->setEmailVerified($openIdUserinfo->getEmailVerified()) + ->setGender($openIdUserinfo->getGender()) + ->setBirthday($openIdUserinfo->getBirthday()) + ->setZoneinfo($openIdUserinfo->getZoneinfo()) + ->setLocale($openIdUserinfo->getLocale()) + ->setLanguage($openIdUserinfo->getLanguage()) + ->setVerified($openIdUserinfo->getVerified()) + ->setPhoneNumber($openIdUserinfo->getPhoneNumber()) + ->setVerifiedAccount($openIdUserinfo->getVerifiedAccount()) + ->setAccountType($openIdUserinfo->getAccountType()) + ->setAgeRange($openIdUserinfo->getAgeRange()) + ->setPayerId($openIdUserinfo->getPayerId()) + ->setPostalCode($openIdUserinfo->getAddress()->getPostalCode()) + ->setLocality($openIdUserinfo->getAddress()->getLocality()) + ->setRegion($openIdUserinfo->getAddress()->getRegion()) + ->setCountry($openIdUserinfo->getAddress()->getCountry()) + ->setStreetAddress($openIdUserinfo->getAddress()->getStreetAddress()) + ; + + $payPalCustomerEvent = new PayPalCustomerEvent($payPalCustomer); + $this->dispatch(PayPalEvents::PAYPAL_CUSTOMER_UPDATE, $payPalCustomerEvent); + + $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($payPalCustomerEvent->getPayPalCustomer()->getCustomer())); + } + + return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getSession()->getReturnToUrl())); + } + + /** + * @param $orderId + * @return RedirectResponse + */ + public function agreementOkAction($orderId) + { + $con = Propel::getConnection(); + $con->beginTransaction(); + + $token = $this->getRequest()->query->get('token'); + $payPalOrder = PaypalOrderQuery::create()->findOneById($orderId); + + if (null !== $payPalOrder && null !== $token) { + + try { + /** @var PayPalAgreementService $payPalAgreementService */ + $payPalAgreementService = $this->container->get(PayPal::PAYPAL_AGREEMENT_SERVICE_ID); + $agreement = $payPalAgreementService->activateBillingAgreementByToken($token); + + $payPalOrder + ->setState($agreement->getState()) + ->setAgreementId($agreement->getId()) + ->setPayerId($agreement->getPayer()->getPayerInfo()->getPayerId()) + ->setToken($token) + ; + $payPalOrderEvent = new PayPalOrderEvent($payPalOrder); + $this->dispatch(PayPalEvents::PAYPAL_ORDER_UPDATE, $payPalOrderEvent); + + $event = new OrderEvent($payPalOrder->getOrder()); + $event->setStatus(OrderStatusQuery::getPaidStatus()->getId()); + $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + + $response = $this->getPaymentSuccessPageUrl($orderId); + PayPalLoggerService::log( + Translator::getInstance()->trans( + 'Order payed with success in PayPal with method : %method', + [ + '%method' => PayPal::PAYPAL_METHOD_PLANIFIED_PAYMENT + ], + PayPal::DOMAIN_NAME + ), + [ + 'order_id' => $payPalOrder->getId(), + 'customer_id' => $payPalOrder->getOrder()->getCustomerId() + ], + Logger::INFO + ); + } catch (PayPalConnectionException $e) { + $con->rollBack(); + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $orderId + ], + Logger::CRITICAL + ); + + $response = $this->getPaymentFailurePageUrl($orderId, $e->getMessage()); + } catch (\Exception $e) { + $con->rollBack(); + PayPalLoggerService::log( + $e->getMessage(), + [ + 'order_id' => $orderId + ], + Logger::CRITICAL + ); + + $response = $this->getPaymentFailurePageUrl($orderId, $e->getMessage()); + } + + } else { + $con->rollBack(); + $message = Translator::getInstance()->trans( + 'Method agreementOkAction => One of this parameter is invalid : $token = %token, $orderId = %order_id', + [ + '%token' => $token, + '%order_id' => $orderId + ], + PayPal::DOMAIN_NAME + ); + + PayPalLoggerService::log( + $message, + [ + 'order_id' => $orderId + ], + Logger::CRITICAL + ); + + $response = $this->getPaymentFailurePageUrl($orderId, $message); + } + + $con->commit(); + return $response; + } + + /** + * @param $orderId + */ + public function ipnAction($orderId) + { + PayPalLoggerService::log('GUIGIT', ['hook' => 'guigit', 'order_id' => $orderId], Logger::DEBUG); + + PayPalLoggerService::log( + print_r($this->getRequest()->request, true), + [ + 'hook' => 'guigit', + 'order_id' => $orderId + ], + Logger::DEBUG + ); + PayPalLoggerService::log( + print_r($this->getRequest()->attributes, true), + [ + 'hook' => 'guigit', + 'order_id' => $orderId + ], + Logger::DEBUG + ); + } + + /** + * Return the order payment success page URL + * + * @param $orderId + * @return RedirectResponse + */ + public function getPaymentSuccessPageUrl($orderId) + { + return $this->getUrlFromRouteId('order.placed', ['order_id' => $orderId]); + } + + /** + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + protected function fillCartWithExpressCheckout() + { + $paymentId = $this->getRequest()->get('paymentId'); + $token = $this->getRequest()->get('token'); + $payerId = $this->getRequest()->get('PayerID'); + $cartId = $this->getRequest()->get('cartId'); + $cart = CartQuery::create()->findOneById($this->getRequest()->get('cartId')); + + if (null === $paymentId || null === $token || null === $payerId || null === $cart) { + PayPalLoggerService::log( + Translator::getInstance()->trans('Express checkout failed in expressCheckoutOkAction() function', [], PayPal::DOMAIN_NAME), + [], + Logger::CRITICAL + ); + } + + PayPalLoggerService::log( + Translator::getInstance()->trans('Express checkout begin with cart %id', ['%id' => $cartId], PayPal::DOMAIN_NAME) + ); + + /** @var PayPalPaymentService $payPalPaymentService */ + $payPalPaymentService = $this->container->get(PayPal::PAYPAL_PAYMENT_SERVICE_ID); + $payment = $payPalPaymentService->getPaymentDetails($paymentId); + + $payerInfo = $payment->getPayer()->getPayerInfo(); + if (null === $customer = CustomerQuery::create()->findOneByEmail($payment->getPayer()->getPayerInfo()->getEmail())) { + + $customerCreateEvent = $this->createEventInstance($payerInfo); + + $this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent); + + $customer = $customerCreateEvent->getCustomer(); + + } + + //Save informations to use them after customer has choosen the delivery method + if (null === $payPalCart = PaypalCartQuery::create()->findOneById($cartId)) { + $payPalCart = new PaypalCart(); + $payPalCart->setId($cartId); + } + + $payPalCart + ->setExpressPaymentId($paymentId) + ->setExpressPayerId($payerId) + ->setExpressToken($token) + ; + $payPalCartEvent = new PayPalCartEvent($payPalCart); + $this->getDispatcher()->dispatch(PayPalEvents::PAYPAL_CART_UPDATE, $payPalCartEvent); + + $cart->setCustomerId($customer->getId())->save(); + $clonedCart = clone $cart; + $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer)); + + //In case of the current customer has changed, re affect the correct cart and customer session + $this->getSecurityContext()->setCustomerUser($customer); + $clonedCart->save(); + $this->getRequest()->getSession()->set("thelia.cart_id", $clonedCart->getId()); + } + + /** + * @param $routeId + * @param array $params + * @return RedirectResponse + */ + protected function getUrlFromRouteId($routeId, $params = []) + { + $frontOfficeRouter = $this->getContainer()->get('router.front'); + + return new RedirectResponse( + URL::getInstance()->absoluteUrl( + $frontOfficeRouter->generate( + $routeId, + $params, + Router::ABSOLUTE_URL + ) + ) + ); + } + + /** + * Redirect the customer to the failure payment page. if $message is null, a generic message is displayed. + * + * @param $orderId + * @param $message + * @return RedirectResponse + */ + public function getPaymentFailurePageUrl($orderId, $message) + { + $frontOfficeRouter = $this->getContainer()->get('router.front'); + + return new RedirectResponse( + URL::getInstance()->absoluteUrl( + $frontOfficeRouter->generate( + "order.failed", + array( + "order_id" => $orderId, + "message" => $message + ), + Router::ABSOLUTE_URL + ) + ) + ); + } + + /** + * @param PaypalOrder $payPalOrder + * @param $paymentId + * @param $payerId + * @param $token + * @param string $method + * @param Details|null $details + * @return RedirectResponse + */ + protected function executePayment(PaypalOrder $payPalOrder, $paymentId, $payerId, $token, $method = PayPal::PAYPAL_METHOD_PAYPAL, Details $details = null) + { + /** @var PayPalPaymentService $payPalService */ + $payPalService = $this->getContainer()->get(PayPal::PAYPAL_PAYMENT_SERVICE_ID); + $payment = $payPalService->executePayment($paymentId, $payerId, $details); + + $payPalOrder + ->setState($payment->getState()) + ->setPayerId($payerId) + ->setToken($token) + ; + $payPalOrderEvent = new PayPalOrderEvent($payPalOrder); + $this->dispatch(PayPalEvents::PAYPAL_ORDER_UPDATE, $payPalOrderEvent); + + $event = new OrderEvent($payPalOrder->getOrder()); + $event->setStatus(OrderStatusQuery::getPaidStatus()->getId()); + $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + + $response = $this->getPaymentSuccessPageUrl($payPalOrder->getId()); + + PayPalLoggerService::log( + Translator::getInstance()->trans( + 'Order payed with success in PayPal with method : %method', + [ + '%method' => $method + ], + PayPal::DOMAIN_NAME + ), + [ + 'order_id' => $payPalOrder->getId(), + 'customer_id' => $payPalOrder->getOrder()->getCustomerId() + ], + Logger::INFO + ); + + + return $response; + } + + /** + * @param PayerInfo $payerInfo + * @return \Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent + */ + protected function createEventInstance(PayerInfo $payerInfo) + { + if (null === $country = CountryQuery::create()->findOneByIsoalpha2($payerInfo->getShippingAddress()->getCountryCode())) { + $country = Country::getDefaultCountry(); + } + + $customerCreateEvent = new CustomerCreateOrUpdateEvent( + CustomerTitleQuery::create()->findOne()->getId(), + $payerInfo->getFirstName(), + $payerInfo->getLastName(), + $payerInfo->getShippingAddress()->getLine1(), + $payerInfo->getShippingAddress()->getLine2(), + null, + $payerInfo->getPhone(), + null, + $payerInfo->getShippingAddress()->getPostalCode(), + $payerInfo->getShippingAddress()->getCity(), + $country->getId(), + $payerInfo->getEmail(), + 'random', + $this->getRequest()->getSession()->getLang()->getId(), + null, + null, + null, + null, + null, + null + ); + + return $customerCreateEvent; + } + + /** + * @param PayerInfo $payerInfo + * @return AddressCreateOrUpdateEvent + */ + protected function createAddressEvent(PayerInfo $payerInfo) + { + if (null !== $payerInfo->getBillingAddress()) { + $countryCode = $payerInfo->getBillingAddress()->getCountryCode(); + $line1 = $payerInfo->getBillingAddress()->getLine1(); + $line2 = $payerInfo->getBillingAddress()->getLine2(); + $zipCode = $payerInfo->getBillingAddress()->getPostalCode(); + $city = $payerInfo->getBillingAddress()->getCity(); + } else { + $countryCode = $payerInfo->getShippingAddress()->getCountryCode(); + $line1 = $payerInfo->getShippingAddress()->getLine1(); + $line2 = $payerInfo->getShippingAddress()->getLine2(); + $zipCode = $payerInfo->getShippingAddress()->getPostalCode(); + $city = $payerInfo->getShippingAddress()->getCity(); + } + + if (null === $country = CountryQuery::create()->findOneByIsoalpha2($countryCode)) { + $country = Country::getDefaultCountry(); + } + + return new AddressCreateOrUpdateEvent( + 'Express checkout PayPal', + CustomerTitleQuery::create()->findOne()->getId(), + $payerInfo->getFirstName(), + $payerInfo->getLastName(), + $line1, + ($line2)?$line2:'', + '', + $zipCode, + $city, + $country->getId(), + $payerInfo->getPhone(), + $payerInfo->getPhone(), + '', + 0, + null + ); + } +} diff --git a/Controller/PayPalWebHookController.php b/Controller/PayPalWebHookController.php new file mode 100644 index 0000000..0ebc216 --- /dev/null +++ b/Controller/PayPalWebHookController.php @@ -0,0 +1,336 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Controller; + +use Monolog\Logger; +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalOrderEvent; +use PayPal\Exception\PayPalConnectionException; +use PayPal\Model\PaypalOrderQuery; +use PayPal\Model\PaypalPlanQuery; +use PayPal\PayPal; +use PayPal\Service\PayPalAgreementService; +use PayPal\Service\PayPalLoggerService; +use Propel\Runtime\Propel; +use Thelia\Controller\Front\BaseFrontController; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Translation\Translator; +use Thelia\Model\OrderStatusQuery; + +/** + * Class PayPalWebHookController + * @package PayPal\Controller + */ +class PayPalWebHookController extends BaseFrontController +{ + const HOOK_BILLING_PLAN_CREATED = 'BILLING.PLAN.CREATED'; + const HOOK_BILLING_PLAN_UPDATED = 'BILLING.PLAN.UPDATED'; + const HOOK_BILLING_SUBSCRIPTION_CREATED = 'BILLING.SUBSCRIPTION.CREATED'; + + const HOOK_PAYMENT_SALE_COMPLETED = 'PAYMENT.SALE.COMPLETED'; + const HOOK_PAYMENT_SALE_DENIED = 'PAYMENT.SALE.DENIED'; + + //Classic PayPal payment + const RESOURCE_TYPE_SALE = 'sale'; + + //Planified payment + const RESOURCE_TYPE_PLAN = 'plan'; + const RESOURCE_TYPE_AGREEMENT = 'agreement'; + + /** + * Example of array received in posted params : + * + * + * Array ( + * 'id' => 'WH-0LU96374794024348-4WG31854RU4949452', + * 'event_version' => 1.0, + * 'create_time' => '2017-02-03T15:31:29Z', + * 'resource_type' => 'plan', + * 'event_type' => 'BILLING.PLAN.CREATED', + * 'summary' => 'A billing plan was created', + * 'resource' => Array ( + * 'merchant_preferences' => Array ( + * 'setup_fee' => Array ( + * 'currency' => 'EUR', + * 'value' => 0 + * ), + * 'return_url' => 'http://25b3ee89.ngrok.io/thelia_2_3_3/web/module/paypal/agreement/ok/208', + * 'cancel_url' => 'http://25b3ee89.ngrok.io/thelia_2_3_3/web/module/paypal/agreement/ko/208', + * 'auto_bill_amount' => 'NO', + * 'initial_fail_amount_action' => 'CONTINUE', + * 'max_fail_attempts' => 0 + * ), + * 'update_time' => '2017-02-03T15:31:29.348Z', + * 'create_time' => '2017-02-03T15:31:29.348Z', + * 'name' => 'plan for order 208', + * 'description' => false, + * 'links' => Array ( + * 0 => Array ( + * 'href' => 'api.sandbox.paypal.com/v1/payments/billing-plans/P-2DV20774VJ3968037ASNA3RA', + * 'rel' => 'self', + * 'method' => 'GET' + * ) + * ), + * 'payment_definitions' => Array ( + * 0 => Array ( + * 'name' => 'payment definition for order 208', + * 'type' => 'REGULAR', + * 'frequency' => 'Day', + * 'frequency_interval' => 1, + * 'amount' => Array ( + * 'currency' => 'EUR', + * 'value' => 3.9 + * ), + * 'cycles' => 5, + * 'charge_models' => Array ( + * 0 => Array ( + * 'type' => 'SHIPPING', + * 'amount' => Array ( + * 'currency' => 'EUR', + * 'value' => 0 + * ), + * 'id' => 'CHM-26B03456D8799461GASNA3RA' + * ) + * ), + * 'id' => 'PD-3FB00313143031422ASNA3RA' + * ) + * ), + * 'id' => 'P-2DV20774VJ3968037ASNA3RA', + * 'state' => 'CREATED', + * 'type' => 'FIXED' + * ), + * 'links' => Array ( + * 0 => Array ( + * 'href' => 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0LU96374794024348-4WG31854RU4949452', + * 'rel' => 'self', + * 'method' => 'GET' + * ), + * 1 => Array ( + * 'href' => 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0LU96374794024348-4WG31854RU4949452/resend', + * 'rel' => 'resend', + * 'method' => 'POST' + * ) + * ) + * ); + */ + public function allAction() + { + $eventType = $this->getRequest()->request->get('event_type'); + $resource = $this->getRequest()->request->get('resource'); + $resourceType = $this->getRequest()->request->get('resource_type'); + + $details = [ + 'request' => $this->getRequest()->request->all() + ]; + + $params = [ + 'hook' => $eventType + ]; + + $con = Propel::getConnection(); + $con->beginTransaction(); + + try { + + $title = $this->getTitle($this->getRequest()); + + if (is_array($resource)) { + + switch (strtolower($resourceType)) { + + case self::RESOURCE_TYPE_SALE: + if (isset($resource['parent_payment'])) { + $params = $this->getParamsForSale($resource['parent_payment'], $params, $eventType); + } + if (isset($resource['billing_agreement_id'])) { + $params = $this->getParamsForAgreement($resource['billing_agreement_id'], $params); + } + break; + + case self::RESOURCE_TYPE_PLAN: + if (isset($resource['id'])) { + $params = $this->getParamsForPlan($resource['id'], $params); + } + break; + + case self::RESOURCE_TYPE_AGREEMENT: + if (isset($resource['id'])) { + $params = $this->getParamsForAgreement($resource['id'], $params); + } + break; + + default: + break; + } + } + + PayPalLoggerService::log( + '

' . $title . '

' . $this->printRecursiveData($details), + $params, + Logger::INFO + ); + + $con->commit(); + } catch (PayPalConnectionException $e) { + + $con->rollBack(); + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log($message, $params, Logger::CRITICAL); + PayPalLoggerService::log($this->printRecursiveData($this->getRequest()->request), $params, Logger::CRITICAL); + + } catch (\Exception $e) { + + $con->rollBack(); + PayPalLoggerService::log($e->getMessage(), $params, Logger::CRITICAL); + PayPalLoggerService::log($this->printRecursiveData($this->getRequest()->request), $params, Logger::CRITICAL); + + } + } + + /** + * @param Request $request + * @return string + */ + protected function getTitle(Request $request) + { + $summary = $request->request->get('summary'); + + $title = ''; + if (null !== $request->get('event_type')) { + $title .= $request->get('event_type') . ' : '; + } + $title .= $summary; + + return $title; + } + + /** + * @param null $paymentId + * @param array $params + * @param null $eventType + * @return array + */ + protected function getParamsForSale($paymentId = null, $params = [], $eventType = null) + { + if (null !== $payPalOrder = PaypalOrderQuery::create()->findOneByPaymentId($paymentId)) { + $params['order_id'] = $payPalOrder->getId(); + $params['customer_id'] = $payPalOrder->getOrder()->getCustomerId(); + + if ($eventType === self::HOOK_PAYMENT_SALE_DENIED) { + $event = new OrderEvent($payPalOrder->getOrder()); + $event->setStatus(OrderStatusQuery::getCancelledStatus()->getId()); + $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + } + } + + return $params; + } + + /** + * @param null $planId + * @param array $params + * @return array + */ + protected function getParamsForPlan($planId = null, $params = []) + { + if (null !== $payPalPlan = PaypalPlanQuery::create()->findOneByPlanId($planId)) { + + $params['order_id'] = $payPalPlan->getPaypalOrderId(); + $params['customer_id'] = $payPalPlan->getPaypalOrder()->getOrder()->getCustomerId(); + + } + + return $params; + } + + /** + * @param null $agreementId + * @param array $params + * @return array + */ + protected function getParamsForAgreement($agreementId = null, $params = []) + { + if (null !== $payPalOrder = PaypalOrderQuery::create()->filterByAgreementId($agreementId)->orderById()->findOne()) { + + // Do not duplicate order for the first PayPal payment because order has just been created. + // We will duplicate this order for the next PayPal payment :) + if ($payPalOrder->getPlanifiedActualCycle() > 0) { + $params['order_id'] = $payPalOrder->getId(); + $params['customer_id'] = $payPalOrder->getOrder()->getCustomerId(); + + /** @var PayPalAgreementService $payPalAgreementService */ + $payPalAgreementService = $this->container->get(PayPal::PAYPAL_AGREEMENT_SERVICE_ID); + $newOrder = $payPalAgreementService->duplicateOrder($payPalOrder->getOrder()); + + Translator::getInstance()->trans( + 'New recursive invoice from order %id', + ['%id' => $payPalOrder->getId()], + PayPal::DOMAIN_NAME + ); + + PayPalLoggerService::log( + '

New recursive invoice from order ' . $payPalOrder->getId() . '

', + [ + 'order_id' => $newOrder->getId(), + 'customer_id' => $payPalOrder->getOrder()->getCustomerId() + ], + Logger::INFO + ); + } + + $payPalOrder->setPlanifiedActualCycle($payPalOrder->getPlanifiedActualCycle() + 1); + $payPalOrderEvent = new PayPalOrderEvent($payPalOrder); + $this->getDispatcher()->dispatch(PayPalEvents::PAYPAL_ORDER_UPDATE, $payPalOrderEvent); + } + + return $params; + } + + /** + * @param array $data + * @param int $deep + * @return string + */ + protected function printRecursiveData($data = [], $deep = 0) + { + $formatedString = ''; + foreach ($data as $key => $value) { + + for ($i = 0; $i <= $deep; $i++) { + $formatedString .= '    '; + } + + if (is_array($value)) { + $formatedString .= '' . $key . ' : 
' . $this->printRecursiveData($value, $deep + 1); + } else { + $formatedString .= '' . $key . ' : ' . $value . '
'; + } + + } + + return $formatedString; + } +} diff --git a/Controller/PaypalResponse.php b/Controller/PaypalResponse.php deleted file mode 100755 index c9da311..0000000 --- a/Controller/PaypalResponse.php +++ /dev/null @@ -1,244 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Controller; - -use Paypal\Classes\API\PaypalApiCredentials; -use Paypal\Classes\API\PaypalApiLogManager; -use Paypal\Classes\API\PaypalApiManager; -use Paypal\Classes\NVP\Operations\PaypalNvpOperationsDoExpressCheckoutPayment; -use Paypal\Classes\NVP\Operations\PaypalNvpOperationsGetExpressCheckoutDetails; -use Paypal\Classes\NVP\PaypalNvpMessageSender; -use Paypal\Paypal; -use Thelia\Core\Event\Order\OrderEvent; -use Thelia\Core\Event\TheliaEvents; -use Thelia\Core\HttpKernel\Exception\RedirectException; -use Thelia\Model\Base\OrderQuery; -use Thelia\Model\OrderStatus; -use Thelia\Model\OrderStatusQuery; -use Thelia\Module\BasePaymentModuleController; -use Thelia\Tools\URL; - -/** - * Class PaypalResponse - * @package Paypal\Controller - * @author Thelia - */ -class PaypalResponse extends BasePaymentModuleController -{ - /** @var PaypalApiLogManager */ - private $logger; - - public function __construct() - { - $this->logger = new PaypalApiLogManager(); - } - - /** - * @param $order_id - * @return \Thelia\Core\HttpFoundation\Response - */ - public function ok($order_id) - { - $token = null; - - $message = ''; - - try { - $order = $this->checkorder($order_id, $token); - /* - * $payerid string value returned by paypal - * $logger PaypalApiLogManager used to log transctions with paypal - */ - $payerid = $this->getRequest()->get('PayerID'); - - if (! empty($payerid)) { - /* - * $config ConfigInterface Object that contains configuration - * $api PaypalApiCredentials Class used by the library to store and use 3T login(username, password, signature) - * $sandbox bool true if sandbox is enabled - */ - $api = new PaypalApiCredentials(); - $sandbox = Paypal::isSandboxMode(); - /* - * Send getExpressCheckout & doExpressCheckout - * empty cart - */ - $getExpressCheckout = new PaypalNvpOperationsGetExpressCheckoutDetails( - $api, - $token - ); - - $request = new PaypalNvpMessageSender($getExpressCheckout, $sandbox); - $response = PaypalApiManager::nvpToArray($request->send()); - - $this->logger->logTransaction($response); - - if (isset($response['ACK']) && $response['ACK'] === 'Success' && - isset($response['PAYERID']) && $response['PAYERID'] === $payerid && - isset($response['TOKEN']) && $response['TOKEN'] === $token - ) { - $doExpressCheckout = new PaypalNvpOperationsDoExpressCheckoutPayment( - $api, - round($order->getTotalAmount(), 2), - $order->getCurrency()->getCode(), - $payerid, - PaypalApiManager::PAYMENT_TYPE_SALE, - $token, - URL::getInstance()->absoluteUrl("/module/paypal/listen"), - PaypalApiManager::BUTTON_SOURCE - ); - - $request = new PaypalNvpMessageSender($doExpressCheckout, $token); - $response = PaypalApiManager::nvpToArray($request->send()); - - $this->logger->logTransaction($response); - - // In case of pending status, log the reason to get usefull information (multi-currency problem, ...) - if (isset($response['ACK']) && $response['ACK'] === "Success" && - isset($response['PAYMENTINFO_0_PAYMENTSTATUS']) && $response['PAYMENTINFO_0_PAYMENTSTATUS'] === "Pending") { - $message = $this->getTranslator()->trans( - "Paypal transaction is pending. Reason: %reason", - [ 'reason' => $response['PAYMENTINFO_0_PENDINGREASON'] ], - Paypal::DOMAIN - ); - } - - /* - * In case of success, go to success page - * In case of error, show it - */ - if (isset($response['ACK']) && $response['ACK'] === "Success" - && isset($response['PAYMENTINFO_0_PAYMENTSTATUS']) && $response['PAYMENTINFO_0_PAYMENTSTATUS'] === "Completed" - && isset($response['TOKEN']) && $response['TOKEN'] === $token - ) { - /* - * Set order status as paid - */ - $event = new OrderEvent($order); - $event->setStatus(OrderStatusQuery::getPaidStatus()->getId()); - $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); - - $this->redirectToSuccessPage($order_id); - } else { - $message = $this->getTranslator()->trans("Failed to validate your payment", [], Paypal::DOMAIN); - } - } else { - $message = $this->getTranslator()->trans("Failed to validate payment parameters", [], Paypal::DOMAIN); - } - } else { - $message = $this->getTranslator()->trans("Failed to find PayerID", [], Paypal::DOMAIN); - } - - $this->logger->getLogger()->info("Order [" . $order_id . "] : " . $message); - } catch (RedirectException $ex) { - throw $ex; - } catch (\Exception $ex) { - $this->logger->getLogger()->error("Error occured while processing express checkout : " . $ex->getMessage()); - - $message = $this->getTranslator()->trans( - "Unexpected error: %mesg", - [ '%mesg' => $ex->getMessage()], - Paypal::DOMAIN - ); - } - - $this->redirectToFailurePage($order_id, $message); - } - - /* - * @param $order_id int - * @return \Thelia\Core\HttpFoundation\Response - */ - public function cancel($order_id) - { - $token = null; - - try { - $order = $this->checkorder($order_id, $token); - - $logger = new PaypalApiLogManager(); - $logger->getLogger()->warning("User canceled payment of order ".$order->getRef()); - - $event = new OrderEvent($order); - $event->setStatus(OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_CANCELED)->getId()); - $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); - - $message = $this->getTranslator()->trans("You canceled your payment", [], Paypal::DOMAIN); - } catch (\Exception $ex) { - $this->logger->getLogger()->error("Error occured while canceling express checkout : " . $ex->getMessage()); - - $message = $this->getTranslator()->trans( - "Unexpected error: %mesg", - [ '%mesg' => $ex->getMessage()], - Paypal::DOMAIN - ); - } - - $this->redirectToFailurePage($order_id, $message); - } - - /* - * @param $order_id int - * @param &$token string|null - * @throws \Exception - * @return \Thelia\Model\Order - */ - public function checkorder($order_id, &$token) - { - $token = $this->getRequest()->getSession()->get('Paypal.token'); - - if ($token !== $this->getRequest()->get('token')) { - throw new \Exception( - $this->getTranslator()->trans( - "Invalid Paypal token. Please try again.", - [], - Paypal::DOMAIN - ) - ); - } - - if (null === $order = OrderQuery::create()->findPk($order_id)) { - throw new \Exception( - $this->getTranslator()->trans( - "Invalid order ID. This order doesn't exists or doesn't belong to you.", - [], - Paypal::DOMAIN - ) - ); - } - - return $order; - } - - /** - * Return a module identifier used to calculate the name of the log file, - * and in the log messages. - * - * @return string the module code - */ - protected function getModuleCode() - { - return "Paypal"; - } -} diff --git a/Classes/PaypalResources.php b/Event/PayPalCartEvent.php old mode 100755 new mode 100644 similarity index 70% rename from Classes/PaypalResources.php rename to Event/PayPalCartEvent.php index f70854e..432fbba --- a/Classes/PaypalResources.php +++ b/Event/PayPalCartEvent.php @@ -21,16 +21,46 @@ /* */ /*************************************************************************************/ -namespace Paypal\Classes; +namespace PayPal\Event; -class PaypalResources +use PayPal\Model\PaypalCart; +use Thelia\Core\Event\ActionEvent; + +/** + * Class PayPalCartEvent + * @package PayPal\Event + */ +class PayPalCartEvent extends ActionEvent { - const LOGO_NORMAL_URL = 'https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_37x23.jpg'; - const LOGO_PAIEMENT_CARDS_URL = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_moyens_paiement_fr.jpg'; + /** @var PaypalCart */ + protected $payPalCart; + + /** + * PayPalCartEvent constructor. + * @param PaypalCart $payPalCart + */ + public function __construct(PaypalCart $payPalCart) + { + $this->payPalCart = $payPalCart; + } + + /** + * @return PaypalCart + */ + public function getPayPalCart() + { + return $this->payPalCart; + } - const PAYPAL_REDIRECT_NORMAL_URL = 'https://www.paypal.com/cgi-bin/webscr'; - const PAYPAL_REDIRECT_SANDBOX_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; + /** + * @param PaypalCart $payPalCart + * + * @return $this + */ + public function setPayPalCart($payPalCart) + { + $this->payPalCart = $payPalCart; - const CMD_EXPRESS_CHECKOUT_KEY = '_express-checkout'; - const CMD_EXPRESS_CHECKOUT_MOBILE_KEY = '_express-checkout-mobile'; + return $this; + } } diff --git a/Classes/NVP/Operations/PaypalNvpOperationsGetExpressCheckoutDetails.php b/Event/PayPalCustomerEvent.php old mode 100755 new mode 100644 similarity index 68% rename from Classes/NVP/Operations/PaypalNvpOperationsGetExpressCheckoutDetails.php rename to Event/PayPalCustomerEvent.php index 9e04582..419afe6 --- a/Classes/NVP/Operations/PaypalNvpOperationsGetExpressCheckoutDetails.php +++ b/Event/PayPalCustomerEvent.php @@ -21,40 +21,46 @@ /* */ /*************************************************************************************/ -namespace Paypal\Classes\NVP\Operations; +namespace PayPal\Event; -use Paypal\Classes\API\PaypalApiCredentials; +use PayPal\Model\PaypalCustomer; +use Thelia\Core\Event\ActionEvent; /** - * Class GetExpressCheckoutDetails - * Manage NVP GetExpressCheckoutDetails Operation + * Class PayPalCustomerEvent + * @package PayPal\Event */ -class PaypalNvpOperationsGetExpressCheckoutDetails extends PaypalNvpOperationsBase +class PayPalCustomerEvent extends ActionEvent { - /** @var string SetExpressCheckout API Token */ - protected $token = null; + /** @var PaypalCustomer */ + protected $payPalCustomer; /** - * Constructor - * - * @param PaypalApiCredentials $credentials API Credentials (3T) - * @param string $token Token from SetExpressCheckout API + * PayPalCustomerEvent constructor. + * @param PaypalCustomer $payPalCustomer */ - public function __construct(PaypalApiCredentials $credentials, $token) + public function __construct(PaypalCustomer $payPalCustomer) { - $this->operationName = 'GetExpressCheckoutDetails'; - $this->credentials = $credentials; - $this->token = $token; + $this->payPalCustomer = $payPalCustomer; } /** - * {@inheritdoc } + * @return PaypalCustomer + */ + public function getPayPalCustomer() + { + return $this->payPalCustomer; + } + + /** + * @param PaypalCustomer $payPalCustomer + * + * @return $this */ - public function getRequest() + public function setPayPalCustomer($payPalCustomer) { - $request = parent::getRequest(); - $request .= '&TOKEN=' . $this->token; + $this->payPalCustomer = $payPalCustomer; - return $request; + return $this; } } diff --git a/Event/PayPalEvents.php b/Event/PayPalEvents.php new file mode 100644 index 0000000..16a5e5a --- /dev/null +++ b/Event/PayPalEvents.php @@ -0,0 +1,57 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Event; + + +/** + * Class PayPalEvents + * @package PayPal\Event + */ +class PayPalEvents +{ + const PAYPAL_ORDER_CREATE = 'action.paypal.order.create'; + const PAYPAL_ORDER_UPDATE = 'action.paypal.order.update'; + const PAYPAL_ORDER_DELETE = 'action.paypal.order.delete'; + const PAYPAL_RECURSIVE_PAYMENT_CREATE = 'action.paypal.recursive.payment.create'; + + const PAYPAL_AGREEMENT_CREATE = 'action.paypal.agreement.create'; + const PAYPAL_AGREEMENT_UPDATE = 'action.paypal.agreement.update'; + const PAYPAL_AGREEMENT_DELETE = 'action.paypal.agreement.delete'; + + const PAYPAL_PLAN_CREATE = 'action.paypal.plan.create'; + const PAYPAL_PLAN_UPDATE = 'action.paypal.plan.update'; + const PAYPAL_PLAN_DELETE = 'action.paypal.plan.delete'; + + const PAYPAL_CUSTOMER_CREATE = 'action.paypal.customer.create'; + const PAYPAL_CUSTOMER_UPDATE = 'action.paypal.customer.update'; + const PAYPAL_CUSTOMER_DELETE = 'action.paypal.customer.delete'; + + const PAYPAL_CART_CREATE = 'action.paypal.cart.create'; + const PAYPAL_CART_UPDATE = 'action.paypal.cart.update'; + const PAYPAL_CART_DELETE = 'action.paypal.cart.delete'; + + const PAYPAL_PLANIFIED_PAYMENT_CREATE = 'action.paypal.planified.payment.create'; + const PAYPAL_PLANIFIED_PAYMENT_UPDATE = 'action.paypal.planified.payment.update'; + const PAYPAL_PLANIFIED_PAYMENT_DELETE = 'action.paypal.planified.payment.delete'; +} diff --git a/Event/PayPalOrderEvent.php b/Event/PayPalOrderEvent.php new file mode 100644 index 0000000..2193bb3 --- /dev/null +++ b/Event/PayPalOrderEvent.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Event; + +use PayPal\Model\PaypalOrder; +use Thelia\Core\Event\ActionEvent; + +/** + * Class PayPalOrderEvent + * @package PayPal\Event + */ +class PayPalOrderEvent extends ActionEvent +{ + /** @var PaypalOrder */ + protected $payPalOrder; + + /** + * PayPalOrderEvent constructor. + * @param PaypalOrder $payPalOrder + */ + public function __construct(PaypalOrder $payPalOrder) + { + $this->payPalOrder = $payPalOrder; + } + + /** + * @return PaypalOrder + */ + public function getPayPalOrder() + { + return $this->payPalOrder; + } + + /** + * @param PaypalOrder $payPalOrder + * + * @return $this + */ + public function setPayPalOrder($payPalOrder) + { + $this->payPalOrder = $payPalOrder; + + return $this; + } +} diff --git a/Event/PayPalPlanEvent.php b/Event/PayPalPlanEvent.php new file mode 100644 index 0000000..b1ff2d4 --- /dev/null +++ b/Event/PayPalPlanEvent.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Event; + +use PayPal\Model\PaypalPlan; +use Thelia\Core\Event\ActionEvent; + +/** + * Class PayPalPlanEvent + * @package PayPal\Event + */ +class PayPalPlanEvent extends ActionEvent +{ + /** @var PaypalPlan */ + protected $payPalPlan; + + /** + * PayPalPlanEvent constructor. + * @param PaypalPlan $payPalPlan + */ + public function __construct(PaypalPlan $payPalPlan) + { + $this->payPalPlan = $payPalPlan; + } + + /** + * @return PaypalPlan + */ + public function getPayPalPlan() + { + return $this->payPalPlan; + } + + /** + * @param PaypalPlan $payPalPlan + * + * @return $this + */ + public function setPayPalPlan($payPalPlan) + { + $this->payPalPlan = $payPalPlan; + + return $this; + } +} diff --git a/Classes/NVP/PaypalNvpMessageSender.php b/Event/PayPalPlanifiedPaymentEvent.php old mode 100755 new mode 100644 similarity index 55% rename from Classes/NVP/PaypalNvpMessageSender.php rename to Event/PayPalPlanifiedPaymentEvent.php index 4f4a09e..2e7988a --- a/Classes/NVP/PaypalNvpMessageSender.php +++ b/Event/PayPalPlanifiedPaymentEvent.php @@ -21,63 +21,46 @@ /* */ /*************************************************************************************/ -namespace Paypal\Classes\NVP; +namespace PayPal\Event; -use Paypal\Classes\NVP\Operations\PaypalNvpOperationInterface; -use Paypal\Classes\API\PaypalApiManager; +use PayPal\Model\PaypalPlanifiedPayment; +use Thelia\Core\Event\ActionEvent; /** - * Class PaypalNvpMessageSender - * - * Send NVP requests via Curl - * - * Example for the API SetExpressCheckout call on the SandBox: - * $paypal = new Paypal(); - * $nvpSetExpressCheckout = new PaypalNvpOperationsSetExpressCheckout( - * new PaypalApiCredentials(new PayPalVariableRepository($paypal->link)), - * $amount, - * $currencyID, - * $return_url, - * $cancel_url, - * ); - * $nvpMessageSender = new PaypalNvpMessageSender($nvpSetExpressCheckout, true); - * $response = $nvpMessageSender->send(); + * Class PayPalPlanifiedPaymentEvent + * @package PayPal\Event */ -class PaypalNvpMessageSender +class PayPalPlanifiedPaymentEvent extends ActionEvent { - /** @var string message to send */ - protected $message = null; + /** @var PaypalPlanifiedPayment */ + protected $payPalPlanifiedPayment; - /** @var bool if sandbox mode is enabled */ - protected $isSandbox = true; + /** + * PayPalPlanifiedPaymentEvent constructor. + * @param PaypalPlanifiedPayment $payPalPlanifiedPayment + */ + public function __construct(PaypalPlanifiedPayment $payPalPlanifiedPayment) + { + $this->payPalPlanifiedPayment = $payPalPlanifiedPayment; + } /** - * Constructor - * - * @param PaypalNvpOperationInterface $nvpMessage NVP message to send - * @param bool $isSandbox if sandbox mode enabled + * @return PaypalPlanifiedPayment */ - public function __construct(PaypalNvpOperationInterface $nvpMessage, $isSandbox = true) + public function getPayPalPlanifiedPayment() { - $this->isSandbox = $isSandbox; - $this->message = $nvpMessage->getRequest(); + return $this->payPalPlanifiedPayment; } /** - * Send request via Curl + * @param PaypalPlanifiedPayment $payPalPlanifiedPayment * - * @return string APÏ response + * @return $this */ - public function send() + public function setPayPalPlanifiedPayment($payPalPlanifiedPayment) { - $paypalApiManager = new PaypalApiManager(); - - $url = $paypalApiManager->getApiUrl() . '?' . $this->message; - - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($ch); + $this->payPalPlanifiedPayment = $payPalPlanifiedPayment; - return $response; + return $this; } } diff --git a/EventListeners/Form/TheliaOrderPaymentForm.php b/EventListeners/Form/TheliaOrderPaymentForm.php new file mode 100644 index 0000000..9f3ae30 --- /dev/null +++ b/EventListeners/Form/TheliaOrderPaymentForm.php @@ -0,0 +1,172 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners\Form; + +use PayPal\Form\PayPalFormFields; +use PayPal\Form\Type\PayPalCreditCardType; +use PayPal\Model\PaypalPlanifiedPayment; +use PayPal\Model\PaypalPlanifiedPaymentQuery; +use PayPal\PayPal; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Event\TheliaFormEvent; +use Thelia\Core\HttpFoundation\Session\Session; +use Thelia\Core\Translation\Translator; +use Thelia\Model\Cart; +use Thelia\Model\Country; +use Thelia\Model\Order; + +/** + * Class TheliaOrderPaymentForm + * @package PayPal\EventListeners\Form + */ +class TheliaOrderPaymentForm implements EventSubscriberInterface +{ + /** @var RequestStack */ + protected $requestStack; + + /** @var EventDispatcherInterface */ + protected $dispatcher; + + /** + * TheliaOrderPaymentForm constructor. + * @param RequestStack $requestStack + */ + public function __construct(RequestStack $requestStack, EventDispatcherInterface $dispatcher) + { + $this->requestStack = $requestStack; + $this->dispatcher = $dispatcher; + } + + /** + * @param TheliaFormEvent $event + */ + public function afterBuildTheliaOrderPayment(TheliaFormEvent $event) + { + $event->getForm()->getFormBuilder() + ->add( + PayPalFormFields::FIELD_PAYPAL_METHOD, + 'choice', + [ + 'choices' => [ + PayPal::PAYPAL_METHOD_PAYPAL => PayPal::PAYPAL_METHOD_PAYPAL, + PayPal::PAYPAL_METHOD_EXPRESS_CHECKOUT => PayPal::PAYPAL_METHOD_EXPRESS_CHECKOUT, + PayPal::PAYPAL_METHOD_CREDIT_CARD => PayPal::PAYPAL_METHOD_CREDIT_CARD, + PayPal::PAYPAL_METHOD_PLANIFIED_PAYMENT => PayPal::PAYPAL_METHOD_PLANIFIED_PAYMENT + ], + 'label' => Translator::getInstance()->trans('PayPal method', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PAYPAL_METHOD], + 'required' => false, + ] + ) + ->add( + PayPalCreditCardType::TYPE_NAME, + new PayPalCreditCardType(), + [ + 'label_attr' => [ + 'for' => PayPalCreditCardType::TYPE_NAME + ] + ] + ) + ->add( + PayPalFormFields::FIELD_PAYPAL_PLANIFIED_PAYMENT, + 'choice', + [ + 'choices' => $this->getAllowedPlanifiedPayments(), + 'choices_as_values' => true, + 'choice_label' => function ($value, $key, $index) { + return $value->getTitle(); + }, + 'choice_value' => function ($value) { + if ($value !== null) { + return $value->getId(); + } + + return null; + }, + "required" => false, + 'empty_data' => null, + 'label' => Translator::getInstance()->trans('Frequency', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PAYPAL_PLANIFIED_PAYMENT], + ] + ) + ; + } + + /** + * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection + */ + protected function getAllowedPlanifiedPayments() + { + /** @var Session $session */ + $session = $this->requestStack->getCurrentRequest()->getSession(); + + /** @var \Thelia\Model\Lang $lang */ + $lang = $session->get('thelia.current.lang'); + + /** @var Cart $cart */ + $cart = $session->getSessionCart($this->dispatcher); + + /** @var Order $order */ + $order = $session->get('thelia.order'); + + $country = Country::getDefaultCountry(); + + $planifiedPayments = (new PaypalPlanifiedPaymentQuery())->joinWithI18n($lang->getLocale())->find(); + if (null !== $cart && null !== $order && null !== $country) { + $totalAmount = $cart->getTaxedAmount($country) + (float)$order->getPostage(); + + $restrictedPlanifiedAmounts = []; + /** @var PaypalPlanifiedPayment $planifiedPayment */ + foreach ($planifiedPayments as $planifiedPayment) { + + if ($planifiedPayment->getMinAmount() > 0 && $planifiedPayment->getMinAmount() > $totalAmount) { + continue; + } + + if ($planifiedPayment->getMaxAmount() > 0 && $planifiedPayment->getMaxAmount() < $totalAmount) { + continue; + } + + $restrictedPlanifiedAmounts[] = $planifiedPayment; + } + + $planifiedPayments = $restrictedPlanifiedAmounts; + } + + return $planifiedPayments; + } + + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + TheliaEvents::FORM_AFTER_BUILD . '.thelia_order_payment' => ['afterBuildTheliaOrderPayment', 128] + ]; + } +} diff --git a/EventListeners/OrderListener.php b/EventListeners/OrderListener.php new file mode 100644 index 0000000..6a96867 --- /dev/null +++ b/EventListeners/OrderListener.php @@ -0,0 +1,273 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners; + +use PayPal\Event\PayPalCartEvent; +use PayPal\Event\PayPalEvents; +use PayPal\Form\PayPalFormFields; +use PayPal\Form\Type\PayPalCreditCardType; +use PayPal\PayPal; +use PayPal\Service\PayPalAgreementService; +use PayPal\Service\PayPalPaymentService; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Mailer\MailerFactory; + +/** + * Class OrderListener + * @package PayPal\EventListeners + */ +class OrderListener implements EventSubscriberInterface +{ + /** @var MailerFactory */ + protected $mailer; + + /** @var EventDispatcherInterface */ + protected $dispatcher; + + /** @var RequestStack */ + protected $requestStack; + + /** @var PayPalPaymentService */ + protected $payPalPaymentService; + + /** @var PayPalAgreementService */ + protected $payPalAgreementService; + + /** + * @param MailerFactory $mailer + * @param EventDispatcherInterface $dispatcher + * @param RequestStack $requestStack + * @param PayPalPaymentService $payPalPaymentService + * @param PayPalAgreementService $payPalAgreementService + */ + public function __construct(MailerFactory $mailer, EventDispatcherInterface $dispatcher, RequestStack $requestStack, PayPalPaymentService $payPalPaymentService, PayPalAgreementService $payPalAgreementService) + { + $this->dispatcher = $dispatcher; + $this->mailer = $mailer; + $this->requestStack = $requestStack; + $this->payPalPaymentService = $payPalPaymentService; + $this->payPalAgreementService = $payPalAgreementService; + } + + /** + * @param OrderEvent $event + */ + public function CancelPayPalTransaction(OrderEvent $event) + { + // @TODO : Inform PayPal that this payment is canceled ? + } + + /** + * @param OrderEvent $event + * + * @throws \Exception if the message cannot be loaded. + */ + public function sendConfirmationEmail(OrderEvent $event) + { + if (PayPal::getConfigValue('send_confirmation_message_only_if_paid')) { + // We send the order confirmation email only if the order is paid + $order = $event->getOrder(); + + if (! $order->isPaid() && $order->getPaymentModuleId() == Paypal::getModuleId()) { + $event->stopPropagation(); + } + } + } + + /** + * Checks if order payment module is paypal and if order new status is paid, send an email to the customer. + * + * @param OrderEvent $event + */ + public function updateStatus(OrderEvent $event) + { + $order = $event->getOrder(); + + if ($order->isPaid() && $order->getPaymentModuleId() === Paypal::getModuleId()) { + if (Paypal::getConfigValue('send_payment_confirmation_message')) { + $this->mailer->sendEmailToCustomer( + PayPal::CONFIRMATION_MESSAGE_NAME, + $order->getCustomer(), + [ + 'order_id' => $order->getId(), + 'order_ref' => $order->getRef() + ] + ); + } + + // Send confirmation email if required. + if (Paypal::getConfigValue('send_confirmation_message_only_if_paid')) { + $this->dispatcher->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event); + } + } + } + + /** + * @param OrderEvent $event + * @throws \Exception + */ + public function checkPayPalMethod(OrderEvent $event) + { + //First be sure that there is no OLD CREDIT card saved in paypal_cart because of fatal error + $payPalCartEvent = new PayPalCartEvent($this->payPalPaymentService->getCurrentPayPalCart()); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_CART_DELETE, $payPalCartEvent); + + $postedData = $this->requestStack->getCurrentRequest()->request->get('thelia_order_payment'); + + if (isset($postedData[PayPalFormFields::FIELD_PAYMENT_MODULE]) && PayPal::getModuleId() === $event->getOrder()->getPaymentModuleId()) { + $this->usePayPalMethod($postedData); + } + } + + /** + * @param OrderEvent $event + */ + public function recursivePayment(OrderEvent $event) + { + $this->payPalAgreementService->duplicateOrder($event->getOrder()); + + if (PayPal::getConfigValue('send_recursive_message')) { + $this->mailer->sendEmailToCustomer( + PayPal::RECURSIVE_MESSAGE_NAME, + $event->getOrder()->getCustomer(), + [ + 'order_id' => $event->getOrder()->getId(), + 'order_ref' => $event->getOrder()->getRef() + ] + ); + } + } + + /** + * @param array $postedData + */ + protected function usePayPalMethod($postedData = []) + { + if (isset($postedData[PayPalFormFields::FIELD_PAYPAL_METHOD])) { + $payPalMethod = $postedData[PayPalFormFields::FIELD_PAYPAL_METHOD]; + + switch ($payPalMethod) { + case PayPal::PAYPAL_METHOD_CREDIT_CARD: + $this->usePayPalCreditCardMethod($postedData); + break; + + case PayPal::PAYPAL_METHOD_PLANIFIED_PAYMENT: + $this->usePayPalPlanifiedPaymentMethod($postedData); + break; + } + } + } + + /** + * @param array $postedData + * @throws \Exception + */ + protected function usePayPalCreditCardMethod($postedData = []) + { + if ($this->isValidPaidByPayPalCreditCard($postedData)) { + //save credit card in cart because we will need it in pay() method for payment module + + $creditCardId = $this->payPalPaymentService->getPayPalCreditCardId( + $postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_TYPE], + $postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_NUMBER], + $postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_EXPIRE_MONTH], + $postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_EXPIRE_YEAR], + $postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_CVV] + ); + + $payPalCart = $this->payPalPaymentService->getCurrentPayPalCart(); + $payPalCart->setCreditCardId($creditCardId); + $payPalCartEvent = new PayPalCartEvent($payPalCart); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_CART_UPDATE, $payPalCartEvent); + } + } + + /** + * @param array $postedData + * @return bool + */ + protected function isValidPaidByPayPalCreditCard($postedData = []) + { + $isValid = false; + + if (isset($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_TYPE]) && $this->isNotBlank($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_TYPE]) && + isset($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_NUMBER]) && $this->isNotBlank($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_NUMBER]) && + isset($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_EXPIRE_MONTH]) && $this->isNotBlank($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_EXPIRE_MONTH]) && + isset($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_EXPIRE_YEAR]) && $this->isNotBlank($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_EXPIRE_YEAR]) && + isset($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_CVV]) && $this->isNotBlank($postedData[PayPalCreditCardType::TYPE_NAME][PayPalFormFields::FIELD_CARD_CVV])) { + $isValid = true; + } + + return $isValid; + } + + /** + * @param array $postedData + */ + protected function usePayPalPlanifiedPaymentMethod($postedData = []) + { + if (isset($postedData[PayPalFormFields::FIELD_PAYPAL_PLANIFIED_PAYMENT]) && + $this->isNotBlank($postedData[PayPalFormFields::FIELD_PAYPAL_PLANIFIED_PAYMENT])) { + + $payPalCart = $this->payPalPaymentService->getCurrentPayPalCart(); + $payPalCart->setPlanifiedPaymentId($postedData[PayPalFormFields::FIELD_PAYPAL_PLANIFIED_PAYMENT]); + $payPalCartEvent = new PayPalCartEvent($payPalCart); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_CART_UPDATE, $payPalCartEvent); + + } + } + + /** + * @param $value + * @return bool + */ + protected function isNotBlank($value) + { + if (false === $value || (empty($value) && '0' != $value)) { + return false; + } + + return true; + } + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + TheliaEvents::ORDER_UPDATE_STATUS => [ + ['CancelPayPalTransaction', 128], + ['updateStatus', 128], + ], + TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL => ['sendConfirmationEmail', 129], + TheliaEvents::ORDER_SEND_NOTIFICATION_EMAIL => ['sendConfirmationEmail', 129], + TheliaEvents::ORDER_SET_PAYMENT_MODULE => ['checkPayPalMethod', 120], + PayPalEvents::PAYPAL_RECURSIVE_PAYMENT_CREATE => ['recursivePayment', 128] + ]; + } +} diff --git a/EventListeners/PayPalCartListener.php b/EventListeners/PayPalCartListener.php new file mode 100644 index 0000000..69a0430 --- /dev/null +++ b/EventListeners/PayPalCartListener.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners; + +use PayPal\Event\PayPalCartEvent; +use PayPal\Event\PayPalEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Class PayPalCartListener + * @package PayPal\EventListeners + */ +class PayPalCartListener implements EventSubscriberInterface +{ + /** + * @param PayPalCartEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function createOrUpdate(PayPalCartEvent $event) + { + $event->getPayPalCart()->save(); + } + + /** + * @param PayPalCartEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function delete(PayPalCartEvent $event) + { + $event->getPayPalCart()->delete(); + } + + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + PayPalEvents::PAYPAL_CART_CREATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_CART_UPDATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_CART_DELETE => ['delete', 128] + ]; + } +} diff --git a/EventListeners/PayPalCustomerListener.php b/EventListeners/PayPalCustomerListener.php new file mode 100644 index 0000000..03026ce --- /dev/null +++ b/EventListeners/PayPalCustomerListener.php @@ -0,0 +1,86 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners; + +use PayPal\Event\PayPalCustomerEvent; +use PayPal\Event\PayPalEvents; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\RequestStack; + +/** + * Class PayPalCustomerListener + * @package PayPal\EventListeners + */ +class PayPalCustomerListener implements EventSubscriberInterface +{ + /** @var RequestStack */ + protected $requestStack; + + /** @var EventDispatcher */ + protected $dispatcher; + + /** + * PayPalCustomerListener constructor. + * @param RequestStack $requestStack + * @param EventDispatcher $dispatcher + */ + public function __construct(RequestStack $requestStack, EventDispatcher $dispatcher) + { + $this->requestStack = $requestStack; + $this->dispatcher = $dispatcher; + } + + /** + * @param PayPalCustomerEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function createOrUpdate(PayPalCustomerEvent $event) + { + $event->getPayPalCustomer()->save(); + } + + /** + * @param PayPalCustomerEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function delete(PayPalCustomerEvent $event) + { + $event->getPayPalCustomer()->delete(); + } + + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + PayPalEvents::PAYPAL_CUSTOMER_CREATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_CUSTOMER_UPDATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_CUSTOMER_DELETE => ['delete', 128] + ]; + } +} diff --git a/EventListeners/PayPalOrderListener.php b/EventListeners/PayPalOrderListener.php new file mode 100644 index 0000000..b8b021f --- /dev/null +++ b/EventListeners/PayPalOrderListener.php @@ -0,0 +1,68 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners; + +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalOrderEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + + +/** + * Class PayPalOrderListener + * @package PayPal\EventListeners + */ +class PayPalOrderListener implements EventSubscriberInterface +{ + /** + * @param PayPalOrderEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function createOrUpdate(PayPalOrderEvent $event) + { + $event->getPayPalOrder()->save(); + } + + /** + * @param PayPalOrderEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function delete(PayPalOrderEvent $event) + { + $event->getPayPalOrder()->delete(); + } + + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + PayPalEvents::PAYPAL_ORDER_CREATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_ORDER_UPDATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_ORDER_DELETE => ['delete', 128] + ]; + } +} diff --git a/EventListeners/PayPalPlanListener.php b/EventListeners/PayPalPlanListener.php new file mode 100644 index 0000000..be9f093 --- /dev/null +++ b/EventListeners/PayPalPlanListener.php @@ -0,0 +1,63 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners; + +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalPlanEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class PayPalPlanListener implements EventSubscriberInterface +{ + /** + * @param PayPalPlanEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function createOrUpdate(PayPalPlanEvent $event) + { + $event->getPayPalPlan()->save(); + } + + /** + * @param PayPalPlanEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function delete(PayPalPlanEvent $event) + { + $event->getPayPalPlan()->delete(); + } + + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + PayPalEvents::PAYPAL_PLAN_CREATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_PLAN_UPDATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_PLAN_DELETE => ['delete', 128] + ]; + } +} diff --git a/EventListeners/PayPalPlanifiedPaymentListener.php b/EventListeners/PayPalPlanifiedPaymentListener.php new file mode 100644 index 0000000..9118a5c --- /dev/null +++ b/EventListeners/PayPalPlanifiedPaymentListener.php @@ -0,0 +1,63 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\EventListeners; + +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalPlanifiedPaymentEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class PayPalPlanifiedPaymentListener implements EventSubscriberInterface +{ + /** + * @param PayPalPlanifiedPaymentEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function createOrUpdate(PayPalPlanifiedPaymentEvent $event) + { + $event->getPayPalPlanifiedPayment()->save(); + } + + /** + * @param PayPalPlanifiedPaymentEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function delete(PayPalPlanifiedPaymentEvent $event) + { + $event->getPayPalPlanifiedPayment()->delete(); + } + + /** + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return [ + PayPalEvents::PAYPAL_PLANIFIED_PAYMENT_CREATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_PLANIFIED_PAYMENT_UPDATE => ['createOrUpdate', 128], + PayPalEvents::PAYPAL_PLANIFIED_PAYMENT_DELETE => ['delete', 128] + ]; + } +} diff --git a/Form/ConfigurationForm.php b/Form/ConfigurationForm.php old mode 100644 new mode 100755 index 4b4bd01..f10289d --- a/Form/ConfigurationForm.php +++ b/Form/ConfigurationForm.php @@ -20,9 +20,10 @@ /* along with this program. If not, see . */ /* */ /*************************************************************************************/ -namespace Paypal\Form; -use Paypal\Paypal; +namespace PayPal\Form; + +use PayPal\PayPal; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; @@ -42,9 +43,9 @@ protected function buildForm() 'text', [ 'constraints' => [ new NotBlank() ], - 'label' => $this->translator->trans('login', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('login', [], PayPal::DOMAIN_NAME), 'label_attr' => [ - 'help' => $this->translator->trans('Your Paypal login', [], Paypal::DOMAIN) + 'help' => $this->translator->trans('Your Paypal login', [], PayPal::DOMAIN_NAME) ] ] ) @@ -53,20 +54,19 @@ protected function buildForm() 'text', [ 'constraints' => [ new NotBlank() ], - 'label' => $this->translator->trans('password', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('password', [], PayPal::DOMAIN_NAME), 'label_attr' => [ - 'help' => $this->translator->trans('Your Paypal password', [], Paypal::DOMAIN) + 'help' => $this->translator->trans('Your Paypal password', [], PayPal::DOMAIN_NAME) ] ] ) ->add( - 'signature', + 'merchant_id', 'text', [ - 'constraints' => [ new NotBlank() ], - 'label' => $this->translator->trans('signature', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Merchant ID', [], PayPal::DOMAIN_NAME), 'label_attr' => [ - 'help' => $this->translator->trans('The Paypal signature', [], Paypal::DOMAIN) + 'help' => $this->translator->trans('The Paypal identity merchant account', ['%url' => 'https://www.paypal.com/businessprofile/settings/'], PayPal::DOMAIN_NAME) ] ] ) @@ -76,7 +76,7 @@ protected function buildForm() [ 'value' => 1, 'required' => false, - 'label' => $this->translator->trans('Activate sandbox mode', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Activate sandbox mode', [], PayPal::DOMAIN_NAME), ] ) ->add( @@ -84,9 +84,9 @@ protected function buildForm() 'text', [ 'required' => false, - 'label' => $this->translator->trans('login', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('login', [], PayPal::DOMAIN_NAME), 'label_attr' => [ - 'help' => $this->translator->trans('Your Paypal sandbox login', [], Paypal::DOMAIN) + 'help' => $this->translator->trans('Your Paypal sandbox login', [], PayPal::DOMAIN_NAME) ] ] ) @@ -95,20 +95,20 @@ protected function buildForm() 'text', [ 'required' => false, - 'label' => $this->translator->trans('password', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('password', [], PayPal::DOMAIN_NAME), 'label_attr' => [ - 'help' => $this->translator->trans('Your Paypal sandbox password', [], Paypal::DOMAIN) + 'help' => $this->translator->trans('Your Paypal sandbox password', [], PayPal::DOMAIN_NAME) ] ] ) ->add( - 'sandbox_signature', + 'sandbox_merchant_id', 'text', [ 'required' => false, - 'label' => $this->translator->trans('signature', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Merchant ID', [], PayPal::DOMAIN_NAME), 'label_attr' => [ - 'help' => $this->translator->trans('The Paypal sandbox signature', [], Paypal::DOMAIN) + 'help' => $this->translator->trans('The Paypal identity merchant account', ['%url' => 'https://www.paypal.com/businessprofile/settings/'], PayPal::DOMAIN_NAME) ] ] ) @@ -117,12 +117,12 @@ protected function buildForm() 'textarea', [ 'required' => false, - 'label' => $this->translator->trans('Allowed IPs in test mode', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Allowed IPs in test mode', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( 'List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line', [ '%ip' => $this->getRequest()->getClientIp() ], - Paypal::DOMAIN + PayPal::DOMAIN_NAME ) ], 'attr' => [ @@ -139,12 +139,12 @@ protected function buildForm() new GreaterThanOrEqual(array('value' => 0)) ], 'required' => false, - 'label' => $this->translator->trans('Minimum order total', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Minimum order total', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( 'Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum', [], - Paypal::DOMAIN + PayPal::DOMAIN_NAME ) ] ] @@ -158,12 +158,12 @@ protected function buildForm() new GreaterThanOrEqual(array('value' => 0)) ], 'required' => false, - 'label' => $this->translator->trans('Maximum order total', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Maximum order total', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( 'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum', [], - Paypal::DOMAIN + PayPal::DOMAIN_NAME ) ] ] @@ -177,12 +177,92 @@ protected function buildForm() new GreaterThanOrEqual(array('value' => 0)) ], 'required' => false, - 'label' => $this->translator->trans('Maximum items in cart', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Maximum items in cart', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( 'Maximum number of items in the customer cart for which this payment method is available.', [], - Paypal::DOMAIN + PayPal::DOMAIN_NAME + ) + ] + ] + ) + ->add( + 'method_paypal', + 'checkbox', + [ + 'value' => 1, + 'required' => false, + 'label' => $this->translator->trans('Activate payment with PayPal account', [], PayPal::DOMAIN_NAME), + 'label_attr' => [ + 'help' => $this->translator->trans( + 'If checked, the order can be paid by PayPal account.', + [], + PayPal::DOMAIN_NAME + ) + ] + ] + ) + ->add( + 'method_paypal_with_in_context', + 'checkbox', + [ + 'value' => 1, + 'required' => false, + 'label' => $this->translator->trans('Use InContext mode for classic PayPal payment', [], PayPal::DOMAIN_NAME), + 'label_attr' => [ + 'help' => $this->translator->trans( + 'If checked, a PayPal popup will be used to execute the payment.', + [], + PayPal::DOMAIN_NAME + ) + ] + ] + ) + ->add( + 'method_express_checkout', + 'checkbox', + [ + 'value' => 1, + 'required' => false, + 'label' => $this->translator->trans('Activate Express Checkout payment with PayPal', [], PayPal::DOMAIN_NAME), + 'label_attr' => [ + 'help' => $this->translator->trans( + 'If checked, the order can be paid directly from cart.', + [], + PayPal::DOMAIN_NAME + ) + ] + ] + ) + ->add( + 'method_credit_card', + 'checkbox', + [ + 'value' => 1, + 'required' => false, + 'label' => $this->translator->trans('Activate payment with credit card', [], PayPal::DOMAIN_NAME), + 'label_attr' => [ + 'help' => $this->translator->trans( + 'If checked, the order can be paid by credit card.', + [], + PayPal::DOMAIN_NAME + ) + ] + ] + ) + ->add( + 'method_planified_payment', + 'checkbox', + [ + 'value' => 1, + 'required' => false, + 'label' => $this->translator->trans('Activate payment with planified payment', [], PayPal::DOMAIN_NAME), + 'label_attr' => [ + 'help' => $this->translator->trans( + 'If checked, the order can be paid by planified payement.', + [], + PayPal::DOMAIN_NAME ) ] ] @@ -193,12 +273,12 @@ protected function buildForm() [ 'value' => 1, 'required' => false, - 'label' => $this->translator->trans('Send order confirmation on payment success', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Send order confirmation on payment success', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( 'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator', [], - Paypal::DOMAIN + PayPal::DOMAIN_NAME ) ] ] @@ -209,28 +289,28 @@ protected function buildForm() [ 'value' => 1, 'required' => false, - 'label' => $this->translator->trans('Send a payment confirmation e-mail', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Send a payment confirmation e-mail', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( 'If checked, a payment confirmation e-mail is sent to the customer.', [], - Paypal::DOMAIN + PayPal::DOMAIN_NAME ) ] ] ) ->add( - 'send_cart_detail', + 'send_recursive_message', 'checkbox', [ 'value' => 1, 'required' => false, - 'label' => $this->translator->trans('Send details of all products to Paypal', [], Paypal::DOMAIN), + 'label' => $this->translator->trans('Send a recursive payment confirmation e-mail', [], PayPal::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans( - 'If checked, all products will be sent to Paypal.', + 'If checked, a payment confirmation e-mail is sent to the customer after each PayPal transaction.', [], - Paypal::DOMAIN + PayPal::DOMAIN_NAME ) ] ] diff --git a/Form/PayPalFormFields.php b/Form/PayPalFormFields.php new file mode 100644 index 0000000..6af046e --- /dev/null +++ b/Form/PayPalFormFields.php @@ -0,0 +1,56 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Form; + +/** + * Class PayPalFormFields + * @package PayPal\Form + */ +class PayPalFormFields +{ + const FIELD_PAYMENT_MODULE = 'payment-module'; + + // \Thelia\Form\OrderPayment + const FIELD_PAYPAL_METHOD = 'paypal_method'; + const FIELD_PAYPAL_PLANIFIED_PAYMENT = 'paypal_planified_payment'; + + // \Form\Type\PayPalCreditCardType + const FIELD_CARD_TYPE = 'card_type'; + const FIELD_CARD_NUMBER = 'card_number'; + const FIELD_CARD_EXPIRE_MONTH = 'card_expire_month'; + const FIELD_CARD_EXPIRE_YEAR = 'card_expire_year'; + const FIELD_CARD_CVV = 'card_cvv'; + + // \Form\PayPalPlanifiedPaymentForm + const FIELD_PP_ID = 'id'; + const FIELD_PP_LOCALE = 'locale'; + const FIELD_PP_TITLE = 'title'; + const FIELD_PP_DESCRIPTION = 'description'; + const FIELD_PP_FREQUENCY = 'frequency'; + const FIELD_PP_FREQUENCY_INTERVAL = 'frequency_interval'; + const FIELD_PP_CYCLE = 'cycle'; + const FIELD_PP_MIN_AMOUNT = 'min_amount'; + const FIELD_PP_MAX_AMOUNT = 'max_amount'; + const FIELD_PP_POSITION = 'position'; +} diff --git a/Form/PayPalPlanifiedPaymentCreateForm.php b/Form/PayPalPlanifiedPaymentCreateForm.php new file mode 100644 index 0000000..749293a --- /dev/null +++ b/Form/PayPalPlanifiedPaymentCreateForm.php @@ -0,0 +1,191 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Form; + +use PayPal\PayPal; +use PayPal\Service\PayPalAgreementService; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; +use Thelia\Form\BaseForm; + +class PayPalPlanifiedPaymentCreateForm extends BaseForm +{ + const FORM_NAME = 'paypal_planified_payment_create_form'; + + /** + * @return null + */ + protected function buildForm() + { + /** @var \Thelia\Model\Lang $lang */ + $lang = $this->getRequest()->getSession()->get('thelia.current.lang'); + + $this->formBuilder + ->add( + PayPalFormFields::FIELD_PP_LOCALE, + HiddenType::class, + [ + 'constraints' => [ + new NotBlank() + ], + 'required' => true, + 'data' => $lang->getLocale(), + 'label' => $this->trans('The locale of the planified payment'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_LOCALE] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_TITLE, + TextType::class, + [ + 'constraints' => [ + new NotBlank() + ], + 'required' => true, + 'label' => $this->trans('The title of the planified payment'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_TITLE] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_DESCRIPTION, + TextType::class, + [ + 'required' => false, + 'label' => $this->trans('The description of the planified payment'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_DESCRIPTION] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_FREQUENCY_INTERVAL, + 'integer', + [ + 'label' => $this->trans('Frequency interval'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_FREQUENCY_INTERVAL], + 'required' => true, + 'constraints' => [ + new NotBlank(), + new GreaterThan(['value' => 0]) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_FREQUENCY, + 'choice', + [ + 'choices' => PayPalAgreementService::getAllowedPaymentFrequency(), + 'label' => $this->trans('Frequency'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_FREQUENCY], + 'required' => true, + 'constraints' => [ + new NotBlank() + ] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_CYCLE, + 'integer', + [ + 'label' => $this->trans('Cycle'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_CYCLE], + 'required' => true, + 'constraints' => [ + new NotBlank(), + new GreaterThan(['value' => 0]) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_MIN_AMOUNT, + 'number', + [ + 'label' => $this->trans('Min amount'), + 'label_attr' => [ + 'for' => PayPalFormFields::FIELD_PP_MIN_AMOUNT, + 'help' => $this->trans("Let value to 0 if you don't want a minimum") + ], + 'required' => false, + 'constraints' => [ + new GreaterThanOrEqual(['value' => 0]) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_MAX_AMOUNT, + 'number', + [ + 'label' => $this->trans('Max amount'), + 'label_attr' => [ + 'for' => PayPalFormFields::FIELD_PP_MAX_AMOUNT, + 'help' => $this->trans("Let value to 0 if you don't want a maximum") + ], + 'required' => false, + 'constraints' => [ + new GreaterThanOrEqual(['value' => 0]) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_PP_POSITION, + 'integer', + [ + 'label' => $this->trans('Position'), + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_POSITION], + 'required' => false + ] + ) + ; + } + + /** + * @return string the name of your form. This name must be unique + */ + public function getName() + { + return self::FORM_NAME; + } + + /** + * Translates the given message. + * + * @param string $id The message id (may also be an object that can be cast to string) + * @param array $parameters An array of parameters for the message + * @param string|null $domain The domain for the message or null to use the default + * + * @throws \InvalidArgumentException If the locale contains invalid characters + * + * @return string The translated string + */ + protected function trans($id, array $parameters = [], $domain = null) + { + return Translator::getInstance()->trans( + $id, + $parameters, + $domain === null ? PayPal::DOMAIN_NAME : $domain + ); + } +} diff --git a/Form/PayPalPlanifiedPaymentUpdateForm.php b/Form/PayPalPlanifiedPaymentUpdateForm.php new file mode 100644 index 0000000..7955ba6 --- /dev/null +++ b/Form/PayPalPlanifiedPaymentUpdateForm.php @@ -0,0 +1,56 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Form; + +use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Validator\Constraints\NotBlank; + +class PayPalPlanifiedPaymentUpdateForm extends PayPalPlanifiedPaymentCreateForm +{ + const FORM_NAME = 'paypal_planified_payment_update_form'; + + protected function buildForm() + { + parent::buildForm(); + + $this->formBuilder + ->add( + PayPalFormFields::FIELD_PP_ID, + HiddenType::class, + [ + 'required' => true, + 'label_attr' => ['for' => PayPalFormFields::FIELD_PP_ID], + 'constraints' => [ + new NotBlank() + ] + ] + ) + ; + } + + public function getName() + { + return self::FORM_NAME; + } +} diff --git a/Form/Type/PayPalCreditCardType.php b/Form/Type/PayPalCreditCardType.php new file mode 100644 index 0000000..9df16c8 --- /dev/null +++ b/Form/Type/PayPalCreditCardType.php @@ -0,0 +1,265 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Form\Type; + +use PayPal\Form\PayPalFormFields; +use PayPal\PayPal; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Thelia\Core\Form\Type\AbstractTheliaType; +use Thelia\Core\Translation\Translator; + + +/** + * Class PayPalCreditCardType + * @package PayPal\Form\Type + */ +class PayPalCreditCardType extends AbstractTheliaType +{ + const TYPE_NAME = 'paypal_credit_card_type'; + + /** + * @param FormBuilderInterface $builder + * @param array $options + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add( + PayPalFormFields::FIELD_CARD_TYPE, + 'choice', + [ + 'choices' => $this->getTypes(), + 'label' => Translator::getInstance()->trans('Card type', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_TYPE], + 'required' => false, + 'constraints' => [ + new Callback( + [ + 'methods' => [ + [$this, 'verifyCardType'] + ], + ] + ) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_CARD_NUMBER, + 'text', + [ + 'label' => Translator::getInstance()->trans('Card number', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_NUMBER], + 'required' => false, + 'constraints' => [ + new Callback( + [ + 'methods' => [ + [$this, 'verifyCardNumber'] + ], + ] + ) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_CARD_EXPIRE_MONTH, + 'choice', + [ + 'choices' => $this->getMonths(), + 'label' => Translator::getInstance()->trans('Expire month', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_EXPIRE_MONTH], + 'required' => false, + 'constraints' => [ + new Callback( + [ + 'methods' => [ + [$this, 'verifyCardExpireMonth'] + ], + ] + ) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_CARD_EXPIRE_YEAR, + 'choice', + [ + 'choices' => $this->getYears(), + 'label' => Translator::getInstance()->trans('Expire year', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_EXPIRE_YEAR], + 'required' => false, + 'constraints' => [ + new Callback( + [ + 'methods' => [ + [$this, 'verifyCardExpireYear'] + ], + ] + ) + ] + ] + ) + ->add( + PayPalFormFields::FIELD_CARD_CVV, + 'text', + [ + 'label' => Translator::getInstance()->trans('CVV', [], PayPal::DOMAIN_NAME), + 'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_CVV], + 'required' => false, + 'constraints' => [ + new Callback( + [ + 'methods' => [ + [$this, 'verifyCardCVV'] + ], + ] + ) + ] + ] + ) + ; + } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + public function verifyCardType($value, ExecutionContextInterface $context) + { + $this->checkNotBlank($value, $context); + } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + public function verifyCardNumber($value, ExecutionContextInterface $context) + { + $this->checkNotBlank($value, $context); + } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + public function verifyCardExpireMonth($value, ExecutionContextInterface $context) + { + $this->checkNotBlank($value, $context); + } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + public function verifyCardExpireYear($value, ExecutionContextInterface $context) + { + $this->checkNotBlank($value, $context); + } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + public function verifyCardCVV($value, ExecutionContextInterface $context) + { + $this->checkNotBlank($value, $context); + } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + protected function checkNotBlank($value, ExecutionContextInterface $context) + { + $data = $context->getRoot()->getData(); + if (isset($data[PayPalFormFields::FIELD_PAYMENT_MODULE]) && PayPal::getModuleId() === $data[PayPalFormFields::FIELD_PAYMENT_MODULE]) { + if (isset($data[PayPalFormFields::FIELD_PAYPAL_METHOD]) && PayPal::PAYPAL_METHOD_CREDIT_CARD === $data[PayPalFormFields::FIELD_PAYPAL_METHOD]) { + if (false === $value || (empty($value) && '0' != $value)) { + $context->addViolation( + Translator::getInstance()->trans('This value should not be blank', [], PayPal::DOMAIN_NAME) + ); + } + } + } + } + + /** + * @inheritDoc + */ + public function getName() + { + return self::TYPE_NAME; + } + + /** + * @return array + */ + protected function getTypes() + { + return [ + PayPal::CREDIT_CARD_TYPE_VISA => 'Visa', + PayPal::CREDIT_CARD_TYPE_MASTERCARD => 'MasterCard', + PayPal::CREDIT_CARD_TYPE_DISCOVER => 'Discover', + PayPal::CREDIT_CARD_TYPE_AMEX => 'Amex' + ]; + } + + /** + * @return array + */ + protected function getMonths() + { + return [ + 1 => '01', + 2 => '02', + 3 => '03', + 4 => '04', + 5 => '05', + 6 => '06', + 7 => '07', + 8 => '08', + 9 => '09', + 10 => '10', + 11 => '11', + 12 => '12' + ]; + } + + /** + * @return array + */ + protected function getYears() + { + $actualYear = date("Y"); + + $years = []; + $years[(int)$actualYear] = $actualYear; + for ($i = 1; $i <= 10; $i++) { + $years[(int)($actualYear + $i)] = $actualYear + $i; + } + return $years; + } +} diff --git a/Hook/HookManager.php b/Hook/BackHookManager.php similarity index 57% rename from Hook/HookManager.php rename to Hook/BackHookManager.php index 4259def..4c477e7 100644 --- a/Hook/HookManager.php +++ b/Hook/BackHookManager.php @@ -20,62 +20,76 @@ /* along with this program. If not, see . */ /* */ /*************************************************************************************/ -/** - * Created by Franck Allimant, CQFDev - * Date: 11/01/2016 11:57 - */ -namespace Paypal\Hook; +namespace PayPal\Hook; -use Paypal\Classes\API\PaypalApiLogManager; -use Paypal\Paypal; +use PayPal\Model\PaypalOrderQuery; +use PayPal\PayPal; +use PayPal\Service\Base\PayPalBaseService; use Thelia\Core\Event\Hook\HookRenderEvent; use Thelia\Core\Hook\BaseHook; use Thelia\Model\ModuleConfig; use Thelia\Model\ModuleConfigQuery; -class HookManager extends BaseHook -{ - const MAX_TRACE_SIZE_IN_BYTES = 40000; +/** + * Class BackHookManager + * @package PayPal\Hook + */ +class BackHookManager extends BaseHook +{ + /** + * @param HookRenderEvent $event + */ public function onModuleConfigure(HookRenderEvent $event) { - $logFilePath = PaypalApiLogManager::getLogFilePath(); - - $traces = @file_get_contents($logFilePath); - - if (false === $traces) { - $traces = $this->translator->trans("The log file doesn't exists yet.", [], Paypal::DOMAIN); - } elseif (empty($traces)) { - $traces = $this->translator->trans("The log file is empty.", [], Paypal::DOMAIN); - } else { - // Limiter la taille des traces à 1MO - if (strlen($traces) > self::MAX_TRACE_SIZE_IN_BYTES) { - $traces = substr($traces, strlen($traces) - self::MAX_TRACE_SIZE_IN_BYTES); - // Cut a first line break; - if (false !== $lineBreakPos = strpos($traces, "\n")) { - $traces = substr($traces, $lineBreakPos+1); - } - - $traces = $this->translator->trans( - "(Previous log is in %file file.)\n", - [ '%file' => sprintf("log".DS."%s.log", Paypal::DOMAIN) ], - Paypal::DOMAIN - ) . $traces; + $vars = []; + if (null !== $moduleConfigs = ModuleConfigQuery::create()->findByModuleId(PayPal::getModuleId())) { + /** @var ModuleConfig $moduleConfig */ + foreach ($moduleConfigs as $moduleConfig) { + $vars[ $moduleConfig->getName() ] = $moduleConfig->getValue(); } } - $vars = ['trace_content' => nl2br($traces) ]; - - if (null !== $params = ModuleConfigQuery::create()->findByModuleId(Paypal::getModuleId())) { - /** @var ModuleConfig $param */ - foreach ($params as $param) { - $vars[ $param->getName() ] = $param->getValue(); - } - } + $vars['paypal_appid'] = PayPalBaseService::getLogin(); + $vars['paypal_authend'] = PayPalBaseService::getMode(); $event->add( $this->render('paypal/module-configuration.html', $vars) ); } + + /** + * @param HookRenderEvent $event + */ + public function onOrderEditPaymentModuleBottom(HookRenderEvent $event) + { + $templateData = $event->getArguments(); + + if (null !== $payPalOrder = PaypalOrderQuery::create()->findOneById($event->getArgument('order_id'))) { + $event->add( + $this->render( + 'paypal/payment-information.html', + $templateData + ) + ); + } + } + + /** + * @param HookRenderEvent $event + */ + public function onOrderEditJs(HookRenderEvent $event) + { + $templateData = $event->getArguments(); + + if (null !== $payPalOrder = PaypalOrderQuery::create()->findOneById($event->getArgument('order_id'))) { + $event->add( + $this->render( + 'paypal/order-edit-js.html', + $templateData + ) + ); + } + } } diff --git a/Hook/FrontHookManager.php b/Hook/FrontHookManager.php new file mode 100644 index 0000000..421a41b --- /dev/null +++ b/Hook/FrontHookManager.php @@ -0,0 +1,208 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Hook; + +use PayPal\Model\PaypalCartQuery; +use PayPal\PayPal; +use PayPal\Service\Base\PayPalBaseService; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Thelia\Core\Event\Hook\HookRenderEvent; +use Thelia\Core\Hook\BaseHook; +use Thelia\Core\HttpFoundation\Session\Session; + + +/** + * Class FrontHookManager + * @package PayPal\Hook + */ +class FrontHookManager extends BaseHook +{ + /** @var RequestStack */ + protected $requestStack; + + /** @var ContainerInterface */ + protected $container; + + /** + * FrontHookManager constructor. + * @param RequestStack $requestStack + * @param ContainerInterface $container + */ + public function __construct(RequestStack $requestStack, ContainerInterface $container) + { + $this->requestStack = $requestStack; + $this->container = $container; + } + + /** + * @param HookRenderEvent $event + */ + public function onLoginMainBottom(HookRenderEvent $event) + { + $templateData = $event->getArguments(); + $templateData['paypal_appid'] = PayPalBaseService::getLogin(); + $templateData['paypal_authend'] = PayPalBaseService::getMode(); + + $event->add( + $this->render( + 'paypal/login-bottom.html', + $templateData + ) + ); + } + + /** + * @param HookRenderEvent $event + */ + public function onOrderInvoicePaymentExtra(HookRenderEvent $event) + { + $templateData = $event->getArguments(); + $templateData['method_paypal_with_in_context'] = PayPal::getConfigValue('method_paypal_with_in_context'); + $event->add( + $this->render( + 'paypal/order-invoice-payment-extra.html', + $templateData + ) + ); + } + + /** + * @param HookRenderEvent $event + */ + public function onOrderInvoiceBottom(HookRenderEvent $event) + { + $templateData = $event->getArguments(); + $templateData['paypal_mode'] = PayPalBaseService::getMode(); + $templateData['paypal_merchantid'] = PayPalBaseService::getMerchantId(); + + $event->add( + $this->render( + 'paypal/order-invoice-bottom.html', + $templateData + ) + ); + } + + public function onOrderInvoiceJavascriptInitialization(HookRenderEvent $event) + { + $render = $this->render( + 'paypal/order-invoice-js.html', + [ + 'module_id' => PayPal::getModuleId(), + ] + ); + + $event->add($render); + } + + /** + * @param HookRenderEvent $event + */ + public function onOrderPlacedAdditionalPaymentInfo(HookRenderEvent $event) + { + $templateData = $event->getArguments(); + $event->add( + $this->render( + 'paypal/order-placed-additional-payment-info.html', + $templateData + ) + ); + } + + /** + * @param HookRenderEvent $event + */ + public function onCartBottom(HookRenderEvent $event) + { + $payPal = new PayPal(); + $payPal->setContainer($this->container); + + if (PayPal::getConfigValue('method_express_checkout') == 1 && $payPal->isValidPayment()) { + $templateData = $event->getArguments(); + $templateData['paypal_mode'] = PayPalBaseService::getMode(); + $templateData['paypal_merchantid'] = PayPalBaseService::getMerchantId(); + $event->add( + $this->render( + 'paypal/cart-bottom.html', + $templateData + ) + ); + } + } + + /** + * @param HookRenderEvent $event + */ + public function onOrderDeliveryFormBottom(HookRenderEvent $event) + { + if ($this->isValidExpressCheckout()) { + $templateData = $event->getArguments(); + $event->add( + $this->render( + 'paypal/order-delivery-bottom.html', + $templateData + ) + ); + } + } + + /** + * @param HookRenderEvent $event + */ + public function onOrderAfterJavascriptInclude(HookRenderEvent $event) + { + if ($this->isValidExpressCheckout()) { + $templateData = $event->getArguments(); + $event->add( + $this->render( + 'paypal/order-delivery-bottom-js.html', + $templateData + ) + ); + } + } + + protected function isValidExpressCheckout() + { + $isValid = false; + + /** @var Session $session */ + $session = $this->requestStack->getCurrentRequest()->getSession(); + $cart = $session->getSessionCart($this->dispatcher); + + $payPal = new PayPal(); + $payPal->setContainer($this->container); + + if (PayPal::getConfigValue('method_express_checkout') == 1 && $payPal->isValidPayment()) { + if (null !== $payPalCart = PaypalCartQuery::create()->findOneById($cart->getId())) { + if ($payPalCart->getExpressPaymentId() && $payPalCart->getExpressPayerId() && $payPalCart->getExpressToken()) { + $isValid = true; + } + } + } + + return $isValid; + } +} diff --git a/Classes/NVP/Operations/PaypalNvpOperationInterface.php b/Hook/PdfHookManager.php old mode 100755 new mode 100644 similarity index 80% rename from Classes/NVP/Operations/PaypalNvpOperationInterface.php rename to Hook/PdfHookManager.php index 343f84f..18f9b35 --- a/Classes/NVP/Operations/PaypalNvpOperationInterface.php +++ b/Hook/PdfHookManager.php @@ -21,24 +21,25 @@ /* */ /*************************************************************************************/ -namespace Paypal\Classes\NVP\Operations; +namespace PayPal\Hook; -/** - * Class NvpOperationInterface - */ -interface PaypalNvpOperationInterface +use Thelia\Core\Event\Hook\HookRenderEvent; +use Thelia\Core\Hook\BaseHook; + +class PdfHookManager extends BaseHook { /** - * Generate NVP request message - * - * @return string + * @param HookRenderEvent $event */ - public function getRequest(); + public function onAfterPaymentModule(HookRenderEvent $event) + { + $templateData = $event->getArguments(); - /** - * Get Operation Name - * - * @return string Operation name - */ - public function getOperationName(); + $event->add( + $this->render( + 'paypal/after-payment-module.html', + $templateData + ) + ); + } } diff --git a/I18n/backOffice/default/en_US.php b/I18n/backOffice/default/en_US.php deleted file mode 100644 index 49a6781..0000000 --- a/I18n/backOffice/default/en_US.php +++ /dev/null @@ -1,11 +0,0 @@ - 'Download full log', - 'Payment configuration' => 'Payment configuration', - 'Paypal Configuration' => 'Paypal Configuration', - 'Paypal Production parameters' => 'Paypal Production parameters', - 'Paypal Sandbox parameters' => 'Paypal Sandbox parameters', - 'Paypal responses history' => 'Paypal responses history', - 'You can edit the payment confirmation email sent to the customer after a successful payment.' => 'You can edit the payment confirmation email sent to the customer after a successful payment.', -); diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php index ecf09ae..0753882 100644 --- a/I18n/backOffice/default/fr_FR.php +++ b/I18n/backOffice/default/fr_FR.php @@ -1,11 +1,89 @@ 'Télécharger l\'historique complet', - 'Payment configuration' => 'Configuration du paiement', - 'Paypal Configuration' => 'Configuration Paypal', - 'Paypal Production parameters' => 'Paramètre de production', - 'Paypal Sandbox parameters' => 'Paramètres sandbox', - 'Paypal responses history' => 'Log des échanges avec la plate-forme Paypal', - 'You can edit the payment confirmation email sent to the customer after a successful payment.' => 'Vous pouvez modifier le mail de confirmation de paiement envoyé au client.', + 'Accept payments' => 'Accept payments', + 'Account Information' => 'Account Information', + 'Add Webhook' => 'Cliquer sur Add Webhook', + 'Add a planified payment' => 'Ajouter un paiement planifié', + 'Address Information' => 'Address Information', + 'Allow the customers who haven\'t yet confirmed their email address with PayPal, to log in to your app' => 'Allow the customers who haven\'t yet confirmed their email address with PayPal, to log in to your app', + 'Automatic PayPal logs' => 'Logs automatiques de PayPal', + 'Billing agreements' => 'Billing agreements', + 'Check' => 'Cocher', + 'Click on Create App' => ' Cliquer sur Create App ', + 'Configuration' => 'Configuration', + 'Copy & Paste the Client ID in the form below' => 'Copier & Coller le Client ID dans le formulaire ci-dessous', + 'Copy & Paste the Client SECRET in the form below' => 'Copier & Coller le Client SECRET dans le formulaire ci-dessous', + 'Create REST API apps here' => 'Créer une REST API apps ici ', + 'Create a new planified payment' => 'Créer un nouveau paiement récurrent', + 'Create this planified payment' => 'Créer ce paiement récurrent', + 'critical_100' => 'DEBUG', + 'critical_200' => 'INFO', + 'critical_250' => 'NOTICE', + 'critical_300' => 'WARNING', + 'critical_400' => 'ERROR', + 'critical_500' => 'CRITICAL', + 'critical_550' => 'ALERT', + 'critical_600' => 'EMERGENCY', + 'Customer ID' => 'Client ID', + 'Cycle' => 'Cycle', + 'Date' => 'Date', + 'Delete planified payment' => 'Supprimer paiement récurrent', + 'Delete this planified payment' => 'Supprimer ce paiement récurrent', + 'Details' => 'Détails', + 'Do you really want to delete this planified payment ?' => 'Voulez-vous vraiment supprimer ce paiement récurrent ?', + 'Edit planified payment' => 'Modifier un paiement récurrent', + 'Edit planified payment %title' => 'Modifier du paiement récurrent "%title" ', + 'Edit this customer' => 'Modifier ce client', + 'Edit this planified payment' => 'Modifier ce paiement récurrent', + 'Editing planified payment "%title"' => 'Modification du paiement récurrent "%title" ', + 'Fill the fields : App Name & Sandbox developer account' => 'Remplir les champs : App Name & Sandbox developer account ', + 'Frequency' => 'Fréquence', + 'Frequency interval' => 'Interval de la fréquence', + 'Future Payments' => 'Future Payments', + 'General configuration' => 'Configuration générale', + 'General description' => 'Description générale', + 'Global informations of this planified payment' => 'Informations générales de ce paiement récurrent', + 'Help' => 'Aide', + 'Home' => 'Accueil', + 'How to configure Plannified payment' => 'Comment configurer un paiement récurrent', + 'In SANDBOX APP SETTINGS' => 'Dans la section SANDBOX APP SETTINGS ', + 'In SANDBOX WEBHOOKS' => 'Dans la section SANDBOX WEBHOOKS', + 'Invoicing' => 'Invoicing', + 'Level' => 'Niveau', + 'List of planified payments' => 'Liste des paiements récurrents', + 'Log' => 'Log', + 'Log In on developer.paypal.com' => 'Se connecter sur https://developer.paypal.com ', + 'Log In with PayPal' => 'Log In with PayPal', + 'Max amount' => 'Montant maximum', + 'Min amount' => 'Montant minium', + 'New recursive invoice from order %id' => 'Nouvelle commande récursive créée à partir de la commande %id', + 'No planified payment has been created yet. Click the + button to create one.' => 'Aucun paiement récurrent trouvé. Cliquer sur le bouton + ci-dessu pour en créer un', + 'None' => 'Aucun', + 'Order ID' => 'Commande ID', + 'PayPal Here' => 'PayPal Here', + 'Payment configuration' => 'Configuration paiement', + 'Payouts' => 'Payouts', + 'Personal Information' => 'Personal Information', + 'Planified payment' => 'Paiement récurrent', + 'Planified payment configuration' => 'Configuration paiement récurrent', + 'Planified payment created on %date_create. Last modification: %date_change' => 'Paiement récurrent créé le %date_create. Dernière modification : %date_change ', + 'Planified payments' => 'Paiements récurrents', + 'Production configuration' => 'Configuration mode Production', + 'Return URL' => ' Return URL ', + 'SandBox configuration' => 'Configuration mode Bac à Sable', + 'See webhook details' => 'Voir détails du webhook', + 'That\'s it !' => 'Et voilà !', + 'These planned payments will appear in step 4 of the purchase tunnel when selecting the payment method.' => 'Ces paiements récurrents apparaitront à l\'étape 4 du tunnel d\'achat lors de la sélection du moyen de paiement.', + 'This feature uses PayPal\'s Billing Plan and Agreement. It allows debiting a client recursively directly from PayPal.' => 'Cette fonctionnalité se sert des Billing Plan et Agreement de PayPal. Elle permet de débiter un client de manière récursive directement depuis PayPal.', + 'This informations can be found directly in concerned order details.' => 'Ces informations peuvent se retrouver directement sur les détails des commandes concernées.', + 'This is where we log all the transactions made with PayPal. PayPal webhooks also automatically feed these logs.' => 'C\'est ici que nous loggons l\'ensemble des transactions réalisées avec PayPal. Les webhooks de PayPal viennent aussi alimenter automatiquement ces logs.', + 'This method use PayPal webhooks and works only in HTTPS !' => 'Cette méthode utilise les WEBHOOKs de PayPal et ne fonctionne donc QUE ET UNIQUEMENT QUE en HTTPS !', + 'This method works only with PayPal PRO UK account. Please contact PayPal to upgrade your account if you need this service. For more informations, go here' => 'Ce moyen de paiement ne fonctionne QUE ET UNIQUEMENT QUE si vous avez un compte PayPal PRO UK. Merci de contacter PayPal pour mettre à jour votre compte si vous avez besoin de ce service. Pour plus d\'informations, rendez-vous ici', + 'This urls can take 3 hours to be taken in consideration' => ' Ces urls peuvent mettre 3 heures pour être prises en considération', + 'Title' => 'Titre', + 'Use Seamless Checkout' => 'Use Seamless Checkout', + 'You can edit the payment confirmation email sent to the customer after a successful payment.' => 'Vous pouvez modifier l\'email de confirmation de paiement envoyé au client après un paiement réalisé avec succès.', + 'You can add some planified payment here.' => 'Vous pouvez ajouter des paiements récurrents ici. ', + 'critical_{$log->getLevel()}' => 'critical_{$log->getLevel()}', ); diff --git a/I18n/email/default/en_US.php b/I18n/email/default/en_US.php deleted file mode 100644 index ebc271c..0000000 --- a/I18n/email/default/en_US.php +++ /dev/null @@ -1,12 +0,0 @@ - 'Dear customer', - 'Payment of your order %ref' => 'Payment of your order %ref', - 'Thank you again for your purchase.' => 'Thank you again for your purchase.', - 'The %store_name team.' => 'The %store_name team.', - 'The payment of your order %ref is confirmed' => 'The payment of your order %ref is confirmed', - 'This is a confirmation of the payment of your order %ref via Paypal on our shop.' => 'This is a confirmation of the payment of your order %ref via Paypal on our shop.', - 'View this order in your account at %shop_name' => 'View this order in your account at %shop_name', - 'Your invoice is now available in your customer account at %url.' => 'Your invoice is now available in your customer account at %url.', -); diff --git a/I18n/email/default/fr_FR.php b/I18n/email/default/fr_FR.php deleted file mode 100644 index 2858202..0000000 --- a/I18n/email/default/fr_FR.php +++ /dev/null @@ -1,12 +0,0 @@ - 'Cher client', - 'Payment of your order %ref' => 'Paiement de votre commande %ref', - 'Thank you again for your purchase.' => 'Merci encore pour votre commande.', - 'The %store_name team.' => 'L\'équipe %store_name', - 'The payment of your order %ref is confirmed' => 'Le paiement Paypal de votre commande %ref est confirmé.', - 'This is a confirmation of the payment of your order %ref via Paypal on our shop.' => 'Ceci est une confirmation du paiement Paypal de votre commande %ref.', - 'View this order in your account at %shop_name' => 'Les détails de cette commande sont disponibles dans votre compte client sur %shop_name', - 'Your invoice is now available in your customer account at %url.' => 'Les détails de cette commande sont disponibles dans votre compte client sur %url', -); diff --git a/I18n/en_US.php b/I18n/en_US.php old mode 100755 new mode 100644 index 9f274cc..0b4fa14 --- a/I18n/en_US.php +++ b/I18n/en_US.php @@ -1,45 +1,4 @@ '(Previous log is in %file file.)\n', - 'Activate sandbox mode' => 'Activate sandbox mode', - 'Allowed IPs in test mode' => 'Allowed IPs in test mode', - 'Discount' => 'Discount', - 'Failed to find PayerID' => 'Failed to find PayerID', - 'Failed to get a valid Paypal response. Please try again' => 'Failed to get a valid Paypal response. Please try again', - 'Failed to get customer delivery address' => 'Failed to get customer delivery address', - 'Failed to validate payment parameters' => 'Failed to validate payment parameters', - 'Failed to validate your payment' => 'Failed to validate your payment', - 'If checked, a payment confirmation e-mail is sent to the customer.' => 'If checked, a payment confirmation e-mail is sent to the customer.', - 'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator' => 'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator', - 'Invalid Paypal token. Please try again.' => 'Invalid Paypal token. Please try again.', - 'Invalid order ID. This order doesn\'t exists or doesn\'t belong to you.' => 'Invalid order ID. This order doesn\'t exists or doesn\'t belong to you.', - 'List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line' => 'List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line', - 'Maximum items in cart' => 'Maximum items in cart', - 'Maximum number of items in the customer cart for which this payment method is available.' => 'Maximum number of items in the customer cart for which this payment method is available.', - 'Maximum order total' => 'Maximum order total', - 'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum' => 'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum', - 'Minimum order total' => 'Minimum order total', - 'Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum' => 'Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum', - 'Paypal configuration' => 'Paypal configuration', - 'Paypal transaction is pending. Reason: %reason' => 'Paypal transaction is pending. Reason: %reason', - 'Send a payment confirmation e-mail' => 'Send a payment confirmation e-mail', - 'Send order confirmation on payment success' => 'Send order confirmation on payment success', - 'Sorry, something did not worked with Paypal. Please try again, or use another payment type' => 'Sorry, something did not worked with Paypal. Please try again, or use another payment type', - 'The Paypal sandbox signature' => 'The Paypal sandbox signature', - 'The Paypal signature' => 'The Paypal signature', - 'The log file doesn\'t exists yet.' => 'The log file doesn\'t exists yet.', - 'The log file is empty.' => 'The log file is empty.', - 'The password option must be set.' => 'The password option must be set.', - 'The signature option must be set.' => 'The signature option must be set.', - 'The username option must be set.' => 'The username option must be set.', - 'Unexpected error: %mesg' => 'Unexpected error: %mesg', - 'You canceled your payment' => 'You canceled your payment', - 'Your Paypal login' => 'Your Paypal login', - 'Your Paypal password' => 'Your Paypal password', - 'Your Paypal sandbox login' => 'Your Paypal sandbox login', - 'Your Paypal sandbox password' => 'Your Paypal sandbox password', - 'login' => 'username', - 'password' => 'password', - 'signature' => 'signature', + // 'an english string' => 'The displayed english string', ); diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php old mode 100755 new mode 100644 index 98898e0..fa5515d --- a/I18n/fr_FR.php +++ b/I18n/fr_FR.php @@ -1,48 +1,76 @@ '(L\'historique précédent est dans %file file.)\n', - 'Activate sandbox mode' => 'Activer la sandbox ( mode de test )', - 'Allowed IPs in test mode' => 'Adresse IP autorisées en mode sandbox', - 'Discount' => 'Remise', - 'Failed to find PayerID' => 'Ne peut obtenir le PayerID', - 'Failed to get a valid Paypal response. Please try again' => 'Ne peut obtenir la réponse de Paypal', - 'Failed to get customer delivery address' => 'Ne peut obtenir l\'adresse de livraison du client', - 'Failed to validate payment parameters' => 'La validation des paramètres de paiement a échoué', - 'Failed to validate your payment' => 'La validation du paiement a échoué', - 'If checked, a payment confirmation e-mail is sent to the customer.' => 'Si cette case est cochée, un mail de confirmation de paiement sera envoyé au client.', - 'If checked, all products will be sent to Paypal.' => 'Si cette case est cochée, tout les produits seront envoyé à Paypal.', - 'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator' => 'Si cette case est cochée, le mail de confirmation de commande sera envoyé au client seulement si son paiement est validé.', - 'Invalid Paypal token. Please try again.' => 'Le token Paypal est invalide. Merci de ré-essayer', - 'Invalid order ID. This order doesn\'t exists or doesn\'t belong to you.' => 'ID de commande invalide', - 'List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line' => 'En mode sandbox, liste des adresses IP autorisées à utiliser le module de paiement en front office. Indiquer une adresse par ligne. Votre IP actuelle est %ip', - 'Maximum items in cart' => 'Nombre maximum d\'éléments dans le panier', - 'Maximum number of items in the customer cart for which this payment method is available.' => 'Nombre d\'éléments dans le panier au delà duquel ce paiement n\'est plus disponible.', - 'Maximum order total' => 'Montant de commande maximum', - 'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum' => 'Montant de commande maximum dans la devise par défaut au delà duquel ce paiement n\'est plus disponible. 0 = pas de maximum', - 'Minimum order total' => 'Montant de commande minimum', - 'Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum' => 'Montant de commande minimum dans la devise par défaut à partir duquel ce paiement devient disponible. 0 = pas de minimum', - 'Order' => 'Commande', - 'Paypal configuration' => 'Configuration Paypal', - 'Paypal transaction is pending. Reason: %reason' => 'La transaction Paypal est suspendue: %reason', - 'Send a payment confirmation e-mail' => 'Envoyer une confirmation de paiement', - 'Send details of all products to Paypal' => 'Envoyer les détails de tout les produits à Paypal', - 'Send order confirmation on payment success' => 'Confirmation de commande si le paiement réussit', - 'Sorry, something did not worked with Paypal. Please try again, or use another payment type' => 'Désolé, quelque chose n\'a pas marché avec Paypal', - 'The Paypal sandbox signature' => 'Le mot de passe de votre compte sandbox Paypal', - 'The Paypal signature' => 'La signature associée à votre compte.', - 'The log file doesn\'t exists yet.' => 'Le fichier de log n\'existe pas encore.', - 'The log file is empty.' => 'Le fichier de log est vide.', - 'The password option must be set.' => 'Veuillez indiquer le mot de passe', - 'The signature option must be set.' => 'Veuillez indiquer la signature', - 'The username option must be set.' => 'Veuillez indiquer le nom d\'utilisateur', - 'Unexpected error: %mesg' => 'Erreur inattendue: %mesg', - 'You canceled your payment' => 'Vous avez annulé votre demande de paiement', - 'Your Paypal login' => 'Le login de votre compte Paypal', - 'Your Paypal password' => 'Le mot de passe de votre compte Paypal', - 'Your Paypal sandbox login' => 'Le login de votre compte sandbox Paypal', - 'Your Paypal sandbox password' => 'Le mot de passe de votre compte sandbox Paypal', - 'login' => 'Nom d\'utilisateur', - 'password' => 'Mot de passe', - 'signature' => 'Signature', + 'Activate Express Checkout payment with PayPal' => 'Activer le paiement : "PAYPAL EXPRESS"', + 'Activate payment with PayPal account' => 'Activer le paiement par : "PAYPAL"', + 'Activate payment with credit card' => 'Activer le paiement par : "CARTE BANCAIRE"', + 'Activate payment with planified payment' => 'Activer le paiement par : "PAIEMENT RECURRENT"', + 'Activate sandbox mode' => 'Activer le mode Bac à Sable', + 'Allowed IPs in test mode' => 'IP autorisées pour le mode Bac à sable', + 'CVV' => 'Code secret (3 chiffres)', + 'Card number' => 'Numéro de la carte', + 'Card type' => 'Type de carte', + 'Credit card is invalid' => 'Carte bancaire invalide', + 'Cycle' => 'Cycle', + 'Expire month' => 'Mois d\'expiration', + 'Expire year' => 'Année d\'expiration', + 'Express checkout begin with cart %id' => 'Début du paiement EXPRESS CHECKOUT avec la panier : %id', + 'Express checkout failed in expressCheckoutOkAction() function' => 'Echec de la méthode Express Checkout de PayPal dans la function expressCheckoutOkAction()', + 'Express Checkout login failed' => 'Echec de la connexion avec EXPRESS CHECKOUT depuis le panier', + 'Frequency' => 'Fréquence', + 'Frequency interval' => 'Interval de la fréquence', + 'If checked, a payment confirmation e-mail is sent to the customer after each PayPal transaction.' => 'Si cochée, un mail de confirmation de paiement sera envoyés grâce aux webhook directement rattachés à PayPal', + 'If checked, a payment confirmation e-mail is sent to the customer.' => 'Si cochée, le client sera informé dès que sa commande passera en payée.', + 'If checked, a PayPal popup will be used to execute the payment.' => 'Si cochée, le paiement se déroulera via une popup PayPal pour rester sur le site marchand.', + 'If checked, the order can be paid by PayPal account.' => 'Si cochée, la commande pourra être payée par un simple compte PayPal', + 'If checked, the order can be paid by credit card.' => 'Si cochée, la commande pourra être payée par carte bancaire (PayPal se chargera de vérifier sa validité)', + 'If checked, the order can be paid by planified payement.' => 'Si cochée, la commande pourra être payée par paiement récurrent (PayPal agreement)', + 'If checked, the order can be paid directly from cart.' => 'Si cochée, la commande pourra être payée directement depuis le panier', + 'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator' => 'Si cochée, le mail de confirmation de commande ne sera pas envoyé au client dès que celui-ci cliquera sur l\'une des méthodes de paiement de PayPal', + 'Invalid charge type send to create charge model' => 'Paramètre "type" invalide pour générer un "Charge Model"', + 'Invalid fail action send to create merchant preference' => 'Paramètre "fail action" invalide pour générer un "Merchant Preference"', + 'Invalid number of charge models send to create payment definition' => 'Nombre de "Charge Models" insuffisant pour générer un "Payment Definition"', + 'Invalid number of payment definition send to generate billing plan' => 'Nombre de "Payment definition" insuffisant pour générer un "Billing Plan"', + 'Invalid payment frequency send to create payment definition' => 'Paramètre "frequency" invalide pour générer un "Payment Definition"', + 'Invalid payment type send to create payment definition' => 'Paramètre "type" invalide pour générer un "Payment Definition"', + 'Invalid planified payment id : %id' => 'ID du paiement récurrent incorrect : %id', + 'Invalid type send to generate billing plan' => 'Paramètre "type" invalide pour générer un "Billing Plan"', + 'Let value to 0 if you don\'t want a maximum' => 'Laisser 0 si vous ne voulez pas de maximum', + 'Let value to 0 if you don\'t want a minimum' => 'Laisser 0 si vous ne voulez pas de minimum', + 'List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line' => 'Liste des adresses IP autorisées pour payer en Front lorsque le mmode Bac à Sable est activé (votre adresse IP actuelle est %ip). Une adresse IP par ligne.', + 'Max amount' => 'Montant maximum', + 'Maximum items in cart' => 'Nombre d\'articles maximum dans le panier', + 'Maximum number of items in the customer cart for which this payment method is available.' => 'Nombre maximum d\'articles dans le panier pour que le moyen de paiement soit valide.', + 'Maximum order total' => 'Montant maximum de la commande', + 'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum' => 'Montant maximum de la commande dans la devise courante pour autoriser le paiement. Mettre 0 pour ne pas avoir de maximum.', + 'Merchant ID' => 'Identifiant du marchand', + 'Method agreementOkAction => One of this parameter is invalid : $token = %token, $orderId = %order_id' => 'Method agreementOkAction => L\'un de ces paramètres est incorrecte : $token = %token, $orderId = %order_id', + 'Method okAction => One of this parameter is invalid : $payerId = %payer_id, $orderId = %order_id' => 'Method okAction => L\'un de ces paramètres est incorrecte : $payerId = %payer_id, $orderId = %order_id', + 'Min amount' => 'Montant minium', + 'Minimum order total' => 'Montant minimum de la commande', + 'Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum' => ' Montant minimum de la commande dans la devise courante pour autoriser le paiement. Mettre 0 pour ne pas avoir de minimum.', + 'Order address no found to generate PayPal shipping address' => 'Adresse de la commande non trouvée pour générer l\'adresse de livraison PayPal', + 'Order created with success in PayPal with method : %method' => 'Commande créée avec succès success via PayPal avec la méthode : %method ', + 'Order failed with method : %method' => 'Echec du paiement avec la méthode : %method', + 'Order payed with success in PayPal with method : %method' => 'Commande créée avec succès avec PayPal avec la méthode : %method ', + 'Order payed with success with method : %method' => 'Paiement réalisé avec succès avec la méthode : %method', + 'PayPal method' => 'Méthode PayPal', + 'Paypal configuration' => 'Configuration PayPal', + 'Position' => 'Position', + 'Send a payment confirmation e-mail' => 'Envoyer le mail de confirmation de paiement', + 'Send a recursive payment confirmation e-mail' => 'Envoyer le mail de confirmation de paiement pour les commandes récursives', + 'Send order confirmation on payment success' => 'Bloquer le mail de confirmation de commande (mail envoyé dès qu\'une commande est créée même si elle n\'est pas payée)', + 'The Paypal identity merchant account' => 'L\'indentifiant PayPal unique du compte marchand ', + 'The delivery module is not valid.' => 'Le module de transport n\'est pas valide.', + 'The description of the planified payment' => 'La description du paiement récurrent', + 'The locale of the planified payment' => 'La locale du paiement récurrent', + 'The title of the planified payment' => 'Le titre du paiement récurrent', + 'This value should not be blank' => 'Cette valeur ne doit pas être vide', + 'Use InContext mode for classic PayPal payment' => 'Utiliser le mode InContext pour le payment classic PayPal', + 'Your Paypal login' => 'Client ID', + 'Your Paypal password' => 'Client SECRET', + 'Your Paypal sandbox login' => 'Client ID', + 'Your Paypal sandbox password' => 'Client SECRET', + 'login' => 'Client ID', + 'password' => 'Client SECRET', ); diff --git a/I18n/frontOffice/default/fr_FR.php b/I18n/frontOffice/default/fr_FR.php new file mode 100644 index 0000000..82d6a7f --- /dev/null +++ b/I18n/frontOffice/default/fr_FR.php @@ -0,0 +1,12 @@ + 'jours', + 'MONTH' => 'Mois', + 'Finish payment with PayPal' => 'Terminer le paiement avec PayPal', + 'Payment in %x times every %frequency_interval %frequency' => 'Paiement en %x fois, tout les %frequency_interval %frequency', + 'Planified payment' => 'Paiement récurrent', + 'planified_payment' => 'Paiement récurrent', + 'WEEK' => 'Semaines', + 'YEAR' => 'Années', +); diff --git a/I18n/pdf/default/fr_FR.php b/I18n/pdf/default/fr_FR.php new file mode 100644 index 0000000..630b4f0 --- /dev/null +++ b/I18n/pdf/default/fr_FR.php @@ -0,0 +1,10 @@ + 'Jours', + 'MONTH' => 'Mois', + 'Payment in %x times every %frequency_interval %frequency' => 'Paiement en %x fois, tout les %frequency_interval %frequency', + 'Planified payment' => 'Paiement récurrent', + 'WEEK' => 'Semaines', + 'YEAR' => 'Années', +); diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 94a9ed0..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/Listener/SendConfirmationEmail.php b/Listener/SendConfirmationEmail.php deleted file mode 100644 index 3032c4b..0000000 --- a/Listener/SendConfirmationEmail.php +++ /dev/null @@ -1,101 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Paypal\Listener; - -use Paypal\Paypal; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Thelia\Action\BaseAction; -use Thelia\Core\Event\Order\OrderEvent; -use Thelia\Core\Event\TheliaEvents; -use Thelia\Mailer\MailerFactory; - -/** - * Class SendEMail - * @package IciRelais\Listener - * @author Thelia - */ -class SendConfirmationEmail extends BaseAction implements EventSubscriberInterface -{ - /** - * @var MailerFactory - */ - protected $mailer; - - public function __construct(MailerFactory $mailer) - { - $this->mailer = $mailer; - } - - /** - * @param OrderEvent $event - * - * @throws \Exception if the message cannot be loaded. - */ - public function sendConfirmationEmail(OrderEvent $event) - { - if (Paypal::getConfigValue('send_confirmation_message_only_if_paid')) { - // We send the order confirmation email only if the order is paid - $order = $event->getOrder(); - - if (! $order->isPaid() && $order->getPaymentModuleId() == Paypal::getModuleId()) { - $event->stopPropagation(); - } - } - } - - /* - * @params OrderEvent $order - * Checks if order payment module is paypal and if order new status is paid, send an email to the customer. - */ - public function updateStatus(OrderEvent $event) - { - $order = $event->getOrder(); - - if ($order->isPaid() && $order->getPaymentModuleId() === Paypal::getModuleId()) { - if (Paypal::getConfigValue('send_payment_confirmation_message')) { - $this->mailer->sendEmailToCustomer( - Paypal::CONFIRMATION_MESSAGE_NAME, - $order->getCustomer(), - [ - 'order_id' => $order->getId(), - 'order_ref' => $order->getRef() - ] - ); - } - - // Send confirmation email if required. - if (Paypal::getConfigValue('send_confirmation_message_only_if_paid')) { - $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event); - } - } - } - - public static function getSubscribedEvents() - { - return array( - TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128), - TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL => array("sendConfirmationEmail", 129) - ); - } -} diff --git a/Loop/PayPalLogLoop.php b/Loop/PayPalLogLoop.php new file mode 100644 index 0000000..8509345 --- /dev/null +++ b/Loop/PayPalLogLoop.php @@ -0,0 +1,154 @@ +getResultDataCollection() as $model) { + + $row = new LoopResultRow($model); + + $row->set('log', $model); + + $this->addOutputFields($row, $model); + + $loopResult->addRow($row); + } + + return $loopResult; + } + + /** + * @return PaypalLogQuery + */ + public function buildModelCriteria() + { + $query = new PaypalLogQuery(); + + if (null != $orderId = $this->getOrderId()) { + $query->filterByOrderId($orderId); + } + + if (null != $customerId = $this->getCustomerId()) { + $query->filterByCustomerId($customerId); + } + + if (null != $channel = $this->getChannel()) { + $query->filterByChannel($channel); + } + + if (null != $level = $this->getLevel()) { + $query->filterByLevel($level); + } + + $this->buildModelCriteriaOrder($query); + $query->groupById(); + + return $query; + } + + /** + * @param PaypalLogQuery $query + */ + protected function buildModelCriteriaOrder(PaypalLogQuery $query) + { + foreach ($this->getOrder() as $order) { + switch ($order) { + case 'id': + $query->orderById(); + break; + case 'id-reverse': + $query->orderById(Criteria::DESC); + break; + case 'order-id': + $query->orderById(); + break; + case 'order-id-reverse': + $query->orderById(Criteria::DESC); + break; + case 'customer-id': + $query->addAscendingOrderByColumn('i18n_TITLE'); + break; + case 'customer-id-reverse': + $query->addDescendingOrderByColumn('i18n_TITLE'); + break; + case 'date': + $query->orderByCreatedAt(); + break; + case 'date-reverse': + $query->orderByCreatedAt(Criteria::DESC); + break; + default: + $query->orderById(); + break; + } + } + } + + /** + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntTypeArgument('order_id'), + Argument::createIntTypeArgument('customer_id'), + Argument::createAnyTypeArgument('channel'), + Argument::createIntTypeArgument('level'), + Argument::createEnumListTypeArgument( + 'order', + [ + 'id', + 'id-reverse', + 'order-id', + 'order-id-reverse', + 'customer-id', + 'customer-id-reverse', + 'date', + 'date-reverse', + ], + 'id' + ) + ); + } +} diff --git a/Loop/PayPalOrderLoop.php b/Loop/PayPalOrderLoop.php new file mode 100644 index 0000000..ed07f81 --- /dev/null +++ b/Loop/PayPalOrderLoop.php @@ -0,0 +1,109 @@ +getResultDataCollection() as $model) { + $row = new LoopResultRow($model); + + $row->set('paypal_order', $model); + + $this->addOutputFields($row, $model); + + $loopResult->addRow($row); + } + + return $loopResult; + } + + /** + * @return PaypalOrderQuery + */ + public function buildModelCriteria() + { + $query = new PaypalOrderQuery(); + + if (null != $id = $this->getId()) { + $query->filterById($id); + } + + $this->buildModelCriteriaOrder($query); + + return $query; + } + + /** + * @param PaypalOrderQuery $query + */ + protected function buildModelCriteriaOrder(PaypalOrderQuery $query) + { + foreach ($this->getOrder() as $order) { + switch ($order) { + case 'id': + $query->orderById(); + break; + case 'id-reverse': + $query->orderById(Criteria::DESC); + break; + default: + break; + } + } + } + + /** + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createEnumListTypeArgument( + 'order', + [ + 'id', + 'id-reverse' + ], + 'id' + ) + ); + } +} diff --git a/Loop/PayPalOrderVersionLoop.php b/Loop/PayPalOrderVersionLoop.php new file mode 100644 index 0000000..334c60c --- /dev/null +++ b/Loop/PayPalOrderVersionLoop.php @@ -0,0 +1,110 @@ +getResultDataCollection() as $model) { + $row = new LoopResultRow($model); + + $row->set('paypal_order_version', $model); + + $this->addOutputFields($row, $model); + + $loopResult->addRow($row); + } + + return $loopResult; + } + + /** + * @return PaypalOrderVersionQuery + */ + public function buildModelCriteria() + { + $query = new PaypalOrderVersionQuery(); + + if (null != $id = $this->getId()) { + $query->filterById($id); + } + + $this->buildModelCriteriaOrder($query); + + return $query; + } + + /** + * @param PaypalOrderVersionQuery $query + */ + protected function buildModelCriteriaOrder(PaypalOrderVersionQuery $query) + { + foreach ($this->getOrder() as $order) { + switch ($order) { + case 'id': + $query->orderById(); + break; + case 'id-reverse': + $query->orderById(Criteria::DESC); + break; + case 'version': + $query->orderByVersion(); + break; + case 'version-reverse': + $query->orderByVersion(Criteria::DESC); + break; + default: + break; + } + } + } + + /** + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createEnumListTypeArgument( + 'order', + [ + 'id', + 'id-reverse', + 'version', + 'version-reverse' + ], + 'version' + ) + ); + } +} diff --git a/Loop/PayPalPlanifiedPaymentLoop.php b/Loop/PayPalPlanifiedPaymentLoop.php new file mode 100644 index 0000000..c488183 --- /dev/null +++ b/Loop/PayPalPlanifiedPaymentLoop.php @@ -0,0 +1,133 @@ +getCurrentRequest()->getSession()->get('thelia.current.lang'); + + /** + * @var PaypalPlanifiedPayment $model + */ + foreach ($loopResult->getResultDataCollection() as $model) { + $model->getTranslation($lang->getLocale()); + $row = new LoopResultRow($model); + + $row->set('planifiedPayment', $model); + + $this->addOutputFields($row, $model); + + $loopResult->addRow($row); + } + + return $loopResult; + } + + /** + * @return PaypalPlanifiedPaymentQuery + */ + public function buildModelCriteria() + { + $query = new PaypalPlanifiedPaymentQuery(); + + if (null != $id = $this->getId()) { + $query->filterById($id); + } + + /* manage translations */ + $this->configureI18nProcessing( + $query, + array( + 'TITLE', + 'DESCRIPTION' + ) + ); + + $this->buildModelCriteriaOrder($query); + $query->groupById(); + + return $query; + } + + /** + * @param PaypalPlanifiedPaymentQuery $query + */ + protected function buildModelCriteriaOrder(PaypalPlanifiedPaymentQuery $query) + { + foreach ($this->getOrder() as $order) { + switch ($order) { + case 'id': + $query->orderById(); + break; + case 'id-reverse': + $query->orderById(Criteria::DESC); + break; + case 'position': + $query->orderById(); + break; + case 'position-reverse': + $query->orderById(Criteria::DESC); + break; + case 'title': + $query->addAscendingOrderByColumn('i18n_TITLE'); + break; + case 'title-reverse': + $query->addDescendingOrderByColumn('i18n_TITLE'); + break; + default: + $query->orderById(); + break; + } + } + } + + /** + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createEnumListTypeArgument( + 'order', + [ + 'id', + 'id-reverse', + 'position', + 'position-reverse', + 'title', + 'title-reverse', + ], + 'id' + ) + ); + } +} diff --git a/Model/Base/PaypalCart.php b/Model/Base/PaypalCart.php new file mode 100644 index 0000000..b7c63ca --- /dev/null +++ b/Model/Base/PaypalCart.php @@ -0,0 +1,1655 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalCart instance. If + * obj is an instance of PaypalCart, delegates to + * equals(PaypalCart). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalCart The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalCart The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [credit_card_id] column value. + * + * @return string + */ + public function getCreditCardId() + { + + return $this->credit_card_id; + } + + /** + * Get the [planified_payment_id] column value. + * + * @return int + */ + public function getPlanifiedPaymentId() + { + + return $this->planified_payment_id; + } + + /** + * Get the [express_payment_id] column value. + * + * @return string + */ + public function getExpressPaymentId() + { + + return $this->express_payment_id; + } + + /** + * Get the [express_payer_id] column value. + * + * @return string + */ + public function getExpressPayerId() + { + + return $this->express_payer_id; + } + + /** + * Get the [express_token] column value. + * + * @return string + */ + public function getExpressToken() + { + + return $this->express_token; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalCartTableMap::ID] = true; + } + + if ($this->aCart !== null && $this->aCart->getId() !== $v) { + $this->aCart = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [credit_card_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setCreditCardId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->credit_card_id !== $v) { + $this->credit_card_id = $v; + $this->modifiedColumns[PaypalCartTableMap::CREDIT_CARD_ID] = true; + } + + + return $this; + } // setCreditCardId() + + /** + * Set the value of [planified_payment_id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setPlanifiedPaymentId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_payment_id !== $v) { + $this->planified_payment_id = $v; + $this->modifiedColumns[PaypalCartTableMap::PLANIFIED_PAYMENT_ID] = true; + } + + if ($this->aPaypalPlanifiedPayment !== null && $this->aPaypalPlanifiedPayment->getId() !== $v) { + $this->aPaypalPlanifiedPayment = null; + } + + + return $this; + } // setPlanifiedPaymentId() + + /** + * Set the value of [express_payment_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setExpressPaymentId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->express_payment_id !== $v) { + $this->express_payment_id = $v; + $this->modifiedColumns[PaypalCartTableMap::EXPRESS_PAYMENT_ID] = true; + } + + + return $this; + } // setExpressPaymentId() + + /** + * Set the value of [express_payer_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setExpressPayerId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->express_payer_id !== $v) { + $this->express_payer_id = $v; + $this->modifiedColumns[PaypalCartTableMap::EXPRESS_PAYER_ID] = true; + } + + + return $this; + } // setExpressPayerId() + + /** + * Set the value of [express_token] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setExpressToken($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->express_token !== $v) { + $this->express_token = $v; + $this->modifiedColumns[PaypalCartTableMap::EXPRESS_TOKEN] = true; + } + + + return $this; + } // setExpressToken() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalCartTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalCartTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalCartTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalCartTableMap::translateFieldName('CreditCardId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->credit_card_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalCartTableMap::translateFieldName('PlanifiedPaymentId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_payment_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalCartTableMap::translateFieldName('ExpressPaymentId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->express_payment_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalCartTableMap::translateFieldName('ExpressPayerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->express_payer_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalCartTableMap::translateFieldName('ExpressToken', TableMap::TYPE_PHPNAME, $indexType)]; + $this->express_token = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PaypalCartTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PaypalCartTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 8; // 8 = PaypalCartTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalCart object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCart !== null && $this->id !== $this->aCart->getId()) { + $this->aCart = null; + } + if ($this->aPaypalPlanifiedPayment !== null && $this->planified_payment_id !== $this->aPaypalPlanifiedPayment->getId()) { + $this->aPaypalPlanifiedPayment = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalCartTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalCartQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCart = null; + $this->aPaypalPlanifiedPayment = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalCart::setDeleted() + * @see PaypalCart::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCartTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalCartQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCartTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(PaypalCartTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(PaypalCartTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(PaypalCartTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalCartTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCart !== null) { + if ($this->aCart->isModified() || $this->aCart->isNew()) { + $affectedRows += $this->aCart->save($con); + } + $this->setCart($this->aCart); + } + + if ($this->aPaypalPlanifiedPayment !== null) { + if ($this->aPaypalPlanifiedPayment->isModified() || $this->aPaypalPlanifiedPayment->isNew()) { + $affectedRows += $this->aPaypalPlanifiedPayment->save($con); + } + $this->setPaypalPlanifiedPayment($this->aPaypalPlanifiedPayment); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalCartTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalCartTableMap::CREDIT_CARD_ID)) { + $modifiedColumns[':p' . $index++] = 'CREDIT_CARD_ID'; + } + if ($this->isColumnModified(PaypalCartTableMap::PLANIFIED_PAYMENT_ID)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_PAYMENT_ID'; + } + if ($this->isColumnModified(PaypalCartTableMap::EXPRESS_PAYMENT_ID)) { + $modifiedColumns[':p' . $index++] = 'EXPRESS_PAYMENT_ID'; + } + if ($this->isColumnModified(PaypalCartTableMap::EXPRESS_PAYER_ID)) { + $modifiedColumns[':p' . $index++] = 'EXPRESS_PAYER_ID'; + } + if ($this->isColumnModified(PaypalCartTableMap::EXPRESS_TOKEN)) { + $modifiedColumns[':p' . $index++] = 'EXPRESS_TOKEN'; + } + if ($this->isColumnModified(PaypalCartTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalCartTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO paypal_cart (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'CREDIT_CARD_ID': + $stmt->bindValue($identifier, $this->credit_card_id, PDO::PARAM_STR); + break; + case 'PLANIFIED_PAYMENT_ID': + $stmt->bindValue($identifier, $this->planified_payment_id, PDO::PARAM_INT); + break; + case 'EXPRESS_PAYMENT_ID': + $stmt->bindValue($identifier, $this->express_payment_id, PDO::PARAM_STR); + break; + case 'EXPRESS_PAYER_ID': + $stmt->bindValue($identifier, $this->express_payer_id, PDO::PARAM_STR); + break; + case 'EXPRESS_TOKEN': + $stmt->bindValue($identifier, $this->express_token, PDO::PARAM_STR); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalCartTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getCreditCardId(); + break; + case 2: + return $this->getPlanifiedPaymentId(); + break; + case 3: + return $this->getExpressPaymentId(); + break; + case 4: + return $this->getExpressPayerId(); + break; + case 5: + return $this->getExpressToken(); + break; + case 6: + return $this->getCreatedAt(); + break; + case 7: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalCart'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalCart'][$this->getPrimaryKey()] = true; + $keys = PaypalCartTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getCreditCardId(), + $keys[2] => $this->getPlanifiedPaymentId(), + $keys[3] => $this->getExpressPaymentId(), + $keys[4] => $this->getExpressPayerId(), + $keys[5] => $this->getExpressToken(), + $keys[6] => $this->getCreatedAt(), + $keys[7] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCart) { + $result['Cart'] = $this->aCart->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aPaypalPlanifiedPayment) { + $result['PaypalPlanifiedPayment'] = $this->aPaypalPlanifiedPayment->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalCartTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setCreditCardId($value); + break; + case 2: + $this->setPlanifiedPaymentId($value); + break; + case 3: + $this->setExpressPaymentId($value); + break; + case 4: + $this->setExpressPayerId($value); + break; + case 5: + $this->setExpressToken($value); + break; + case 6: + $this->setCreatedAt($value); + break; + case 7: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalCartTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setCreditCardId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setPlanifiedPaymentId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setExpressPaymentId($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setExpressPayerId($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setExpressToken($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalCartTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalCartTableMap::ID)) $criteria->add(PaypalCartTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalCartTableMap::CREDIT_CARD_ID)) $criteria->add(PaypalCartTableMap::CREDIT_CARD_ID, $this->credit_card_id); + if ($this->isColumnModified(PaypalCartTableMap::PLANIFIED_PAYMENT_ID)) $criteria->add(PaypalCartTableMap::PLANIFIED_PAYMENT_ID, $this->planified_payment_id); + if ($this->isColumnModified(PaypalCartTableMap::EXPRESS_PAYMENT_ID)) $criteria->add(PaypalCartTableMap::EXPRESS_PAYMENT_ID, $this->express_payment_id); + if ($this->isColumnModified(PaypalCartTableMap::EXPRESS_PAYER_ID)) $criteria->add(PaypalCartTableMap::EXPRESS_PAYER_ID, $this->express_payer_id); + if ($this->isColumnModified(PaypalCartTableMap::EXPRESS_TOKEN)) $criteria->add(PaypalCartTableMap::EXPRESS_TOKEN, $this->express_token); + if ($this->isColumnModified(PaypalCartTableMap::CREATED_AT)) $criteria->add(PaypalCartTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalCartTableMap::UPDATED_AT)) $criteria->add(PaypalCartTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalCartTableMap::DATABASE_NAME); + $criteria->add(PaypalCartTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalCart (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setCreditCardId($this->getCreditCardId()); + $copyObj->setPlanifiedPaymentId($this->getPlanifiedPaymentId()); + $copyObj->setExpressPaymentId($this->getExpressPaymentId()); + $copyObj->setExpressPayerId($this->getExpressPayerId()); + $copyObj->setExpressToken($this->getExpressToken()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalCart Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCart object. + * + * @param ChildCart $v + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + * @throws PropelException + */ + public function setCart(ChildCart $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aCart = $v; + + // Add binding for other direction of this 1:1 relationship. + if ($v !== null) { + $v->setPaypalCart($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCart object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCart The associated ChildCart object. + * @throws PropelException + */ + public function getCart(ConnectionInterface $con = null) + { + if ($this->aCart === null && ($this->id !== null)) { + $this->aCart = CartQuery::create()->findPk($this->id, $con); + // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. + $this->aCart->setPaypalCart($this); + } + + return $this->aCart; + } + + /** + * Declares an association between this object and a ChildPaypalPlanifiedPayment object. + * + * @param ChildPaypalPlanifiedPayment $v + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + * @throws PropelException + */ + public function setPaypalPlanifiedPayment(ChildPaypalPlanifiedPayment $v = null) + { + if ($v === null) { + $this->setPlanifiedPaymentId(NULL); + } else { + $this->setPlanifiedPaymentId($v->getId()); + } + + $this->aPaypalPlanifiedPayment = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildPaypalPlanifiedPayment object, it will not be re-added. + if ($v !== null) { + $v->addPaypalCart($this); + } + + + return $this; + } + + + /** + * Get the associated ChildPaypalPlanifiedPayment object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildPaypalPlanifiedPayment The associated ChildPaypalPlanifiedPayment object. + * @throws PropelException + */ + public function getPaypalPlanifiedPayment(ConnectionInterface $con = null) + { + if ($this->aPaypalPlanifiedPayment === null && ($this->planified_payment_id !== null)) { + $this->aPaypalPlanifiedPayment = ChildPaypalPlanifiedPaymentQuery::create()->findPk($this->planified_payment_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aPaypalPlanifiedPayment->addPaypalCarts($this); + */ + } + + return $this->aPaypalPlanifiedPayment; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->credit_card_id = null; + $this->planified_payment_id = null; + $this->express_payment_id = null; + $this->express_payer_id = null; + $this->express_token = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCart = null; + $this->aPaypalPlanifiedPayment = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalCartTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildPaypalCart The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[PaypalCartTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalCartQuery.php b/Model/Base/PaypalCartQuery.php new file mode 100644 index 0000000..de08593 --- /dev/null +++ b/Model/Base/PaypalCartQuery.php @@ -0,0 +1,847 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalCart|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalCartTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalCartTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalCart A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, CREDIT_CARD_ID, PLANIFIED_PAYMENT_ID, EXPRESS_PAYMENT_ID, EXPRESS_PAYER_ID, EXPRESS_TOKEN, CREATED_AT, UPDATED_AT FROM paypal_cart WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalCart(); + $obj->hydrate($row); + PaypalCartTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalCart|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(PaypalCartTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(PaypalCartTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByCart() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalCartTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalCartTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the credit_card_id column + * + * Example usage: + * + * $query->filterByCreditCardId('fooValue'); // WHERE credit_card_id = 'fooValue' + * $query->filterByCreditCardId('%fooValue%'); // WHERE credit_card_id LIKE '%fooValue%' + * + * + * @param string $creditCardId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByCreditCardId($creditCardId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($creditCardId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $creditCardId)) { + $creditCardId = str_replace('*', '%', $creditCardId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::CREDIT_CARD_ID, $creditCardId, $comparison); + } + + /** + * Filter the query on the planified_payment_id column + * + * Example usage: + * + * $query->filterByPlanifiedPaymentId(1234); // WHERE planified_payment_id = 1234 + * $query->filterByPlanifiedPaymentId(array(12, 34)); // WHERE planified_payment_id IN (12, 34) + * $query->filterByPlanifiedPaymentId(array('min' => 12)); // WHERE planified_payment_id > 12 + * + * + * @see filterByPaypalPlanifiedPayment() + * + * @param mixed $planifiedPaymentId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByPlanifiedPaymentId($planifiedPaymentId = null, $comparison = null) + { + if (is_array($planifiedPaymentId)) { + $useMinMax = false; + if (isset($planifiedPaymentId['min'])) { + $this->addUsingAlias(PaypalCartTableMap::PLANIFIED_PAYMENT_ID, $planifiedPaymentId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedPaymentId['max'])) { + $this->addUsingAlias(PaypalCartTableMap::PLANIFIED_PAYMENT_ID, $planifiedPaymentId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::PLANIFIED_PAYMENT_ID, $planifiedPaymentId, $comparison); + } + + /** + * Filter the query on the express_payment_id column + * + * Example usage: + * + * $query->filterByExpressPaymentId('fooValue'); // WHERE express_payment_id = 'fooValue' + * $query->filterByExpressPaymentId('%fooValue%'); // WHERE express_payment_id LIKE '%fooValue%' + * + * + * @param string $expressPaymentId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByExpressPaymentId($expressPaymentId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($expressPaymentId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $expressPaymentId)) { + $expressPaymentId = str_replace('*', '%', $expressPaymentId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::EXPRESS_PAYMENT_ID, $expressPaymentId, $comparison); + } + + /** + * Filter the query on the express_payer_id column + * + * Example usage: + * + * $query->filterByExpressPayerId('fooValue'); // WHERE express_payer_id = 'fooValue' + * $query->filterByExpressPayerId('%fooValue%'); // WHERE express_payer_id LIKE '%fooValue%' + * + * + * @param string $expressPayerId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByExpressPayerId($expressPayerId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($expressPayerId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $expressPayerId)) { + $expressPayerId = str_replace('*', '%', $expressPayerId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::EXPRESS_PAYER_ID, $expressPayerId, $comparison); + } + + /** + * Filter the query on the express_token column + * + * Example usage: + * + * $query->filterByExpressToken('fooValue'); // WHERE express_token = 'fooValue' + * $query->filterByExpressToken('%fooValue%'); // WHERE express_token LIKE '%fooValue%' + * + * + * @param string $expressToken The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByExpressToken($expressToken = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($expressToken)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $expressToken)) { + $expressToken = str_replace('*', '%', $expressToken); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::EXPRESS_TOKEN, $expressToken, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalCartTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalCartTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalCartTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalCartTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCartTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Cart object + * + * @param \Thelia\Model\Cart|ObjectCollection $cart The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByCart($cart, $comparison = null) + { + if ($cart instanceof \Thelia\Model\Cart) { + return $this + ->addUsingAlias(PaypalCartTableMap::ID, $cart->getId(), $comparison); + } elseif ($cart instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalCartTableMap::ID, $cart->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCart() only accepts arguments of type \Thelia\Model\Cart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Cart relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function joinCart($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Cart'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Cart'); + } + + return $this; + } + + /** + * Use the Cart relation Cart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CartQuery A secondary query class using the current class as primary query + */ + public function useCartQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCart($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Cart', '\Thelia\Model\CartQuery'); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalPlanifiedPayment object + * + * @param \PayPal\Model\PaypalPlanifiedPayment|ObjectCollection $paypalPlanifiedPayment The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function filterByPaypalPlanifiedPayment($paypalPlanifiedPayment, $comparison = null) + { + if ($paypalPlanifiedPayment instanceof \PayPal\Model\PaypalPlanifiedPayment) { + return $this + ->addUsingAlias(PaypalCartTableMap::PLANIFIED_PAYMENT_ID, $paypalPlanifiedPayment->getId(), $comparison); + } elseif ($paypalPlanifiedPayment instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalCartTableMap::PLANIFIED_PAYMENT_ID, $paypalPlanifiedPayment->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByPaypalPlanifiedPayment() only accepts arguments of type \PayPal\Model\PaypalPlanifiedPayment or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalPlanifiedPayment relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function joinPaypalPlanifiedPayment($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalPlanifiedPayment'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalPlanifiedPayment'); + } + + return $this; + } + + /** + * Use the PaypalPlanifiedPayment relation PaypalPlanifiedPayment object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalPlanifiedPaymentQuery A secondary query class using the current class as primary query + */ + public function usePaypalPlanifiedPaymentQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinPaypalPlanifiedPayment($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalPlanifiedPayment', '\PayPal\Model\PaypalPlanifiedPaymentQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalCart $paypalCart Object to remove from the list of results + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function prune($paypalCart = null) + { + if ($paypalCart) { + $this->addUsingAlias(PaypalCartTableMap::ID, $paypalCart->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_cart table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCartTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalCartTableMap::clearInstancePool(); + PaypalCartTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalCart or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalCart object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCartTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalCartTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalCartTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalCartTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(PaypalCartTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(PaypalCartTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalCartTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalCartTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalCartTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildPaypalCartQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalCartTableMap::CREATED_AT); + } + +} // PaypalCartQuery diff --git a/Model/Base/PaypalCustomer.php b/Model/Base/PaypalCustomer.php new file mode 100644 index 0000000..c34dff1 --- /dev/null +++ b/Model/Base/PaypalCustomer.php @@ -0,0 +1,2693 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalCustomer instance. If + * obj is an instance of PaypalCustomer, delegates to + * equals(PaypalCustomer). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalCustomer The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalCustomer The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [paypal_user_id] column value. + * + * @return int + */ + public function getPaypalUserId() + { + + return $this->paypal_user_id; + } + + /** + * Get the [credit_card_id] column value. + * + * @return string + */ + public function getCreditCardId() + { + + return $this->credit_card_id; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + + return $this->name; + } + + /** + * Get the [given_name] column value. + * + * @return string + */ + public function getGivenName() + { + + return $this->given_name; + } + + /** + * Get the [family_name] column value. + * + * @return string + */ + public function getFamilyName() + { + + return $this->family_name; + } + + /** + * Get the [middle_name] column value. + * + * @return string + */ + public function getMiddleName() + { + + return $this->middle_name; + } + + /** + * Get the [picture] column value. + * + * @return string + */ + public function getPicture() + { + + return $this->picture; + } + + /** + * Get the [email_verified] column value. + * + * @return int + */ + public function getEmailVerified() + { + + return $this->email_verified; + } + + /** + * Get the [gender] column value. + * + * @return string + */ + public function getGender() + { + + return $this->gender; + } + + /** + * Get the [birthday] column value. + * + * @return string + */ + public function getBirthday() + { + + return $this->birthday; + } + + /** + * Get the [zoneinfo] column value. + * + * @return string + */ + public function getZoneinfo() + { + + return $this->zoneinfo; + } + + /** + * Get the [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [language] column value. + * + * @return string + */ + public function getLanguage() + { + + return $this->language; + } + + /** + * Get the [verified] column value. + * + * @return int + */ + public function getVerified() + { + + return $this->verified; + } + + /** + * Get the [phone_number] column value. + * + * @return string + */ + public function getPhoneNumber() + { + + return $this->phone_number; + } + + /** + * Get the [verified_account] column value. + * + * @return string + */ + public function getVerifiedAccount() + { + + return $this->verified_account; + } + + /** + * Get the [account_type] column value. + * + * @return string + */ + public function getAccountType() + { + + return $this->account_type; + } + + /** + * Get the [age_range] column value. + * + * @return string + */ + public function getAgeRange() + { + + return $this->age_range; + } + + /** + * Get the [payer_id] column value. + * + * @return string + */ + public function getPayerId() + { + + return $this->payer_id; + } + + /** + * Get the [postal_code] column value. + * + * @return string + */ + public function getPostalCode() + { + + return $this->postal_code; + } + + /** + * Get the [locality] column value. + * + * @return string + */ + public function getLocality() + { + + return $this->locality; + } + + /** + * Get the [region] column value. + * + * @return string + */ + public function getRegion() + { + + return $this->region; + } + + /** + * Get the [country] column value. + * + * @return string + */ + public function getCountry() + { + + return $this->country; + } + + /** + * Get the [street_address] column value. + * + * @return string + */ + public function getStreetAddress() + { + + return $this->street_address; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalCustomerTableMap::ID] = true; + } + + if ($this->aCustomer !== null && $this->aCustomer->getId() !== $v) { + $this->aCustomer = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [paypal_user_id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setPaypalUserId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->paypal_user_id !== $v) { + $this->paypal_user_id = $v; + $this->modifiedColumns[PaypalCustomerTableMap::PAYPAL_USER_ID] = true; + } + + + return $this; + } // setPaypalUserId() + + /** + * Set the value of [credit_card_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setCreditCardId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->credit_card_id !== $v) { + $this->credit_card_id = $v; + $this->modifiedColumns[PaypalCustomerTableMap::CREDIT_CARD_ID] = true; + } + + + return $this; + } // setCreditCardId() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[PaypalCustomerTableMap::NAME] = true; + } + + + return $this; + } // setName() + + /** + * Set the value of [given_name] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setGivenName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->given_name !== $v) { + $this->given_name = $v; + $this->modifiedColumns[PaypalCustomerTableMap::GIVEN_NAME] = true; + } + + + return $this; + } // setGivenName() + + /** + * Set the value of [family_name] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setFamilyName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->family_name !== $v) { + $this->family_name = $v; + $this->modifiedColumns[PaypalCustomerTableMap::FAMILY_NAME] = true; + } + + + return $this; + } // setFamilyName() + + /** + * Set the value of [middle_name] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setMiddleName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->middle_name !== $v) { + $this->middle_name = $v; + $this->modifiedColumns[PaypalCustomerTableMap::MIDDLE_NAME] = true; + } + + + return $this; + } // setMiddleName() + + /** + * Set the value of [picture] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setPicture($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->picture !== $v) { + $this->picture = $v; + $this->modifiedColumns[PaypalCustomerTableMap::PICTURE] = true; + } + + + return $this; + } // setPicture() + + /** + * Set the value of [email_verified] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setEmailVerified($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->email_verified !== $v) { + $this->email_verified = $v; + $this->modifiedColumns[PaypalCustomerTableMap::EMAIL_VERIFIED] = true; + } + + + return $this; + } // setEmailVerified() + + /** + * Set the value of [gender] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setGender($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->gender !== $v) { + $this->gender = $v; + $this->modifiedColumns[PaypalCustomerTableMap::GENDER] = true; + } + + + return $this; + } // setGender() + + /** + * Set the value of [birthday] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setBirthday($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->birthday !== $v) { + $this->birthday = $v; + $this->modifiedColumns[PaypalCustomerTableMap::BIRTHDAY] = true; + } + + + return $this; + } // setBirthday() + + /** + * Set the value of [zoneinfo] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setZoneinfo($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->zoneinfo !== $v) { + $this->zoneinfo = $v; + $this->modifiedColumns[PaypalCustomerTableMap::ZONEINFO] = true; + } + + + return $this; + } // setZoneinfo() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[PaypalCustomerTableMap::LOCALE] = true; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [language] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setLanguage($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->language !== $v) { + $this->language = $v; + $this->modifiedColumns[PaypalCustomerTableMap::LANGUAGE] = true; + } + + + return $this; + } // setLanguage() + + /** + * Set the value of [verified] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setVerified($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->verified !== $v) { + $this->verified = $v; + $this->modifiedColumns[PaypalCustomerTableMap::VERIFIED] = true; + } + + + return $this; + } // setVerified() + + /** + * Set the value of [phone_number] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setPhoneNumber($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->phone_number !== $v) { + $this->phone_number = $v; + $this->modifiedColumns[PaypalCustomerTableMap::PHONE_NUMBER] = true; + } + + + return $this; + } // setPhoneNumber() + + /** + * Set the value of [verified_account] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setVerifiedAccount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->verified_account !== $v) { + $this->verified_account = $v; + $this->modifiedColumns[PaypalCustomerTableMap::VERIFIED_ACCOUNT] = true; + } + + + return $this; + } // setVerifiedAccount() + + /** + * Set the value of [account_type] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setAccountType($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->account_type !== $v) { + $this->account_type = $v; + $this->modifiedColumns[PaypalCustomerTableMap::ACCOUNT_TYPE] = true; + } + + + return $this; + } // setAccountType() + + /** + * Set the value of [age_range] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setAgeRange($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->age_range !== $v) { + $this->age_range = $v; + $this->modifiedColumns[PaypalCustomerTableMap::AGE_RANGE] = true; + } + + + return $this; + } // setAgeRange() + + /** + * Set the value of [payer_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setPayerId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->payer_id !== $v) { + $this->payer_id = $v; + $this->modifiedColumns[PaypalCustomerTableMap::PAYER_ID] = true; + } + + + return $this; + } // setPayerId() + + /** + * Set the value of [postal_code] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setPostalCode($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->postal_code !== $v) { + $this->postal_code = $v; + $this->modifiedColumns[PaypalCustomerTableMap::POSTAL_CODE] = true; + } + + + return $this; + } // setPostalCode() + + /** + * Set the value of [locality] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setLocality($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locality !== $v) { + $this->locality = $v; + $this->modifiedColumns[PaypalCustomerTableMap::LOCALITY] = true; + } + + + return $this; + } // setLocality() + + /** + * Set the value of [region] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setRegion($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->region !== $v) { + $this->region = $v; + $this->modifiedColumns[PaypalCustomerTableMap::REGION] = true; + } + + + return $this; + } // setRegion() + + /** + * Set the value of [country] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setCountry($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->country !== $v) { + $this->country = $v; + $this->modifiedColumns[PaypalCustomerTableMap::COUNTRY] = true; + } + + + return $this; + } // setCountry() + + /** + * Set the value of [street_address] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setStreetAddress($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->street_address !== $v) { + $this->street_address = $v; + $this->modifiedColumns[PaypalCustomerTableMap::STREET_ADDRESS] = true; + } + + + return $this; + } // setStreetAddress() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalCustomerTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalCustomerTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalCustomerTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalCustomerTableMap::translateFieldName('PaypalUserId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->paypal_user_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalCustomerTableMap::translateFieldName('CreditCardId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->credit_card_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalCustomerTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalCustomerTableMap::translateFieldName('GivenName', TableMap::TYPE_PHPNAME, $indexType)]; + $this->given_name = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalCustomerTableMap::translateFieldName('FamilyName', TableMap::TYPE_PHPNAME, $indexType)]; + $this->family_name = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PaypalCustomerTableMap::translateFieldName('MiddleName', TableMap::TYPE_PHPNAME, $indexType)]; + $this->middle_name = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PaypalCustomerTableMap::translateFieldName('Picture', TableMap::TYPE_PHPNAME, $indexType)]; + $this->picture = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : PaypalCustomerTableMap::translateFieldName('EmailVerified', TableMap::TYPE_PHPNAME, $indexType)]; + $this->email_verified = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : PaypalCustomerTableMap::translateFieldName('Gender', TableMap::TYPE_PHPNAME, $indexType)]; + $this->gender = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : PaypalCustomerTableMap::translateFieldName('Birthday', TableMap::TYPE_PHPNAME, $indexType)]; + $this->birthday = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : PaypalCustomerTableMap::translateFieldName('Zoneinfo', TableMap::TYPE_PHPNAME, $indexType)]; + $this->zoneinfo = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : PaypalCustomerTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : PaypalCustomerTableMap::translateFieldName('Language', TableMap::TYPE_PHPNAME, $indexType)]; + $this->language = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : PaypalCustomerTableMap::translateFieldName('Verified', TableMap::TYPE_PHPNAME, $indexType)]; + $this->verified = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : PaypalCustomerTableMap::translateFieldName('PhoneNumber', TableMap::TYPE_PHPNAME, $indexType)]; + $this->phone_number = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 16 + $startcol : PaypalCustomerTableMap::translateFieldName('VerifiedAccount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->verified_account = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 17 + $startcol : PaypalCustomerTableMap::translateFieldName('AccountType', TableMap::TYPE_PHPNAME, $indexType)]; + $this->account_type = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 18 + $startcol : PaypalCustomerTableMap::translateFieldName('AgeRange', TableMap::TYPE_PHPNAME, $indexType)]; + $this->age_range = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 19 + $startcol : PaypalCustomerTableMap::translateFieldName('PayerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->payer_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 20 + $startcol : PaypalCustomerTableMap::translateFieldName('PostalCode', TableMap::TYPE_PHPNAME, $indexType)]; + $this->postal_code = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 21 + $startcol : PaypalCustomerTableMap::translateFieldName('Locality', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locality = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 22 + $startcol : PaypalCustomerTableMap::translateFieldName('Region', TableMap::TYPE_PHPNAME, $indexType)]; + $this->region = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 23 + $startcol : PaypalCustomerTableMap::translateFieldName('Country', TableMap::TYPE_PHPNAME, $indexType)]; + $this->country = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 24 + $startcol : PaypalCustomerTableMap::translateFieldName('StreetAddress', TableMap::TYPE_PHPNAME, $indexType)]; + $this->street_address = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 25 + $startcol : PaypalCustomerTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 26 + $startcol : PaypalCustomerTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 27; // 27 = PaypalCustomerTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalCustomer object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCustomer !== null && $this->id !== $this->aCustomer->getId()) { + $this->aCustomer = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalCustomerQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCustomer = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalCustomer::setDeleted() + * @see PaypalCustomer::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalCustomerQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(PaypalCustomerTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(PaypalCustomerTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(PaypalCustomerTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalCustomerTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCustomer !== null) { + if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) { + $affectedRows += $this->aCustomer->save($con); + } + $this->setCustomer($this->aCustomer); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalCustomerTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::PAYPAL_USER_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYPAL_USER_ID'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::CREDIT_CARD_ID)) { + $modifiedColumns[':p' . $index++] = 'CREDIT_CARD_ID'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::NAME)) { + $modifiedColumns[':p' . $index++] = 'NAME'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::GIVEN_NAME)) { + $modifiedColumns[':p' . $index++] = 'GIVEN_NAME'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::FAMILY_NAME)) { + $modifiedColumns[':p' . $index++] = 'FAMILY_NAME'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::MIDDLE_NAME)) { + $modifiedColumns[':p' . $index++] = 'MIDDLE_NAME'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::PICTURE)) { + $modifiedColumns[':p' . $index++] = 'PICTURE'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::EMAIL_VERIFIED)) { + $modifiedColumns[':p' . $index++] = 'EMAIL_VERIFIED'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::GENDER)) { + $modifiedColumns[':p' . $index++] = 'GENDER'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::BIRTHDAY)) { + $modifiedColumns[':p' . $index++] = 'BIRTHDAY'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::ZONEINFO)) { + $modifiedColumns[':p' . $index++] = 'ZONEINFO'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = 'LOCALE'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::LANGUAGE)) { + $modifiedColumns[':p' . $index++] = 'LANGUAGE'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::VERIFIED)) { + $modifiedColumns[':p' . $index++] = 'VERIFIED'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::PHONE_NUMBER)) { + $modifiedColumns[':p' . $index++] = 'PHONE_NUMBER'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::VERIFIED_ACCOUNT)) { + $modifiedColumns[':p' . $index++] = 'VERIFIED_ACCOUNT'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::ACCOUNT_TYPE)) { + $modifiedColumns[':p' . $index++] = 'ACCOUNT_TYPE'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::AGE_RANGE)) { + $modifiedColumns[':p' . $index++] = 'AGE_RANGE'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::PAYER_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYER_ID'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::POSTAL_CODE)) { + $modifiedColumns[':p' . $index++] = 'POSTAL_CODE'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::LOCALITY)) { + $modifiedColumns[':p' . $index++] = 'LOCALITY'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::REGION)) { + $modifiedColumns[':p' . $index++] = 'REGION'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::COUNTRY)) { + $modifiedColumns[':p' . $index++] = 'COUNTRY'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::STREET_ADDRESS)) { + $modifiedColumns[':p' . $index++] = 'STREET_ADDRESS'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalCustomerTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO paypal_customer (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'PAYPAL_USER_ID': + $stmt->bindValue($identifier, $this->paypal_user_id, PDO::PARAM_INT); + break; + case 'CREDIT_CARD_ID': + $stmt->bindValue($identifier, $this->credit_card_id, PDO::PARAM_STR); + break; + case 'NAME': + $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + break; + case 'GIVEN_NAME': + $stmt->bindValue($identifier, $this->given_name, PDO::PARAM_STR); + break; + case 'FAMILY_NAME': + $stmt->bindValue($identifier, $this->family_name, PDO::PARAM_STR); + break; + case 'MIDDLE_NAME': + $stmt->bindValue($identifier, $this->middle_name, PDO::PARAM_STR); + break; + case 'PICTURE': + $stmt->bindValue($identifier, $this->picture, PDO::PARAM_STR); + break; + case 'EMAIL_VERIFIED': + $stmt->bindValue($identifier, $this->email_verified, PDO::PARAM_INT); + break; + case 'GENDER': + $stmt->bindValue($identifier, $this->gender, PDO::PARAM_STR); + break; + case 'BIRTHDAY': + $stmt->bindValue($identifier, $this->birthday, PDO::PARAM_STR); + break; + case 'ZONEINFO': + $stmt->bindValue($identifier, $this->zoneinfo, PDO::PARAM_STR); + break; + case 'LOCALE': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case 'LANGUAGE': + $stmt->bindValue($identifier, $this->language, PDO::PARAM_STR); + break; + case 'VERIFIED': + $stmt->bindValue($identifier, $this->verified, PDO::PARAM_INT); + break; + case 'PHONE_NUMBER': + $stmt->bindValue($identifier, $this->phone_number, PDO::PARAM_STR); + break; + case 'VERIFIED_ACCOUNT': + $stmt->bindValue($identifier, $this->verified_account, PDO::PARAM_STR); + break; + case 'ACCOUNT_TYPE': + $stmt->bindValue($identifier, $this->account_type, PDO::PARAM_STR); + break; + case 'AGE_RANGE': + $stmt->bindValue($identifier, $this->age_range, PDO::PARAM_STR); + break; + case 'PAYER_ID': + $stmt->bindValue($identifier, $this->payer_id, PDO::PARAM_STR); + break; + case 'POSTAL_CODE': + $stmt->bindValue($identifier, $this->postal_code, PDO::PARAM_STR); + break; + case 'LOCALITY': + $stmt->bindValue($identifier, $this->locality, PDO::PARAM_STR); + break; + case 'REGION': + $stmt->bindValue($identifier, $this->region, PDO::PARAM_STR); + break; + case 'COUNTRY': + $stmt->bindValue($identifier, $this->country, PDO::PARAM_STR); + break; + case 'STREET_ADDRESS': + $stmt->bindValue($identifier, $this->street_address, PDO::PARAM_STR); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalCustomerTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPaypalUserId(); + break; + case 2: + return $this->getCreditCardId(); + break; + case 3: + return $this->getName(); + break; + case 4: + return $this->getGivenName(); + break; + case 5: + return $this->getFamilyName(); + break; + case 6: + return $this->getMiddleName(); + break; + case 7: + return $this->getPicture(); + break; + case 8: + return $this->getEmailVerified(); + break; + case 9: + return $this->getGender(); + break; + case 10: + return $this->getBirthday(); + break; + case 11: + return $this->getZoneinfo(); + break; + case 12: + return $this->getLocale(); + break; + case 13: + return $this->getLanguage(); + break; + case 14: + return $this->getVerified(); + break; + case 15: + return $this->getPhoneNumber(); + break; + case 16: + return $this->getVerifiedAccount(); + break; + case 17: + return $this->getAccountType(); + break; + case 18: + return $this->getAgeRange(); + break; + case 19: + return $this->getPayerId(); + break; + case 20: + return $this->getPostalCode(); + break; + case 21: + return $this->getLocality(); + break; + case 22: + return $this->getRegion(); + break; + case 23: + return $this->getCountry(); + break; + case 24: + return $this->getStreetAddress(); + break; + case 25: + return $this->getCreatedAt(); + break; + case 26: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalCustomer'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalCustomer'][serialize($this->getPrimaryKey())] = true; + $keys = PaypalCustomerTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPaypalUserId(), + $keys[2] => $this->getCreditCardId(), + $keys[3] => $this->getName(), + $keys[4] => $this->getGivenName(), + $keys[5] => $this->getFamilyName(), + $keys[6] => $this->getMiddleName(), + $keys[7] => $this->getPicture(), + $keys[8] => $this->getEmailVerified(), + $keys[9] => $this->getGender(), + $keys[10] => $this->getBirthday(), + $keys[11] => $this->getZoneinfo(), + $keys[12] => $this->getLocale(), + $keys[13] => $this->getLanguage(), + $keys[14] => $this->getVerified(), + $keys[15] => $this->getPhoneNumber(), + $keys[16] => $this->getVerifiedAccount(), + $keys[17] => $this->getAccountType(), + $keys[18] => $this->getAgeRange(), + $keys[19] => $this->getPayerId(), + $keys[20] => $this->getPostalCode(), + $keys[21] => $this->getLocality(), + $keys[22] => $this->getRegion(), + $keys[23] => $this->getCountry(), + $keys[24] => $this->getStreetAddress(), + $keys[25] => $this->getCreatedAt(), + $keys[26] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCustomer) { + $result['Customer'] = $this->aCustomer->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalCustomerTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPaypalUserId($value); + break; + case 2: + $this->setCreditCardId($value); + break; + case 3: + $this->setName($value); + break; + case 4: + $this->setGivenName($value); + break; + case 5: + $this->setFamilyName($value); + break; + case 6: + $this->setMiddleName($value); + break; + case 7: + $this->setPicture($value); + break; + case 8: + $this->setEmailVerified($value); + break; + case 9: + $this->setGender($value); + break; + case 10: + $this->setBirthday($value); + break; + case 11: + $this->setZoneinfo($value); + break; + case 12: + $this->setLocale($value); + break; + case 13: + $this->setLanguage($value); + break; + case 14: + $this->setVerified($value); + break; + case 15: + $this->setPhoneNumber($value); + break; + case 16: + $this->setVerifiedAccount($value); + break; + case 17: + $this->setAccountType($value); + break; + case 18: + $this->setAgeRange($value); + break; + case 19: + $this->setPayerId($value); + break; + case 20: + $this->setPostalCode($value); + break; + case 21: + $this->setLocality($value); + break; + case 22: + $this->setRegion($value); + break; + case 23: + $this->setCountry($value); + break; + case 24: + $this->setStreetAddress($value); + break; + case 25: + $this->setCreatedAt($value); + break; + case 26: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalCustomerTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setPaypalUserId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCreditCardId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setName($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setGivenName($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setFamilyName($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setMiddleName($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setPicture($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setEmailVerified($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setGender($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setBirthday($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setZoneinfo($arr[$keys[11]]); + if (array_key_exists($keys[12], $arr)) $this->setLocale($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setLanguage($arr[$keys[13]]); + if (array_key_exists($keys[14], $arr)) $this->setVerified($arr[$keys[14]]); + if (array_key_exists($keys[15], $arr)) $this->setPhoneNumber($arr[$keys[15]]); + if (array_key_exists($keys[16], $arr)) $this->setVerifiedAccount($arr[$keys[16]]); + if (array_key_exists($keys[17], $arr)) $this->setAccountType($arr[$keys[17]]); + if (array_key_exists($keys[18], $arr)) $this->setAgeRange($arr[$keys[18]]); + if (array_key_exists($keys[19], $arr)) $this->setPayerId($arr[$keys[19]]); + if (array_key_exists($keys[20], $arr)) $this->setPostalCode($arr[$keys[20]]); + if (array_key_exists($keys[21], $arr)) $this->setLocality($arr[$keys[21]]); + if (array_key_exists($keys[22], $arr)) $this->setRegion($arr[$keys[22]]); + if (array_key_exists($keys[23], $arr)) $this->setCountry($arr[$keys[23]]); + if (array_key_exists($keys[24], $arr)) $this->setStreetAddress($arr[$keys[24]]); + if (array_key_exists($keys[25], $arr)) $this->setCreatedAt($arr[$keys[25]]); + if (array_key_exists($keys[26], $arr)) $this->setUpdatedAt($arr[$keys[26]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalCustomerTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalCustomerTableMap::ID)) $criteria->add(PaypalCustomerTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalCustomerTableMap::PAYPAL_USER_ID)) $criteria->add(PaypalCustomerTableMap::PAYPAL_USER_ID, $this->paypal_user_id); + if ($this->isColumnModified(PaypalCustomerTableMap::CREDIT_CARD_ID)) $criteria->add(PaypalCustomerTableMap::CREDIT_CARD_ID, $this->credit_card_id); + if ($this->isColumnModified(PaypalCustomerTableMap::NAME)) $criteria->add(PaypalCustomerTableMap::NAME, $this->name); + if ($this->isColumnModified(PaypalCustomerTableMap::GIVEN_NAME)) $criteria->add(PaypalCustomerTableMap::GIVEN_NAME, $this->given_name); + if ($this->isColumnModified(PaypalCustomerTableMap::FAMILY_NAME)) $criteria->add(PaypalCustomerTableMap::FAMILY_NAME, $this->family_name); + if ($this->isColumnModified(PaypalCustomerTableMap::MIDDLE_NAME)) $criteria->add(PaypalCustomerTableMap::MIDDLE_NAME, $this->middle_name); + if ($this->isColumnModified(PaypalCustomerTableMap::PICTURE)) $criteria->add(PaypalCustomerTableMap::PICTURE, $this->picture); + if ($this->isColumnModified(PaypalCustomerTableMap::EMAIL_VERIFIED)) $criteria->add(PaypalCustomerTableMap::EMAIL_VERIFIED, $this->email_verified); + if ($this->isColumnModified(PaypalCustomerTableMap::GENDER)) $criteria->add(PaypalCustomerTableMap::GENDER, $this->gender); + if ($this->isColumnModified(PaypalCustomerTableMap::BIRTHDAY)) $criteria->add(PaypalCustomerTableMap::BIRTHDAY, $this->birthday); + if ($this->isColumnModified(PaypalCustomerTableMap::ZONEINFO)) $criteria->add(PaypalCustomerTableMap::ZONEINFO, $this->zoneinfo); + if ($this->isColumnModified(PaypalCustomerTableMap::LOCALE)) $criteria->add(PaypalCustomerTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(PaypalCustomerTableMap::LANGUAGE)) $criteria->add(PaypalCustomerTableMap::LANGUAGE, $this->language); + if ($this->isColumnModified(PaypalCustomerTableMap::VERIFIED)) $criteria->add(PaypalCustomerTableMap::VERIFIED, $this->verified); + if ($this->isColumnModified(PaypalCustomerTableMap::PHONE_NUMBER)) $criteria->add(PaypalCustomerTableMap::PHONE_NUMBER, $this->phone_number); + if ($this->isColumnModified(PaypalCustomerTableMap::VERIFIED_ACCOUNT)) $criteria->add(PaypalCustomerTableMap::VERIFIED_ACCOUNT, $this->verified_account); + if ($this->isColumnModified(PaypalCustomerTableMap::ACCOUNT_TYPE)) $criteria->add(PaypalCustomerTableMap::ACCOUNT_TYPE, $this->account_type); + if ($this->isColumnModified(PaypalCustomerTableMap::AGE_RANGE)) $criteria->add(PaypalCustomerTableMap::AGE_RANGE, $this->age_range); + if ($this->isColumnModified(PaypalCustomerTableMap::PAYER_ID)) $criteria->add(PaypalCustomerTableMap::PAYER_ID, $this->payer_id); + if ($this->isColumnModified(PaypalCustomerTableMap::POSTAL_CODE)) $criteria->add(PaypalCustomerTableMap::POSTAL_CODE, $this->postal_code); + if ($this->isColumnModified(PaypalCustomerTableMap::LOCALITY)) $criteria->add(PaypalCustomerTableMap::LOCALITY, $this->locality); + if ($this->isColumnModified(PaypalCustomerTableMap::REGION)) $criteria->add(PaypalCustomerTableMap::REGION, $this->region); + if ($this->isColumnModified(PaypalCustomerTableMap::COUNTRY)) $criteria->add(PaypalCustomerTableMap::COUNTRY, $this->country); + if ($this->isColumnModified(PaypalCustomerTableMap::STREET_ADDRESS)) $criteria->add(PaypalCustomerTableMap::STREET_ADDRESS, $this->street_address); + if ($this->isColumnModified(PaypalCustomerTableMap::CREATED_AT)) $criteria->add(PaypalCustomerTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalCustomerTableMap::UPDATED_AT)) $criteria->add(PaypalCustomerTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalCustomerTableMap::DATABASE_NAME); + $criteria->add(PaypalCustomerTableMap::ID, $this->id); + $criteria->add(PaypalCustomerTableMap::PAYPAL_USER_ID, $this->paypal_user_id); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getPaypalUserId(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setPaypalUserId($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getPaypalUserId()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalCustomer (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setPaypalUserId($this->getPaypalUserId()); + $copyObj->setCreditCardId($this->getCreditCardId()); + $copyObj->setName($this->getName()); + $copyObj->setGivenName($this->getGivenName()); + $copyObj->setFamilyName($this->getFamilyName()); + $copyObj->setMiddleName($this->getMiddleName()); + $copyObj->setPicture($this->getPicture()); + $copyObj->setEmailVerified($this->getEmailVerified()); + $copyObj->setGender($this->getGender()); + $copyObj->setBirthday($this->getBirthday()); + $copyObj->setZoneinfo($this->getZoneinfo()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setLanguage($this->getLanguage()); + $copyObj->setVerified($this->getVerified()); + $copyObj->setPhoneNumber($this->getPhoneNumber()); + $copyObj->setVerifiedAccount($this->getVerifiedAccount()); + $copyObj->setAccountType($this->getAccountType()); + $copyObj->setAgeRange($this->getAgeRange()); + $copyObj->setPayerId($this->getPayerId()); + $copyObj->setPostalCode($this->getPostalCode()); + $copyObj->setLocality($this->getLocality()); + $copyObj->setRegion($this->getRegion()); + $copyObj->setCountry($this->getCountry()); + $copyObj->setStreetAddress($this->getStreetAddress()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalCustomer Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCustomer object. + * + * @param ChildCustomer $v + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + * @throws PropelException + */ + public function setCustomer(ChildCustomer $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aCustomer = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCustomer object, it will not be re-added. + if ($v !== null) { + $v->addPaypalCustomer($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCustomer object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCustomer The associated ChildCustomer object. + * @throws PropelException + */ + public function getCustomer(ConnectionInterface $con = null) + { + if ($this->aCustomer === null && ($this->id !== null)) { + $this->aCustomer = CustomerQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCustomer->addPaypalCustomers($this); + */ + } + + return $this->aCustomer; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->paypal_user_id = null; + $this->credit_card_id = null; + $this->name = null; + $this->given_name = null; + $this->family_name = null; + $this->middle_name = null; + $this->picture = null; + $this->email_verified = null; + $this->gender = null; + $this->birthday = null; + $this->zoneinfo = null; + $this->locale = null; + $this->language = null; + $this->verified = null; + $this->phone_number = null; + $this->verified_account = null; + $this->account_type = null; + $this->age_range = null; + $this->payer_id = null; + $this->postal_code = null; + $this->locality = null; + $this->region = null; + $this->country = null; + $this->street_address = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCustomer = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalCustomerTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildPaypalCustomer The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[PaypalCustomerTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalCustomerQuery.php b/Model/Base/PaypalCustomerQuery.php new file mode 100644 index 0000000..fd7d553 --- /dev/null +++ b/Model/Base/PaypalCustomerQuery.php @@ -0,0 +1,1431 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $paypal_user_id] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalCustomer|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalCustomerTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalCustomer A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, PAYPAL_USER_ID, CREDIT_CARD_ID, NAME, GIVEN_NAME, FAMILY_NAME, MIDDLE_NAME, PICTURE, EMAIL_VERIFIED, GENDER, BIRTHDAY, ZONEINFO, LOCALE, LANGUAGE, VERIFIED, PHONE_NUMBER, VERIFIED_ACCOUNT, ACCOUNT_TYPE, AGE_RANGE, PAYER_ID, POSTAL_CODE, LOCALITY, REGION, COUNTRY, STREET_ADDRESS, CREATED_AT, UPDATED_AT FROM paypal_customer WHERE ID = :p0 AND PAYPAL_USER_ID = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalCustomer(); + $obj->hydrate($row); + PaypalCustomerTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalCustomer|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(PaypalCustomerTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(PaypalCustomerTableMap::PAYPAL_USER_ID, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(PaypalCustomerTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(PaypalCustomerTableMap::PAYPAL_USER_ID, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByCustomer() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalCustomerTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalCustomerTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the paypal_user_id column + * + * Example usage: + * + * $query->filterByPaypalUserId(1234); // WHERE paypal_user_id = 1234 + * $query->filterByPaypalUserId(array(12, 34)); // WHERE paypal_user_id IN (12, 34) + * $query->filterByPaypalUserId(array('min' => 12)); // WHERE paypal_user_id > 12 + * + * + * @param mixed $paypalUserId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPaypalUserId($paypalUserId = null, $comparison = null) + { + if (is_array($paypalUserId)) { + $useMinMax = false; + if (isset($paypalUserId['min'])) { + $this->addUsingAlias(PaypalCustomerTableMap::PAYPAL_USER_ID, $paypalUserId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($paypalUserId['max'])) { + $this->addUsingAlias(PaypalCustomerTableMap::PAYPAL_USER_ID, $paypalUserId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::PAYPAL_USER_ID, $paypalUserId, $comparison); + } + + /** + * Filter the query on the credit_card_id column + * + * Example usage: + * + * $query->filterByCreditCardId('fooValue'); // WHERE credit_card_id = 'fooValue' + * $query->filterByCreditCardId('%fooValue%'); // WHERE credit_card_id LIKE '%fooValue%' + * + * + * @param string $creditCardId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByCreditCardId($creditCardId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($creditCardId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $creditCardId)) { + $creditCardId = str_replace('*', '%', $creditCardId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::CREDIT_CARD_ID, $creditCardId, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $name)) { + $name = str_replace('*', '%', $name); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::NAME, $name, $comparison); + } + + /** + * Filter the query on the given_name column + * + * Example usage: + * + * $query->filterByGivenName('fooValue'); // WHERE given_name = 'fooValue' + * $query->filterByGivenName('%fooValue%'); // WHERE given_name LIKE '%fooValue%' + * + * + * @param string $givenName The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByGivenName($givenName = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($givenName)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $givenName)) { + $givenName = str_replace('*', '%', $givenName); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::GIVEN_NAME, $givenName, $comparison); + } + + /** + * Filter the query on the family_name column + * + * Example usage: + * + * $query->filterByFamilyName('fooValue'); // WHERE family_name = 'fooValue' + * $query->filterByFamilyName('%fooValue%'); // WHERE family_name LIKE '%fooValue%' + * + * + * @param string $familyName The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByFamilyName($familyName = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($familyName)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $familyName)) { + $familyName = str_replace('*', '%', $familyName); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::FAMILY_NAME, $familyName, $comparison); + } + + /** + * Filter the query on the middle_name column + * + * Example usage: + * + * $query->filterByMiddleName('fooValue'); // WHERE middle_name = 'fooValue' + * $query->filterByMiddleName('%fooValue%'); // WHERE middle_name LIKE '%fooValue%' + * + * + * @param string $middleName The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByMiddleName($middleName = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($middleName)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $middleName)) { + $middleName = str_replace('*', '%', $middleName); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::MIDDLE_NAME, $middleName, $comparison); + } + + /** + * Filter the query on the picture column + * + * Example usage: + * + * $query->filterByPicture('fooValue'); // WHERE picture = 'fooValue' + * $query->filterByPicture('%fooValue%'); // WHERE picture LIKE '%fooValue%' + * + * + * @param string $picture The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPicture($picture = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($picture)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $picture)) { + $picture = str_replace('*', '%', $picture); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::PICTURE, $picture, $comparison); + } + + /** + * Filter the query on the email_verified column + * + * Example usage: + * + * $query->filterByEmailVerified(1234); // WHERE email_verified = 1234 + * $query->filterByEmailVerified(array(12, 34)); // WHERE email_verified IN (12, 34) + * $query->filterByEmailVerified(array('min' => 12)); // WHERE email_verified > 12 + * + * + * @param mixed $emailVerified The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByEmailVerified($emailVerified = null, $comparison = null) + { + if (is_array($emailVerified)) { + $useMinMax = false; + if (isset($emailVerified['min'])) { + $this->addUsingAlias(PaypalCustomerTableMap::EMAIL_VERIFIED, $emailVerified['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($emailVerified['max'])) { + $this->addUsingAlias(PaypalCustomerTableMap::EMAIL_VERIFIED, $emailVerified['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::EMAIL_VERIFIED, $emailVerified, $comparison); + } + + /** + * Filter the query on the gender column + * + * Example usage: + * + * $query->filterByGender('fooValue'); // WHERE gender = 'fooValue' + * $query->filterByGender('%fooValue%'); // WHERE gender LIKE '%fooValue%' + * + * + * @param string $gender The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByGender($gender = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($gender)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $gender)) { + $gender = str_replace('*', '%', $gender); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::GENDER, $gender, $comparison); + } + + /** + * Filter the query on the birthday column + * + * Example usage: + * + * $query->filterByBirthday('fooValue'); // WHERE birthday = 'fooValue' + * $query->filterByBirthday('%fooValue%'); // WHERE birthday LIKE '%fooValue%' + * + * + * @param string $birthday The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByBirthday($birthday = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($birthday)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $birthday)) { + $birthday = str_replace('*', '%', $birthday); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::BIRTHDAY, $birthday, $comparison); + } + + /** + * Filter the query on the zoneinfo column + * + * Example usage: + * + * $query->filterByZoneinfo('fooValue'); // WHERE zoneinfo = 'fooValue' + * $query->filterByZoneinfo('%fooValue%'); // WHERE zoneinfo LIKE '%fooValue%' + * + * + * @param string $zoneinfo The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByZoneinfo($zoneinfo = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($zoneinfo)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $zoneinfo)) { + $zoneinfo = str_replace('*', '%', $zoneinfo); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::ZONEINFO, $zoneinfo, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the language column + * + * Example usage: + * + * $query->filterByLanguage('fooValue'); // WHERE language = 'fooValue' + * $query->filterByLanguage('%fooValue%'); // WHERE language LIKE '%fooValue%' + * + * + * @param string $language The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByLanguage($language = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($language)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $language)) { + $language = str_replace('*', '%', $language); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::LANGUAGE, $language, $comparison); + } + + /** + * Filter the query on the verified column + * + * Example usage: + * + * $query->filterByVerified(1234); // WHERE verified = 1234 + * $query->filterByVerified(array(12, 34)); // WHERE verified IN (12, 34) + * $query->filterByVerified(array('min' => 12)); // WHERE verified > 12 + * + * + * @param mixed $verified The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByVerified($verified = null, $comparison = null) + { + if (is_array($verified)) { + $useMinMax = false; + if (isset($verified['min'])) { + $this->addUsingAlias(PaypalCustomerTableMap::VERIFIED, $verified['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($verified['max'])) { + $this->addUsingAlias(PaypalCustomerTableMap::VERIFIED, $verified['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::VERIFIED, $verified, $comparison); + } + + /** + * Filter the query on the phone_number column + * + * Example usage: + * + * $query->filterByPhoneNumber('fooValue'); // WHERE phone_number = 'fooValue' + * $query->filterByPhoneNumber('%fooValue%'); // WHERE phone_number LIKE '%fooValue%' + * + * + * @param string $phoneNumber The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPhoneNumber($phoneNumber = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($phoneNumber)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $phoneNumber)) { + $phoneNumber = str_replace('*', '%', $phoneNumber); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::PHONE_NUMBER, $phoneNumber, $comparison); + } + + /** + * Filter the query on the verified_account column + * + * Example usage: + * + * $query->filterByVerifiedAccount('fooValue'); // WHERE verified_account = 'fooValue' + * $query->filterByVerifiedAccount('%fooValue%'); // WHERE verified_account LIKE '%fooValue%' + * + * + * @param string $verifiedAccount The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByVerifiedAccount($verifiedAccount = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($verifiedAccount)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $verifiedAccount)) { + $verifiedAccount = str_replace('*', '%', $verifiedAccount); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::VERIFIED_ACCOUNT, $verifiedAccount, $comparison); + } + + /** + * Filter the query on the account_type column + * + * Example usage: + * + * $query->filterByAccountType('fooValue'); // WHERE account_type = 'fooValue' + * $query->filterByAccountType('%fooValue%'); // WHERE account_type LIKE '%fooValue%' + * + * + * @param string $accountType The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByAccountType($accountType = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($accountType)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $accountType)) { + $accountType = str_replace('*', '%', $accountType); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::ACCOUNT_TYPE, $accountType, $comparison); + } + + /** + * Filter the query on the age_range column + * + * Example usage: + * + * $query->filterByAgeRange('fooValue'); // WHERE age_range = 'fooValue' + * $query->filterByAgeRange('%fooValue%'); // WHERE age_range LIKE '%fooValue%' + * + * + * @param string $ageRange The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByAgeRange($ageRange = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($ageRange)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $ageRange)) { + $ageRange = str_replace('*', '%', $ageRange); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::AGE_RANGE, $ageRange, $comparison); + } + + /** + * Filter the query on the payer_id column + * + * Example usage: + * + * $query->filterByPayerId('fooValue'); // WHERE payer_id = 'fooValue' + * $query->filterByPayerId('%fooValue%'); // WHERE payer_id LIKE '%fooValue%' + * + * + * @param string $payerId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPayerId($payerId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($payerId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $payerId)) { + $payerId = str_replace('*', '%', $payerId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::PAYER_ID, $payerId, $comparison); + } + + /** + * Filter the query on the postal_code column + * + * Example usage: + * + * $query->filterByPostalCode('fooValue'); // WHERE postal_code = 'fooValue' + * $query->filterByPostalCode('%fooValue%'); // WHERE postal_code LIKE '%fooValue%' + * + * + * @param string $postalCode The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByPostalCode($postalCode = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($postalCode)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $postalCode)) { + $postalCode = str_replace('*', '%', $postalCode); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::POSTAL_CODE, $postalCode, $comparison); + } + + /** + * Filter the query on the locality column + * + * Example usage: + * + * $query->filterByLocality('fooValue'); // WHERE locality = 'fooValue' + * $query->filterByLocality('%fooValue%'); // WHERE locality LIKE '%fooValue%' + * + * + * @param string $locality The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByLocality($locality = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locality)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locality)) { + $locality = str_replace('*', '%', $locality); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::LOCALITY, $locality, $comparison); + } + + /** + * Filter the query on the region column + * + * Example usage: + * + * $query->filterByRegion('fooValue'); // WHERE region = 'fooValue' + * $query->filterByRegion('%fooValue%'); // WHERE region LIKE '%fooValue%' + * + * + * @param string $region The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByRegion($region = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($region)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $region)) { + $region = str_replace('*', '%', $region); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::REGION, $region, $comparison); + } + + /** + * Filter the query on the country column + * + * Example usage: + * + * $query->filterByCountry('fooValue'); // WHERE country = 'fooValue' + * $query->filterByCountry('%fooValue%'); // WHERE country LIKE '%fooValue%' + * + * + * @param string $country The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByCountry($country = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($country)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $country)) { + $country = str_replace('*', '%', $country); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::COUNTRY, $country, $comparison); + } + + /** + * Filter the query on the street_address column + * + * Example usage: + * + * $query->filterByStreetAddress('fooValue'); // WHERE street_address = 'fooValue' + * $query->filterByStreetAddress('%fooValue%'); // WHERE street_address LIKE '%fooValue%' + * + * + * @param string $streetAddress The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByStreetAddress($streetAddress = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($streetAddress)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $streetAddress)) { + $streetAddress = str_replace('*', '%', $streetAddress); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::STREET_ADDRESS, $streetAddress, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalCustomerTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalCustomerTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalCustomerTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalCustomerTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalCustomerTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Customer object + * + * @param \Thelia\Model\Customer|ObjectCollection $customer The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function filterByCustomer($customer, $comparison = null) + { + if ($customer instanceof \Thelia\Model\Customer) { + return $this + ->addUsingAlias(PaypalCustomerTableMap::ID, $customer->getId(), $comparison); + } elseif ($customer instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalCustomerTableMap::ID, $customer->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCustomer() only accepts arguments of type \Thelia\Model\Customer or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Customer relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function joinCustomer($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Customer'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Customer'); + } + + return $this; + } + + /** + * Use the Customer relation Customer object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CustomerQuery A secondary query class using the current class as primary query + */ + public function useCustomerQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCustomer($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Customer', '\Thelia\Model\CustomerQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalCustomer $paypalCustomer Object to remove from the list of results + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function prune($paypalCustomer = null) + { + if ($paypalCustomer) { + $this->addCond('pruneCond0', $this->getAliasedColName(PaypalCustomerTableMap::ID), $paypalCustomer->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(PaypalCustomerTableMap::PAYPAL_USER_ID), $paypalCustomer->getPaypalUserId(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_customer table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalCustomerTableMap::clearInstancePool(); + PaypalCustomerTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalCustomer or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalCustomer object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalCustomerTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalCustomerTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalCustomerTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(PaypalCustomerTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(PaypalCustomerTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalCustomerTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalCustomerTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalCustomerTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildPaypalCustomerQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalCustomerTableMap::CREATED_AT); + } + +} // PaypalCustomerQuery diff --git a/Model/Base/PaypalLog.php b/Model/Base/PaypalLog.php new file mode 100644 index 0000000..882b6b5 --- /dev/null +++ b/Model/Base/PaypalLog.php @@ -0,0 +1,1788 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalLog instance. If + * obj is an instance of PaypalLog, delegates to + * equals(PaypalLog). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalLog The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalLog The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [customer_id] column value. + * + * @return int + */ + public function getCustomerId() + { + + return $this->customer_id; + } + + /** + * Get the [order_id] column value. + * + * @return int + */ + public function getOrderId() + { + + return $this->order_id; + } + + /** + * Get the [hook] column value. + * + * @return string + */ + public function getHook() + { + + return $this->hook; + } + + /** + * Get the [channel] column value. + * + * @return string + */ + public function getChannel() + { + + return $this->channel; + } + + /** + * Get the [level] column value. + * + * @return int + */ + public function getLevel() + { + + return $this->level; + } + + /** + * Get the [message] column value. + * + * @return string + */ + public function getMessage() + { + + return $this->message; + } + + /** + * Get the [time] column value. + * + * @return int + */ + public function getTime() + { + + return $this->time; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalLogTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [customer_id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setCustomerId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->customer_id !== $v) { + $this->customer_id = $v; + $this->modifiedColumns[PaypalLogTableMap::CUSTOMER_ID] = true; + } + + if ($this->aCustomer !== null && $this->aCustomer->getId() !== $v) { + $this->aCustomer = null; + } + + + return $this; + } // setCustomerId() + + /** + * Set the value of [order_id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setOrderId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->order_id !== $v) { + $this->order_id = $v; + $this->modifiedColumns[PaypalLogTableMap::ORDER_ID] = true; + } + + if ($this->aOrder !== null && $this->aOrder->getId() !== $v) { + $this->aOrder = null; + } + + + return $this; + } // setOrderId() + + /** + * Set the value of [hook] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setHook($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->hook !== $v) { + $this->hook = $v; + $this->modifiedColumns[PaypalLogTableMap::HOOK] = true; + } + + + return $this; + } // setHook() + + /** + * Set the value of [channel] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setChannel($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->channel !== $v) { + $this->channel = $v; + $this->modifiedColumns[PaypalLogTableMap::CHANNEL] = true; + } + + + return $this; + } // setChannel() + + /** + * Set the value of [level] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setLevel($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->level !== $v) { + $this->level = $v; + $this->modifiedColumns[PaypalLogTableMap::LEVEL] = true; + } + + + return $this; + } // setLevel() + + /** + * Set the value of [message] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setMessage($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->message !== $v) { + $this->message = $v; + $this->modifiedColumns[PaypalLogTableMap::MESSAGE] = true; + } + + + return $this; + } // setMessage() + + /** + * Set the value of [time] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setTime($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->time !== $v) { + $this->time = $v; + $this->modifiedColumns[PaypalLogTableMap::TIME] = true; + } + + + return $this; + } // setTime() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalLogTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalLogTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalLogTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalLogTableMap::translateFieldName('CustomerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->customer_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalLogTableMap::translateFieldName('OrderId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->order_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalLogTableMap::translateFieldName('Hook', TableMap::TYPE_PHPNAME, $indexType)]; + $this->hook = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalLogTableMap::translateFieldName('Channel', TableMap::TYPE_PHPNAME, $indexType)]; + $this->channel = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalLogTableMap::translateFieldName('Level', TableMap::TYPE_PHPNAME, $indexType)]; + $this->level = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PaypalLogTableMap::translateFieldName('Message', TableMap::TYPE_PHPNAME, $indexType)]; + $this->message = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PaypalLogTableMap::translateFieldName('Time', TableMap::TYPE_PHPNAME, $indexType)]; + $this->time = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : PaypalLogTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : PaypalLogTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 10; // 10 = PaypalLogTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalLog object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCustomer !== null && $this->customer_id !== $this->aCustomer->getId()) { + $this->aCustomer = null; + } + if ($this->aOrder !== null && $this->order_id !== $this->aOrder->getId()) { + $this->aOrder = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalLogTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalLogQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCustomer = null; + $this->aOrder = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalLog::setDeleted() + * @see PaypalLog::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalLogTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalLogQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalLogTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(PaypalLogTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(PaypalLogTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(PaypalLogTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalLogTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCustomer !== null) { + if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) { + $affectedRows += $this->aCustomer->save($con); + } + $this->setCustomer($this->aCustomer); + } + + if ($this->aOrder !== null) { + if ($this->aOrder->isModified() || $this->aOrder->isNew()) { + $affectedRows += $this->aOrder->save($con); + } + $this->setOrder($this->aOrder); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[PaypalLogTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . PaypalLogTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalLogTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalLogTableMap::CUSTOMER_ID)) { + $modifiedColumns[':p' . $index++] = 'CUSTOMER_ID'; + } + if ($this->isColumnModified(PaypalLogTableMap::ORDER_ID)) { + $modifiedColumns[':p' . $index++] = 'ORDER_ID'; + } + if ($this->isColumnModified(PaypalLogTableMap::HOOK)) { + $modifiedColumns[':p' . $index++] = 'HOOK'; + } + if ($this->isColumnModified(PaypalLogTableMap::CHANNEL)) { + $modifiedColumns[':p' . $index++] = 'CHANNEL'; + } + if ($this->isColumnModified(PaypalLogTableMap::LEVEL)) { + $modifiedColumns[':p' . $index++] = 'LEVEL'; + } + if ($this->isColumnModified(PaypalLogTableMap::MESSAGE)) { + $modifiedColumns[':p' . $index++] = 'MESSAGE'; + } + if ($this->isColumnModified(PaypalLogTableMap::TIME)) { + $modifiedColumns[':p' . $index++] = 'TIME'; + } + if ($this->isColumnModified(PaypalLogTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalLogTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO paypal_log (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'CUSTOMER_ID': + $stmt->bindValue($identifier, $this->customer_id, PDO::PARAM_INT); + break; + case 'ORDER_ID': + $stmt->bindValue($identifier, $this->order_id, PDO::PARAM_INT); + break; + case 'HOOK': + $stmt->bindValue($identifier, $this->hook, PDO::PARAM_STR); + break; + case 'CHANNEL': + $stmt->bindValue($identifier, $this->channel, PDO::PARAM_STR); + break; + case 'LEVEL': + $stmt->bindValue($identifier, $this->level, PDO::PARAM_INT); + break; + case 'MESSAGE': + $stmt->bindValue($identifier, $this->message, PDO::PARAM_STR); + break; + case 'TIME': + $stmt->bindValue($identifier, $this->time, PDO::PARAM_INT); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalLogTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getCustomerId(); + break; + case 2: + return $this->getOrderId(); + break; + case 3: + return $this->getHook(); + break; + case 4: + return $this->getChannel(); + break; + case 5: + return $this->getLevel(); + break; + case 6: + return $this->getMessage(); + break; + case 7: + return $this->getTime(); + break; + case 8: + return $this->getCreatedAt(); + break; + case 9: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalLog'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalLog'][$this->getPrimaryKey()] = true; + $keys = PaypalLogTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getCustomerId(), + $keys[2] => $this->getOrderId(), + $keys[3] => $this->getHook(), + $keys[4] => $this->getChannel(), + $keys[5] => $this->getLevel(), + $keys[6] => $this->getMessage(), + $keys[7] => $this->getTime(), + $keys[8] => $this->getCreatedAt(), + $keys[9] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCustomer) { + $result['Customer'] = $this->aCustomer->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aOrder) { + $result['Order'] = $this->aOrder->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalLogTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setCustomerId($value); + break; + case 2: + $this->setOrderId($value); + break; + case 3: + $this->setHook($value); + break; + case 4: + $this->setChannel($value); + break; + case 5: + $this->setLevel($value); + break; + case 6: + $this->setMessage($value); + break; + case 7: + $this->setTime($value); + break; + case 8: + $this->setCreatedAt($value); + break; + case 9: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalLogTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setCustomerId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setOrderId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setHook($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setChannel($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setLevel($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setMessage($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setTime($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setUpdatedAt($arr[$keys[9]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalLogTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalLogTableMap::ID)) $criteria->add(PaypalLogTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalLogTableMap::CUSTOMER_ID)) $criteria->add(PaypalLogTableMap::CUSTOMER_ID, $this->customer_id); + if ($this->isColumnModified(PaypalLogTableMap::ORDER_ID)) $criteria->add(PaypalLogTableMap::ORDER_ID, $this->order_id); + if ($this->isColumnModified(PaypalLogTableMap::HOOK)) $criteria->add(PaypalLogTableMap::HOOK, $this->hook); + if ($this->isColumnModified(PaypalLogTableMap::CHANNEL)) $criteria->add(PaypalLogTableMap::CHANNEL, $this->channel); + if ($this->isColumnModified(PaypalLogTableMap::LEVEL)) $criteria->add(PaypalLogTableMap::LEVEL, $this->level); + if ($this->isColumnModified(PaypalLogTableMap::MESSAGE)) $criteria->add(PaypalLogTableMap::MESSAGE, $this->message); + if ($this->isColumnModified(PaypalLogTableMap::TIME)) $criteria->add(PaypalLogTableMap::TIME, $this->time); + if ($this->isColumnModified(PaypalLogTableMap::CREATED_AT)) $criteria->add(PaypalLogTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalLogTableMap::UPDATED_AT)) $criteria->add(PaypalLogTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalLogTableMap::DATABASE_NAME); + $criteria->add(PaypalLogTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalLog (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setCustomerId($this->getCustomerId()); + $copyObj->setOrderId($this->getOrderId()); + $copyObj->setHook($this->getHook()); + $copyObj->setChannel($this->getChannel()); + $copyObj->setLevel($this->getLevel()); + $copyObj->setMessage($this->getMessage()); + $copyObj->setTime($this->getTime()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalLog Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCustomer object. + * + * @param ChildCustomer $v + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + * @throws PropelException + */ + public function setCustomer(ChildCustomer $v = null) + { + if ($v === null) { + $this->setCustomerId(NULL); + } else { + $this->setCustomerId($v->getId()); + } + + $this->aCustomer = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCustomer object, it will not be re-added. + if ($v !== null) { + $v->addPaypalLog($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCustomer object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCustomer The associated ChildCustomer object. + * @throws PropelException + */ + public function getCustomer(ConnectionInterface $con = null) + { + if ($this->aCustomer === null && ($this->customer_id !== null)) { + $this->aCustomer = CustomerQuery::create()->findPk($this->customer_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCustomer->addPaypalLogs($this); + */ + } + + return $this->aCustomer; + } + + /** + * Declares an association between this object and a ChildOrder object. + * + * @param ChildOrder $v + * @return \PayPal\Model\PaypalLog The current object (for fluent API support) + * @throws PropelException + */ + public function setOrder(ChildOrder $v = null) + { + if ($v === null) { + $this->setOrderId(NULL); + } else { + $this->setOrderId($v->getId()); + } + + $this->aOrder = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildOrder object, it will not be re-added. + if ($v !== null) { + $v->addPaypalLog($this); + } + + + return $this; + } + + + /** + * Get the associated ChildOrder object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildOrder The associated ChildOrder object. + * @throws PropelException + */ + public function getOrder(ConnectionInterface $con = null) + { + if ($this->aOrder === null && ($this->order_id !== null)) { + $this->aOrder = OrderQuery::create()->findPk($this->order_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aOrder->addPaypalLogs($this); + */ + } + + return $this->aOrder; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->customer_id = null; + $this->order_id = null; + $this->hook = null; + $this->channel = null; + $this->level = null; + $this->message = null; + $this->time = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCustomer = null; + $this->aOrder = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalLogTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildPaypalLog The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[PaypalLogTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalLogQuery.php b/Model/Base/PaypalLogQuery.php new file mode 100644 index 0000000..df2e3f0 --- /dev/null +++ b/Model/Base/PaypalLogQuery.php @@ -0,0 +1,950 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalLog|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalLogTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalLogTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalLog A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, CUSTOMER_ID, ORDER_ID, HOOK, CHANNEL, LEVEL, MESSAGE, TIME, CREATED_AT, UPDATED_AT FROM paypal_log WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalLog(); + $obj->hydrate($row); + PaypalLogTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalLog|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(PaypalLogTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(PaypalLogTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalLogTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalLogTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the customer_id column + * + * Example usage: + * + * $query->filterByCustomerId(1234); // WHERE customer_id = 1234 + * $query->filterByCustomerId(array(12, 34)); // WHERE customer_id IN (12, 34) + * $query->filterByCustomerId(array('min' => 12)); // WHERE customer_id > 12 + * + * + * @see filterByCustomer() + * + * @param mixed $customerId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByCustomerId($customerId = null, $comparison = null) + { + if (is_array($customerId)) { + $useMinMax = false; + if (isset($customerId['min'])) { + $this->addUsingAlias(PaypalLogTableMap::CUSTOMER_ID, $customerId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($customerId['max'])) { + $this->addUsingAlias(PaypalLogTableMap::CUSTOMER_ID, $customerId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::CUSTOMER_ID, $customerId, $comparison); + } + + /** + * Filter the query on the order_id column + * + * Example usage: + * + * $query->filterByOrderId(1234); // WHERE order_id = 1234 + * $query->filterByOrderId(array(12, 34)); // WHERE order_id IN (12, 34) + * $query->filterByOrderId(array('min' => 12)); // WHERE order_id > 12 + * + * + * @see filterByOrder() + * + * @param mixed $orderId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByOrderId($orderId = null, $comparison = null) + { + if (is_array($orderId)) { + $useMinMax = false; + if (isset($orderId['min'])) { + $this->addUsingAlias(PaypalLogTableMap::ORDER_ID, $orderId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($orderId['max'])) { + $this->addUsingAlias(PaypalLogTableMap::ORDER_ID, $orderId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::ORDER_ID, $orderId, $comparison); + } + + /** + * Filter the query on the hook column + * + * Example usage: + * + * $query->filterByHook('fooValue'); // WHERE hook = 'fooValue' + * $query->filterByHook('%fooValue%'); // WHERE hook LIKE '%fooValue%' + * + * + * @param string $hook The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByHook($hook = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($hook)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $hook)) { + $hook = str_replace('*', '%', $hook); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::HOOK, $hook, $comparison); + } + + /** + * Filter the query on the channel column + * + * Example usage: + * + * $query->filterByChannel('fooValue'); // WHERE channel = 'fooValue' + * $query->filterByChannel('%fooValue%'); // WHERE channel LIKE '%fooValue%' + * + * + * @param string $channel The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByChannel($channel = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($channel)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $channel)) { + $channel = str_replace('*', '%', $channel); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::CHANNEL, $channel, $comparison); + } + + /** + * Filter the query on the level column + * + * Example usage: + * + * $query->filterByLevel(1234); // WHERE level = 1234 + * $query->filterByLevel(array(12, 34)); // WHERE level IN (12, 34) + * $query->filterByLevel(array('min' => 12)); // WHERE level > 12 + * + * + * @param mixed $level The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByLevel($level = null, $comparison = null) + { + if (is_array($level)) { + $useMinMax = false; + if (isset($level['min'])) { + $this->addUsingAlias(PaypalLogTableMap::LEVEL, $level['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($level['max'])) { + $this->addUsingAlias(PaypalLogTableMap::LEVEL, $level['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::LEVEL, $level, $comparison); + } + + /** + * Filter the query on the message column + * + * Example usage: + * + * $query->filterByMessage('fooValue'); // WHERE message = 'fooValue' + * $query->filterByMessage('%fooValue%'); // WHERE message LIKE '%fooValue%' + * + * + * @param string $message The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByMessage($message = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($message)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $message)) { + $message = str_replace('*', '%', $message); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::MESSAGE, $message, $comparison); + } + + /** + * Filter the query on the time column + * + * Example usage: + * + * $query->filterByTime(1234); // WHERE time = 1234 + * $query->filterByTime(array(12, 34)); // WHERE time IN (12, 34) + * $query->filterByTime(array('min' => 12)); // WHERE time > 12 + * + * + * @param mixed $time The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByTime($time = null, $comparison = null) + { + if (is_array($time)) { + $useMinMax = false; + if (isset($time['min'])) { + $this->addUsingAlias(PaypalLogTableMap::TIME, $time['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($time['max'])) { + $this->addUsingAlias(PaypalLogTableMap::TIME, $time['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::TIME, $time, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalLogTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalLogTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalLogTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalLogTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalLogTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Customer object + * + * @param \Thelia\Model\Customer|ObjectCollection $customer The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByCustomer($customer, $comparison = null) + { + if ($customer instanceof \Thelia\Model\Customer) { + return $this + ->addUsingAlias(PaypalLogTableMap::CUSTOMER_ID, $customer->getId(), $comparison); + } elseif ($customer instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalLogTableMap::CUSTOMER_ID, $customer->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCustomer() only accepts arguments of type \Thelia\Model\Customer or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Customer relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function joinCustomer($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Customer'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Customer'); + } + + return $this; + } + + /** + * Use the Customer relation Customer object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\CustomerQuery A secondary query class using the current class as primary query + */ + public function useCustomerQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCustomer($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Customer', '\Thelia\Model\CustomerQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Order object + * + * @param \Thelia\Model\Order|ObjectCollection $order The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function filterByOrder($order, $comparison = null) + { + if ($order instanceof \Thelia\Model\Order) { + return $this + ->addUsingAlias(PaypalLogTableMap::ORDER_ID, $order->getId(), $comparison); + } elseif ($order instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalLogTableMap::ORDER_ID, $order->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByOrder() only accepts arguments of type \Thelia\Model\Order or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Order relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function joinOrder($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Order'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Order'); + } + + return $this; + } + + /** + * Use the Order relation Order object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\OrderQuery A secondary query class using the current class as primary query + */ + public function useOrderQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinOrder($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Order', '\Thelia\Model\OrderQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalLog $paypalLog Object to remove from the list of results + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function prune($paypalLog = null) + { + if ($paypalLog) { + $this->addUsingAlias(PaypalLogTableMap::ID, $paypalLog->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_log table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalLogTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalLogTableMap::clearInstancePool(); + PaypalLogTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalLog or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalLog object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalLogTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalLogTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalLogTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalLogTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(PaypalLogTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(PaypalLogTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalLogTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalLogTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalLogTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildPaypalLogQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalLogTableMap::CREATED_AT); + } + +} // PaypalLogQuery diff --git a/Model/Base/PaypalOrder.php b/Model/Base/PaypalOrder.php new file mode 100644 index 0000000..d365d3e --- /dev/null +++ b/Model/Base/PaypalOrder.php @@ -0,0 +1,3361 @@ +amount = '0.000000'; + $this->planified_actual_cycle = 0; + $this->planified_min_amount = '0.000000'; + $this->planified_max_amount = '0.000000'; + $this->version = 0; + } + + /** + * Initializes internal state of PayPal\Model\Base\PaypalOrder object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalOrder instance. If + * obj is an instance of PaypalOrder, delegates to + * equals(PaypalOrder). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalOrder The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalOrder The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [payment_id] column value. + * + * @return string + */ + public function getPaymentId() + { + + return $this->payment_id; + } + + /** + * Get the [agreement_id] column value. + * + * @return string + */ + public function getAgreementId() + { + + return $this->agreement_id; + } + + /** + * Get the [credit_card_id] column value. + * + * @return string + */ + public function getCreditCardId() + { + + return $this->credit_card_id; + } + + /** + * Get the [state] column value. + * + * @return string + */ + public function getState() + { + + return $this->state; + } + + /** + * Get the [amount] column value. + * + * @return string + */ + public function getAmount() + { + + return $this->amount; + } + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + + return $this->description; + } + + /** + * Get the [payer_id] column value. + * + * @return string + */ + public function getPayerId() + { + + return $this->payer_id; + } + + /** + * Get the [token] column value. + * + * @return string + */ + public function getToken() + { + + return $this->token; + } + + /** + * Get the [planified_title] column value. + * + * @return string + */ + public function getPlanifiedTitle() + { + + return $this->planified_title; + } + + /** + * Get the [planified_description] column value. + * + * @return string + */ + public function getPlanifiedDescription() + { + + return $this->planified_description; + } + + /** + * Get the [planified_frequency] column value. + * + * @return string + */ + public function getPlanifiedFrequency() + { + + return $this->planified_frequency; + } + + /** + * Get the [planified_frequency_interval] column value. + * + * @return int + */ + public function getPlanifiedFrequencyInterval() + { + + return $this->planified_frequency_interval; + } + + /** + * Get the [planified_cycle] column value. + * + * @return int + */ + public function getPlanifiedCycle() + { + + return $this->planified_cycle; + } + + /** + * Get the [planified_actual_cycle] column value. + * + * @return int + */ + public function getPlanifiedActualCycle() + { + + return $this->planified_actual_cycle; + } + + /** + * Get the [planified_min_amount] column value. + * + * @return string + */ + public function getPlanifiedMinAmount() + { + + return $this->planified_min_amount; + } + + /** + * Get the [planified_max_amount] column value. + * + * @return string + */ + public function getPlanifiedMaxAmount() + { + + return $this->planified_max_amount; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Get the [version] column value. + * + * @return int + */ + public function getVersion() + { + + return $this->version; + } + + /** + * Get the [optionally formatted] temporal [version_created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getVersionCreatedAt($format = NULL) + { + if ($format === null) { + return $this->version_created_at; + } else { + return $this->version_created_at instanceof \DateTime ? $this->version_created_at->format($format) : null; + } + } + + /** + * Get the [version_created_by] column value. + * + * @return string + */ + public function getVersionCreatedBy() + { + + return $this->version_created_by; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalOrderTableMap::ID] = true; + } + + if ($this->aOrder !== null && $this->aOrder->getId() !== $v) { + $this->aOrder = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [payment_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPaymentId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->payment_id !== $v) { + $this->payment_id = $v; + $this->modifiedColumns[PaypalOrderTableMap::PAYMENT_ID] = true; + } + + + return $this; + } // setPaymentId() + + /** + * Set the value of [agreement_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setAgreementId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->agreement_id !== $v) { + $this->agreement_id = $v; + $this->modifiedColumns[PaypalOrderTableMap::AGREEMENT_ID] = true; + } + + + return $this; + } // setAgreementId() + + /** + * Set the value of [credit_card_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setCreditCardId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->credit_card_id !== $v) { + $this->credit_card_id = $v; + $this->modifiedColumns[PaypalOrderTableMap::CREDIT_CARD_ID] = true; + } + + + return $this; + } // setCreditCardId() + + /** + * Set the value of [state] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setState($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->state !== $v) { + $this->state = $v; + $this->modifiedColumns[PaypalOrderTableMap::STATE] = true; + } + + + return $this; + } // setState() + + /** + * Set the value of [amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->amount !== $v) { + $this->amount = $v; + $this->modifiedColumns[PaypalOrderTableMap::AMOUNT] = true; + } + + + return $this; + } // setAmount() + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->description !== $v) { + $this->description = $v; + $this->modifiedColumns[PaypalOrderTableMap::DESCRIPTION] = true; + } + + + return $this; + } // setDescription() + + /** + * Set the value of [payer_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPayerId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->payer_id !== $v) { + $this->payer_id = $v; + $this->modifiedColumns[PaypalOrderTableMap::PAYER_ID] = true; + } + + + return $this; + } // setPayerId() + + /** + * Set the value of [token] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setToken($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->token !== $v) { + $this->token = $v; + $this->modifiedColumns[PaypalOrderTableMap::TOKEN] = true; + } + + + return $this; + } // setToken() + + /** + * Set the value of [planified_title] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_title !== $v) { + $this->planified_title = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_TITLE] = true; + } + + + return $this; + } // setPlanifiedTitle() + + /** + * Set the value of [planified_description] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_description !== $v) { + $this->planified_description = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_DESCRIPTION] = true; + } + + + return $this; + } // setPlanifiedDescription() + + /** + * Set the value of [planified_frequency] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedFrequency($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_frequency !== $v) { + $this->planified_frequency = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_FREQUENCY] = true; + } + + + return $this; + } // setPlanifiedFrequency() + + /** + * Set the value of [planified_frequency_interval] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedFrequencyInterval($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_frequency_interval !== $v) { + $this->planified_frequency_interval = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL] = true; + } + + + return $this; + } // setPlanifiedFrequencyInterval() + + /** + * Set the value of [planified_cycle] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedCycle($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_cycle !== $v) { + $this->planified_cycle = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_CYCLE] = true; + } + + + return $this; + } // setPlanifiedCycle() + + /** + * Set the value of [planified_actual_cycle] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedActualCycle($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_actual_cycle !== $v) { + $this->planified_actual_cycle = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE] = true; + } + + + return $this; + } // setPlanifiedActualCycle() + + /** + * Set the value of [planified_min_amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedMinAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_min_amount !== $v) { + $this->planified_min_amount = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT] = true; + } + + + return $this; + } // setPlanifiedMinAmount() + + /** + * Set the value of [planified_max_amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setPlanifiedMaxAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_max_amount !== $v) { + $this->planified_max_amount = $v; + $this->modifiedColumns[PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT] = true; + } + + + return $this; + } // setPlanifiedMaxAmount() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalOrderTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalOrderTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Set the value of [version] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setVersion($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->version !== $v) { + $this->version = $v; + $this->modifiedColumns[PaypalOrderTableMap::VERSION] = true; + } + + + return $this; + } // setVersion() + + /** + * Sets the value of [version_created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setVersionCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->version_created_at !== null || $dt !== null) { + if ($dt !== $this->version_created_at) { + $this->version_created_at = $dt; + $this->modifiedColumns[PaypalOrderTableMap::VERSION_CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setVersionCreatedAt() + + /** + * Set the value of [version_created_by] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function setVersionCreatedBy($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->version_created_by !== $v) { + $this->version_created_by = $v; + $this->modifiedColumns[PaypalOrderTableMap::VERSION_CREATED_BY] = true; + } + + + return $this; + } // setVersionCreatedBy() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->amount !== '0.000000') { + return false; + } + + if ($this->planified_actual_cycle !== 0) { + return false; + } + + if ($this->planified_min_amount !== '0.000000') { + return false; + } + + if ($this->planified_max_amount !== '0.000000') { + return false; + } + + if ($this->version !== 0) { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalOrderTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalOrderTableMap::translateFieldName('PaymentId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->payment_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalOrderTableMap::translateFieldName('AgreementId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->agreement_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalOrderTableMap::translateFieldName('CreditCardId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->credit_card_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalOrderTableMap::translateFieldName('State', TableMap::TYPE_PHPNAME, $indexType)]; + $this->state = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalOrderTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PaypalOrderTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; + $this->description = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PaypalOrderTableMap::translateFieldName('PayerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->payer_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : PaypalOrderTableMap::translateFieldName('Token', TableMap::TYPE_PHPNAME, $indexType)]; + $this->token = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedTitle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_title = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedDescription', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_description = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedFrequency', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_frequency = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedFrequencyInterval', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_frequency_interval = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedCycle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_cycle = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedActualCycle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_actual_cycle = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedMinAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_min_amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 16 + $startcol : PaypalOrderTableMap::translateFieldName('PlanifiedMaxAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_max_amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 17 + $startcol : PaypalOrderTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 18 + $startcol : PaypalOrderTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 19 + $startcol : PaypalOrderTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 20 + $startcol : PaypalOrderTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->version_created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 21 + $startcol : PaypalOrderTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version_created_by = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 22; // 22 = PaypalOrderTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalOrder object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aOrder !== null && $this->id !== $this->aOrder->getId()) { + $this->aOrder = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalOrderTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalOrderQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aOrder = null; + $this->collPaypalPlans = null; + + $this->collPaypalOrderVersions = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalOrder::setDeleted() + * @see PaypalOrder::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalOrderQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + // versionable behavior + if ($this->isVersioningNecessary()) { + $this->setVersion($this->isNew() ? 1 : $this->getLastVersionNumber($con) + 1); + if (!$this->isColumnModified(PaypalOrderTableMap::VERSION_CREATED_AT)) { + $this->setVersionCreatedAt(time()); + } + $createVersion = true; // for postSave hook + } + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(PaypalOrderTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(PaypalOrderTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(PaypalOrderTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + // versionable behavior + if (isset($createVersion)) { + $this->addVersion($con); + } + PaypalOrderTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aOrder !== null) { + if ($this->aOrder->isModified() || $this->aOrder->isNew()) { + $affectedRows += $this->aOrder->save($con); + } + $this->setOrder($this->aOrder); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->paypalPlansScheduledForDeletion !== null) { + if (!$this->paypalPlansScheduledForDeletion->isEmpty()) { + \PayPal\Model\PaypalPlanQuery::create() + ->filterByPrimaryKeys($this->paypalPlansScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->paypalPlansScheduledForDeletion = null; + } + } + + if ($this->collPaypalPlans !== null) { + foreach ($this->collPaypalPlans as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->paypalOrderVersionsScheduledForDeletion !== null) { + if (!$this->paypalOrderVersionsScheduledForDeletion->isEmpty()) { + \PayPal\Model\PaypalOrderVersionQuery::create() + ->filterByPrimaryKeys($this->paypalOrderVersionsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->paypalOrderVersionsScheduledForDeletion = null; + } + } + + if ($this->collPaypalOrderVersions !== null) { + foreach ($this->collPaypalOrderVersions as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalOrderTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PAYMENT_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYMENT_ID'; + } + if ($this->isColumnModified(PaypalOrderTableMap::AGREEMENT_ID)) { + $modifiedColumns[':p' . $index++] = 'AGREEMENT_ID'; + } + if ($this->isColumnModified(PaypalOrderTableMap::CREDIT_CARD_ID)) { + $modifiedColumns[':p' . $index++] = 'CREDIT_CARD_ID'; + } + if ($this->isColumnModified(PaypalOrderTableMap::STATE)) { + $modifiedColumns[':p' . $index++] = 'STATE'; + } + if ($this->isColumnModified(PaypalOrderTableMap::AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'AMOUNT'; + } + if ($this->isColumnModified(PaypalOrderTableMap::DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = 'DESCRIPTION'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PAYER_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYER_ID'; + } + if ($this->isColumnModified(PaypalOrderTableMap::TOKEN)) { + $modifiedColumns[':p' . $index++] = 'TOKEN'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_TITLE)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_TITLE'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_DESCRIPTION'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_FREQUENCY)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_FREQUENCY'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_FREQUENCY_INTERVAL'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_CYCLE)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_CYCLE'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_ACTUAL_CYCLE'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_MIN_AMOUNT'; + } + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_MAX_AMOUNT'; + } + if ($this->isColumnModified(PaypalOrderTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalOrderTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + if ($this->isColumnModified(PaypalOrderTableMap::VERSION)) { + $modifiedColumns[':p' . $index++] = 'VERSION'; + } + if ($this->isColumnModified(PaypalOrderTableMap::VERSION_CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'VERSION_CREATED_AT'; + } + if ($this->isColumnModified(PaypalOrderTableMap::VERSION_CREATED_BY)) { + $modifiedColumns[':p' . $index++] = 'VERSION_CREATED_BY'; + } + + $sql = sprintf( + 'INSERT INTO paypal_order (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'PAYMENT_ID': + $stmt->bindValue($identifier, $this->payment_id, PDO::PARAM_STR); + break; + case 'AGREEMENT_ID': + $stmt->bindValue($identifier, $this->agreement_id, PDO::PARAM_STR); + break; + case 'CREDIT_CARD_ID': + $stmt->bindValue($identifier, $this->credit_card_id, PDO::PARAM_STR); + break; + case 'STATE': + $stmt->bindValue($identifier, $this->state, PDO::PARAM_STR); + break; + case 'AMOUNT': + $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); + break; + case 'DESCRIPTION': + $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR); + break; + case 'PAYER_ID': + $stmt->bindValue($identifier, $this->payer_id, PDO::PARAM_STR); + break; + case 'TOKEN': + $stmt->bindValue($identifier, $this->token, PDO::PARAM_STR); + break; + case 'PLANIFIED_TITLE': + $stmt->bindValue($identifier, $this->planified_title, PDO::PARAM_STR); + break; + case 'PLANIFIED_DESCRIPTION': + $stmt->bindValue($identifier, $this->planified_description, PDO::PARAM_STR); + break; + case 'PLANIFIED_FREQUENCY': + $stmt->bindValue($identifier, $this->planified_frequency, PDO::PARAM_STR); + break; + case 'PLANIFIED_FREQUENCY_INTERVAL': + $stmt->bindValue($identifier, $this->planified_frequency_interval, PDO::PARAM_INT); + break; + case 'PLANIFIED_CYCLE': + $stmt->bindValue($identifier, $this->planified_cycle, PDO::PARAM_INT); + break; + case 'PLANIFIED_ACTUAL_CYCLE': + $stmt->bindValue($identifier, $this->planified_actual_cycle, PDO::PARAM_INT); + break; + case 'PLANIFIED_MIN_AMOUNT': + $stmt->bindValue($identifier, $this->planified_min_amount, PDO::PARAM_STR); + break; + case 'PLANIFIED_MAX_AMOUNT': + $stmt->bindValue($identifier, $this->planified_max_amount, PDO::PARAM_STR); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'VERSION': + $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT); + break; + case 'VERSION_CREATED_AT': + $stmt->bindValue($identifier, $this->version_created_at ? $this->version_created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'VERSION_CREATED_BY': + $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalOrderTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPaymentId(); + break; + case 2: + return $this->getAgreementId(); + break; + case 3: + return $this->getCreditCardId(); + break; + case 4: + return $this->getState(); + break; + case 5: + return $this->getAmount(); + break; + case 6: + return $this->getDescription(); + break; + case 7: + return $this->getPayerId(); + break; + case 8: + return $this->getToken(); + break; + case 9: + return $this->getPlanifiedTitle(); + break; + case 10: + return $this->getPlanifiedDescription(); + break; + case 11: + return $this->getPlanifiedFrequency(); + break; + case 12: + return $this->getPlanifiedFrequencyInterval(); + break; + case 13: + return $this->getPlanifiedCycle(); + break; + case 14: + return $this->getPlanifiedActualCycle(); + break; + case 15: + return $this->getPlanifiedMinAmount(); + break; + case 16: + return $this->getPlanifiedMaxAmount(); + break; + case 17: + return $this->getCreatedAt(); + break; + case 18: + return $this->getUpdatedAt(); + break; + case 19: + return $this->getVersion(); + break; + case 20: + return $this->getVersionCreatedAt(); + break; + case 21: + return $this->getVersionCreatedBy(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalOrder'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalOrder'][$this->getPrimaryKey()] = true; + $keys = PaypalOrderTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPaymentId(), + $keys[2] => $this->getAgreementId(), + $keys[3] => $this->getCreditCardId(), + $keys[4] => $this->getState(), + $keys[5] => $this->getAmount(), + $keys[6] => $this->getDescription(), + $keys[7] => $this->getPayerId(), + $keys[8] => $this->getToken(), + $keys[9] => $this->getPlanifiedTitle(), + $keys[10] => $this->getPlanifiedDescription(), + $keys[11] => $this->getPlanifiedFrequency(), + $keys[12] => $this->getPlanifiedFrequencyInterval(), + $keys[13] => $this->getPlanifiedCycle(), + $keys[14] => $this->getPlanifiedActualCycle(), + $keys[15] => $this->getPlanifiedMinAmount(), + $keys[16] => $this->getPlanifiedMaxAmount(), + $keys[17] => $this->getCreatedAt(), + $keys[18] => $this->getUpdatedAt(), + $keys[19] => $this->getVersion(), + $keys[20] => $this->getVersionCreatedAt(), + $keys[21] => $this->getVersionCreatedBy(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aOrder) { + $result['Order'] = $this->aOrder->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->collPaypalPlans) { + $result['PaypalPlans'] = $this->collPaypalPlans->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collPaypalOrderVersions) { + $result['PaypalOrderVersions'] = $this->collPaypalOrderVersions->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalOrderTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPaymentId($value); + break; + case 2: + $this->setAgreementId($value); + break; + case 3: + $this->setCreditCardId($value); + break; + case 4: + $this->setState($value); + break; + case 5: + $this->setAmount($value); + break; + case 6: + $this->setDescription($value); + break; + case 7: + $this->setPayerId($value); + break; + case 8: + $this->setToken($value); + break; + case 9: + $this->setPlanifiedTitle($value); + break; + case 10: + $this->setPlanifiedDescription($value); + break; + case 11: + $this->setPlanifiedFrequency($value); + break; + case 12: + $this->setPlanifiedFrequencyInterval($value); + break; + case 13: + $this->setPlanifiedCycle($value); + break; + case 14: + $this->setPlanifiedActualCycle($value); + break; + case 15: + $this->setPlanifiedMinAmount($value); + break; + case 16: + $this->setPlanifiedMaxAmount($value); + break; + case 17: + $this->setCreatedAt($value); + break; + case 18: + $this->setUpdatedAt($value); + break; + case 19: + $this->setVersion($value); + break; + case 20: + $this->setVersionCreatedAt($value); + break; + case 21: + $this->setVersionCreatedBy($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalOrderTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setPaymentId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setAgreementId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setCreditCardId($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setState($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setAmount($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setDescription($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setPayerId($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setToken($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setPlanifiedTitle($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setPlanifiedDescription($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setPlanifiedFrequency($arr[$keys[11]]); + if (array_key_exists($keys[12], $arr)) $this->setPlanifiedFrequencyInterval($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setPlanifiedCycle($arr[$keys[13]]); + if (array_key_exists($keys[14], $arr)) $this->setPlanifiedActualCycle($arr[$keys[14]]); + if (array_key_exists($keys[15], $arr)) $this->setPlanifiedMinAmount($arr[$keys[15]]); + if (array_key_exists($keys[16], $arr)) $this->setPlanifiedMaxAmount($arr[$keys[16]]); + if (array_key_exists($keys[17], $arr)) $this->setCreatedAt($arr[$keys[17]]); + if (array_key_exists($keys[18], $arr)) $this->setUpdatedAt($arr[$keys[18]]); + if (array_key_exists($keys[19], $arr)) $this->setVersion($arr[$keys[19]]); + if (array_key_exists($keys[20], $arr)) $this->setVersionCreatedAt($arr[$keys[20]]); + if (array_key_exists($keys[21], $arr)) $this->setVersionCreatedBy($arr[$keys[21]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalOrderTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalOrderTableMap::ID)) $criteria->add(PaypalOrderTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalOrderTableMap::PAYMENT_ID)) $criteria->add(PaypalOrderTableMap::PAYMENT_ID, $this->payment_id); + if ($this->isColumnModified(PaypalOrderTableMap::AGREEMENT_ID)) $criteria->add(PaypalOrderTableMap::AGREEMENT_ID, $this->agreement_id); + if ($this->isColumnModified(PaypalOrderTableMap::CREDIT_CARD_ID)) $criteria->add(PaypalOrderTableMap::CREDIT_CARD_ID, $this->credit_card_id); + if ($this->isColumnModified(PaypalOrderTableMap::STATE)) $criteria->add(PaypalOrderTableMap::STATE, $this->state); + if ($this->isColumnModified(PaypalOrderTableMap::AMOUNT)) $criteria->add(PaypalOrderTableMap::AMOUNT, $this->amount); + if ($this->isColumnModified(PaypalOrderTableMap::DESCRIPTION)) $criteria->add(PaypalOrderTableMap::DESCRIPTION, $this->description); + if ($this->isColumnModified(PaypalOrderTableMap::PAYER_ID)) $criteria->add(PaypalOrderTableMap::PAYER_ID, $this->payer_id); + if ($this->isColumnModified(PaypalOrderTableMap::TOKEN)) $criteria->add(PaypalOrderTableMap::TOKEN, $this->token); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_TITLE)) $criteria->add(PaypalOrderTableMap::PLANIFIED_TITLE, $this->planified_title); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_DESCRIPTION)) $criteria->add(PaypalOrderTableMap::PLANIFIED_DESCRIPTION, $this->planified_description); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_FREQUENCY)) $criteria->add(PaypalOrderTableMap::PLANIFIED_FREQUENCY, $this->planified_frequency); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL)) $criteria->add(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL, $this->planified_frequency_interval); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_CYCLE)) $criteria->add(PaypalOrderTableMap::PLANIFIED_CYCLE, $this->planified_cycle); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE)) $criteria->add(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE, $this->planified_actual_cycle); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT)) $criteria->add(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT, $this->planified_min_amount); + if ($this->isColumnModified(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT)) $criteria->add(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT, $this->planified_max_amount); + if ($this->isColumnModified(PaypalOrderTableMap::CREATED_AT)) $criteria->add(PaypalOrderTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalOrderTableMap::UPDATED_AT)) $criteria->add(PaypalOrderTableMap::UPDATED_AT, $this->updated_at); + if ($this->isColumnModified(PaypalOrderTableMap::VERSION)) $criteria->add(PaypalOrderTableMap::VERSION, $this->version); + if ($this->isColumnModified(PaypalOrderTableMap::VERSION_CREATED_AT)) $criteria->add(PaypalOrderTableMap::VERSION_CREATED_AT, $this->version_created_at); + if ($this->isColumnModified(PaypalOrderTableMap::VERSION_CREATED_BY)) $criteria->add(PaypalOrderTableMap::VERSION_CREATED_BY, $this->version_created_by); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalOrderTableMap::DATABASE_NAME); + $criteria->add(PaypalOrderTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalOrder (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setPaymentId($this->getPaymentId()); + $copyObj->setAgreementId($this->getAgreementId()); + $copyObj->setCreditCardId($this->getCreditCardId()); + $copyObj->setState($this->getState()); + $copyObj->setAmount($this->getAmount()); + $copyObj->setDescription($this->getDescription()); + $copyObj->setPayerId($this->getPayerId()); + $copyObj->setToken($this->getToken()); + $copyObj->setPlanifiedTitle($this->getPlanifiedTitle()); + $copyObj->setPlanifiedDescription($this->getPlanifiedDescription()); + $copyObj->setPlanifiedFrequency($this->getPlanifiedFrequency()); + $copyObj->setPlanifiedFrequencyInterval($this->getPlanifiedFrequencyInterval()); + $copyObj->setPlanifiedCycle($this->getPlanifiedCycle()); + $copyObj->setPlanifiedActualCycle($this->getPlanifiedActualCycle()); + $copyObj->setPlanifiedMinAmount($this->getPlanifiedMinAmount()); + $copyObj->setPlanifiedMaxAmount($this->getPlanifiedMaxAmount()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + $copyObj->setVersion($this->getVersion()); + $copyObj->setVersionCreatedAt($this->getVersionCreatedAt()); + $copyObj->setVersionCreatedBy($this->getVersionCreatedBy()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getPaypalPlans() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addPaypalPlan($relObj->copy($deepCopy)); + } + } + + foreach ($this->getPaypalOrderVersions() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addPaypalOrderVersion($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalOrder Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildOrder object. + * + * @param ChildOrder $v + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + * @throws PropelException + */ + public function setOrder(ChildOrder $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aOrder = $v; + + // Add binding for other direction of this 1:1 relationship. + if ($v !== null) { + $v->setPaypalOrder($this); + } + + + return $this; + } + + + /** + * Get the associated ChildOrder object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildOrder The associated ChildOrder object. + * @throws PropelException + */ + public function getOrder(ConnectionInterface $con = null) + { + if ($this->aOrder === null && ($this->id !== null)) { + $this->aOrder = OrderQuery::create()->findPk($this->id, $con); + // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. + $this->aOrder->setPaypalOrder($this); + } + + return $this->aOrder; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('PaypalPlan' == $relationName) { + return $this->initPaypalPlans(); + } + if ('PaypalOrderVersion' == $relationName) { + return $this->initPaypalOrderVersions(); + } + } + + /** + * Clears out the collPaypalPlans collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addPaypalPlans() + */ + public function clearPaypalPlans() + { + $this->collPaypalPlans = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collPaypalPlans collection loaded partially. + */ + public function resetPartialPaypalPlans($v = true) + { + $this->collPaypalPlansPartial = $v; + } + + /** + * Initializes the collPaypalPlans collection. + * + * By default this just sets the collPaypalPlans collection to an empty array (like clearcollPaypalPlans()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initPaypalPlans($overrideExisting = true) + { + if (null !== $this->collPaypalPlans && !$overrideExisting) { + return; + } + $this->collPaypalPlans = new ObjectCollection(); + $this->collPaypalPlans->setModel('\PayPal\Model\PaypalPlan'); + } + + /** + * Gets an array of ChildPaypalPlan objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildPaypalOrder is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildPaypalPlan[] List of ChildPaypalPlan objects + * @throws PropelException + */ + public function getPaypalPlans($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collPaypalPlansPartial && !$this->isNew(); + if (null === $this->collPaypalPlans || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalPlans) { + // return empty collection + $this->initPaypalPlans(); + } else { + $collPaypalPlans = ChildPaypalPlanQuery::create(null, $criteria) + ->filterByPaypalOrder($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collPaypalPlansPartial && count($collPaypalPlans)) { + $this->initPaypalPlans(false); + + foreach ($collPaypalPlans as $obj) { + if (false == $this->collPaypalPlans->contains($obj)) { + $this->collPaypalPlans->append($obj); + } + } + + $this->collPaypalPlansPartial = true; + } + + reset($collPaypalPlans); + + return $collPaypalPlans; + } + + if ($partial && $this->collPaypalPlans) { + foreach ($this->collPaypalPlans as $obj) { + if ($obj->isNew()) { + $collPaypalPlans[] = $obj; + } + } + } + + $this->collPaypalPlans = $collPaypalPlans; + $this->collPaypalPlansPartial = false; + } + } + + return $this->collPaypalPlans; + } + + /** + * Sets a collection of PaypalPlan objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $paypalPlans A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function setPaypalPlans(Collection $paypalPlans, ConnectionInterface $con = null) + { + $paypalPlansToDelete = $this->getPaypalPlans(new Criteria(), $con)->diff($paypalPlans); + + + $this->paypalPlansScheduledForDeletion = $paypalPlansToDelete; + + foreach ($paypalPlansToDelete as $paypalPlanRemoved) { + $paypalPlanRemoved->setPaypalOrder(null); + } + + $this->collPaypalPlans = null; + foreach ($paypalPlans as $paypalPlan) { + $this->addPaypalPlan($paypalPlan); + } + + $this->collPaypalPlans = $paypalPlans; + $this->collPaypalPlansPartial = false; + + return $this; + } + + /** + * Returns the number of related PaypalPlan objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related PaypalPlan objects. + * @throws PropelException + */ + public function countPaypalPlans(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collPaypalPlansPartial && !$this->isNew(); + if (null === $this->collPaypalPlans || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalPlans) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getPaypalPlans()); + } + + $query = ChildPaypalPlanQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByPaypalOrder($this) + ->count($con); + } + + return count($this->collPaypalPlans); + } + + /** + * Method called to associate a ChildPaypalPlan object to this object + * through the ChildPaypalPlan foreign key attribute. + * + * @param ChildPaypalPlan $l ChildPaypalPlan + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function addPaypalPlan(ChildPaypalPlan $l) + { + if ($this->collPaypalPlans === null) { + $this->initPaypalPlans(); + $this->collPaypalPlansPartial = true; + } + + if (!in_array($l, $this->collPaypalPlans->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddPaypalPlan($l); + } + + return $this; + } + + /** + * @param PaypalPlan $paypalPlan The paypalPlan object to add. + */ + protected function doAddPaypalPlan($paypalPlan) + { + $this->collPaypalPlans[]= $paypalPlan; + $paypalPlan->setPaypalOrder($this); + } + + /** + * @param PaypalPlan $paypalPlan The paypalPlan object to remove. + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function removePaypalPlan($paypalPlan) + { + if ($this->getPaypalPlans()->contains($paypalPlan)) { + $this->collPaypalPlans->remove($this->collPaypalPlans->search($paypalPlan)); + if (null === $this->paypalPlansScheduledForDeletion) { + $this->paypalPlansScheduledForDeletion = clone $this->collPaypalPlans; + $this->paypalPlansScheduledForDeletion->clear(); + } + $this->paypalPlansScheduledForDeletion[]= clone $paypalPlan; + $paypalPlan->setPaypalOrder(null); + } + + return $this; + } + + /** + * Clears out the collPaypalOrderVersions collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addPaypalOrderVersions() + */ + public function clearPaypalOrderVersions() + { + $this->collPaypalOrderVersions = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collPaypalOrderVersions collection loaded partially. + */ + public function resetPartialPaypalOrderVersions($v = true) + { + $this->collPaypalOrderVersionsPartial = $v; + } + + /** + * Initializes the collPaypalOrderVersions collection. + * + * By default this just sets the collPaypalOrderVersions collection to an empty array (like clearcollPaypalOrderVersions()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initPaypalOrderVersions($overrideExisting = true) + { + if (null !== $this->collPaypalOrderVersions && !$overrideExisting) { + return; + } + $this->collPaypalOrderVersions = new ObjectCollection(); + $this->collPaypalOrderVersions->setModel('\PayPal\Model\PaypalOrderVersion'); + } + + /** + * Gets an array of ChildPaypalOrderVersion objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildPaypalOrder is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildPaypalOrderVersion[] List of ChildPaypalOrderVersion objects + * @throws PropelException + */ + public function getPaypalOrderVersions($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collPaypalOrderVersionsPartial && !$this->isNew(); + if (null === $this->collPaypalOrderVersions || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalOrderVersions) { + // return empty collection + $this->initPaypalOrderVersions(); + } else { + $collPaypalOrderVersions = ChildPaypalOrderVersionQuery::create(null, $criteria) + ->filterByPaypalOrder($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collPaypalOrderVersionsPartial && count($collPaypalOrderVersions)) { + $this->initPaypalOrderVersions(false); + + foreach ($collPaypalOrderVersions as $obj) { + if (false == $this->collPaypalOrderVersions->contains($obj)) { + $this->collPaypalOrderVersions->append($obj); + } + } + + $this->collPaypalOrderVersionsPartial = true; + } + + reset($collPaypalOrderVersions); + + return $collPaypalOrderVersions; + } + + if ($partial && $this->collPaypalOrderVersions) { + foreach ($this->collPaypalOrderVersions as $obj) { + if ($obj->isNew()) { + $collPaypalOrderVersions[] = $obj; + } + } + } + + $this->collPaypalOrderVersions = $collPaypalOrderVersions; + $this->collPaypalOrderVersionsPartial = false; + } + } + + return $this->collPaypalOrderVersions; + } + + /** + * Sets a collection of PaypalOrderVersion objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $paypalOrderVersions A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function setPaypalOrderVersions(Collection $paypalOrderVersions, ConnectionInterface $con = null) + { + $paypalOrderVersionsToDelete = $this->getPaypalOrderVersions(new Criteria(), $con)->diff($paypalOrderVersions); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->paypalOrderVersionsScheduledForDeletion = clone $paypalOrderVersionsToDelete; + + foreach ($paypalOrderVersionsToDelete as $paypalOrderVersionRemoved) { + $paypalOrderVersionRemoved->setPaypalOrder(null); + } + + $this->collPaypalOrderVersions = null; + foreach ($paypalOrderVersions as $paypalOrderVersion) { + $this->addPaypalOrderVersion($paypalOrderVersion); + } + + $this->collPaypalOrderVersions = $paypalOrderVersions; + $this->collPaypalOrderVersionsPartial = false; + + return $this; + } + + /** + * Returns the number of related PaypalOrderVersion objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related PaypalOrderVersion objects. + * @throws PropelException + */ + public function countPaypalOrderVersions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collPaypalOrderVersionsPartial && !$this->isNew(); + if (null === $this->collPaypalOrderVersions || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalOrderVersions) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getPaypalOrderVersions()); + } + + $query = ChildPaypalOrderVersionQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByPaypalOrder($this) + ->count($con); + } + + return count($this->collPaypalOrderVersions); + } + + /** + * Method called to associate a ChildPaypalOrderVersion object to this object + * through the ChildPaypalOrderVersion foreign key attribute. + * + * @param ChildPaypalOrderVersion $l ChildPaypalOrderVersion + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + */ + public function addPaypalOrderVersion(ChildPaypalOrderVersion $l) + { + if ($this->collPaypalOrderVersions === null) { + $this->initPaypalOrderVersions(); + $this->collPaypalOrderVersionsPartial = true; + } + + if (!in_array($l, $this->collPaypalOrderVersions->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddPaypalOrderVersion($l); + } + + return $this; + } + + /** + * @param PaypalOrderVersion $paypalOrderVersion The paypalOrderVersion object to add. + */ + protected function doAddPaypalOrderVersion($paypalOrderVersion) + { + $this->collPaypalOrderVersions[]= $paypalOrderVersion; + $paypalOrderVersion->setPaypalOrder($this); + } + + /** + * @param PaypalOrderVersion $paypalOrderVersion The paypalOrderVersion object to remove. + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function removePaypalOrderVersion($paypalOrderVersion) + { + if ($this->getPaypalOrderVersions()->contains($paypalOrderVersion)) { + $this->collPaypalOrderVersions->remove($this->collPaypalOrderVersions->search($paypalOrderVersion)); + if (null === $this->paypalOrderVersionsScheduledForDeletion) { + $this->paypalOrderVersionsScheduledForDeletion = clone $this->collPaypalOrderVersions; + $this->paypalOrderVersionsScheduledForDeletion->clear(); + } + $this->paypalOrderVersionsScheduledForDeletion[]= clone $paypalOrderVersion; + $paypalOrderVersion->setPaypalOrder(null); + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->payment_id = null; + $this->agreement_id = null; + $this->credit_card_id = null; + $this->state = null; + $this->amount = null; + $this->description = null; + $this->payer_id = null; + $this->token = null; + $this->planified_title = null; + $this->planified_description = null; + $this->planified_frequency = null; + $this->planified_frequency_interval = null; + $this->planified_cycle = null; + $this->planified_actual_cycle = null; + $this->planified_min_amount = null; + $this->planified_max_amount = null; + $this->created_at = null; + $this->updated_at = null; + $this->version = null; + $this->version_created_at = null; + $this->version_created_by = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collPaypalPlans) { + foreach ($this->collPaypalPlans as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collPaypalOrderVersions) { + foreach ($this->collPaypalOrderVersions as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + $this->collPaypalPlans = null; + $this->collPaypalOrderVersions = null; + $this->aOrder = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalOrderTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[PaypalOrderTableMap::UPDATED_AT] = true; + + return $this; + } + + // versionable behavior + + /** + * Enforce a new Version of this object upon next save. + * + * @return \PayPal\Model\PaypalOrder + */ + public function enforceVersioning() + { + $this->enforceVersion = true; + + return $this; + } + + /** + * Checks whether the current state must be recorded as a version + * + * @return boolean + */ + public function isVersioningNecessary($con = null) + { + if ($this->alreadyInSave) { + return false; + } + + if ($this->enforceVersion) { + return true; + } + + if (ChildPaypalOrderQuery::isVersioningEnabled() && ($this->isNew() || $this->isModified()) || $this->isDeleted()) { + return true; + } + if (null !== ($object = $this->getOrder($con)) && $object->isVersioningNecessary($con)) { + return true; + } + + + return false; + } + + /** + * Creates a version of the current object and saves it. + * + * @param ConnectionInterface $con the connection to use + * + * @return ChildPaypalOrderVersion A version object + */ + public function addVersion($con = null) + { + $this->enforceVersion = false; + + $version = new ChildPaypalOrderVersion(); + $version->setId($this->getId()); + $version->setPaymentId($this->getPaymentId()); + $version->setAgreementId($this->getAgreementId()); + $version->setCreditCardId($this->getCreditCardId()); + $version->setState($this->getState()); + $version->setAmount($this->getAmount()); + $version->setDescription($this->getDescription()); + $version->setPayerId($this->getPayerId()); + $version->setToken($this->getToken()); + $version->setPlanifiedTitle($this->getPlanifiedTitle()); + $version->setPlanifiedDescription($this->getPlanifiedDescription()); + $version->setPlanifiedFrequency($this->getPlanifiedFrequency()); + $version->setPlanifiedFrequencyInterval($this->getPlanifiedFrequencyInterval()); + $version->setPlanifiedCycle($this->getPlanifiedCycle()); + $version->setPlanifiedActualCycle($this->getPlanifiedActualCycle()); + $version->setPlanifiedMinAmount($this->getPlanifiedMinAmount()); + $version->setPlanifiedMaxAmount($this->getPlanifiedMaxAmount()); + $version->setCreatedAt($this->getCreatedAt()); + $version->setUpdatedAt($this->getUpdatedAt()); + $version->setVersion($this->getVersion()); + $version->setVersionCreatedAt($this->getVersionCreatedAt()); + $version->setVersionCreatedBy($this->getVersionCreatedBy()); + $version->setPaypalOrder($this); + if (($related = $this->getOrder($con)) && $related->getVersion()) { + $version->setIdVersion($related->getVersion()); + } + $version->save($con); + + return $version; + } + + /** + * Sets the properties of the current object to the value they had at a specific version + * + * @param integer $versionNumber The version number to read + * @param ConnectionInterface $con The connection to use + * + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function toVersion($versionNumber, $con = null) + { + $version = $this->getOneVersion($versionNumber, $con); + if (!$version) { + throw new PropelException(sprintf('No ChildPaypalOrder object found with version %d', $version)); + } + $this->populateFromVersion($version, $con); + + return $this; + } + + /** + * Sets the properties of the current object to the value they had at a specific version + * + * @param ChildPaypalOrderVersion $version The version object to use + * @param ConnectionInterface $con the connection to use + * @param array $loadedObjects objects that been loaded in a chain of populateFromVersion calls on referrer or fk objects. + * + * @return ChildPaypalOrder The current object (for fluent API support) + */ + public function populateFromVersion($version, $con = null, &$loadedObjects = array()) + { + $loadedObjects['ChildPaypalOrder'][$version->getId()][$version->getVersion()] = $this; + $this->setId($version->getId()); + $this->setPaymentId($version->getPaymentId()); + $this->setAgreementId($version->getAgreementId()); + $this->setCreditCardId($version->getCreditCardId()); + $this->setState($version->getState()); + $this->setAmount($version->getAmount()); + $this->setDescription($version->getDescription()); + $this->setPayerId($version->getPayerId()); + $this->setToken($version->getToken()); + $this->setPlanifiedTitle($version->getPlanifiedTitle()); + $this->setPlanifiedDescription($version->getPlanifiedDescription()); + $this->setPlanifiedFrequency($version->getPlanifiedFrequency()); + $this->setPlanifiedFrequencyInterval($version->getPlanifiedFrequencyInterval()); + $this->setPlanifiedCycle($version->getPlanifiedCycle()); + $this->setPlanifiedActualCycle($version->getPlanifiedActualCycle()); + $this->setPlanifiedMinAmount($version->getPlanifiedMinAmount()); + $this->setPlanifiedMaxAmount($version->getPlanifiedMaxAmount()); + $this->setCreatedAt($version->getCreatedAt()); + $this->setUpdatedAt($version->getUpdatedAt()); + $this->setVersion($version->getVersion()); + $this->setVersionCreatedAt($version->getVersionCreatedAt()); + $this->setVersionCreatedBy($version->getVersionCreatedBy()); + if ($fkValue = $version->getId()) { + if (isset($loadedObjects['ChildOrder']) && isset($loadedObjects['ChildOrder'][$fkValue]) && isset($loadedObjects['ChildOrder'][$fkValue][$version->getIdVersion()])) { + $related = $loadedObjects['ChildOrder'][$fkValue][$version->getIdVersion()]; + } else { + $related = new ChildOrder(); + $relatedVersion = OrderVersionQuery::create() + ->filterById($fkValue) + ->filterByVersion($version->getIdVersion()) + ->findOne($con); + $related->populateFromVersion($relatedVersion, $con, $loadedObjects); + $related->setNew(false); + } + $this->setOrder($related); + } + + return $this; + } + + /** + * Gets the latest persisted version number for the current object + * + * @param ConnectionInterface $con the connection to use + * + * @return integer + */ + public function getLastVersionNumber($con = null) + { + $v = ChildPaypalOrderVersionQuery::create() + ->filterByPaypalOrder($this) + ->orderByVersion('desc') + ->findOne($con); + if (!$v) { + return 0; + } + + return $v->getVersion(); + } + + /** + * Checks whether the current object is the latest one + * + * @param ConnectionInterface $con the connection to use + * + * @return Boolean + */ + public function isLastVersion($con = null) + { + return $this->getLastVersionNumber($con) == $this->getVersion(); + } + + /** + * Retrieves a version object for this entity and a version number + * + * @param integer $versionNumber The version number to read + * @param ConnectionInterface $con the connection to use + * + * @return ChildPaypalOrderVersion A version object + */ + public function getOneVersion($versionNumber, $con = null) + { + return ChildPaypalOrderVersionQuery::create() + ->filterByPaypalOrder($this) + ->filterByVersion($versionNumber) + ->findOne($con); + } + + /** + * Gets all the versions of this object, in incremental order + * + * @param ConnectionInterface $con the connection to use + * + * @return ObjectCollection A list of ChildPaypalOrderVersion objects + */ + public function getAllVersions($con = null) + { + $criteria = new Criteria(); + $criteria->addAscendingOrderByColumn(PaypalOrderVersionTableMap::VERSION); + + return $this->getPaypalOrderVersions($criteria, $con); + } + + /** + * Compares the current object with another of its version. + * + * print_r($book->compareVersion(1)); + * => array( + * '1' => array('Title' => 'Book title at version 1'), + * '2' => array('Title' => 'Book title at version 2') + * ); + * + * + * @param integer $versionNumber + * @param string $keys Main key used for the result diff (versions|columns) + * @param ConnectionInterface $con the connection to use + * @param array $ignoredColumns The columns to exclude from the diff. + * + * @return array A list of differences + */ + public function compareVersion($versionNumber, $keys = 'columns', $con = null, $ignoredColumns = array()) + { + $fromVersion = $this->toArray(); + $toVersion = $this->getOneVersion($versionNumber, $con)->toArray(); + + return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns); + } + + /** + * Compares two versions of the current object. + * + * print_r($book->compareVersions(1, 2)); + * => array( + * '1' => array('Title' => 'Book title at version 1'), + * '2' => array('Title' => 'Book title at version 2') + * ); + * + * + * @param integer $fromVersionNumber + * @param integer $toVersionNumber + * @param string $keys Main key used for the result diff (versions|columns) + * @param ConnectionInterface $con the connection to use + * @param array $ignoredColumns The columns to exclude from the diff. + * + * @return array A list of differences + */ + public function compareVersions($fromVersionNumber, $toVersionNumber, $keys = 'columns', $con = null, $ignoredColumns = array()) + { + $fromVersion = $this->getOneVersion($fromVersionNumber, $con)->toArray(); + $toVersion = $this->getOneVersion($toVersionNumber, $con)->toArray(); + + return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns); + } + + /** + * Computes the diff between two versions. + * + * print_r($book->computeDiff(1, 2)); + * => array( + * '1' => array('Title' => 'Book title at version 1'), + * '2' => array('Title' => 'Book title at version 2') + * ); + * + * + * @param array $fromVersion An array representing the original version. + * @param array $toVersion An array representing the destination version. + * @param string $keys Main key used for the result diff (versions|columns). + * @param array $ignoredColumns The columns to exclude from the diff. + * + * @return array A list of differences + */ + protected function computeDiff($fromVersion, $toVersion, $keys = 'columns', $ignoredColumns = array()) + { + $fromVersionNumber = $fromVersion['Version']; + $toVersionNumber = $toVersion['Version']; + $ignoredColumns = array_merge(array( + 'Version', + 'VersionCreatedAt', + 'VersionCreatedBy', + ), $ignoredColumns); + $diff = array(); + foreach ($fromVersion as $key => $value) { + if (in_array($key, $ignoredColumns)) { + continue; + } + if ($toVersion[$key] != $value) { + switch ($keys) { + case 'versions': + $diff[$fromVersionNumber][$key] = $value; + $diff[$toVersionNumber][$key] = $toVersion[$key]; + break; + default: + $diff[$key] = array( + $fromVersionNumber => $value, + $toVersionNumber => $toVersion[$key], + ); + break; + } + } + } + + return $diff; + } + /** + * retrieve the last $number versions. + * + * @param Integer $number the number of record to return. + * @return PropelCollection|array \PayPal\Model\PaypalOrderVersion[] List of \PayPal\Model\PaypalOrderVersion objects + */ + public function getLastVersions($number = 10, $criteria = null, $con = null) + { + $criteria = ChildPaypalOrderVersionQuery::create(null, $criteria); + $criteria->addDescendingOrderByColumn(PaypalOrderVersionTableMap::VERSION); + $criteria->limit($number); + + return $this->getPaypalOrderVersions($criteria, $con); + } + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalOrderQuery.php b/Model/Base/PaypalOrderQuery.php new file mode 100644 index 0000000..06073d1 --- /dev/null +++ b/Model/Base/PaypalOrderQuery.php @@ -0,0 +1,1503 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalOrder|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalOrderTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalOrderTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalOrder A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, PAYMENT_ID, AGREEMENT_ID, CREDIT_CARD_ID, STATE, AMOUNT, DESCRIPTION, PAYER_ID, TOKEN, PLANIFIED_TITLE, PLANIFIED_DESCRIPTION, PLANIFIED_FREQUENCY, PLANIFIED_FREQUENCY_INTERVAL, PLANIFIED_CYCLE, PLANIFIED_ACTUAL_CYCLE, PLANIFIED_MIN_AMOUNT, PLANIFIED_MAX_AMOUNT, CREATED_AT, UPDATED_AT, VERSION, VERSION_CREATED_AT, VERSION_CREATED_BY FROM paypal_order WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalOrder(); + $obj->hydrate($row); + PaypalOrderTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalOrder|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(PaypalOrderTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(PaypalOrderTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByOrder() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the payment_id column + * + * Example usage: + * + * $query->filterByPaymentId('fooValue'); // WHERE payment_id = 'fooValue' + * $query->filterByPaymentId('%fooValue%'); // WHERE payment_id LIKE '%fooValue%' + * + * + * @param string $paymentId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPaymentId($paymentId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($paymentId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $paymentId)) { + $paymentId = str_replace('*', '%', $paymentId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PAYMENT_ID, $paymentId, $comparison); + } + + /** + * Filter the query on the agreement_id column + * + * Example usage: + * + * $query->filterByAgreementId('fooValue'); // WHERE agreement_id = 'fooValue' + * $query->filterByAgreementId('%fooValue%'); // WHERE agreement_id LIKE '%fooValue%' + * + * + * @param string $agreementId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByAgreementId($agreementId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($agreementId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $agreementId)) { + $agreementId = str_replace('*', '%', $agreementId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::AGREEMENT_ID, $agreementId, $comparison); + } + + /** + * Filter the query on the credit_card_id column + * + * Example usage: + * + * $query->filterByCreditCardId('fooValue'); // WHERE credit_card_id = 'fooValue' + * $query->filterByCreditCardId('%fooValue%'); // WHERE credit_card_id LIKE '%fooValue%' + * + * + * @param string $creditCardId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByCreditCardId($creditCardId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($creditCardId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $creditCardId)) { + $creditCardId = str_replace('*', '%', $creditCardId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::CREDIT_CARD_ID, $creditCardId, $comparison); + } + + /** + * Filter the query on the state column + * + * Example usage: + * + * $query->filterByState('fooValue'); // WHERE state = 'fooValue' + * $query->filterByState('%fooValue%'); // WHERE state LIKE '%fooValue%' + * + * + * @param string $state The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByState($state = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($state)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $state)) { + $state = str_replace('*', '%', $state); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::STATE, $state, $comparison); + } + + /** + * Filter the query on the amount column + * + * Example usage: + * + * $query->filterByAmount(1234); // WHERE amount = 1234 + * $query->filterByAmount(array(12, 34)); // WHERE amount IN (12, 34) + * $query->filterByAmount(array('min' => 12)); // WHERE amount > 12 + * + * + * @param mixed $amount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByAmount($amount = null, $comparison = null) + { + if (is_array($amount)) { + $useMinMax = false; + if (isset($amount['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::AMOUNT, $amount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($amount['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::AMOUNT, $amount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::AMOUNT, $amount, $comparison); + } + + /** + * Filter the query on the description column + * + * Example usage: + * + * $query->filterByDescription('fooValue'); // WHERE description = 'fooValue' + * $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%' + * + * + * @param string $description The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByDescription($description = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($description)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $description)) { + $description = str_replace('*', '%', $description); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::DESCRIPTION, $description, $comparison); + } + + /** + * Filter the query on the payer_id column + * + * Example usage: + * + * $query->filterByPayerId('fooValue'); // WHERE payer_id = 'fooValue' + * $query->filterByPayerId('%fooValue%'); // WHERE payer_id LIKE '%fooValue%' + * + * + * @param string $payerId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPayerId($payerId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($payerId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $payerId)) { + $payerId = str_replace('*', '%', $payerId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PAYER_ID, $payerId, $comparison); + } + + /** + * Filter the query on the token column + * + * Example usage: + * + * $query->filterByToken('fooValue'); // WHERE token = 'fooValue' + * $query->filterByToken('%fooValue%'); // WHERE token LIKE '%fooValue%' + * + * + * @param string $token The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByToken($token = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($token)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $token)) { + $token = str_replace('*', '%', $token); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::TOKEN, $token, $comparison); + } + + /** + * Filter the query on the planified_title column + * + * Example usage: + * + * $query->filterByPlanifiedTitle('fooValue'); // WHERE planified_title = 'fooValue' + * $query->filterByPlanifiedTitle('%fooValue%'); // WHERE planified_title LIKE '%fooValue%' + * + * + * @param string $planifiedTitle The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedTitle($planifiedTitle = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planifiedTitle)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planifiedTitle)) { + $planifiedTitle = str_replace('*', '%', $planifiedTitle); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_TITLE, $planifiedTitle, $comparison); + } + + /** + * Filter the query on the planified_description column + * + * Example usage: + * + * $query->filterByPlanifiedDescription('fooValue'); // WHERE planified_description = 'fooValue' + * $query->filterByPlanifiedDescription('%fooValue%'); // WHERE planified_description LIKE '%fooValue%' + * + * + * @param string $planifiedDescription The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedDescription($planifiedDescription = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planifiedDescription)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planifiedDescription)) { + $planifiedDescription = str_replace('*', '%', $planifiedDescription); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_DESCRIPTION, $planifiedDescription, $comparison); + } + + /** + * Filter the query on the planified_frequency column + * + * Example usage: + * + * $query->filterByPlanifiedFrequency('fooValue'); // WHERE planified_frequency = 'fooValue' + * $query->filterByPlanifiedFrequency('%fooValue%'); // WHERE planified_frequency LIKE '%fooValue%' + * + * + * @param string $planifiedFrequency The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedFrequency($planifiedFrequency = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planifiedFrequency)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planifiedFrequency)) { + $planifiedFrequency = str_replace('*', '%', $planifiedFrequency); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_FREQUENCY, $planifiedFrequency, $comparison); + } + + /** + * Filter the query on the planified_frequency_interval column + * + * Example usage: + * + * $query->filterByPlanifiedFrequencyInterval(1234); // WHERE planified_frequency_interval = 1234 + * $query->filterByPlanifiedFrequencyInterval(array(12, 34)); // WHERE planified_frequency_interval IN (12, 34) + * $query->filterByPlanifiedFrequencyInterval(array('min' => 12)); // WHERE planified_frequency_interval > 12 + * + * + * @param mixed $planifiedFrequencyInterval The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedFrequencyInterval($planifiedFrequencyInterval = null, $comparison = null) + { + if (is_array($planifiedFrequencyInterval)) { + $useMinMax = false; + if (isset($planifiedFrequencyInterval['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL, $planifiedFrequencyInterval['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedFrequencyInterval['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL, $planifiedFrequencyInterval['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL, $planifiedFrequencyInterval, $comparison); + } + + /** + * Filter the query on the planified_cycle column + * + * Example usage: + * + * $query->filterByPlanifiedCycle(1234); // WHERE planified_cycle = 1234 + * $query->filterByPlanifiedCycle(array(12, 34)); // WHERE planified_cycle IN (12, 34) + * $query->filterByPlanifiedCycle(array('min' => 12)); // WHERE planified_cycle > 12 + * + * + * @param mixed $planifiedCycle The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedCycle($planifiedCycle = null, $comparison = null) + { + if (is_array($planifiedCycle)) { + $useMinMax = false; + if (isset($planifiedCycle['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_CYCLE, $planifiedCycle['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedCycle['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_CYCLE, $planifiedCycle['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_CYCLE, $planifiedCycle, $comparison); + } + + /** + * Filter the query on the planified_actual_cycle column + * + * Example usage: + * + * $query->filterByPlanifiedActualCycle(1234); // WHERE planified_actual_cycle = 1234 + * $query->filterByPlanifiedActualCycle(array(12, 34)); // WHERE planified_actual_cycle IN (12, 34) + * $query->filterByPlanifiedActualCycle(array('min' => 12)); // WHERE planified_actual_cycle > 12 + * + * + * @param mixed $planifiedActualCycle The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedActualCycle($planifiedActualCycle = null, $comparison = null) + { + if (is_array($planifiedActualCycle)) { + $useMinMax = false; + if (isset($planifiedActualCycle['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE, $planifiedActualCycle['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedActualCycle['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE, $planifiedActualCycle['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE, $planifiedActualCycle, $comparison); + } + + /** + * Filter the query on the planified_min_amount column + * + * Example usage: + * + * $query->filterByPlanifiedMinAmount(1234); // WHERE planified_min_amount = 1234 + * $query->filterByPlanifiedMinAmount(array(12, 34)); // WHERE planified_min_amount IN (12, 34) + * $query->filterByPlanifiedMinAmount(array('min' => 12)); // WHERE planified_min_amount > 12 + * + * + * @param mixed $planifiedMinAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedMinAmount($planifiedMinAmount = null, $comparison = null) + { + if (is_array($planifiedMinAmount)) { + $useMinMax = false; + if (isset($planifiedMinAmount['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT, $planifiedMinAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedMinAmount['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT, $planifiedMinAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT, $planifiedMinAmount, $comparison); + } + + /** + * Filter the query on the planified_max_amount column + * + * Example usage: + * + * $query->filterByPlanifiedMaxAmount(1234); // WHERE planified_max_amount = 1234 + * $query->filterByPlanifiedMaxAmount(array(12, 34)); // WHERE planified_max_amount IN (12, 34) + * $query->filterByPlanifiedMaxAmount(array('min' => 12)); // WHERE planified_max_amount > 12 + * + * + * @param mixed $planifiedMaxAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPlanifiedMaxAmount($planifiedMaxAmount = null, $comparison = null) + { + if (is_array($planifiedMaxAmount)) { + $useMinMax = false; + if (isset($planifiedMaxAmount['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT, $planifiedMaxAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedMaxAmount['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT, $planifiedMaxAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT, $planifiedMaxAmount, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query on the version column + * + * Example usage: + * + * $query->filterByVersion(1234); // WHERE version = 1234 + * $query->filterByVersion(array(12, 34)); // WHERE version IN (12, 34) + * $query->filterByVersion(array('min' => 12)); // WHERE version > 12 + * + * + * @param mixed $version The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByVersion($version = null, $comparison = null) + { + if (is_array($version)) { + $useMinMax = false; + if (isset($version['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::VERSION, $version['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($version['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::VERSION, $version['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::VERSION, $version, $comparison); + } + + /** + * Filter the query on the version_created_at column + * + * Example usage: + * + * $query->filterByVersionCreatedAt('2011-03-14'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt('now'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt(array('max' => 'yesterday')); // WHERE version_created_at > '2011-03-13' + * + * + * @param mixed $versionCreatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByVersionCreatedAt($versionCreatedAt = null, $comparison = null) + { + if (is_array($versionCreatedAt)) { + $useMinMax = false; + if (isset($versionCreatedAt['min'])) { + $this->addUsingAlias(PaypalOrderTableMap::VERSION_CREATED_AT, $versionCreatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($versionCreatedAt['max'])) { + $this->addUsingAlias(PaypalOrderTableMap::VERSION_CREATED_AT, $versionCreatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::VERSION_CREATED_AT, $versionCreatedAt, $comparison); + } + + /** + * Filter the query on the version_created_by column + * + * Example usage: + * + * $query->filterByVersionCreatedBy('fooValue'); // WHERE version_created_by = 'fooValue' + * $query->filterByVersionCreatedBy('%fooValue%'); // WHERE version_created_by LIKE '%fooValue%' + * + * + * @param string $versionCreatedBy The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByVersionCreatedBy($versionCreatedBy = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($versionCreatedBy)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $versionCreatedBy)) { + $versionCreatedBy = str_replace('*', '%', $versionCreatedBy); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderTableMap::VERSION_CREATED_BY, $versionCreatedBy, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Order object + * + * @param \Thelia\Model\Order|ObjectCollection $order The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByOrder($order, $comparison = null) + { + if ($order instanceof \Thelia\Model\Order) { + return $this + ->addUsingAlias(PaypalOrderTableMap::ID, $order->getId(), $comparison); + } elseif ($order instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalOrderTableMap::ID, $order->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByOrder() only accepts arguments of type \Thelia\Model\Order or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Order relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function joinOrder($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Order'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Order'); + } + + return $this; + } + + /** + * Use the Order relation Order object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\OrderQuery A secondary query class using the current class as primary query + */ + public function useOrderQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinOrder($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Order', '\Thelia\Model\OrderQuery'); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalPlan object + * + * @param \PayPal\Model\PaypalPlan|ObjectCollection $paypalPlan the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPaypalPlan($paypalPlan, $comparison = null) + { + if ($paypalPlan instanceof \PayPal\Model\PaypalPlan) { + return $this + ->addUsingAlias(PaypalOrderTableMap::ID, $paypalPlan->getPaypalOrderId(), $comparison); + } elseif ($paypalPlan instanceof ObjectCollection) { + return $this + ->usePaypalPlanQuery() + ->filterByPrimaryKeys($paypalPlan->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByPaypalPlan() only accepts arguments of type \PayPal\Model\PaypalPlan or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalPlan relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function joinPaypalPlan($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalPlan'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalPlan'); + } + + return $this; + } + + /** + * Use the PaypalPlan relation PaypalPlan object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalPlanQuery A secondary query class using the current class as primary query + */ + public function usePaypalPlanQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinPaypalPlan($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalPlan', '\PayPal\Model\PaypalPlanQuery'); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalOrderVersion object + * + * @param \PayPal\Model\PaypalOrderVersion|ObjectCollection $paypalOrderVersion the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function filterByPaypalOrderVersion($paypalOrderVersion, $comparison = null) + { + if ($paypalOrderVersion instanceof \PayPal\Model\PaypalOrderVersion) { + return $this + ->addUsingAlias(PaypalOrderTableMap::ID, $paypalOrderVersion->getId(), $comparison); + } elseif ($paypalOrderVersion instanceof ObjectCollection) { + return $this + ->usePaypalOrderVersionQuery() + ->filterByPrimaryKeys($paypalOrderVersion->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByPaypalOrderVersion() only accepts arguments of type \PayPal\Model\PaypalOrderVersion or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalOrderVersion relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function joinPaypalOrderVersion($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalOrderVersion'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalOrderVersion'); + } + + return $this; + } + + /** + * Use the PaypalOrderVersion relation PaypalOrderVersion object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalOrderVersionQuery A secondary query class using the current class as primary query + */ + public function usePaypalOrderVersionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinPaypalOrderVersion($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalOrderVersion', '\PayPal\Model\PaypalOrderVersionQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalOrder $paypalOrder Object to remove from the list of results + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function prune($paypalOrder = null) + { + if ($paypalOrder) { + $this->addUsingAlias(PaypalOrderTableMap::ID, $paypalOrder->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_order table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalOrderTableMap::clearInstancePool(); + PaypalOrderTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalOrder or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalOrder object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalOrderTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalOrderTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalOrderTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(PaypalOrderTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(PaypalOrderTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalOrderTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalOrderTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalOrderTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildPaypalOrderQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalOrderTableMap::CREATED_AT); + } + + // versionable behavior + + /** + * Checks whether versioning is enabled + * + * @return boolean + */ + static public function isVersioningEnabled() + { + return self::$isVersioningEnabled; + } + + /** + * Enables versioning + */ + static public function enableVersioning() + { + self::$isVersioningEnabled = true; + } + + /** + * Disables versioning + */ + static public function disableVersioning() + { + self::$isVersioningEnabled = false; + } + +} // PaypalOrderQuery diff --git a/Model/Base/PaypalOrderVersion.php b/Model/Base/PaypalOrderVersion.php new file mode 100644 index 0000000..1ef2f86 --- /dev/null +++ b/Model/Base/PaypalOrderVersion.php @@ -0,0 +1,2496 @@ +amount = '0.000000'; + $this->planified_actual_cycle = 0; + $this->planified_min_amount = '0.000000'; + $this->planified_max_amount = '0.000000'; + $this->version = 0; + $this->id_version = 0; + } + + /** + * Initializes internal state of PayPal\Model\Base\PaypalOrderVersion object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalOrderVersion instance. If + * obj is an instance of PaypalOrderVersion, delegates to + * equals(PaypalOrderVersion). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalOrderVersion The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalOrderVersion The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [payment_id] column value. + * + * @return string + */ + public function getPaymentId() + { + + return $this->payment_id; + } + + /** + * Get the [agreement_id] column value. + * + * @return string + */ + public function getAgreementId() + { + + return $this->agreement_id; + } + + /** + * Get the [credit_card_id] column value. + * + * @return string + */ + public function getCreditCardId() + { + + return $this->credit_card_id; + } + + /** + * Get the [state] column value. + * + * @return string + */ + public function getState() + { + + return $this->state; + } + + /** + * Get the [amount] column value. + * + * @return string + */ + public function getAmount() + { + + return $this->amount; + } + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + + return $this->description; + } + + /** + * Get the [payer_id] column value. + * + * @return string + */ + public function getPayerId() + { + + return $this->payer_id; + } + + /** + * Get the [token] column value. + * + * @return string + */ + public function getToken() + { + + return $this->token; + } + + /** + * Get the [planified_title] column value. + * + * @return string + */ + public function getPlanifiedTitle() + { + + return $this->planified_title; + } + + /** + * Get the [planified_description] column value. + * + * @return string + */ + public function getPlanifiedDescription() + { + + return $this->planified_description; + } + + /** + * Get the [planified_frequency] column value. + * + * @return string + */ + public function getPlanifiedFrequency() + { + + return $this->planified_frequency; + } + + /** + * Get the [planified_frequency_interval] column value. + * + * @return int + */ + public function getPlanifiedFrequencyInterval() + { + + return $this->planified_frequency_interval; + } + + /** + * Get the [planified_cycle] column value. + * + * @return int + */ + public function getPlanifiedCycle() + { + + return $this->planified_cycle; + } + + /** + * Get the [planified_actual_cycle] column value. + * + * @return int + */ + public function getPlanifiedActualCycle() + { + + return $this->planified_actual_cycle; + } + + /** + * Get the [planified_min_amount] column value. + * + * @return string + */ + public function getPlanifiedMinAmount() + { + + return $this->planified_min_amount; + } + + /** + * Get the [planified_max_amount] column value. + * + * @return string + */ + public function getPlanifiedMaxAmount() + { + + return $this->planified_max_amount; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Get the [version] column value. + * + * @return int + */ + public function getVersion() + { + + return $this->version; + } + + /** + * Get the [optionally formatted] temporal [version_created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getVersionCreatedAt($format = NULL) + { + if ($format === null) { + return $this->version_created_at; + } else { + return $this->version_created_at instanceof \DateTime ? $this->version_created_at->format($format) : null; + } + } + + /** + * Get the [version_created_by] column value. + * + * @return string + */ + public function getVersionCreatedBy() + { + + return $this->version_created_by; + } + + /** + * Get the [id_version] column value. + * + * @return int + */ + public function getIdVersion() + { + + return $this->id_version; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::ID] = true; + } + + if ($this->aPaypalOrder !== null && $this->aPaypalOrder->getId() !== $v) { + $this->aPaypalOrder = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [payment_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPaymentId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->payment_id !== $v) { + $this->payment_id = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PAYMENT_ID] = true; + } + + + return $this; + } // setPaymentId() + + /** + * Set the value of [agreement_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setAgreementId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->agreement_id !== $v) { + $this->agreement_id = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::AGREEMENT_ID] = true; + } + + + return $this; + } // setAgreementId() + + /** + * Set the value of [credit_card_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setCreditCardId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->credit_card_id !== $v) { + $this->credit_card_id = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::CREDIT_CARD_ID] = true; + } + + + return $this; + } // setCreditCardId() + + /** + * Set the value of [state] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setState($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->state !== $v) { + $this->state = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::STATE] = true; + } + + + return $this; + } // setState() + + /** + * Set the value of [amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->amount !== $v) { + $this->amount = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::AMOUNT] = true; + } + + + return $this; + } // setAmount() + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->description !== $v) { + $this->description = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::DESCRIPTION] = true; + } + + + return $this; + } // setDescription() + + /** + * Set the value of [payer_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPayerId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->payer_id !== $v) { + $this->payer_id = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PAYER_ID] = true; + } + + + return $this; + } // setPayerId() + + /** + * Set the value of [token] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setToken($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->token !== $v) { + $this->token = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::TOKEN] = true; + } + + + return $this; + } // setToken() + + /** + * Set the value of [planified_title] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_title !== $v) { + $this->planified_title = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_TITLE] = true; + } + + + return $this; + } // setPlanifiedTitle() + + /** + * Set the value of [planified_description] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_description !== $v) { + $this->planified_description = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION] = true; + } + + + return $this; + } // setPlanifiedDescription() + + /** + * Set the value of [planified_frequency] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedFrequency($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_frequency !== $v) { + $this->planified_frequency = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY] = true; + } + + + return $this; + } // setPlanifiedFrequency() + + /** + * Set the value of [planified_frequency_interval] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedFrequencyInterval($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_frequency_interval !== $v) { + $this->planified_frequency_interval = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL] = true; + } + + + return $this; + } // setPlanifiedFrequencyInterval() + + /** + * Set the value of [planified_cycle] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedCycle($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_cycle !== $v) { + $this->planified_cycle = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_CYCLE] = true; + } + + + return $this; + } // setPlanifiedCycle() + + /** + * Set the value of [planified_actual_cycle] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedActualCycle($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->planified_actual_cycle !== $v) { + $this->planified_actual_cycle = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE] = true; + } + + + return $this; + } // setPlanifiedActualCycle() + + /** + * Set the value of [planified_min_amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedMinAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_min_amount !== $v) { + $this->planified_min_amount = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT] = true; + } + + + return $this; + } // setPlanifiedMinAmount() + + /** + * Set the value of [planified_max_amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setPlanifiedMaxAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->planified_max_amount !== $v) { + $this->planified_max_amount = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT] = true; + } + + + return $this; + } // setPlanifiedMaxAmount() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalOrderVersionTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalOrderVersionTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Set the value of [version] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setVersion($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->version !== $v) { + $this->version = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::VERSION] = true; + } + + + return $this; + } // setVersion() + + /** + * Sets the value of [version_created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setVersionCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->version_created_at !== null || $dt !== null) { + if ($dt !== $this->version_created_at) { + $this->version_created_at = $dt; + $this->modifiedColumns[PaypalOrderVersionTableMap::VERSION_CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setVersionCreatedAt() + + /** + * Set the value of [version_created_by] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setVersionCreatedBy($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->version_created_by !== $v) { + $this->version_created_by = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::VERSION_CREATED_BY] = true; + } + + + return $this; + } // setVersionCreatedBy() + + /** + * Set the value of [id_version] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + */ + public function setIdVersion($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id_version !== $v) { + $this->id_version = $v; + $this->modifiedColumns[PaypalOrderVersionTableMap::ID_VERSION] = true; + } + + + return $this; + } // setIdVersion() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->amount !== '0.000000') { + return false; + } + + if ($this->planified_actual_cycle !== 0) { + return false; + } + + if ($this->planified_min_amount !== '0.000000') { + return false; + } + + if ($this->planified_max_amount !== '0.000000') { + return false; + } + + if ($this->version !== 0) { + return false; + } + + if ($this->id_version !== 0) { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalOrderVersionTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PaymentId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->payment_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalOrderVersionTableMap::translateFieldName('AgreementId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->agreement_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalOrderVersionTableMap::translateFieldName('CreditCardId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->credit_card_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalOrderVersionTableMap::translateFieldName('State', TableMap::TYPE_PHPNAME, $indexType)]; + $this->state = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalOrderVersionTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PaypalOrderVersionTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; + $this->description = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PayerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->payer_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : PaypalOrderVersionTableMap::translateFieldName('Token', TableMap::TYPE_PHPNAME, $indexType)]; + $this->token = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedTitle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_title = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedDescription', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_description = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedFrequency', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_frequency = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedFrequencyInterval', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_frequency_interval = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedCycle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_cycle = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedActualCycle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_actual_cycle = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedMinAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_min_amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 16 + $startcol : PaypalOrderVersionTableMap::translateFieldName('PlanifiedMaxAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->planified_max_amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 17 + $startcol : PaypalOrderVersionTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 18 + $startcol : PaypalOrderVersionTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 19 + $startcol : PaypalOrderVersionTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 20 + $startcol : PaypalOrderVersionTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->version_created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 21 + $startcol : PaypalOrderVersionTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version_created_by = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 22 + $startcol : PaypalOrderVersionTableMap::translateFieldName('IdVersion', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id_version = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 23; // 23 = PaypalOrderVersionTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalOrderVersion object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aPaypalOrder !== null && $this->id !== $this->aPaypalOrder->getId()) { + $this->aPaypalOrder = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalOrderVersionQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aPaypalOrder = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalOrderVersion::setDeleted() + * @see PaypalOrderVersion::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalOrderVersionQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalOrderVersionTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aPaypalOrder !== null) { + if ($this->aPaypalOrder->isModified() || $this->aPaypalOrder->isNew()) { + $affectedRows += $this->aPaypalOrder->save($con); + } + $this->setPaypalOrder($this->aPaypalOrder); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalOrderVersionTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PAYMENT_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYMENT_ID'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::AGREEMENT_ID)) { + $modifiedColumns[':p' . $index++] = 'AGREEMENT_ID'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::CREDIT_CARD_ID)) { + $modifiedColumns[':p' . $index++] = 'CREDIT_CARD_ID'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::STATE)) { + $modifiedColumns[':p' . $index++] = 'STATE'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'AMOUNT'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = 'DESCRIPTION'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PAYER_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYER_ID'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::TOKEN)) { + $modifiedColumns[':p' . $index++] = 'TOKEN'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_TITLE)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_TITLE'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_DESCRIPTION'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_FREQUENCY'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_FREQUENCY_INTERVAL'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_CYCLE)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_CYCLE'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_ACTUAL_CYCLE'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_MIN_AMOUNT'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'PLANIFIED_MAX_AMOUNT'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::VERSION)) { + $modifiedColumns[':p' . $index++] = 'VERSION'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::VERSION_CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'VERSION_CREATED_AT'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::VERSION_CREATED_BY)) { + $modifiedColumns[':p' . $index++] = 'VERSION_CREATED_BY'; + } + if ($this->isColumnModified(PaypalOrderVersionTableMap::ID_VERSION)) { + $modifiedColumns[':p' . $index++] = 'ID_VERSION'; + } + + $sql = sprintf( + 'INSERT INTO paypal_order_version (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'PAYMENT_ID': + $stmt->bindValue($identifier, $this->payment_id, PDO::PARAM_STR); + break; + case 'AGREEMENT_ID': + $stmt->bindValue($identifier, $this->agreement_id, PDO::PARAM_STR); + break; + case 'CREDIT_CARD_ID': + $stmt->bindValue($identifier, $this->credit_card_id, PDO::PARAM_STR); + break; + case 'STATE': + $stmt->bindValue($identifier, $this->state, PDO::PARAM_STR); + break; + case 'AMOUNT': + $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); + break; + case 'DESCRIPTION': + $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR); + break; + case 'PAYER_ID': + $stmt->bindValue($identifier, $this->payer_id, PDO::PARAM_STR); + break; + case 'TOKEN': + $stmt->bindValue($identifier, $this->token, PDO::PARAM_STR); + break; + case 'PLANIFIED_TITLE': + $stmt->bindValue($identifier, $this->planified_title, PDO::PARAM_STR); + break; + case 'PLANIFIED_DESCRIPTION': + $stmt->bindValue($identifier, $this->planified_description, PDO::PARAM_STR); + break; + case 'PLANIFIED_FREQUENCY': + $stmt->bindValue($identifier, $this->planified_frequency, PDO::PARAM_STR); + break; + case 'PLANIFIED_FREQUENCY_INTERVAL': + $stmt->bindValue($identifier, $this->planified_frequency_interval, PDO::PARAM_INT); + break; + case 'PLANIFIED_CYCLE': + $stmt->bindValue($identifier, $this->planified_cycle, PDO::PARAM_INT); + break; + case 'PLANIFIED_ACTUAL_CYCLE': + $stmt->bindValue($identifier, $this->planified_actual_cycle, PDO::PARAM_INT); + break; + case 'PLANIFIED_MIN_AMOUNT': + $stmt->bindValue($identifier, $this->planified_min_amount, PDO::PARAM_STR); + break; + case 'PLANIFIED_MAX_AMOUNT': + $stmt->bindValue($identifier, $this->planified_max_amount, PDO::PARAM_STR); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'VERSION': + $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT); + break; + case 'VERSION_CREATED_AT': + $stmt->bindValue($identifier, $this->version_created_at ? $this->version_created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'VERSION_CREATED_BY': + $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR); + break; + case 'ID_VERSION': + $stmt->bindValue($identifier, $this->id_version, PDO::PARAM_INT); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalOrderVersionTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPaymentId(); + break; + case 2: + return $this->getAgreementId(); + break; + case 3: + return $this->getCreditCardId(); + break; + case 4: + return $this->getState(); + break; + case 5: + return $this->getAmount(); + break; + case 6: + return $this->getDescription(); + break; + case 7: + return $this->getPayerId(); + break; + case 8: + return $this->getToken(); + break; + case 9: + return $this->getPlanifiedTitle(); + break; + case 10: + return $this->getPlanifiedDescription(); + break; + case 11: + return $this->getPlanifiedFrequency(); + break; + case 12: + return $this->getPlanifiedFrequencyInterval(); + break; + case 13: + return $this->getPlanifiedCycle(); + break; + case 14: + return $this->getPlanifiedActualCycle(); + break; + case 15: + return $this->getPlanifiedMinAmount(); + break; + case 16: + return $this->getPlanifiedMaxAmount(); + break; + case 17: + return $this->getCreatedAt(); + break; + case 18: + return $this->getUpdatedAt(); + break; + case 19: + return $this->getVersion(); + break; + case 20: + return $this->getVersionCreatedAt(); + break; + case 21: + return $this->getVersionCreatedBy(); + break; + case 22: + return $this->getIdVersion(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalOrderVersion'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalOrderVersion'][serialize($this->getPrimaryKey())] = true; + $keys = PaypalOrderVersionTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPaymentId(), + $keys[2] => $this->getAgreementId(), + $keys[3] => $this->getCreditCardId(), + $keys[4] => $this->getState(), + $keys[5] => $this->getAmount(), + $keys[6] => $this->getDescription(), + $keys[7] => $this->getPayerId(), + $keys[8] => $this->getToken(), + $keys[9] => $this->getPlanifiedTitle(), + $keys[10] => $this->getPlanifiedDescription(), + $keys[11] => $this->getPlanifiedFrequency(), + $keys[12] => $this->getPlanifiedFrequencyInterval(), + $keys[13] => $this->getPlanifiedCycle(), + $keys[14] => $this->getPlanifiedActualCycle(), + $keys[15] => $this->getPlanifiedMinAmount(), + $keys[16] => $this->getPlanifiedMaxAmount(), + $keys[17] => $this->getCreatedAt(), + $keys[18] => $this->getUpdatedAt(), + $keys[19] => $this->getVersion(), + $keys[20] => $this->getVersionCreatedAt(), + $keys[21] => $this->getVersionCreatedBy(), + $keys[22] => $this->getIdVersion(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aPaypalOrder) { + $result['PaypalOrder'] = $this->aPaypalOrder->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalOrderVersionTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPaymentId($value); + break; + case 2: + $this->setAgreementId($value); + break; + case 3: + $this->setCreditCardId($value); + break; + case 4: + $this->setState($value); + break; + case 5: + $this->setAmount($value); + break; + case 6: + $this->setDescription($value); + break; + case 7: + $this->setPayerId($value); + break; + case 8: + $this->setToken($value); + break; + case 9: + $this->setPlanifiedTitle($value); + break; + case 10: + $this->setPlanifiedDescription($value); + break; + case 11: + $this->setPlanifiedFrequency($value); + break; + case 12: + $this->setPlanifiedFrequencyInterval($value); + break; + case 13: + $this->setPlanifiedCycle($value); + break; + case 14: + $this->setPlanifiedActualCycle($value); + break; + case 15: + $this->setPlanifiedMinAmount($value); + break; + case 16: + $this->setPlanifiedMaxAmount($value); + break; + case 17: + $this->setCreatedAt($value); + break; + case 18: + $this->setUpdatedAt($value); + break; + case 19: + $this->setVersion($value); + break; + case 20: + $this->setVersionCreatedAt($value); + break; + case 21: + $this->setVersionCreatedBy($value); + break; + case 22: + $this->setIdVersion($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalOrderVersionTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setPaymentId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setAgreementId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setCreditCardId($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setState($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setAmount($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setDescription($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setPayerId($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setToken($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setPlanifiedTitle($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setPlanifiedDescription($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setPlanifiedFrequency($arr[$keys[11]]); + if (array_key_exists($keys[12], $arr)) $this->setPlanifiedFrequencyInterval($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setPlanifiedCycle($arr[$keys[13]]); + if (array_key_exists($keys[14], $arr)) $this->setPlanifiedActualCycle($arr[$keys[14]]); + if (array_key_exists($keys[15], $arr)) $this->setPlanifiedMinAmount($arr[$keys[15]]); + if (array_key_exists($keys[16], $arr)) $this->setPlanifiedMaxAmount($arr[$keys[16]]); + if (array_key_exists($keys[17], $arr)) $this->setCreatedAt($arr[$keys[17]]); + if (array_key_exists($keys[18], $arr)) $this->setUpdatedAt($arr[$keys[18]]); + if (array_key_exists($keys[19], $arr)) $this->setVersion($arr[$keys[19]]); + if (array_key_exists($keys[20], $arr)) $this->setVersionCreatedAt($arr[$keys[20]]); + if (array_key_exists($keys[21], $arr)) $this->setVersionCreatedBy($arr[$keys[21]]); + if (array_key_exists($keys[22], $arr)) $this->setIdVersion($arr[$keys[22]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalOrderVersionTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalOrderVersionTableMap::ID)) $criteria->add(PaypalOrderVersionTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PAYMENT_ID)) $criteria->add(PaypalOrderVersionTableMap::PAYMENT_ID, $this->payment_id); + if ($this->isColumnModified(PaypalOrderVersionTableMap::AGREEMENT_ID)) $criteria->add(PaypalOrderVersionTableMap::AGREEMENT_ID, $this->agreement_id); + if ($this->isColumnModified(PaypalOrderVersionTableMap::CREDIT_CARD_ID)) $criteria->add(PaypalOrderVersionTableMap::CREDIT_CARD_ID, $this->credit_card_id); + if ($this->isColumnModified(PaypalOrderVersionTableMap::STATE)) $criteria->add(PaypalOrderVersionTableMap::STATE, $this->state); + if ($this->isColumnModified(PaypalOrderVersionTableMap::AMOUNT)) $criteria->add(PaypalOrderVersionTableMap::AMOUNT, $this->amount); + if ($this->isColumnModified(PaypalOrderVersionTableMap::DESCRIPTION)) $criteria->add(PaypalOrderVersionTableMap::DESCRIPTION, $this->description); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PAYER_ID)) $criteria->add(PaypalOrderVersionTableMap::PAYER_ID, $this->payer_id); + if ($this->isColumnModified(PaypalOrderVersionTableMap::TOKEN)) $criteria->add(PaypalOrderVersionTableMap::TOKEN, $this->token); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_TITLE)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_TITLE, $this->planified_title); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION, $this->planified_description); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY, $this->planified_frequency); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL, $this->planified_frequency_interval); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_CYCLE)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_CYCLE, $this->planified_cycle); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE, $this->planified_actual_cycle); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT, $this->planified_min_amount); + if ($this->isColumnModified(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT)) $criteria->add(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT, $this->planified_max_amount); + if ($this->isColumnModified(PaypalOrderVersionTableMap::CREATED_AT)) $criteria->add(PaypalOrderVersionTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalOrderVersionTableMap::UPDATED_AT)) $criteria->add(PaypalOrderVersionTableMap::UPDATED_AT, $this->updated_at); + if ($this->isColumnModified(PaypalOrderVersionTableMap::VERSION)) $criteria->add(PaypalOrderVersionTableMap::VERSION, $this->version); + if ($this->isColumnModified(PaypalOrderVersionTableMap::VERSION_CREATED_AT)) $criteria->add(PaypalOrderVersionTableMap::VERSION_CREATED_AT, $this->version_created_at); + if ($this->isColumnModified(PaypalOrderVersionTableMap::VERSION_CREATED_BY)) $criteria->add(PaypalOrderVersionTableMap::VERSION_CREATED_BY, $this->version_created_by); + if ($this->isColumnModified(PaypalOrderVersionTableMap::ID_VERSION)) $criteria->add(PaypalOrderVersionTableMap::ID_VERSION, $this->id_version); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalOrderVersionTableMap::DATABASE_NAME); + $criteria->add(PaypalOrderVersionTableMap::ID, $this->id); + $criteria->add(PaypalOrderVersionTableMap::VERSION, $this->version); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getVersion(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setVersion($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getVersion()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalOrderVersion (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setPaymentId($this->getPaymentId()); + $copyObj->setAgreementId($this->getAgreementId()); + $copyObj->setCreditCardId($this->getCreditCardId()); + $copyObj->setState($this->getState()); + $copyObj->setAmount($this->getAmount()); + $copyObj->setDescription($this->getDescription()); + $copyObj->setPayerId($this->getPayerId()); + $copyObj->setToken($this->getToken()); + $copyObj->setPlanifiedTitle($this->getPlanifiedTitle()); + $copyObj->setPlanifiedDescription($this->getPlanifiedDescription()); + $copyObj->setPlanifiedFrequency($this->getPlanifiedFrequency()); + $copyObj->setPlanifiedFrequencyInterval($this->getPlanifiedFrequencyInterval()); + $copyObj->setPlanifiedCycle($this->getPlanifiedCycle()); + $copyObj->setPlanifiedActualCycle($this->getPlanifiedActualCycle()); + $copyObj->setPlanifiedMinAmount($this->getPlanifiedMinAmount()); + $copyObj->setPlanifiedMaxAmount($this->getPlanifiedMaxAmount()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + $copyObj->setVersion($this->getVersion()); + $copyObj->setVersionCreatedAt($this->getVersionCreatedAt()); + $copyObj->setVersionCreatedBy($this->getVersionCreatedBy()); + $copyObj->setIdVersion($this->getIdVersion()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalOrderVersion Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildPaypalOrder object. + * + * @param ChildPaypalOrder $v + * @return \PayPal\Model\PaypalOrderVersion The current object (for fluent API support) + * @throws PropelException + */ + public function setPaypalOrder(ChildPaypalOrder $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aPaypalOrder = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildPaypalOrder object, it will not be re-added. + if ($v !== null) { + $v->addPaypalOrderVersion($this); + } + + + return $this; + } + + + /** + * Get the associated ChildPaypalOrder object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildPaypalOrder The associated ChildPaypalOrder object. + * @throws PropelException + */ + public function getPaypalOrder(ConnectionInterface $con = null) + { + if ($this->aPaypalOrder === null && ($this->id !== null)) { + $this->aPaypalOrder = ChildPaypalOrderQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aPaypalOrder->addPaypalOrderVersions($this); + */ + } + + return $this->aPaypalOrder; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->payment_id = null; + $this->agreement_id = null; + $this->credit_card_id = null; + $this->state = null; + $this->amount = null; + $this->description = null; + $this->payer_id = null; + $this->token = null; + $this->planified_title = null; + $this->planified_description = null; + $this->planified_frequency = null; + $this->planified_frequency_interval = null; + $this->planified_cycle = null; + $this->planified_actual_cycle = null; + $this->planified_min_amount = null; + $this->planified_max_amount = null; + $this->created_at = null; + $this->updated_at = null; + $this->version = null; + $this->version_created_at = null; + $this->version_created_by = null; + $this->id_version = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aPaypalOrder = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalOrderVersionTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalOrderVersionQuery.php b/Model/Base/PaypalOrderVersionQuery.php new file mode 100644 index 0000000..23717fb --- /dev/null +++ b/Model/Base/PaypalOrderVersionQuery.php @@ -0,0 +1,1306 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $version] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalOrderVersion|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalOrderVersionTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalOrderVersion A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, PAYMENT_ID, AGREEMENT_ID, CREDIT_CARD_ID, STATE, AMOUNT, DESCRIPTION, PAYER_ID, TOKEN, PLANIFIED_TITLE, PLANIFIED_DESCRIPTION, PLANIFIED_FREQUENCY, PLANIFIED_FREQUENCY_INTERVAL, PLANIFIED_CYCLE, PLANIFIED_ACTUAL_CYCLE, PLANIFIED_MIN_AMOUNT, PLANIFIED_MAX_AMOUNT, CREATED_AT, UPDATED_AT, VERSION, VERSION_CREATED_AT, VERSION_CREATED_BY, ID_VERSION FROM paypal_order_version WHERE ID = :p0 AND VERSION = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalOrderVersion(); + $obj->hydrate($row); + PaypalOrderVersionTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalOrderVersion|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(PaypalOrderVersionTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(PaypalOrderVersionTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(PaypalOrderVersionTableMap::VERSION, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByPaypalOrder() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the payment_id column + * + * Example usage: + * + * $query->filterByPaymentId('fooValue'); // WHERE payment_id = 'fooValue' + * $query->filterByPaymentId('%fooValue%'); // WHERE payment_id LIKE '%fooValue%' + * + * + * @param string $paymentId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPaymentId($paymentId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($paymentId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $paymentId)) { + $paymentId = str_replace('*', '%', $paymentId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PAYMENT_ID, $paymentId, $comparison); + } + + /** + * Filter the query on the agreement_id column + * + * Example usage: + * + * $query->filterByAgreementId('fooValue'); // WHERE agreement_id = 'fooValue' + * $query->filterByAgreementId('%fooValue%'); // WHERE agreement_id LIKE '%fooValue%' + * + * + * @param string $agreementId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByAgreementId($agreementId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($agreementId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $agreementId)) { + $agreementId = str_replace('*', '%', $agreementId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::AGREEMENT_ID, $agreementId, $comparison); + } + + /** + * Filter the query on the credit_card_id column + * + * Example usage: + * + * $query->filterByCreditCardId('fooValue'); // WHERE credit_card_id = 'fooValue' + * $query->filterByCreditCardId('%fooValue%'); // WHERE credit_card_id LIKE '%fooValue%' + * + * + * @param string $creditCardId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByCreditCardId($creditCardId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($creditCardId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $creditCardId)) { + $creditCardId = str_replace('*', '%', $creditCardId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::CREDIT_CARD_ID, $creditCardId, $comparison); + } + + /** + * Filter the query on the state column + * + * Example usage: + * + * $query->filterByState('fooValue'); // WHERE state = 'fooValue' + * $query->filterByState('%fooValue%'); // WHERE state LIKE '%fooValue%' + * + * + * @param string $state The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByState($state = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($state)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $state)) { + $state = str_replace('*', '%', $state); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::STATE, $state, $comparison); + } + + /** + * Filter the query on the amount column + * + * Example usage: + * + * $query->filterByAmount(1234); // WHERE amount = 1234 + * $query->filterByAmount(array(12, 34)); // WHERE amount IN (12, 34) + * $query->filterByAmount(array('min' => 12)); // WHERE amount > 12 + * + * + * @param mixed $amount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByAmount($amount = null, $comparison = null) + { + if (is_array($amount)) { + $useMinMax = false; + if (isset($amount['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::AMOUNT, $amount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($amount['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::AMOUNT, $amount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::AMOUNT, $amount, $comparison); + } + + /** + * Filter the query on the description column + * + * Example usage: + * + * $query->filterByDescription('fooValue'); // WHERE description = 'fooValue' + * $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%' + * + * + * @param string $description The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByDescription($description = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($description)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $description)) { + $description = str_replace('*', '%', $description); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::DESCRIPTION, $description, $comparison); + } + + /** + * Filter the query on the payer_id column + * + * Example usage: + * + * $query->filterByPayerId('fooValue'); // WHERE payer_id = 'fooValue' + * $query->filterByPayerId('%fooValue%'); // WHERE payer_id LIKE '%fooValue%' + * + * + * @param string $payerId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPayerId($payerId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($payerId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $payerId)) { + $payerId = str_replace('*', '%', $payerId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PAYER_ID, $payerId, $comparison); + } + + /** + * Filter the query on the token column + * + * Example usage: + * + * $query->filterByToken('fooValue'); // WHERE token = 'fooValue' + * $query->filterByToken('%fooValue%'); // WHERE token LIKE '%fooValue%' + * + * + * @param string $token The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByToken($token = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($token)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $token)) { + $token = str_replace('*', '%', $token); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::TOKEN, $token, $comparison); + } + + /** + * Filter the query on the planified_title column + * + * Example usage: + * + * $query->filterByPlanifiedTitle('fooValue'); // WHERE planified_title = 'fooValue' + * $query->filterByPlanifiedTitle('%fooValue%'); // WHERE planified_title LIKE '%fooValue%' + * + * + * @param string $planifiedTitle The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedTitle($planifiedTitle = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planifiedTitle)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planifiedTitle)) { + $planifiedTitle = str_replace('*', '%', $planifiedTitle); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_TITLE, $planifiedTitle, $comparison); + } + + /** + * Filter the query on the planified_description column + * + * Example usage: + * + * $query->filterByPlanifiedDescription('fooValue'); // WHERE planified_description = 'fooValue' + * $query->filterByPlanifiedDescription('%fooValue%'); // WHERE planified_description LIKE '%fooValue%' + * + * + * @param string $planifiedDescription The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedDescription($planifiedDescription = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planifiedDescription)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planifiedDescription)) { + $planifiedDescription = str_replace('*', '%', $planifiedDescription); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION, $planifiedDescription, $comparison); + } + + /** + * Filter the query on the planified_frequency column + * + * Example usage: + * + * $query->filterByPlanifiedFrequency('fooValue'); // WHERE planified_frequency = 'fooValue' + * $query->filterByPlanifiedFrequency('%fooValue%'); // WHERE planified_frequency LIKE '%fooValue%' + * + * + * @param string $planifiedFrequency The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedFrequency($planifiedFrequency = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planifiedFrequency)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planifiedFrequency)) { + $planifiedFrequency = str_replace('*', '%', $planifiedFrequency); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY, $planifiedFrequency, $comparison); + } + + /** + * Filter the query on the planified_frequency_interval column + * + * Example usage: + * + * $query->filterByPlanifiedFrequencyInterval(1234); // WHERE planified_frequency_interval = 1234 + * $query->filterByPlanifiedFrequencyInterval(array(12, 34)); // WHERE planified_frequency_interval IN (12, 34) + * $query->filterByPlanifiedFrequencyInterval(array('min' => 12)); // WHERE planified_frequency_interval > 12 + * + * + * @param mixed $planifiedFrequencyInterval The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedFrequencyInterval($planifiedFrequencyInterval = null, $comparison = null) + { + if (is_array($planifiedFrequencyInterval)) { + $useMinMax = false; + if (isset($planifiedFrequencyInterval['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL, $planifiedFrequencyInterval['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedFrequencyInterval['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL, $planifiedFrequencyInterval['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL, $planifiedFrequencyInterval, $comparison); + } + + /** + * Filter the query on the planified_cycle column + * + * Example usage: + * + * $query->filterByPlanifiedCycle(1234); // WHERE planified_cycle = 1234 + * $query->filterByPlanifiedCycle(array(12, 34)); // WHERE planified_cycle IN (12, 34) + * $query->filterByPlanifiedCycle(array('min' => 12)); // WHERE planified_cycle > 12 + * + * + * @param mixed $planifiedCycle The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedCycle($planifiedCycle = null, $comparison = null) + { + if (is_array($planifiedCycle)) { + $useMinMax = false; + if (isset($planifiedCycle['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_CYCLE, $planifiedCycle['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedCycle['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_CYCLE, $planifiedCycle['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_CYCLE, $planifiedCycle, $comparison); + } + + /** + * Filter the query on the planified_actual_cycle column + * + * Example usage: + * + * $query->filterByPlanifiedActualCycle(1234); // WHERE planified_actual_cycle = 1234 + * $query->filterByPlanifiedActualCycle(array(12, 34)); // WHERE planified_actual_cycle IN (12, 34) + * $query->filterByPlanifiedActualCycle(array('min' => 12)); // WHERE planified_actual_cycle > 12 + * + * + * @param mixed $planifiedActualCycle The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedActualCycle($planifiedActualCycle = null, $comparison = null) + { + if (is_array($planifiedActualCycle)) { + $useMinMax = false; + if (isset($planifiedActualCycle['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE, $planifiedActualCycle['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedActualCycle['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE, $planifiedActualCycle['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE, $planifiedActualCycle, $comparison); + } + + /** + * Filter the query on the planified_min_amount column + * + * Example usage: + * + * $query->filterByPlanifiedMinAmount(1234); // WHERE planified_min_amount = 1234 + * $query->filterByPlanifiedMinAmount(array(12, 34)); // WHERE planified_min_amount IN (12, 34) + * $query->filterByPlanifiedMinAmount(array('min' => 12)); // WHERE planified_min_amount > 12 + * + * + * @param mixed $planifiedMinAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedMinAmount($planifiedMinAmount = null, $comparison = null) + { + if (is_array($planifiedMinAmount)) { + $useMinMax = false; + if (isset($planifiedMinAmount['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT, $planifiedMinAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedMinAmount['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT, $planifiedMinAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT, $planifiedMinAmount, $comparison); + } + + /** + * Filter the query on the planified_max_amount column + * + * Example usage: + * + * $query->filterByPlanifiedMaxAmount(1234); // WHERE planified_max_amount = 1234 + * $query->filterByPlanifiedMaxAmount(array(12, 34)); // WHERE planified_max_amount IN (12, 34) + * $query->filterByPlanifiedMaxAmount(array('min' => 12)); // WHERE planified_max_amount > 12 + * + * + * @param mixed $planifiedMaxAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPlanifiedMaxAmount($planifiedMaxAmount = null, $comparison = null) + { + if (is_array($planifiedMaxAmount)) { + $useMinMax = false; + if (isset($planifiedMaxAmount['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT, $planifiedMaxAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($planifiedMaxAmount['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT, $planifiedMaxAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT, $planifiedMaxAmount, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query on the version column + * + * Example usage: + * + * $query->filterByVersion(1234); // WHERE version = 1234 + * $query->filterByVersion(array(12, 34)); // WHERE version IN (12, 34) + * $query->filterByVersion(array('min' => 12)); // WHERE version > 12 + * + * + * @param mixed $version The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByVersion($version = null, $comparison = null) + { + if (is_array($version)) { + $useMinMax = false; + if (isset($version['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION, $version['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($version['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION, $version['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION, $version, $comparison); + } + + /** + * Filter the query on the version_created_at column + * + * Example usage: + * + * $query->filterByVersionCreatedAt('2011-03-14'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt('now'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt(array('max' => 'yesterday')); // WHERE version_created_at > '2011-03-13' + * + * + * @param mixed $versionCreatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByVersionCreatedAt($versionCreatedAt = null, $comparison = null) + { + if (is_array($versionCreatedAt)) { + $useMinMax = false; + if (isset($versionCreatedAt['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION_CREATED_AT, $versionCreatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($versionCreatedAt['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION_CREATED_AT, $versionCreatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION_CREATED_AT, $versionCreatedAt, $comparison); + } + + /** + * Filter the query on the version_created_by column + * + * Example usage: + * + * $query->filterByVersionCreatedBy('fooValue'); // WHERE version_created_by = 'fooValue' + * $query->filterByVersionCreatedBy('%fooValue%'); // WHERE version_created_by LIKE '%fooValue%' + * + * + * @param string $versionCreatedBy The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByVersionCreatedBy($versionCreatedBy = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($versionCreatedBy)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $versionCreatedBy)) { + $versionCreatedBy = str_replace('*', '%', $versionCreatedBy); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::VERSION_CREATED_BY, $versionCreatedBy, $comparison); + } + + /** + * Filter the query on the id_version column + * + * Example usage: + * + * $query->filterByIdVersion(1234); // WHERE id_version = 1234 + * $query->filterByIdVersion(array(12, 34)); // WHERE id_version IN (12, 34) + * $query->filterByIdVersion(array('min' => 12)); // WHERE id_version > 12 + * + * + * @param mixed $idVersion The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByIdVersion($idVersion = null, $comparison = null) + { + if (is_array($idVersion)) { + $useMinMax = false; + if (isset($idVersion['min'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::ID_VERSION, $idVersion['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($idVersion['max'])) { + $this->addUsingAlias(PaypalOrderVersionTableMap::ID_VERSION, $idVersion['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalOrderVersionTableMap::ID_VERSION, $idVersion, $comparison); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalOrder object + * + * @param \PayPal\Model\PaypalOrder|ObjectCollection $paypalOrder The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function filterByPaypalOrder($paypalOrder, $comparison = null) + { + if ($paypalOrder instanceof \PayPal\Model\PaypalOrder) { + return $this + ->addUsingAlias(PaypalOrderVersionTableMap::ID, $paypalOrder->getId(), $comparison); + } elseif ($paypalOrder instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalOrderVersionTableMap::ID, $paypalOrder->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByPaypalOrder() only accepts arguments of type \PayPal\Model\PaypalOrder or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalOrder relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function joinPaypalOrder($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalOrder'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalOrder'); + } + + return $this; + } + + /** + * Use the PaypalOrder relation PaypalOrder object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalOrderQuery A secondary query class using the current class as primary query + */ + public function usePaypalOrderQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinPaypalOrder($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalOrder', '\PayPal\Model\PaypalOrderQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalOrderVersion $paypalOrderVersion Object to remove from the list of results + * + * @return ChildPaypalOrderVersionQuery The current query, for fluid interface + */ + public function prune($paypalOrderVersion = null) + { + if ($paypalOrderVersion) { + $this->addCond('pruneCond0', $this->getAliasedColName(PaypalOrderVersionTableMap::ID), $paypalOrderVersion->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(PaypalOrderVersionTableMap::VERSION), $paypalOrderVersion->getVersion(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_order_version table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalOrderVersionTableMap::clearInstancePool(); + PaypalOrderVersionTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalOrderVersion or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalOrderVersion object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalOrderVersionTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalOrderVersionTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalOrderVersionTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // PaypalOrderVersionQuery diff --git a/Model/Base/PaypalPlan.php b/Model/Base/PaypalPlan.php new file mode 100644 index 0000000..5a0955d --- /dev/null +++ b/Model/Base/PaypalPlan.php @@ -0,0 +1,1479 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalPlan instance. If + * obj is an instance of PaypalPlan, delegates to + * equals(PaypalPlan). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalPlan The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalPlan The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [paypal_order_id] column value. + * + * @return int + */ + public function getPaypalOrderId() + { + + return $this->paypal_order_id; + } + + /** + * Get the [plan_id] column value. + * + * @return string + */ + public function getPlanId() + { + + return $this->plan_id; + } + + /** + * Get the [state] column value. + * + * @return string + */ + public function getState() + { + + return $this->state; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalPlanTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [paypal_order_id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + */ + public function setPaypalOrderId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->paypal_order_id !== $v) { + $this->paypal_order_id = $v; + $this->modifiedColumns[PaypalPlanTableMap::PAYPAL_ORDER_ID] = true; + } + + if ($this->aPaypalOrder !== null && $this->aPaypalOrder->getId() !== $v) { + $this->aPaypalOrder = null; + } + + + return $this; + } // setPaypalOrderId() + + /** + * Set the value of [plan_id] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + */ + public function setPlanId($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->plan_id !== $v) { + $this->plan_id = $v; + $this->modifiedColumns[PaypalPlanTableMap::PLAN_ID] = true; + } + + + return $this; + } // setPlanId() + + /** + * Set the value of [state] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + */ + public function setState($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->state !== $v) { + $this->state = $v; + $this->modifiedColumns[PaypalPlanTableMap::STATE] = true; + } + + + return $this; + } // setState() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalPlanTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalPlanTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalPlanTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalPlanTableMap::translateFieldName('PaypalOrderId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->paypal_order_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalPlanTableMap::translateFieldName('PlanId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->plan_id = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalPlanTableMap::translateFieldName('State', TableMap::TYPE_PHPNAME, $indexType)]; + $this->state = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalPlanTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalPlanTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 6; // 6 = PaypalPlanTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalPlan object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aPaypalOrder !== null && $this->paypal_order_id !== $this->aPaypalOrder->getId()) { + $this->aPaypalOrder = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalPlanTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalPlanQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aPaypalOrder = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalPlan::setDeleted() + * @see PaypalPlan::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalPlanQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(PaypalPlanTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(PaypalPlanTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(PaypalPlanTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalPlanTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aPaypalOrder !== null) { + if ($this->aPaypalOrder->isModified() || $this->aPaypalOrder->isNew()) { + $affectedRows += $this->aPaypalOrder->save($con); + } + $this->setPaypalOrder($this->aPaypalOrder); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[PaypalPlanTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . PaypalPlanTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalPlanTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalPlanTableMap::PAYPAL_ORDER_ID)) { + $modifiedColumns[':p' . $index++] = 'PAYPAL_ORDER_ID'; + } + if ($this->isColumnModified(PaypalPlanTableMap::PLAN_ID)) { + $modifiedColumns[':p' . $index++] = 'PLAN_ID'; + } + if ($this->isColumnModified(PaypalPlanTableMap::STATE)) { + $modifiedColumns[':p' . $index++] = 'STATE'; + } + if ($this->isColumnModified(PaypalPlanTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalPlanTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO paypal_plan (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'PAYPAL_ORDER_ID': + $stmt->bindValue($identifier, $this->paypal_order_id, PDO::PARAM_INT); + break; + case 'PLAN_ID': + $stmt->bindValue($identifier, $this->plan_id, PDO::PARAM_STR); + break; + case 'STATE': + $stmt->bindValue($identifier, $this->state, PDO::PARAM_STR); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalPlanTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPaypalOrderId(); + break; + case 2: + return $this->getPlanId(); + break; + case 3: + return $this->getState(); + break; + case 4: + return $this->getCreatedAt(); + break; + case 5: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalPlan'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalPlan'][$this->getPrimaryKey()] = true; + $keys = PaypalPlanTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPaypalOrderId(), + $keys[2] => $this->getPlanId(), + $keys[3] => $this->getState(), + $keys[4] => $this->getCreatedAt(), + $keys[5] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aPaypalOrder) { + $result['PaypalOrder'] = $this->aPaypalOrder->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalPlanTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPaypalOrderId($value); + break; + case 2: + $this->setPlanId($value); + break; + case 3: + $this->setState($value); + break; + case 4: + $this->setCreatedAt($value); + break; + case 5: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalPlanTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setPaypalOrderId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setPlanId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setState($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalPlanTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalPlanTableMap::ID)) $criteria->add(PaypalPlanTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalPlanTableMap::PAYPAL_ORDER_ID)) $criteria->add(PaypalPlanTableMap::PAYPAL_ORDER_ID, $this->paypal_order_id); + if ($this->isColumnModified(PaypalPlanTableMap::PLAN_ID)) $criteria->add(PaypalPlanTableMap::PLAN_ID, $this->plan_id); + if ($this->isColumnModified(PaypalPlanTableMap::STATE)) $criteria->add(PaypalPlanTableMap::STATE, $this->state); + if ($this->isColumnModified(PaypalPlanTableMap::CREATED_AT)) $criteria->add(PaypalPlanTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalPlanTableMap::UPDATED_AT)) $criteria->add(PaypalPlanTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalPlanTableMap::DATABASE_NAME); + $criteria->add(PaypalPlanTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalPlan (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setPaypalOrderId($this->getPaypalOrderId()); + $copyObj->setPlanId($this->getPlanId()); + $copyObj->setState($this->getState()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalPlan Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildPaypalOrder object. + * + * @param ChildPaypalOrder $v + * @return \PayPal\Model\PaypalPlan The current object (for fluent API support) + * @throws PropelException + */ + public function setPaypalOrder(ChildPaypalOrder $v = null) + { + if ($v === null) { + $this->setPaypalOrderId(NULL); + } else { + $this->setPaypalOrderId($v->getId()); + } + + $this->aPaypalOrder = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildPaypalOrder object, it will not be re-added. + if ($v !== null) { + $v->addPaypalPlan($this); + } + + + return $this; + } + + + /** + * Get the associated ChildPaypalOrder object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildPaypalOrder The associated ChildPaypalOrder object. + * @throws PropelException + */ + public function getPaypalOrder(ConnectionInterface $con = null) + { + if ($this->aPaypalOrder === null && ($this->paypal_order_id !== null)) { + $this->aPaypalOrder = ChildPaypalOrderQuery::create()->findPk($this->paypal_order_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aPaypalOrder->addPaypalPlans($this); + */ + } + + return $this->aPaypalOrder; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->paypal_order_id = null; + $this->plan_id = null; + $this->state = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aPaypalOrder = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalPlanTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildPaypalPlan The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[PaypalPlanTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalPlanQuery.php b/Model/Base/PaypalPlanQuery.php new file mode 100644 index 0000000..8c5e246 --- /dev/null +++ b/Model/Base/PaypalPlanQuery.php @@ -0,0 +1,699 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalPlan|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalPlanTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalPlanTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalPlan A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, PAYPAL_ORDER_ID, PLAN_ID, STATE, CREATED_AT, UPDATED_AT FROM paypal_plan WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalPlan(); + $obj->hydrate($row); + PaypalPlanTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalPlan|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(PaypalPlanTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(PaypalPlanTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalPlanTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalPlanTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the paypal_order_id column + * + * Example usage: + * + * $query->filterByPaypalOrderId(1234); // WHERE paypal_order_id = 1234 + * $query->filterByPaypalOrderId(array(12, 34)); // WHERE paypal_order_id IN (12, 34) + * $query->filterByPaypalOrderId(array('min' => 12)); // WHERE paypal_order_id > 12 + * + * + * @see filterByPaypalOrder() + * + * @param mixed $paypalOrderId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByPaypalOrderId($paypalOrderId = null, $comparison = null) + { + if (is_array($paypalOrderId)) { + $useMinMax = false; + if (isset($paypalOrderId['min'])) { + $this->addUsingAlias(PaypalPlanTableMap::PAYPAL_ORDER_ID, $paypalOrderId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($paypalOrderId['max'])) { + $this->addUsingAlias(PaypalPlanTableMap::PAYPAL_ORDER_ID, $paypalOrderId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanTableMap::PAYPAL_ORDER_ID, $paypalOrderId, $comparison); + } + + /** + * Filter the query on the plan_id column + * + * Example usage: + * + * $query->filterByPlanId('fooValue'); // WHERE plan_id = 'fooValue' + * $query->filterByPlanId('%fooValue%'); // WHERE plan_id LIKE '%fooValue%' + * + * + * @param string $planId The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByPlanId($planId = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($planId)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $planId)) { + $planId = str_replace('*', '%', $planId); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalPlanTableMap::PLAN_ID, $planId, $comparison); + } + + /** + * Filter the query on the state column + * + * Example usage: + * + * $query->filterByState('fooValue'); // WHERE state = 'fooValue' + * $query->filterByState('%fooValue%'); // WHERE state LIKE '%fooValue%' + * + * + * @param string $state The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByState($state = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($state)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $state)) { + $state = str_replace('*', '%', $state); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalPlanTableMap::STATE, $state, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalPlanTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalPlanTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalPlanTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalPlanTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalOrder object + * + * @param \PayPal\Model\PaypalOrder|ObjectCollection $paypalOrder The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function filterByPaypalOrder($paypalOrder, $comparison = null) + { + if ($paypalOrder instanceof \PayPal\Model\PaypalOrder) { + return $this + ->addUsingAlias(PaypalPlanTableMap::PAYPAL_ORDER_ID, $paypalOrder->getId(), $comparison); + } elseif ($paypalOrder instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalPlanTableMap::PAYPAL_ORDER_ID, $paypalOrder->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByPaypalOrder() only accepts arguments of type \PayPal\Model\PaypalOrder or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalOrder relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function joinPaypalOrder($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalOrder'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalOrder'); + } + + return $this; + } + + /** + * Use the PaypalOrder relation PaypalOrder object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalOrderQuery A secondary query class using the current class as primary query + */ + public function usePaypalOrderQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinPaypalOrder($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalOrder', '\PayPal\Model\PaypalOrderQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalPlan $paypalPlan Object to remove from the list of results + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function prune($paypalPlan = null) + { + if ($paypalPlan) { + $this->addUsingAlias(PaypalPlanTableMap::ID, $paypalPlan->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_plan table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalPlanTableMap::clearInstancePool(); + PaypalPlanTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalPlan or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalPlan object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalPlanTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalPlanTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalPlanTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(PaypalPlanTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(PaypalPlanTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalPlanTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalPlanTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalPlanTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildPaypalPlanQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalPlanTableMap::CREATED_AT); + } + +} // PaypalPlanQuery diff --git a/Model/Base/PaypalPlanifiedPayment.php b/Model/Base/PaypalPlanifiedPayment.php new file mode 100644 index 0000000..9529eb2 --- /dev/null +++ b/Model/Base/PaypalPlanifiedPayment.php @@ -0,0 +1,2359 @@ +min_amount = '0.000000'; + $this->max_amount = '0.000000'; + $this->position = 0; + } + + /** + * Initializes internal state of PayPal\Model\Base\PaypalPlanifiedPayment object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalPlanifiedPayment instance. If + * obj is an instance of PaypalPlanifiedPayment, delegates to + * equals(PaypalPlanifiedPayment). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalPlanifiedPayment The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalPlanifiedPayment The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [frequency] column value. + * + * @return string + */ + public function getFrequency() + { + + return $this->frequency; + } + + /** + * Get the [frequency_interval] column value. + * + * @return int + */ + public function getFrequencyInterval() + { + + return $this->frequency_interval; + } + + /** + * Get the [cycle] column value. + * + * @return int + */ + public function getCycle() + { + + return $this->cycle; + } + + /** + * Get the [min_amount] column value. + * + * @return string + */ + public function getMinAmount() + { + + return $this->min_amount; + } + + /** + * Get the [max_amount] column value. + * + * @return string + */ + public function getMaxAmount() + { + + return $this->max_amount; + } + + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [frequency] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setFrequency($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->frequency !== $v) { + $this->frequency = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::FREQUENCY] = true; + } + + + return $this; + } // setFrequency() + + /** + * Set the value of [frequency_interval] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setFrequencyInterval($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->frequency_interval !== $v) { + $this->frequency_interval = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL] = true; + } + + + return $this; + } // setFrequencyInterval() + + /** + * Set the value of [cycle] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setCycle($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->cycle !== $v) { + $this->cycle = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::CYCLE] = true; + } + + + return $this; + } // setCycle() + + /** + * Set the value of [min_amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setMinAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->min_amount !== $v) { + $this->min_amount = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::MIN_AMOUNT] = true; + } + + + return $this; + } // setMinAmount() + + /** + * Set the value of [max_amount] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setMaxAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->max_amount !== $v) { + $this->max_amount = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::MAX_AMOUNT] = true; + } + + + return $this; + } // setMaxAmount() + + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::POSITION] = true; + } + + + return $this; + } // setPosition() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->min_amount !== '0.000000') { + return false; + } + + if ($this->max_amount !== '0.000000') { + return false; + } + + if ($this->position !== 0) { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('Frequency', TableMap::TYPE_PHPNAME, $indexType)]; + $this->frequency = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('FrequencyInterval', TableMap::TYPE_PHPNAME, $indexType)]; + $this->frequency_interval = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('Cycle', TableMap::TYPE_PHPNAME, $indexType)]; + $this->cycle = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('MinAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->min_amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('MaxAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->max_amount = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : PaypalPlanifiedPaymentTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 9; // 9 = PaypalPlanifiedPaymentTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalPlanifiedPayment object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalPlanifiedPaymentQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->collPaypalCarts = null; + + $this->collPaypalPlanifiedPaymentI18ns = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalPlanifiedPayment::setDeleted() + * @see PaypalPlanifiedPayment::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalPlanifiedPaymentQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(PaypalPlanifiedPaymentTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(PaypalPlanifiedPaymentTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(PaypalPlanifiedPaymentTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalPlanifiedPaymentTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->paypalCartsScheduledForDeletion !== null) { + if (!$this->paypalCartsScheduledForDeletion->isEmpty()) { + \PayPal\Model\PaypalCartQuery::create() + ->filterByPrimaryKeys($this->paypalCartsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->paypalCartsScheduledForDeletion = null; + } + } + + if ($this->collPaypalCarts !== null) { + foreach ($this->collPaypalCarts as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->paypalPlanifiedPaymentI18nsScheduledForDeletion !== null) { + if (!$this->paypalPlanifiedPaymentI18nsScheduledForDeletion->isEmpty()) { + \PayPal\Model\PaypalPlanifiedPaymentI18nQuery::create() + ->filterByPrimaryKeys($this->paypalPlanifiedPaymentI18nsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->paypalPlanifiedPaymentI18nsScheduledForDeletion = null; + } + } + + if ($this->collPaypalPlanifiedPaymentI18ns !== null) { + foreach ($this->collPaypalPlanifiedPaymentI18ns as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . PaypalPlanifiedPaymentTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::FREQUENCY)) { + $modifiedColumns[':p' . $index++] = 'FREQUENCY'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL)) { + $modifiedColumns[':p' . $index++] = 'FREQUENCY_INTERVAL'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::CYCLE)) { + $modifiedColumns[':p' . $index++] = 'CYCLE'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'MIN_AMOUNT'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'MAX_AMOUNT'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = 'POSITION'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO paypal_planified_payment (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'FREQUENCY': + $stmt->bindValue($identifier, $this->frequency, PDO::PARAM_STR); + break; + case 'FREQUENCY_INTERVAL': + $stmt->bindValue($identifier, $this->frequency_interval, PDO::PARAM_INT); + break; + case 'CYCLE': + $stmt->bindValue($identifier, $this->cycle, PDO::PARAM_INT); + break; + case 'MIN_AMOUNT': + $stmt->bindValue($identifier, $this->min_amount, PDO::PARAM_STR); + break; + case 'MAX_AMOUNT': + $stmt->bindValue($identifier, $this->max_amount, PDO::PARAM_STR); + break; + case 'POSITION': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; + case 'CREATED_AT': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case 'UPDATED_AT': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalPlanifiedPaymentTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getFrequency(); + break; + case 2: + return $this->getFrequencyInterval(); + break; + case 3: + return $this->getCycle(); + break; + case 4: + return $this->getMinAmount(); + break; + case 5: + return $this->getMaxAmount(); + break; + case 6: + return $this->getPosition(); + break; + case 7: + return $this->getCreatedAt(); + break; + case 8: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalPlanifiedPayment'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalPlanifiedPayment'][$this->getPrimaryKey()] = true; + $keys = PaypalPlanifiedPaymentTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getFrequency(), + $keys[2] => $this->getFrequencyInterval(), + $keys[3] => $this->getCycle(), + $keys[4] => $this->getMinAmount(), + $keys[5] => $this->getMaxAmount(), + $keys[6] => $this->getPosition(), + $keys[7] => $this->getCreatedAt(), + $keys[8] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collPaypalCarts) { + $result['PaypalCarts'] = $this->collPaypalCarts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collPaypalPlanifiedPaymentI18ns) { + $result['PaypalPlanifiedPaymentI18ns'] = $this->collPaypalPlanifiedPaymentI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalPlanifiedPaymentTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setFrequency($value); + break; + case 2: + $this->setFrequencyInterval($value); + break; + case 3: + $this->setCycle($value); + break; + case 4: + $this->setMinAmount($value); + break; + case 5: + $this->setMaxAmount($value); + break; + case 6: + $this->setPosition($value); + break; + case 7: + $this->setCreatedAt($value); + break; + case 8: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalPlanifiedPaymentTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setFrequency($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setFrequencyInterval($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setCycle($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setMinAmount($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setMaxAmount($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setPosition($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::ID)) $criteria->add(PaypalPlanifiedPaymentTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::FREQUENCY)) $criteria->add(PaypalPlanifiedPaymentTableMap::FREQUENCY, $this->frequency); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL)) $criteria->add(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL, $this->frequency_interval); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::CYCLE)) $criteria->add(PaypalPlanifiedPaymentTableMap::CYCLE, $this->cycle); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT)) $criteria->add(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT, $this->min_amount); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT)) $criteria->add(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT, $this->max_amount); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::POSITION)) $criteria->add(PaypalPlanifiedPaymentTableMap::POSITION, $this->position); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::CREATED_AT)) $criteria->add(PaypalPlanifiedPaymentTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(PaypalPlanifiedPaymentTableMap::UPDATED_AT)) $criteria->add(PaypalPlanifiedPaymentTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + $criteria->add(PaypalPlanifiedPaymentTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalPlanifiedPayment (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setFrequency($this->getFrequency()); + $copyObj->setFrequencyInterval($this->getFrequencyInterval()); + $copyObj->setCycle($this->getCycle()); + $copyObj->setMinAmount($this->getMinAmount()); + $copyObj->setMaxAmount($this->getMaxAmount()); + $copyObj->setPosition($this->getPosition()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getPaypalCarts() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addPaypalCart($relObj->copy($deepCopy)); + } + } + + foreach ($this->getPaypalPlanifiedPaymentI18ns() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addPaypalPlanifiedPaymentI18n($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalPlanifiedPayment Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('PaypalCart' == $relationName) { + return $this->initPaypalCarts(); + } + if ('PaypalPlanifiedPaymentI18n' == $relationName) { + return $this->initPaypalPlanifiedPaymentI18ns(); + } + } + + /** + * Clears out the collPaypalCarts collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addPaypalCarts() + */ + public function clearPaypalCarts() + { + $this->collPaypalCarts = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collPaypalCarts collection loaded partially. + */ + public function resetPartialPaypalCarts($v = true) + { + $this->collPaypalCartsPartial = $v; + } + + /** + * Initializes the collPaypalCarts collection. + * + * By default this just sets the collPaypalCarts collection to an empty array (like clearcollPaypalCarts()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initPaypalCarts($overrideExisting = true) + { + if (null !== $this->collPaypalCarts && !$overrideExisting) { + return; + } + $this->collPaypalCarts = new ObjectCollection(); + $this->collPaypalCarts->setModel('\PayPal\Model\PaypalCart'); + } + + /** + * Gets an array of ChildPaypalCart objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildPaypalPlanifiedPayment is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildPaypalCart[] List of ChildPaypalCart objects + * @throws PropelException + */ + public function getPaypalCarts($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collPaypalCartsPartial && !$this->isNew(); + if (null === $this->collPaypalCarts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalCarts) { + // return empty collection + $this->initPaypalCarts(); + } else { + $collPaypalCarts = ChildPaypalCartQuery::create(null, $criteria) + ->filterByPaypalPlanifiedPayment($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collPaypalCartsPartial && count($collPaypalCarts)) { + $this->initPaypalCarts(false); + + foreach ($collPaypalCarts as $obj) { + if (false == $this->collPaypalCarts->contains($obj)) { + $this->collPaypalCarts->append($obj); + } + } + + $this->collPaypalCartsPartial = true; + } + + reset($collPaypalCarts); + + return $collPaypalCarts; + } + + if ($partial && $this->collPaypalCarts) { + foreach ($this->collPaypalCarts as $obj) { + if ($obj->isNew()) { + $collPaypalCarts[] = $obj; + } + } + } + + $this->collPaypalCarts = $collPaypalCarts; + $this->collPaypalCartsPartial = false; + } + } + + return $this->collPaypalCarts; + } + + /** + * Sets a collection of PaypalCart objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $paypalCarts A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setPaypalCarts(Collection $paypalCarts, ConnectionInterface $con = null) + { + $paypalCartsToDelete = $this->getPaypalCarts(new Criteria(), $con)->diff($paypalCarts); + + + $this->paypalCartsScheduledForDeletion = $paypalCartsToDelete; + + foreach ($paypalCartsToDelete as $paypalCartRemoved) { + $paypalCartRemoved->setPaypalPlanifiedPayment(null); + } + + $this->collPaypalCarts = null; + foreach ($paypalCarts as $paypalCart) { + $this->addPaypalCart($paypalCart); + } + + $this->collPaypalCarts = $paypalCarts; + $this->collPaypalCartsPartial = false; + + return $this; + } + + /** + * Returns the number of related PaypalCart objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related PaypalCart objects. + * @throws PropelException + */ + public function countPaypalCarts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collPaypalCartsPartial && !$this->isNew(); + if (null === $this->collPaypalCarts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalCarts) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getPaypalCarts()); + } + + $query = ChildPaypalCartQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByPaypalPlanifiedPayment($this) + ->count($con); + } + + return count($this->collPaypalCarts); + } + + /** + * Method called to associate a ChildPaypalCart object to this object + * through the ChildPaypalCart foreign key attribute. + * + * @param ChildPaypalCart $l ChildPaypalCart + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function addPaypalCart(ChildPaypalCart $l) + { + if ($this->collPaypalCarts === null) { + $this->initPaypalCarts(); + $this->collPaypalCartsPartial = true; + } + + if (!in_array($l, $this->collPaypalCarts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddPaypalCart($l); + } + + return $this; + } + + /** + * @param PaypalCart $paypalCart The paypalCart object to add. + */ + protected function doAddPaypalCart($paypalCart) + { + $this->collPaypalCarts[]= $paypalCart; + $paypalCart->setPaypalPlanifiedPayment($this); + } + + /** + * @param PaypalCart $paypalCart The paypalCart object to remove. + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function removePaypalCart($paypalCart) + { + if ($this->getPaypalCarts()->contains($paypalCart)) { + $this->collPaypalCarts->remove($this->collPaypalCarts->search($paypalCart)); + if (null === $this->paypalCartsScheduledForDeletion) { + $this->paypalCartsScheduledForDeletion = clone $this->collPaypalCarts; + $this->paypalCartsScheduledForDeletion->clear(); + } + $this->paypalCartsScheduledForDeletion[]= $paypalCart; + $paypalCart->setPaypalPlanifiedPayment(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this PaypalPlanifiedPayment is new, it will return + * an empty collection; or if this PaypalPlanifiedPayment has previously + * been saved, it will retrieve related PaypalCarts from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in PaypalPlanifiedPayment. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildPaypalCart[] List of ChildPaypalCart objects + */ + public function getPaypalCartsJoinCart($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildPaypalCartQuery::create(null, $criteria); + $query->joinWith('Cart', $joinBehavior); + + return $this->getPaypalCarts($query, $con); + } + + /** + * Clears out the collPaypalPlanifiedPaymentI18ns collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addPaypalPlanifiedPaymentI18ns() + */ + public function clearPaypalPlanifiedPaymentI18ns() + { + $this->collPaypalPlanifiedPaymentI18ns = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collPaypalPlanifiedPaymentI18ns collection loaded partially. + */ + public function resetPartialPaypalPlanifiedPaymentI18ns($v = true) + { + $this->collPaypalPlanifiedPaymentI18nsPartial = $v; + } + + /** + * Initializes the collPaypalPlanifiedPaymentI18ns collection. + * + * By default this just sets the collPaypalPlanifiedPaymentI18ns collection to an empty array (like clearcollPaypalPlanifiedPaymentI18ns()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initPaypalPlanifiedPaymentI18ns($overrideExisting = true) + { + if (null !== $this->collPaypalPlanifiedPaymentI18ns && !$overrideExisting) { + return; + } + $this->collPaypalPlanifiedPaymentI18ns = new ObjectCollection(); + $this->collPaypalPlanifiedPaymentI18ns->setModel('\PayPal\Model\PaypalPlanifiedPaymentI18n'); + } + + /** + * Gets an array of ChildPaypalPlanifiedPaymentI18n objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildPaypalPlanifiedPayment is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildPaypalPlanifiedPaymentI18n[] List of ChildPaypalPlanifiedPaymentI18n objects + * @throws PropelException + */ + public function getPaypalPlanifiedPaymentI18ns($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collPaypalPlanifiedPaymentI18nsPartial && !$this->isNew(); + if (null === $this->collPaypalPlanifiedPaymentI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalPlanifiedPaymentI18ns) { + // return empty collection + $this->initPaypalPlanifiedPaymentI18ns(); + } else { + $collPaypalPlanifiedPaymentI18ns = ChildPaypalPlanifiedPaymentI18nQuery::create(null, $criteria) + ->filterByPaypalPlanifiedPayment($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collPaypalPlanifiedPaymentI18nsPartial && count($collPaypalPlanifiedPaymentI18ns)) { + $this->initPaypalPlanifiedPaymentI18ns(false); + + foreach ($collPaypalPlanifiedPaymentI18ns as $obj) { + if (false == $this->collPaypalPlanifiedPaymentI18ns->contains($obj)) { + $this->collPaypalPlanifiedPaymentI18ns->append($obj); + } + } + + $this->collPaypalPlanifiedPaymentI18nsPartial = true; + } + + reset($collPaypalPlanifiedPaymentI18ns); + + return $collPaypalPlanifiedPaymentI18ns; + } + + if ($partial && $this->collPaypalPlanifiedPaymentI18ns) { + foreach ($this->collPaypalPlanifiedPaymentI18ns as $obj) { + if ($obj->isNew()) { + $collPaypalPlanifiedPaymentI18ns[] = $obj; + } + } + } + + $this->collPaypalPlanifiedPaymentI18ns = $collPaypalPlanifiedPaymentI18ns; + $this->collPaypalPlanifiedPaymentI18nsPartial = false; + } + } + + return $this->collPaypalPlanifiedPaymentI18ns; + } + + /** + * Sets a collection of PaypalPlanifiedPaymentI18n objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $paypalPlanifiedPaymentI18ns A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setPaypalPlanifiedPaymentI18ns(Collection $paypalPlanifiedPaymentI18ns, ConnectionInterface $con = null) + { + $paypalPlanifiedPaymentI18nsToDelete = $this->getPaypalPlanifiedPaymentI18ns(new Criteria(), $con)->diff($paypalPlanifiedPaymentI18ns); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->paypalPlanifiedPaymentI18nsScheduledForDeletion = clone $paypalPlanifiedPaymentI18nsToDelete; + + foreach ($paypalPlanifiedPaymentI18nsToDelete as $paypalPlanifiedPaymentI18nRemoved) { + $paypalPlanifiedPaymentI18nRemoved->setPaypalPlanifiedPayment(null); + } + + $this->collPaypalPlanifiedPaymentI18ns = null; + foreach ($paypalPlanifiedPaymentI18ns as $paypalPlanifiedPaymentI18n) { + $this->addPaypalPlanifiedPaymentI18n($paypalPlanifiedPaymentI18n); + } + + $this->collPaypalPlanifiedPaymentI18ns = $paypalPlanifiedPaymentI18ns; + $this->collPaypalPlanifiedPaymentI18nsPartial = false; + + return $this; + } + + /** + * Returns the number of related PaypalPlanifiedPaymentI18n objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related PaypalPlanifiedPaymentI18n objects. + * @throws PropelException + */ + public function countPaypalPlanifiedPaymentI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collPaypalPlanifiedPaymentI18nsPartial && !$this->isNew(); + if (null === $this->collPaypalPlanifiedPaymentI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collPaypalPlanifiedPaymentI18ns) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getPaypalPlanifiedPaymentI18ns()); + } + + $query = ChildPaypalPlanifiedPaymentI18nQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByPaypalPlanifiedPayment($this) + ->count($con); + } + + return count($this->collPaypalPlanifiedPaymentI18ns); + } + + /** + * Method called to associate a ChildPaypalPlanifiedPaymentI18n object to this object + * through the ChildPaypalPlanifiedPaymentI18n foreign key attribute. + * + * @param ChildPaypalPlanifiedPaymentI18n $l ChildPaypalPlanifiedPaymentI18n + * @return \PayPal\Model\PaypalPlanifiedPayment The current object (for fluent API support) + */ + public function addPaypalPlanifiedPaymentI18n(ChildPaypalPlanifiedPaymentI18n $l) + { + if ($l && $locale = $l->getLocale()) { + $this->setLocale($locale); + $this->currentTranslations[$locale] = $l; + } + if ($this->collPaypalPlanifiedPaymentI18ns === null) { + $this->initPaypalPlanifiedPaymentI18ns(); + $this->collPaypalPlanifiedPaymentI18nsPartial = true; + } + + if (!in_array($l, $this->collPaypalPlanifiedPaymentI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddPaypalPlanifiedPaymentI18n($l); + } + + return $this; + } + + /** + * @param PaypalPlanifiedPaymentI18n $paypalPlanifiedPaymentI18n The paypalPlanifiedPaymentI18n object to add. + */ + protected function doAddPaypalPlanifiedPaymentI18n($paypalPlanifiedPaymentI18n) + { + $this->collPaypalPlanifiedPaymentI18ns[]= $paypalPlanifiedPaymentI18n; + $paypalPlanifiedPaymentI18n->setPaypalPlanifiedPayment($this); + } + + /** + * @param PaypalPlanifiedPaymentI18n $paypalPlanifiedPaymentI18n The paypalPlanifiedPaymentI18n object to remove. + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function removePaypalPlanifiedPaymentI18n($paypalPlanifiedPaymentI18n) + { + if ($this->getPaypalPlanifiedPaymentI18ns()->contains($paypalPlanifiedPaymentI18n)) { + $this->collPaypalPlanifiedPaymentI18ns->remove($this->collPaypalPlanifiedPaymentI18ns->search($paypalPlanifiedPaymentI18n)); + if (null === $this->paypalPlanifiedPaymentI18nsScheduledForDeletion) { + $this->paypalPlanifiedPaymentI18nsScheduledForDeletion = clone $this->collPaypalPlanifiedPaymentI18ns; + $this->paypalPlanifiedPaymentI18nsScheduledForDeletion->clear(); + } + $this->paypalPlanifiedPaymentI18nsScheduledForDeletion[]= clone $paypalPlanifiedPaymentI18n; + $paypalPlanifiedPaymentI18n->setPaypalPlanifiedPayment(null); + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->frequency = null; + $this->frequency_interval = null; + $this->cycle = null; + $this->min_amount = null; + $this->max_amount = null; + $this->position = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collPaypalCarts) { + foreach ($this->collPaypalCarts as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collPaypalPlanifiedPaymentI18ns) { + foreach ($this->collPaypalPlanifiedPaymentI18ns as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + // i18n behavior + $this->currentLocale = 'en_US'; + $this->currentTranslations = null; + + $this->collPaypalCarts = null; + $this->collPaypalPlanifiedPaymentI18ns = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalPlanifiedPaymentTableMap::DEFAULT_STRING_FORMAT); + } + + // i18n behavior + + /** + * Sets the locale for translations + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function setLocale($locale = 'en_US') + { + $this->currentLocale = $locale; + + return $this; + } + + /** + * Gets the locale for translations + * + * @return string $locale Locale to use for the translation, e.g. 'fr_FR' + */ + public function getLocale() + { + return $this->currentLocale; + } + + /** + * Returns the current translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalPlanifiedPaymentI18n */ + public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!isset($this->currentTranslations[$locale])) { + if (null !== $this->collPaypalPlanifiedPaymentI18ns) { + foreach ($this->collPaypalPlanifiedPaymentI18ns as $translation) { + if ($translation->getLocale() == $locale) { + $this->currentTranslations[$locale] = $translation; + + return $translation; + } + } + } + if ($this->isNew()) { + $translation = new ChildPaypalPlanifiedPaymentI18n(); + $translation->setLocale($locale); + } else { + $translation = ChildPaypalPlanifiedPaymentI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->findOneOrCreate($con); + $this->currentTranslations[$locale] = $translation; + } + $this->addPaypalPlanifiedPaymentI18n($translation); + } + + return $this->currentTranslations[$locale]; + } + + /** + * Remove the translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!$this->isNew()) { + ChildPaypalPlanifiedPaymentI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->delete($con); + } + if (isset($this->currentTranslations[$locale])) { + unset($this->currentTranslations[$locale]); + } + foreach ($this->collPaypalPlanifiedPaymentI18ns as $key => $translation) { + if ($translation->getLocale() == $locale) { + unset($this->collPaypalPlanifiedPaymentI18ns[$key]); + break; + } + } + + return $this; + } + + /** + * Returns the current translation + * + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalPlanifiedPaymentI18n */ + public function getCurrentTranslation(ConnectionInterface $con = null) + { + return $this->getTranslation($this->getLocale(), $con); + } + + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + return $this->getCurrentTranslation()->getTitle(); + } + + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + */ + public function setTitle($v) + { $this->getCurrentTranslation()->setTitle($v); + + return $this; + } + + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + return $this->getCurrentTranslation()->getDescription(); + } + + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + */ + public function setDescription($v) + { $this->getCurrentTranslation()->setDescription($v); + + return $this; + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildPaypalPlanifiedPayment The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[PaypalPlanifiedPaymentTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalPlanifiedPaymentI18n.php b/Model/Base/PaypalPlanifiedPaymentI18n.php new file mode 100644 index 0000000..3fceb7e --- /dev/null +++ b/Model/Base/PaypalPlanifiedPaymentI18n.php @@ -0,0 +1,1326 @@ +locale = 'en_US'; + } + + /** + * Initializes internal state of PayPal\Model\Base\PaypalPlanifiedPaymentI18n object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another PaypalPlanifiedPaymentI18n instance. If + * obj is an instance of PaypalPlanifiedPaymentI18n, delegates to + * equals(PaypalPlanifiedPaymentI18n). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return PaypalPlanifiedPaymentI18n The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return PaypalPlanifiedPaymentI18n The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + + return $this->title; + } + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + + return $this->description; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentI18nTableMap::ID] = true; + } + + if ($this->aPaypalPlanifiedPayment !== null && $this->aPaypalPlanifiedPayment->getId() !== $v) { + $this->aPaypalPlanifiedPayment = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentI18nTableMap::LOCALE] = true; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + */ + public function setTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->title !== $v) { + $this->title = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentI18nTableMap::TITLE] = true; + } + + + return $this; + } // setTitle() + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + */ + public function setDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->description !== $v) { + $this->description = $v; + $this->modifiedColumns[PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION] = true; + } + + + return $this; + } // setDescription() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->locale !== 'en_US') { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PaypalPlanifiedPaymentI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PaypalPlanifiedPaymentI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PaypalPlanifiedPaymentI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $this->title = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PaypalPlanifiedPaymentI18nTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; + $this->description = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 4; // 4 = PaypalPlanifiedPaymentI18nTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \PayPal\Model\PaypalPlanifiedPaymentI18n object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aPaypalPlanifiedPayment !== null && $this->id !== $this->aPaypalPlanifiedPayment->getId()) { + $this->aPaypalPlanifiedPayment = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildPaypalPlanifiedPaymentI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aPaypalPlanifiedPayment = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see PaypalPlanifiedPaymentI18n::setDeleted() + * @see PaypalPlanifiedPaymentI18n::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildPaypalPlanifiedPaymentI18nQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + PaypalPlanifiedPaymentI18nTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aPaypalPlanifiedPayment !== null) { + if ($this->aPaypalPlanifiedPayment->isModified() || $this->aPaypalPlanifiedPayment->isNew()) { + $affectedRows += $this->aPaypalPlanifiedPayment->save($con); + } + $this->setPaypalPlanifiedPayment($this->aPaypalPlanifiedPayment); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = 'LOCALE'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::TITLE)) { + $modifiedColumns[':p' . $index++] = 'TITLE'; + } + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = 'DESCRIPTION'; + } + + $sql = sprintf( + 'INSERT INTO paypal_planified_payment_i18n (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'LOCALE': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case 'TITLE': + $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR); + break; + case 'DESCRIPTION': + $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalPlanifiedPaymentI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getLocale(); + break; + case 2: + return $this->getTitle(); + break; + case 3: + return $this->getDescription(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['PaypalPlanifiedPaymentI18n'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['PaypalPlanifiedPaymentI18n'][serialize($this->getPrimaryKey())] = true; + $keys = PaypalPlanifiedPaymentI18nTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getLocale(), + $keys[2] => $this->getTitle(), + $keys[3] => $this->getDescription(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aPaypalPlanifiedPayment) { + $result['PaypalPlanifiedPayment'] = $this->aPaypalPlanifiedPayment->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = PaypalPlanifiedPaymentI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setLocale($value); + break; + case 2: + $this->setTitle($value); + break; + case 3: + $this->setDescription($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = PaypalPlanifiedPaymentI18nTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setDescription($arr[$keys[3]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::ID)) $criteria->add(PaypalPlanifiedPaymentI18nTableMap::ID, $this->id); + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::LOCALE)) $criteria->add(PaypalPlanifiedPaymentI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::TITLE)) $criteria->add(PaypalPlanifiedPaymentI18nTableMap::TITLE, $this->title); + if ($this->isColumnModified(PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION)) $criteria->add(PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION, $this->description); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + $criteria->add(PaypalPlanifiedPaymentI18nTableMap::ID, $this->id); + $criteria->add(PaypalPlanifiedPaymentI18nTableMap::LOCALE, $this->locale); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getLocale(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setLocale($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getLocale()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \PayPal\Model\PaypalPlanifiedPaymentI18n (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setTitle($this->getTitle()); + $copyObj->setDescription($this->getDescription()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildPaypalPlanifiedPayment object. + * + * @param ChildPaypalPlanifiedPayment $v + * @return \PayPal\Model\PaypalPlanifiedPaymentI18n The current object (for fluent API support) + * @throws PropelException + */ + public function setPaypalPlanifiedPayment(ChildPaypalPlanifiedPayment $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aPaypalPlanifiedPayment = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildPaypalPlanifiedPayment object, it will not be re-added. + if ($v !== null) { + $v->addPaypalPlanifiedPaymentI18n($this); + } + + + return $this; + } + + + /** + * Get the associated ChildPaypalPlanifiedPayment object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildPaypalPlanifiedPayment The associated ChildPaypalPlanifiedPayment object. + * @throws PropelException + */ + public function getPaypalPlanifiedPayment(ConnectionInterface $con = null) + { + if ($this->aPaypalPlanifiedPayment === null && ($this->id !== null)) { + $this->aPaypalPlanifiedPayment = ChildPaypalPlanifiedPaymentQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aPaypalPlanifiedPayment->addPaypalPlanifiedPaymentI18ns($this); + */ + } + + return $this->aPaypalPlanifiedPayment; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->locale = null; + $this->title = null; + $this->description = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aPaypalPlanifiedPayment = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(PaypalPlanifiedPaymentI18nTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/Model/Base/PaypalPlanifiedPaymentI18nQuery.php b/Model/Base/PaypalPlanifiedPaymentI18nQuery.php new file mode 100644 index 0000000..5bf447a --- /dev/null +++ b/Model/Base/PaypalPlanifiedPaymentI18nQuery.php @@ -0,0 +1,541 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $locale] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalPlanifiedPaymentI18n|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalPlanifiedPaymentI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalPlanifiedPaymentI18n A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, LOCALE, TITLE, DESCRIPTION FROM paypal_planified_payment_i18n WHERE ID = :p0 AND LOCALE = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_STR); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalPlanifiedPaymentI18n(); + $obj->hydrate($row); + PaypalPlanifiedPaymentI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalPlanifiedPaymentI18n|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(PaypalPlanifiedPaymentI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(PaypalPlanifiedPaymentI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByPaypalPlanifiedPayment() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the title column + * + * Example usage: + * + * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' + * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' + * + * + * @param string $title The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterByTitle($title = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($title)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $title)) { + $title = str_replace('*', '%', $title); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::TITLE, $title, $comparison); + } + + /** + * Filter the query on the description column + * + * Example usage: + * + * $query->filterByDescription('fooValue'); // WHERE description = 'fooValue' + * $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%' + * + * + * @param string $description The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterByDescription($description = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($description)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $description)) { + $description = str_replace('*', '%', $description); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION, $description, $comparison); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalPlanifiedPayment object + * + * @param \PayPal\Model\PaypalPlanifiedPayment|ObjectCollection $paypalPlanifiedPayment The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function filterByPaypalPlanifiedPayment($paypalPlanifiedPayment, $comparison = null) + { + if ($paypalPlanifiedPayment instanceof \PayPal\Model\PaypalPlanifiedPayment) { + return $this + ->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::ID, $paypalPlanifiedPayment->getId(), $comparison); + } elseif ($paypalPlanifiedPayment instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(PaypalPlanifiedPaymentI18nTableMap::ID, $paypalPlanifiedPayment->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByPaypalPlanifiedPayment() only accepts arguments of type \PayPal\Model\PaypalPlanifiedPayment or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalPlanifiedPayment relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function joinPaypalPlanifiedPayment($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalPlanifiedPayment'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalPlanifiedPayment'); + } + + return $this; + } + + /** + * Use the PaypalPlanifiedPayment relation PaypalPlanifiedPayment object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalPlanifiedPaymentQuery A secondary query class using the current class as primary query + */ + public function usePaypalPlanifiedPaymentQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinPaypalPlanifiedPayment($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalPlanifiedPayment', '\PayPal\Model\PaypalPlanifiedPaymentQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalPlanifiedPaymentI18n $paypalPlanifiedPaymentI18n Object to remove from the list of results + * + * @return ChildPaypalPlanifiedPaymentI18nQuery The current query, for fluid interface + */ + public function prune($paypalPlanifiedPaymentI18n = null) + { + if ($paypalPlanifiedPaymentI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(PaypalPlanifiedPaymentI18nTableMap::ID), $paypalPlanifiedPaymentI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(PaypalPlanifiedPaymentI18nTableMap::LOCALE), $paypalPlanifiedPaymentI18n->getLocale(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_planified_payment_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalPlanifiedPaymentI18nTableMap::clearInstancePool(); + PaypalPlanifiedPaymentI18nTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalPlanifiedPaymentI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalPlanifiedPaymentI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalPlanifiedPaymentI18nTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalPlanifiedPaymentI18nTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // PaypalPlanifiedPaymentI18nQuery diff --git a/Model/Base/PaypalPlanifiedPaymentQuery.php b/Model/Base/PaypalPlanifiedPaymentQuery.php new file mode 100644 index 0000000..ebddc44 --- /dev/null +++ b/Model/Base/PaypalPlanifiedPaymentQuery.php @@ -0,0 +1,977 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildPaypalPlanifiedPayment|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = PaypalPlanifiedPaymentTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalPlanifiedPayment A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, FREQUENCY, FREQUENCY_INTERVAL, CYCLE, MIN_AMOUNT, MAX_AMOUNT, POSITION, CREATED_AT, UPDATED_AT FROM paypal_planified_payment WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildPaypalPlanifiedPayment(); + $obj->hydrate($row); + PaypalPlanifiedPaymentTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildPaypalPlanifiedPayment|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the frequency column + * + * Example usage: + * + * $query->filterByFrequency('fooValue'); // WHERE frequency = 'fooValue' + * $query->filterByFrequency('%fooValue%'); // WHERE frequency LIKE '%fooValue%' + * + * + * @param string $frequency The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByFrequency($frequency = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($frequency)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $frequency)) { + $frequency = str_replace('*', '%', $frequency); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::FREQUENCY, $frequency, $comparison); + } + + /** + * Filter the query on the frequency_interval column + * + * Example usage: + * + * $query->filterByFrequencyInterval(1234); // WHERE frequency_interval = 1234 + * $query->filterByFrequencyInterval(array(12, 34)); // WHERE frequency_interval IN (12, 34) + * $query->filterByFrequencyInterval(array('min' => 12)); // WHERE frequency_interval > 12 + * + * + * @param mixed $frequencyInterval The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByFrequencyInterval($frequencyInterval = null, $comparison = null) + { + if (is_array($frequencyInterval)) { + $useMinMax = false; + if (isset($frequencyInterval['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL, $frequencyInterval['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($frequencyInterval['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL, $frequencyInterval['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL, $frequencyInterval, $comparison); + } + + /** + * Filter the query on the cycle column + * + * Example usage: + * + * $query->filterByCycle(1234); // WHERE cycle = 1234 + * $query->filterByCycle(array(12, 34)); // WHERE cycle IN (12, 34) + * $query->filterByCycle(array('min' => 12)); // WHERE cycle > 12 + * + * + * @param mixed $cycle The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByCycle($cycle = null, $comparison = null) + { + if (is_array($cycle)) { + $useMinMax = false; + if (isset($cycle['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CYCLE, $cycle['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($cycle['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CYCLE, $cycle['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CYCLE, $cycle, $comparison); + } + + /** + * Filter the query on the min_amount column + * + * Example usage: + * + * $query->filterByMinAmount(1234); // WHERE min_amount = 1234 + * $query->filterByMinAmount(array(12, 34)); // WHERE min_amount IN (12, 34) + * $query->filterByMinAmount(array('min' => 12)); // WHERE min_amount > 12 + * + * + * @param mixed $minAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByMinAmount($minAmount = null, $comparison = null) + { + if (is_array($minAmount)) { + $useMinMax = false; + if (isset($minAmount['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT, $minAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($minAmount['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT, $minAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT, $minAmount, $comparison); + } + + /** + * Filter the query on the max_amount column + * + * Example usage: + * + * $query->filterByMaxAmount(1234); // WHERE max_amount = 1234 + * $query->filterByMaxAmount(array(12, 34)); // WHERE max_amount IN (12, 34) + * $query->filterByMaxAmount(array('min' => 12)); // WHERE max_amount > 12 + * + * + * @param mixed $maxAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByMaxAmount($maxAmount = null, $comparison = null) + { + if (is_array($maxAmount)) { + $useMinMax = false; + if (isset($maxAmount['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT, $maxAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($maxAmount['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT, $maxAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT, $maxAmount, $comparison); + } + + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::POSITION, $position, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalCart object + * + * @param \PayPal\Model\PaypalCart|ObjectCollection $paypalCart the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByPaypalCart($paypalCart, $comparison = null) + { + if ($paypalCart instanceof \PayPal\Model\PaypalCart) { + return $this + ->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $paypalCart->getPlanifiedPaymentId(), $comparison); + } elseif ($paypalCart instanceof ObjectCollection) { + return $this + ->usePaypalCartQuery() + ->filterByPrimaryKeys($paypalCart->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByPaypalCart() only accepts arguments of type \PayPal\Model\PaypalCart or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalCart relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function joinPaypalCart($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalCart'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalCart'); + } + + return $this; + } + + /** + * Use the PaypalCart relation PaypalCart object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalCartQuery A secondary query class using the current class as primary query + */ + public function usePaypalCartQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinPaypalCart($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalCart', '\PayPal\Model\PaypalCartQuery'); + } + + /** + * Filter the query by a related \PayPal\Model\PaypalPlanifiedPaymentI18n object + * + * @param \PayPal\Model\PaypalPlanifiedPaymentI18n|ObjectCollection $paypalPlanifiedPaymentI18n the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function filterByPaypalPlanifiedPaymentI18n($paypalPlanifiedPaymentI18n, $comparison = null) + { + if ($paypalPlanifiedPaymentI18n instanceof \PayPal\Model\PaypalPlanifiedPaymentI18n) { + return $this + ->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $paypalPlanifiedPaymentI18n->getId(), $comparison); + } elseif ($paypalPlanifiedPaymentI18n instanceof ObjectCollection) { + return $this + ->usePaypalPlanifiedPaymentI18nQuery() + ->filterByPrimaryKeys($paypalPlanifiedPaymentI18n->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByPaypalPlanifiedPaymentI18n() only accepts arguments of type \PayPal\Model\PaypalPlanifiedPaymentI18n or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the PaypalPlanifiedPaymentI18n relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function joinPaypalPlanifiedPaymentI18n($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('PaypalPlanifiedPaymentI18n'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'PaypalPlanifiedPaymentI18n'); + } + + return $this; + } + + /** + * Use the PaypalPlanifiedPaymentI18n relation PaypalPlanifiedPaymentI18n object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \PayPal\Model\PaypalPlanifiedPaymentI18nQuery A secondary query class using the current class as primary query + */ + public function usePaypalPlanifiedPaymentI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinPaypalPlanifiedPaymentI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalPlanifiedPaymentI18n', '\PayPal\Model\PaypalPlanifiedPaymentI18nQuery'); + } + + /** + * Exclude object from result + * + * @param ChildPaypalPlanifiedPayment $paypalPlanifiedPayment Object to remove from the list of results + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function prune($paypalPlanifiedPayment = null) + { + if ($paypalPlanifiedPayment) { + $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::ID, $paypalPlanifiedPayment->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the paypal_planified_payment table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + PaypalPlanifiedPaymentTableMap::clearInstancePool(); + PaypalPlanifiedPaymentTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildPaypalPlanifiedPayment or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildPaypalPlanifiedPayment object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + PaypalPlanifiedPaymentTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + PaypalPlanifiedPaymentTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // i18n behavior + + /** + * Adds a JOIN clause to the query using the i18n relation + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $relationName = $relationAlias ? $relationAlias : 'PaypalPlanifiedPaymentI18n'; + + return $this + ->joinPaypalPlanifiedPaymentI18n($relationAlias, $joinType) + ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); + } + + /** + * Adds a JOIN clause to the query and hydrates the related I18n object. + * Shortcut for $c->joinI18n($locale)->with() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) + { + $this + ->joinI18n($locale, null, $joinType) + ->with('PaypalPlanifiedPaymentI18n'); + $this->with['PaypalPlanifiedPaymentI18n']->setIsWithOneToMany(false); + + return $this; + } + + /** + * Use the I18n relation query object + * + * @see useQuery() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildPaypalPlanifiedPaymentI18nQuery A secondary query class using the current class as primary query + */ + public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinI18n($locale, $relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'PaypalPlanifiedPaymentI18n', '\PayPal\Model\PaypalPlanifiedPaymentI18nQuery'); + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(PaypalPlanifiedPaymentTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalPlanifiedPaymentTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalPlanifiedPaymentTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(PaypalPlanifiedPaymentTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildPaypalPlanifiedPaymentQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(PaypalPlanifiedPaymentTableMap::CREATED_AT); + } + +} // PaypalPlanifiedPaymentQuery diff --git a/Model/Map/PaypalCartTableMap.php b/Model/Map/PaypalCartTableMap.php new file mode 100644 index 0000000..0557eff --- /dev/null +++ b/Model/Map/PaypalCartTableMap.php @@ -0,0 +1,469 @@ + array('Id', 'CreditCardId', 'PlanifiedPaymentId', 'ExpressPaymentId', 'ExpressPayerId', 'ExpressToken', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'creditCardId', 'planifiedPaymentId', 'expressPaymentId', 'expressPayerId', 'expressToken', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(PaypalCartTableMap::ID, PaypalCartTableMap::CREDIT_CARD_ID, PaypalCartTableMap::PLANIFIED_PAYMENT_ID, PaypalCartTableMap::EXPRESS_PAYMENT_ID, PaypalCartTableMap::EXPRESS_PAYER_ID, PaypalCartTableMap::EXPRESS_TOKEN, PaypalCartTableMap::CREATED_AT, PaypalCartTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'CREDIT_CARD_ID', 'PLANIFIED_PAYMENT_ID', 'EXPRESS_PAYMENT_ID', 'EXPRESS_PAYER_ID', 'EXPRESS_TOKEN', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'credit_card_id', 'planified_payment_id', 'express_payment_id', 'express_payer_id', 'express_token', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'CreditCardId' => 1, 'PlanifiedPaymentId' => 2, 'ExpressPaymentId' => 3, 'ExpressPayerId' => 4, 'ExpressToken' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'creditCardId' => 1, 'planifiedPaymentId' => 2, 'expressPaymentId' => 3, 'expressPayerId' => 4, 'expressToken' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), + self::TYPE_COLNAME => array(PaypalCartTableMap::ID => 0, PaypalCartTableMap::CREDIT_CARD_ID => 1, PaypalCartTableMap::PLANIFIED_PAYMENT_ID => 2, PaypalCartTableMap::EXPRESS_PAYMENT_ID => 3, PaypalCartTableMap::EXPRESS_PAYER_ID => 4, PaypalCartTableMap::EXPRESS_TOKEN => 5, PaypalCartTableMap::CREATED_AT => 6, PaypalCartTableMap::UPDATED_AT => 7, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CREDIT_CARD_ID' => 1, 'PLANIFIED_PAYMENT_ID' => 2, 'EXPRESS_PAYMENT_ID' => 3, 'EXPRESS_PAYER_ID' => 4, 'EXPRESS_TOKEN' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), + self::TYPE_FIELDNAME => array('id' => 0, 'credit_card_id' => 1, 'planified_payment_id' => 2, 'express_payment_id' => 3, 'express_payer_id' => 4, 'express_token' => 5, 'created_at' => 6, 'updated_at' => 7, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_cart'); + $this->setPhpName('PaypalCart'); + $this->setClassName('\\PayPal\\Model\\PaypalCart'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'cart', 'ID', true, null, null); + $this->addColumn('CREDIT_CARD_ID', 'CreditCardId', 'VARCHAR', false, 40, null); + $this->addForeignKey('PLANIFIED_PAYMENT_ID', 'PlanifiedPaymentId', 'INTEGER', 'paypal_planified_payment', 'ID', false, null, null); + $this->addColumn('EXPRESS_PAYMENT_ID', 'ExpressPaymentId', 'VARCHAR', false, 255, null); + $this->addColumn('EXPRESS_PAYER_ID', 'ExpressPayerId', 'VARCHAR', false, 255, null); + $this->addColumn('EXPRESS_TOKEN', 'ExpressToken', 'VARCHAR', false, 255, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Cart', '\\Thelia\\Model\\Cart', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('PaypalPlanifiedPayment', '\\PayPal\\Model\\PaypalPlanifiedPayment', RelationMap::MANY_TO_ONE, array('planified_payment_id' => 'id', ), 'CASCADE', 'RESTRICT'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalCartTableMap::CLASS_DEFAULT : PaypalCartTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalCart object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalCartTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalCartTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalCartTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalCartTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalCartTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalCartTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalCartTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalCartTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalCartTableMap::ID); + $criteria->addSelectColumn(PaypalCartTableMap::CREDIT_CARD_ID); + $criteria->addSelectColumn(PaypalCartTableMap::PLANIFIED_PAYMENT_ID); + $criteria->addSelectColumn(PaypalCartTableMap::EXPRESS_PAYMENT_ID); + $criteria->addSelectColumn(PaypalCartTableMap::EXPRESS_PAYER_ID); + $criteria->addSelectColumn(PaypalCartTableMap::EXPRESS_TOKEN); + $criteria->addSelectColumn(PaypalCartTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalCartTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.CREDIT_CARD_ID'); + $criteria->addSelectColumn($alias . '.PLANIFIED_PAYMENT_ID'); + $criteria->addSelectColumn($alias . '.EXPRESS_PAYMENT_ID'); + $criteria->addSelectColumn($alias . '.EXPRESS_PAYER_ID'); + $criteria->addSelectColumn($alias . '.EXPRESS_TOKEN'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalCartTableMap::DATABASE_NAME)->getTable(PaypalCartTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalCartTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalCartTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalCartTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalCart or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalCart object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCartTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalCart) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalCartTableMap::DATABASE_NAME); + $criteria->add(PaypalCartTableMap::ID, (array) $values, Criteria::IN); + } + + $query = PaypalCartQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalCartTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalCartTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_cart table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalCartQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalCart or Criteria object. + * + * @param mixed $criteria Criteria or PaypalCart object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCartTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalCart object + } + + + // Set the correct dbName + $query = PaypalCartQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalCartTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalCartTableMap::buildTableMap(); diff --git a/Model/Map/PaypalCustomerTableMap.php b/Model/Map/PaypalCustomerTableMap.php new file mode 100644 index 0000000..459fbd4 --- /dev/null +++ b/Model/Map/PaypalCustomerTableMap.php @@ -0,0 +1,679 @@ + array('Id', 'PaypalUserId', 'CreditCardId', 'Name', 'GivenName', 'FamilyName', 'MiddleName', 'Picture', 'EmailVerified', 'Gender', 'Birthday', 'Zoneinfo', 'Locale', 'Language', 'Verified', 'PhoneNumber', 'VerifiedAccount', 'AccountType', 'AgeRange', 'PayerId', 'PostalCode', 'Locality', 'Region', 'Country', 'StreetAddress', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'paypalUserId', 'creditCardId', 'name', 'givenName', 'familyName', 'middleName', 'picture', 'emailVerified', 'gender', 'birthday', 'zoneinfo', 'locale', 'language', 'verified', 'phoneNumber', 'verifiedAccount', 'accountType', 'ageRange', 'payerId', 'postalCode', 'locality', 'region', 'country', 'streetAddress', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(PaypalCustomerTableMap::ID, PaypalCustomerTableMap::PAYPAL_USER_ID, PaypalCustomerTableMap::CREDIT_CARD_ID, PaypalCustomerTableMap::NAME, PaypalCustomerTableMap::GIVEN_NAME, PaypalCustomerTableMap::FAMILY_NAME, PaypalCustomerTableMap::MIDDLE_NAME, PaypalCustomerTableMap::PICTURE, PaypalCustomerTableMap::EMAIL_VERIFIED, PaypalCustomerTableMap::GENDER, PaypalCustomerTableMap::BIRTHDAY, PaypalCustomerTableMap::ZONEINFO, PaypalCustomerTableMap::LOCALE, PaypalCustomerTableMap::LANGUAGE, PaypalCustomerTableMap::VERIFIED, PaypalCustomerTableMap::PHONE_NUMBER, PaypalCustomerTableMap::VERIFIED_ACCOUNT, PaypalCustomerTableMap::ACCOUNT_TYPE, PaypalCustomerTableMap::AGE_RANGE, PaypalCustomerTableMap::PAYER_ID, PaypalCustomerTableMap::POSTAL_CODE, PaypalCustomerTableMap::LOCALITY, PaypalCustomerTableMap::REGION, PaypalCustomerTableMap::COUNTRY, PaypalCustomerTableMap::STREET_ADDRESS, PaypalCustomerTableMap::CREATED_AT, PaypalCustomerTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'PAYPAL_USER_ID', 'CREDIT_CARD_ID', 'NAME', 'GIVEN_NAME', 'FAMILY_NAME', 'MIDDLE_NAME', 'PICTURE', 'EMAIL_VERIFIED', 'GENDER', 'BIRTHDAY', 'ZONEINFO', 'LOCALE', 'LANGUAGE', 'VERIFIED', 'PHONE_NUMBER', 'VERIFIED_ACCOUNT', 'ACCOUNT_TYPE', 'AGE_RANGE', 'PAYER_ID', 'POSTAL_CODE', 'LOCALITY', 'REGION', 'COUNTRY', 'STREET_ADDRESS', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'paypal_user_id', 'credit_card_id', 'name', 'given_name', 'family_name', 'middle_name', 'picture', 'email_verified', 'gender', 'birthday', 'zoneinfo', 'locale', 'language', 'verified', 'phone_number', 'verified_account', 'account_type', 'age_range', 'payer_id', 'postal_code', 'locality', 'region', 'country', 'street_address', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'PaypalUserId' => 1, 'CreditCardId' => 2, 'Name' => 3, 'GivenName' => 4, 'FamilyName' => 5, 'MiddleName' => 6, 'Picture' => 7, 'EmailVerified' => 8, 'Gender' => 9, 'Birthday' => 10, 'Zoneinfo' => 11, 'Locale' => 12, 'Language' => 13, 'Verified' => 14, 'PhoneNumber' => 15, 'VerifiedAccount' => 16, 'AccountType' => 17, 'AgeRange' => 18, 'PayerId' => 19, 'PostalCode' => 20, 'Locality' => 21, 'Region' => 22, 'Country' => 23, 'StreetAddress' => 24, 'CreatedAt' => 25, 'UpdatedAt' => 26, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'paypalUserId' => 1, 'creditCardId' => 2, 'name' => 3, 'givenName' => 4, 'familyName' => 5, 'middleName' => 6, 'picture' => 7, 'emailVerified' => 8, 'gender' => 9, 'birthday' => 10, 'zoneinfo' => 11, 'locale' => 12, 'language' => 13, 'verified' => 14, 'phoneNumber' => 15, 'verifiedAccount' => 16, 'accountType' => 17, 'ageRange' => 18, 'payerId' => 19, 'postalCode' => 20, 'locality' => 21, 'region' => 22, 'country' => 23, 'streetAddress' => 24, 'createdAt' => 25, 'updatedAt' => 26, ), + self::TYPE_COLNAME => array(PaypalCustomerTableMap::ID => 0, PaypalCustomerTableMap::PAYPAL_USER_ID => 1, PaypalCustomerTableMap::CREDIT_CARD_ID => 2, PaypalCustomerTableMap::NAME => 3, PaypalCustomerTableMap::GIVEN_NAME => 4, PaypalCustomerTableMap::FAMILY_NAME => 5, PaypalCustomerTableMap::MIDDLE_NAME => 6, PaypalCustomerTableMap::PICTURE => 7, PaypalCustomerTableMap::EMAIL_VERIFIED => 8, PaypalCustomerTableMap::GENDER => 9, PaypalCustomerTableMap::BIRTHDAY => 10, PaypalCustomerTableMap::ZONEINFO => 11, PaypalCustomerTableMap::LOCALE => 12, PaypalCustomerTableMap::LANGUAGE => 13, PaypalCustomerTableMap::VERIFIED => 14, PaypalCustomerTableMap::PHONE_NUMBER => 15, PaypalCustomerTableMap::VERIFIED_ACCOUNT => 16, PaypalCustomerTableMap::ACCOUNT_TYPE => 17, PaypalCustomerTableMap::AGE_RANGE => 18, PaypalCustomerTableMap::PAYER_ID => 19, PaypalCustomerTableMap::POSTAL_CODE => 20, PaypalCustomerTableMap::LOCALITY => 21, PaypalCustomerTableMap::REGION => 22, PaypalCustomerTableMap::COUNTRY => 23, PaypalCustomerTableMap::STREET_ADDRESS => 24, PaypalCustomerTableMap::CREATED_AT => 25, PaypalCustomerTableMap::UPDATED_AT => 26, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PAYPAL_USER_ID' => 1, 'CREDIT_CARD_ID' => 2, 'NAME' => 3, 'GIVEN_NAME' => 4, 'FAMILY_NAME' => 5, 'MIDDLE_NAME' => 6, 'PICTURE' => 7, 'EMAIL_VERIFIED' => 8, 'GENDER' => 9, 'BIRTHDAY' => 10, 'ZONEINFO' => 11, 'LOCALE' => 12, 'LANGUAGE' => 13, 'VERIFIED' => 14, 'PHONE_NUMBER' => 15, 'VERIFIED_ACCOUNT' => 16, 'ACCOUNT_TYPE' => 17, 'AGE_RANGE' => 18, 'PAYER_ID' => 19, 'POSTAL_CODE' => 20, 'LOCALITY' => 21, 'REGION' => 22, 'COUNTRY' => 23, 'STREET_ADDRESS' => 24, 'CREATED_AT' => 25, 'UPDATED_AT' => 26, ), + self::TYPE_FIELDNAME => array('id' => 0, 'paypal_user_id' => 1, 'credit_card_id' => 2, 'name' => 3, 'given_name' => 4, 'family_name' => 5, 'middle_name' => 6, 'picture' => 7, 'email_verified' => 8, 'gender' => 9, 'birthday' => 10, 'zoneinfo' => 11, 'locale' => 12, 'language' => 13, 'verified' => 14, 'phone_number' => 15, 'verified_account' => 16, 'account_type' => 17, 'age_range' => 18, 'payer_id' => 19, 'postal_code' => 20, 'locality' => 21, 'region' => 22, 'country' => 23, 'street_address' => 24, 'created_at' => 25, 'updated_at' => 26, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_customer'); + $this->setPhpName('PaypalCustomer'); + $this->setClassName('\\PayPal\\Model\\PaypalCustomer'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'customer', 'ID', true, null, null); + $this->addPrimaryKey('PAYPAL_USER_ID', 'PaypalUserId', 'INTEGER', true, null, null); + $this->addColumn('CREDIT_CARD_ID', 'CreditCardId', 'VARCHAR', false, 40, null); + $this->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null); + $this->addColumn('GIVEN_NAME', 'GivenName', 'VARCHAR', false, 255, null); + $this->addColumn('FAMILY_NAME', 'FamilyName', 'VARCHAR', false, 255, null); + $this->addColumn('MIDDLE_NAME', 'MiddleName', 'VARCHAR', false, 255, null); + $this->addColumn('PICTURE', 'Picture', 'VARCHAR', false, 255, null); + $this->addColumn('EMAIL_VERIFIED', 'EmailVerified', 'TINYINT', false, null, null); + $this->addColumn('GENDER', 'Gender', 'VARCHAR', false, 255, null); + $this->addColumn('BIRTHDAY', 'Birthday', 'VARCHAR', false, 255, null); + $this->addColumn('ZONEINFO', 'Zoneinfo', 'VARCHAR', false, 255, null); + $this->addColumn('LOCALE', 'Locale', 'VARCHAR', false, 255, null); + $this->addColumn('LANGUAGE', 'Language', 'VARCHAR', false, 255, null); + $this->addColumn('VERIFIED', 'Verified', 'TINYINT', false, null, null); + $this->addColumn('PHONE_NUMBER', 'PhoneNumber', 'VARCHAR', false, 255, null); + $this->addColumn('VERIFIED_ACCOUNT', 'VerifiedAccount', 'VARCHAR', false, 255, null); + $this->addColumn('ACCOUNT_TYPE', 'AccountType', 'VARCHAR', false, 255, null); + $this->addColumn('AGE_RANGE', 'AgeRange', 'VARCHAR', false, 255, null); + $this->addColumn('PAYER_ID', 'PayerId', 'VARCHAR', false, 255, null); + $this->addColumn('POSTAL_CODE', 'PostalCode', 'VARCHAR', false, 255, null); + $this->addColumn('LOCALITY', 'Locality', 'VARCHAR', false, 255, null); + $this->addColumn('REGION', 'Region', 'VARCHAR', false, 255, null); + $this->addColumn('COUNTRY', 'Country', 'VARCHAR', false, 255, null); + $this->addColumn('STREET_ADDRESS', 'StreetAddress', 'VARCHAR', false, 255, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Customer', '\\Thelia\\Model\\Customer', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', 'RESTRICT'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \PayPal\Model\PaypalCustomer $obj A \PayPal\Model\PaypalCustomer object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getPaypalUserId())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \PayPal\Model\PaypalCustomer object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \PayPal\Model\PaypalCustomer) { + $key = serialize(array((string) $value->getId(), (string) $value->getPaypalUserId())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \PayPal\Model\PaypalCustomer object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('PaypalUserId', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('PaypalUserId', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalCustomerTableMap::CLASS_DEFAULT : PaypalCustomerTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalCustomer object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalCustomerTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalCustomerTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalCustomerTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalCustomerTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalCustomerTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalCustomerTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalCustomerTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalCustomerTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalCustomerTableMap::ID); + $criteria->addSelectColumn(PaypalCustomerTableMap::PAYPAL_USER_ID); + $criteria->addSelectColumn(PaypalCustomerTableMap::CREDIT_CARD_ID); + $criteria->addSelectColumn(PaypalCustomerTableMap::NAME); + $criteria->addSelectColumn(PaypalCustomerTableMap::GIVEN_NAME); + $criteria->addSelectColumn(PaypalCustomerTableMap::FAMILY_NAME); + $criteria->addSelectColumn(PaypalCustomerTableMap::MIDDLE_NAME); + $criteria->addSelectColumn(PaypalCustomerTableMap::PICTURE); + $criteria->addSelectColumn(PaypalCustomerTableMap::EMAIL_VERIFIED); + $criteria->addSelectColumn(PaypalCustomerTableMap::GENDER); + $criteria->addSelectColumn(PaypalCustomerTableMap::BIRTHDAY); + $criteria->addSelectColumn(PaypalCustomerTableMap::ZONEINFO); + $criteria->addSelectColumn(PaypalCustomerTableMap::LOCALE); + $criteria->addSelectColumn(PaypalCustomerTableMap::LANGUAGE); + $criteria->addSelectColumn(PaypalCustomerTableMap::VERIFIED); + $criteria->addSelectColumn(PaypalCustomerTableMap::PHONE_NUMBER); + $criteria->addSelectColumn(PaypalCustomerTableMap::VERIFIED_ACCOUNT); + $criteria->addSelectColumn(PaypalCustomerTableMap::ACCOUNT_TYPE); + $criteria->addSelectColumn(PaypalCustomerTableMap::AGE_RANGE); + $criteria->addSelectColumn(PaypalCustomerTableMap::PAYER_ID); + $criteria->addSelectColumn(PaypalCustomerTableMap::POSTAL_CODE); + $criteria->addSelectColumn(PaypalCustomerTableMap::LOCALITY); + $criteria->addSelectColumn(PaypalCustomerTableMap::REGION); + $criteria->addSelectColumn(PaypalCustomerTableMap::COUNTRY); + $criteria->addSelectColumn(PaypalCustomerTableMap::STREET_ADDRESS); + $criteria->addSelectColumn(PaypalCustomerTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalCustomerTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.PAYPAL_USER_ID'); + $criteria->addSelectColumn($alias . '.CREDIT_CARD_ID'); + $criteria->addSelectColumn($alias . '.NAME'); + $criteria->addSelectColumn($alias . '.GIVEN_NAME'); + $criteria->addSelectColumn($alias . '.FAMILY_NAME'); + $criteria->addSelectColumn($alias . '.MIDDLE_NAME'); + $criteria->addSelectColumn($alias . '.PICTURE'); + $criteria->addSelectColumn($alias . '.EMAIL_VERIFIED'); + $criteria->addSelectColumn($alias . '.GENDER'); + $criteria->addSelectColumn($alias . '.BIRTHDAY'); + $criteria->addSelectColumn($alias . '.ZONEINFO'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.LANGUAGE'); + $criteria->addSelectColumn($alias . '.VERIFIED'); + $criteria->addSelectColumn($alias . '.PHONE_NUMBER'); + $criteria->addSelectColumn($alias . '.VERIFIED_ACCOUNT'); + $criteria->addSelectColumn($alias . '.ACCOUNT_TYPE'); + $criteria->addSelectColumn($alias . '.AGE_RANGE'); + $criteria->addSelectColumn($alias . '.PAYER_ID'); + $criteria->addSelectColumn($alias . '.POSTAL_CODE'); + $criteria->addSelectColumn($alias . '.LOCALITY'); + $criteria->addSelectColumn($alias . '.REGION'); + $criteria->addSelectColumn($alias . '.COUNTRY'); + $criteria->addSelectColumn($alias . '.STREET_ADDRESS'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalCustomerTableMap::DATABASE_NAME)->getTable(PaypalCustomerTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalCustomerTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalCustomerTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalCustomerTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalCustomer or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalCustomer object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalCustomer) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalCustomerTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(PaypalCustomerTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(PaypalCustomerTableMap::PAYPAL_USER_ID, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = PaypalCustomerQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalCustomerTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalCustomerTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_customer table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalCustomerQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalCustomer or Criteria object. + * + * @param mixed $criteria Criteria or PaypalCustomer object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalCustomerTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalCustomer object + } + + + // Set the correct dbName + $query = PaypalCustomerQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalCustomerTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalCustomerTableMap::buildTableMap(); diff --git a/Model/Map/PaypalLogTableMap.php b/Model/Map/PaypalLogTableMap.php new file mode 100644 index 0000000..eb6ef2c --- /dev/null +++ b/Model/Map/PaypalLogTableMap.php @@ -0,0 +1,489 @@ + array('Id', 'CustomerId', 'OrderId', 'Hook', 'Channel', 'Level', 'Message', 'Time', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'customerId', 'orderId', 'hook', 'channel', 'level', 'message', 'time', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(PaypalLogTableMap::ID, PaypalLogTableMap::CUSTOMER_ID, PaypalLogTableMap::ORDER_ID, PaypalLogTableMap::HOOK, PaypalLogTableMap::CHANNEL, PaypalLogTableMap::LEVEL, PaypalLogTableMap::MESSAGE, PaypalLogTableMap::TIME, PaypalLogTableMap::CREATED_AT, PaypalLogTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'CUSTOMER_ID', 'ORDER_ID', 'HOOK', 'CHANNEL', 'LEVEL', 'MESSAGE', 'TIME', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'customer_id', 'order_id', 'hook', 'channel', 'level', 'message', 'time', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'CustomerId' => 1, 'OrderId' => 2, 'Hook' => 3, 'Channel' => 4, 'Level' => 5, 'Message' => 6, 'Time' => 7, 'CreatedAt' => 8, 'UpdatedAt' => 9, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'customerId' => 1, 'orderId' => 2, 'hook' => 3, 'channel' => 4, 'level' => 5, 'message' => 6, 'time' => 7, 'createdAt' => 8, 'updatedAt' => 9, ), + self::TYPE_COLNAME => array(PaypalLogTableMap::ID => 0, PaypalLogTableMap::CUSTOMER_ID => 1, PaypalLogTableMap::ORDER_ID => 2, PaypalLogTableMap::HOOK => 3, PaypalLogTableMap::CHANNEL => 4, PaypalLogTableMap::LEVEL => 5, PaypalLogTableMap::MESSAGE => 6, PaypalLogTableMap::TIME => 7, PaypalLogTableMap::CREATED_AT => 8, PaypalLogTableMap::UPDATED_AT => 9, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CUSTOMER_ID' => 1, 'ORDER_ID' => 2, 'HOOK' => 3, 'CHANNEL' => 4, 'LEVEL' => 5, 'MESSAGE' => 6, 'TIME' => 7, 'CREATED_AT' => 8, 'UPDATED_AT' => 9, ), + self::TYPE_FIELDNAME => array('id' => 0, 'customer_id' => 1, 'order_id' => 2, 'hook' => 3, 'channel' => 4, 'level' => 5, 'message' => 6, 'time' => 7, 'created_at' => 8, 'updated_at' => 9, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_log'); + $this->setPhpName('PaypalLog'); + $this->setClassName('\\PayPal\\Model\\PaypalLog'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('CUSTOMER_ID', 'CustomerId', 'INTEGER', 'customer', 'ID', false, null, null); + $this->addForeignKey('ORDER_ID', 'OrderId', 'INTEGER', 'order', 'ID', false, null, null); + $this->addColumn('HOOK', 'Hook', 'VARCHAR', false, 255, null); + $this->addColumn('CHANNEL', 'Channel', 'VARCHAR', false, 255, null); + $this->addColumn('LEVEL', 'Level', 'INTEGER', false, null, null); + $this->addColumn('MESSAGE', 'Message', 'CLOB', false, null, null); + $this->addColumn('TIME', 'Time', 'INTEGER', false, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Customer', '\\Thelia\\Model\\Customer', RelationMap::MANY_TO_ONE, array('customer_id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('Order', '\\Thelia\\Model\\Order', RelationMap::MANY_TO_ONE, array('order_id' => 'id', ), 'CASCADE', 'RESTRICT'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalLogTableMap::CLASS_DEFAULT : PaypalLogTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalLog object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalLogTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalLogTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalLogTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalLogTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalLogTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalLogTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalLogTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalLogTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalLogTableMap::ID); + $criteria->addSelectColumn(PaypalLogTableMap::CUSTOMER_ID); + $criteria->addSelectColumn(PaypalLogTableMap::ORDER_ID); + $criteria->addSelectColumn(PaypalLogTableMap::HOOK); + $criteria->addSelectColumn(PaypalLogTableMap::CHANNEL); + $criteria->addSelectColumn(PaypalLogTableMap::LEVEL); + $criteria->addSelectColumn(PaypalLogTableMap::MESSAGE); + $criteria->addSelectColumn(PaypalLogTableMap::TIME); + $criteria->addSelectColumn(PaypalLogTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalLogTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.CUSTOMER_ID'); + $criteria->addSelectColumn($alias . '.ORDER_ID'); + $criteria->addSelectColumn($alias . '.HOOK'); + $criteria->addSelectColumn($alias . '.CHANNEL'); + $criteria->addSelectColumn($alias . '.LEVEL'); + $criteria->addSelectColumn($alias . '.MESSAGE'); + $criteria->addSelectColumn($alias . '.TIME'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalLogTableMap::DATABASE_NAME)->getTable(PaypalLogTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalLogTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalLogTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalLogTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalLog or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalLog object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalLogTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalLog) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalLogTableMap::DATABASE_NAME); + $criteria->add(PaypalLogTableMap::ID, (array) $values, Criteria::IN); + } + + $query = PaypalLogQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalLogTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalLogTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_log table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalLogQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalLog or Criteria object. + * + * @param mixed $criteria Criteria or PaypalLog object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalLogTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalLog object + } + + if ($criteria->containsKey(PaypalLogTableMap::ID) && $criteria->keyContainsValue(PaypalLogTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.PaypalLogTableMap::ID.')'); + } + + + // Set the correct dbName + $query = PaypalLogQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalLogTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalLogTableMap::buildTableMap(); diff --git a/Model/Map/PaypalOrderTableMap.php b/Model/Map/PaypalOrderTableMap.php new file mode 100644 index 0000000..efb5006 --- /dev/null +++ b/Model/Map/PaypalOrderTableMap.php @@ -0,0 +1,593 @@ + array('Id', 'PaymentId', 'AgreementId', 'CreditCardId', 'State', 'Amount', 'Description', 'PayerId', 'Token', 'PlanifiedTitle', 'PlanifiedDescription', 'PlanifiedFrequency', 'PlanifiedFrequencyInterval', 'PlanifiedCycle', 'PlanifiedActualCycle', 'PlanifiedMinAmount', 'PlanifiedMaxAmount', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), + self::TYPE_STUDLYPHPNAME => array('id', 'paymentId', 'agreementId', 'creditCardId', 'state', 'amount', 'description', 'payerId', 'token', 'planifiedTitle', 'planifiedDescription', 'planifiedFrequency', 'planifiedFrequencyInterval', 'planifiedCycle', 'planifiedActualCycle', 'planifiedMinAmount', 'planifiedMaxAmount', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), + self::TYPE_COLNAME => array(PaypalOrderTableMap::ID, PaypalOrderTableMap::PAYMENT_ID, PaypalOrderTableMap::AGREEMENT_ID, PaypalOrderTableMap::CREDIT_CARD_ID, PaypalOrderTableMap::STATE, PaypalOrderTableMap::AMOUNT, PaypalOrderTableMap::DESCRIPTION, PaypalOrderTableMap::PAYER_ID, PaypalOrderTableMap::TOKEN, PaypalOrderTableMap::PLANIFIED_TITLE, PaypalOrderTableMap::PLANIFIED_DESCRIPTION, PaypalOrderTableMap::PLANIFIED_FREQUENCY, PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL, PaypalOrderTableMap::PLANIFIED_CYCLE, PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE, PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT, PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT, PaypalOrderTableMap::CREATED_AT, PaypalOrderTableMap::UPDATED_AT, PaypalOrderTableMap::VERSION, PaypalOrderTableMap::VERSION_CREATED_AT, PaypalOrderTableMap::VERSION_CREATED_BY, ), + self::TYPE_RAW_COLNAME => array('ID', 'PAYMENT_ID', 'AGREEMENT_ID', 'CREDIT_CARD_ID', 'STATE', 'AMOUNT', 'DESCRIPTION', 'PAYER_ID', 'TOKEN', 'PLANIFIED_TITLE', 'PLANIFIED_DESCRIPTION', 'PLANIFIED_FREQUENCY', 'PLANIFIED_FREQUENCY_INTERVAL', 'PLANIFIED_CYCLE', 'PLANIFIED_ACTUAL_CYCLE', 'PLANIFIED_MIN_AMOUNT', 'PLANIFIED_MAX_AMOUNT', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), + self::TYPE_FIELDNAME => array('id', 'payment_id', 'agreement_id', 'credit_card_id', 'state', 'amount', 'description', 'payer_id', 'token', 'planified_title', 'planified_description', 'planified_frequency', 'planified_frequency_interval', 'planified_cycle', 'planified_actual_cycle', 'planified_min_amount', 'planified_max_amount', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'PaymentId' => 1, 'AgreementId' => 2, 'CreditCardId' => 3, 'State' => 4, 'Amount' => 5, 'Description' => 6, 'PayerId' => 7, 'Token' => 8, 'PlanifiedTitle' => 9, 'PlanifiedDescription' => 10, 'PlanifiedFrequency' => 11, 'PlanifiedFrequencyInterval' => 12, 'PlanifiedCycle' => 13, 'PlanifiedActualCycle' => 14, 'PlanifiedMinAmount' => 15, 'PlanifiedMaxAmount' => 16, 'CreatedAt' => 17, 'UpdatedAt' => 18, 'Version' => 19, 'VersionCreatedAt' => 20, 'VersionCreatedBy' => 21, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'paymentId' => 1, 'agreementId' => 2, 'creditCardId' => 3, 'state' => 4, 'amount' => 5, 'description' => 6, 'payerId' => 7, 'token' => 8, 'planifiedTitle' => 9, 'planifiedDescription' => 10, 'planifiedFrequency' => 11, 'planifiedFrequencyInterval' => 12, 'planifiedCycle' => 13, 'planifiedActualCycle' => 14, 'planifiedMinAmount' => 15, 'planifiedMaxAmount' => 16, 'createdAt' => 17, 'updatedAt' => 18, 'version' => 19, 'versionCreatedAt' => 20, 'versionCreatedBy' => 21, ), + self::TYPE_COLNAME => array(PaypalOrderTableMap::ID => 0, PaypalOrderTableMap::PAYMENT_ID => 1, PaypalOrderTableMap::AGREEMENT_ID => 2, PaypalOrderTableMap::CREDIT_CARD_ID => 3, PaypalOrderTableMap::STATE => 4, PaypalOrderTableMap::AMOUNT => 5, PaypalOrderTableMap::DESCRIPTION => 6, PaypalOrderTableMap::PAYER_ID => 7, PaypalOrderTableMap::TOKEN => 8, PaypalOrderTableMap::PLANIFIED_TITLE => 9, PaypalOrderTableMap::PLANIFIED_DESCRIPTION => 10, PaypalOrderTableMap::PLANIFIED_FREQUENCY => 11, PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL => 12, PaypalOrderTableMap::PLANIFIED_CYCLE => 13, PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE => 14, PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT => 15, PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT => 16, PaypalOrderTableMap::CREATED_AT => 17, PaypalOrderTableMap::UPDATED_AT => 18, PaypalOrderTableMap::VERSION => 19, PaypalOrderTableMap::VERSION_CREATED_AT => 20, PaypalOrderTableMap::VERSION_CREATED_BY => 21, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PAYMENT_ID' => 1, 'AGREEMENT_ID' => 2, 'CREDIT_CARD_ID' => 3, 'STATE' => 4, 'AMOUNT' => 5, 'DESCRIPTION' => 6, 'PAYER_ID' => 7, 'TOKEN' => 8, 'PLANIFIED_TITLE' => 9, 'PLANIFIED_DESCRIPTION' => 10, 'PLANIFIED_FREQUENCY' => 11, 'PLANIFIED_FREQUENCY_INTERVAL' => 12, 'PLANIFIED_CYCLE' => 13, 'PLANIFIED_ACTUAL_CYCLE' => 14, 'PLANIFIED_MIN_AMOUNT' => 15, 'PLANIFIED_MAX_AMOUNT' => 16, 'CREATED_AT' => 17, 'UPDATED_AT' => 18, 'VERSION' => 19, 'VERSION_CREATED_AT' => 20, 'VERSION_CREATED_BY' => 21, ), + self::TYPE_FIELDNAME => array('id' => 0, 'payment_id' => 1, 'agreement_id' => 2, 'credit_card_id' => 3, 'state' => 4, 'amount' => 5, 'description' => 6, 'payer_id' => 7, 'token' => 8, 'planified_title' => 9, 'planified_description' => 10, 'planified_frequency' => 11, 'planified_frequency_interval' => 12, 'planified_cycle' => 13, 'planified_actual_cycle' => 14, 'planified_min_amount' => 15, 'planified_max_amount' => 16, 'created_at' => 17, 'updated_at' => 18, 'version' => 19, 'version_created_at' => 20, 'version_created_by' => 21, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_order'); + $this->setPhpName('PaypalOrder'); + $this->setClassName('\\PayPal\\Model\\PaypalOrder'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'order', 'ID', true, null, null); + $this->addColumn('PAYMENT_ID', 'PaymentId', 'VARCHAR', false, 50, null); + $this->addColumn('AGREEMENT_ID', 'AgreementId', 'VARCHAR', false, 255, null); + $this->addColumn('CREDIT_CARD_ID', 'CreditCardId', 'VARCHAR', false, 40, null); + $this->addColumn('STATE', 'State', 'VARCHAR', false, 20, null); + $this->addColumn('AMOUNT', 'Amount', 'DECIMAL', false, 16, 0); + $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); + $this->addColumn('PAYER_ID', 'PayerId', 'VARCHAR', false, 255, null); + $this->addColumn('TOKEN', 'Token', 'VARCHAR', false, 255, null); + $this->addColumn('PLANIFIED_TITLE', 'PlanifiedTitle', 'VARCHAR', true, 255, null); + $this->addColumn('PLANIFIED_DESCRIPTION', 'PlanifiedDescription', 'CLOB', false, null, null); + $this->addColumn('PLANIFIED_FREQUENCY', 'PlanifiedFrequency', 'VARCHAR', true, 255, null); + $this->addColumn('PLANIFIED_FREQUENCY_INTERVAL', 'PlanifiedFrequencyInterval', 'INTEGER', true, null, null); + $this->addColumn('PLANIFIED_CYCLE', 'PlanifiedCycle', 'INTEGER', true, null, null); + $this->addColumn('PLANIFIED_ACTUAL_CYCLE', 'PlanifiedActualCycle', 'INTEGER', true, null, 0); + $this->addColumn('PLANIFIED_MIN_AMOUNT', 'PlanifiedMinAmount', 'DECIMAL', false, 16, 0); + $this->addColumn('PLANIFIED_MAX_AMOUNT', 'PlanifiedMaxAmount', 'DECIMAL', false, 16, 0); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('VERSION', 'Version', 'INTEGER', false, null, 0); + $this->addColumn('VERSION_CREATED_AT', 'VersionCreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('VERSION_CREATED_BY', 'VersionCreatedBy', 'VARCHAR', false, 100, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Order', '\\Thelia\\Model\\Order', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('PaypalPlan', '\\PayPal\\Model\\PaypalPlan', RelationMap::ONE_TO_MANY, array('id' => 'paypal_order_id', ), 'CASCADE', 'RESTRICT', 'PaypalPlans'); + $this->addRelation('PaypalOrderVersion', '\\PayPal\\Model\\PaypalOrderVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'PaypalOrderVersions'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + 'versionable' => array('version_column' => 'version', 'version_table' => '', 'log_created_at' => 'true', 'log_created_by' => 'true', 'log_comment' => 'false', 'version_created_at_column' => 'version_created_at', 'version_created_by_column' => 'version_created_by', 'version_comment_column' => 'version_comment', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to paypal_order * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + PaypalPlanTableMap::clearInstancePool(); + PaypalOrderVersionTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalOrderTableMap::CLASS_DEFAULT : PaypalOrderTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalOrder object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalOrderTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalOrderTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalOrderTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalOrderTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalOrderTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalOrderTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalOrderTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalOrderTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalOrderTableMap::ID); + $criteria->addSelectColumn(PaypalOrderTableMap::PAYMENT_ID); + $criteria->addSelectColumn(PaypalOrderTableMap::AGREEMENT_ID); + $criteria->addSelectColumn(PaypalOrderTableMap::CREDIT_CARD_ID); + $criteria->addSelectColumn(PaypalOrderTableMap::STATE); + $criteria->addSelectColumn(PaypalOrderTableMap::AMOUNT); + $criteria->addSelectColumn(PaypalOrderTableMap::DESCRIPTION); + $criteria->addSelectColumn(PaypalOrderTableMap::PAYER_ID); + $criteria->addSelectColumn(PaypalOrderTableMap::TOKEN); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_TITLE); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_DESCRIPTION); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_FREQUENCY); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_FREQUENCY_INTERVAL); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_CYCLE); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_ACTUAL_CYCLE); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_MIN_AMOUNT); + $criteria->addSelectColumn(PaypalOrderTableMap::PLANIFIED_MAX_AMOUNT); + $criteria->addSelectColumn(PaypalOrderTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalOrderTableMap::UPDATED_AT); + $criteria->addSelectColumn(PaypalOrderTableMap::VERSION); + $criteria->addSelectColumn(PaypalOrderTableMap::VERSION_CREATED_AT); + $criteria->addSelectColumn(PaypalOrderTableMap::VERSION_CREATED_BY); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.PAYMENT_ID'); + $criteria->addSelectColumn($alias . '.AGREEMENT_ID'); + $criteria->addSelectColumn($alias . '.CREDIT_CARD_ID'); + $criteria->addSelectColumn($alias . '.STATE'); + $criteria->addSelectColumn($alias . '.AMOUNT'); + $criteria->addSelectColumn($alias . '.DESCRIPTION'); + $criteria->addSelectColumn($alias . '.PAYER_ID'); + $criteria->addSelectColumn($alias . '.TOKEN'); + $criteria->addSelectColumn($alias . '.PLANIFIED_TITLE'); + $criteria->addSelectColumn($alias . '.PLANIFIED_DESCRIPTION'); + $criteria->addSelectColumn($alias . '.PLANIFIED_FREQUENCY'); + $criteria->addSelectColumn($alias . '.PLANIFIED_FREQUENCY_INTERVAL'); + $criteria->addSelectColumn($alias . '.PLANIFIED_CYCLE'); + $criteria->addSelectColumn($alias . '.PLANIFIED_ACTUAL_CYCLE'); + $criteria->addSelectColumn($alias . '.PLANIFIED_MIN_AMOUNT'); + $criteria->addSelectColumn($alias . '.PLANIFIED_MAX_AMOUNT'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_BY'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalOrderTableMap::DATABASE_NAME)->getTable(PaypalOrderTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalOrderTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalOrderTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalOrderTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalOrder or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalOrder object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalOrder) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalOrderTableMap::DATABASE_NAME); + $criteria->add(PaypalOrderTableMap::ID, (array) $values, Criteria::IN); + } + + $query = PaypalOrderQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalOrderTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalOrderTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_order table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalOrderQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalOrder or Criteria object. + * + * @param mixed $criteria Criteria or PaypalOrder object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalOrder object + } + + + // Set the correct dbName + $query = PaypalOrderQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalOrderTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalOrderTableMap::buildTableMap(); diff --git a/Model/Map/PaypalOrderVersionTableMap.php b/Model/Map/PaypalOrderVersionTableMap.php new file mode 100644 index 0000000..7d9727d --- /dev/null +++ b/Model/Map/PaypalOrderVersionTableMap.php @@ -0,0 +1,634 @@ + array('Id', 'PaymentId', 'AgreementId', 'CreditCardId', 'State', 'Amount', 'Description', 'PayerId', 'Token', 'PlanifiedTitle', 'PlanifiedDescription', 'PlanifiedFrequency', 'PlanifiedFrequencyInterval', 'PlanifiedCycle', 'PlanifiedActualCycle', 'PlanifiedMinAmount', 'PlanifiedMaxAmount', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', 'IdVersion', ), + self::TYPE_STUDLYPHPNAME => array('id', 'paymentId', 'agreementId', 'creditCardId', 'state', 'amount', 'description', 'payerId', 'token', 'planifiedTitle', 'planifiedDescription', 'planifiedFrequency', 'planifiedFrequencyInterval', 'planifiedCycle', 'planifiedActualCycle', 'planifiedMinAmount', 'planifiedMaxAmount', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', 'idVersion', ), + self::TYPE_COLNAME => array(PaypalOrderVersionTableMap::ID, PaypalOrderVersionTableMap::PAYMENT_ID, PaypalOrderVersionTableMap::AGREEMENT_ID, PaypalOrderVersionTableMap::CREDIT_CARD_ID, PaypalOrderVersionTableMap::STATE, PaypalOrderVersionTableMap::AMOUNT, PaypalOrderVersionTableMap::DESCRIPTION, PaypalOrderVersionTableMap::PAYER_ID, PaypalOrderVersionTableMap::TOKEN, PaypalOrderVersionTableMap::PLANIFIED_TITLE, PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION, PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY, PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL, PaypalOrderVersionTableMap::PLANIFIED_CYCLE, PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE, PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT, PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT, PaypalOrderVersionTableMap::CREATED_AT, PaypalOrderVersionTableMap::UPDATED_AT, PaypalOrderVersionTableMap::VERSION, PaypalOrderVersionTableMap::VERSION_CREATED_AT, PaypalOrderVersionTableMap::VERSION_CREATED_BY, PaypalOrderVersionTableMap::ID_VERSION, ), + self::TYPE_RAW_COLNAME => array('ID', 'PAYMENT_ID', 'AGREEMENT_ID', 'CREDIT_CARD_ID', 'STATE', 'AMOUNT', 'DESCRIPTION', 'PAYER_ID', 'TOKEN', 'PLANIFIED_TITLE', 'PLANIFIED_DESCRIPTION', 'PLANIFIED_FREQUENCY', 'PLANIFIED_FREQUENCY_INTERVAL', 'PLANIFIED_CYCLE', 'PLANIFIED_ACTUAL_CYCLE', 'PLANIFIED_MIN_AMOUNT', 'PLANIFIED_MAX_AMOUNT', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', 'ID_VERSION', ), + self::TYPE_FIELDNAME => array('id', 'payment_id', 'agreement_id', 'credit_card_id', 'state', 'amount', 'description', 'payer_id', 'token', 'planified_title', 'planified_description', 'planified_frequency', 'planified_frequency_interval', 'planified_cycle', 'planified_actual_cycle', 'planified_min_amount', 'planified_max_amount', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', 'id_version', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'PaymentId' => 1, 'AgreementId' => 2, 'CreditCardId' => 3, 'State' => 4, 'Amount' => 5, 'Description' => 6, 'PayerId' => 7, 'Token' => 8, 'PlanifiedTitle' => 9, 'PlanifiedDescription' => 10, 'PlanifiedFrequency' => 11, 'PlanifiedFrequencyInterval' => 12, 'PlanifiedCycle' => 13, 'PlanifiedActualCycle' => 14, 'PlanifiedMinAmount' => 15, 'PlanifiedMaxAmount' => 16, 'CreatedAt' => 17, 'UpdatedAt' => 18, 'Version' => 19, 'VersionCreatedAt' => 20, 'VersionCreatedBy' => 21, 'IdVersion' => 22, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'paymentId' => 1, 'agreementId' => 2, 'creditCardId' => 3, 'state' => 4, 'amount' => 5, 'description' => 6, 'payerId' => 7, 'token' => 8, 'planifiedTitle' => 9, 'planifiedDescription' => 10, 'planifiedFrequency' => 11, 'planifiedFrequencyInterval' => 12, 'planifiedCycle' => 13, 'planifiedActualCycle' => 14, 'planifiedMinAmount' => 15, 'planifiedMaxAmount' => 16, 'createdAt' => 17, 'updatedAt' => 18, 'version' => 19, 'versionCreatedAt' => 20, 'versionCreatedBy' => 21, 'idVersion' => 22, ), + self::TYPE_COLNAME => array(PaypalOrderVersionTableMap::ID => 0, PaypalOrderVersionTableMap::PAYMENT_ID => 1, PaypalOrderVersionTableMap::AGREEMENT_ID => 2, PaypalOrderVersionTableMap::CREDIT_CARD_ID => 3, PaypalOrderVersionTableMap::STATE => 4, PaypalOrderVersionTableMap::AMOUNT => 5, PaypalOrderVersionTableMap::DESCRIPTION => 6, PaypalOrderVersionTableMap::PAYER_ID => 7, PaypalOrderVersionTableMap::TOKEN => 8, PaypalOrderVersionTableMap::PLANIFIED_TITLE => 9, PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION => 10, PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY => 11, PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL => 12, PaypalOrderVersionTableMap::PLANIFIED_CYCLE => 13, PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE => 14, PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT => 15, PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT => 16, PaypalOrderVersionTableMap::CREATED_AT => 17, PaypalOrderVersionTableMap::UPDATED_AT => 18, PaypalOrderVersionTableMap::VERSION => 19, PaypalOrderVersionTableMap::VERSION_CREATED_AT => 20, PaypalOrderVersionTableMap::VERSION_CREATED_BY => 21, PaypalOrderVersionTableMap::ID_VERSION => 22, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PAYMENT_ID' => 1, 'AGREEMENT_ID' => 2, 'CREDIT_CARD_ID' => 3, 'STATE' => 4, 'AMOUNT' => 5, 'DESCRIPTION' => 6, 'PAYER_ID' => 7, 'TOKEN' => 8, 'PLANIFIED_TITLE' => 9, 'PLANIFIED_DESCRIPTION' => 10, 'PLANIFIED_FREQUENCY' => 11, 'PLANIFIED_FREQUENCY_INTERVAL' => 12, 'PLANIFIED_CYCLE' => 13, 'PLANIFIED_ACTUAL_CYCLE' => 14, 'PLANIFIED_MIN_AMOUNT' => 15, 'PLANIFIED_MAX_AMOUNT' => 16, 'CREATED_AT' => 17, 'UPDATED_AT' => 18, 'VERSION' => 19, 'VERSION_CREATED_AT' => 20, 'VERSION_CREATED_BY' => 21, 'ID_VERSION' => 22, ), + self::TYPE_FIELDNAME => array('id' => 0, 'payment_id' => 1, 'agreement_id' => 2, 'credit_card_id' => 3, 'state' => 4, 'amount' => 5, 'description' => 6, 'payer_id' => 7, 'token' => 8, 'planified_title' => 9, 'planified_description' => 10, 'planified_frequency' => 11, 'planified_frequency_interval' => 12, 'planified_cycle' => 13, 'planified_actual_cycle' => 14, 'planified_min_amount' => 15, 'planified_max_amount' => 16, 'created_at' => 17, 'updated_at' => 18, 'version' => 19, 'version_created_at' => 20, 'version_created_by' => 21, 'id_version' => 22, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_order_version'); + $this->setPhpName('PaypalOrderVersion'); + $this->setClassName('\\PayPal\\Model\\PaypalOrderVersion'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'paypal_order', 'ID', true, null, null); + $this->addColumn('PAYMENT_ID', 'PaymentId', 'VARCHAR', false, 50, null); + $this->addColumn('AGREEMENT_ID', 'AgreementId', 'VARCHAR', false, 255, null); + $this->addColumn('CREDIT_CARD_ID', 'CreditCardId', 'VARCHAR', false, 40, null); + $this->addColumn('STATE', 'State', 'VARCHAR', false, 20, null); + $this->addColumn('AMOUNT', 'Amount', 'DECIMAL', false, 16, 0); + $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); + $this->addColumn('PAYER_ID', 'PayerId', 'VARCHAR', false, 255, null); + $this->addColumn('TOKEN', 'Token', 'VARCHAR', false, 255, null); + $this->addColumn('PLANIFIED_TITLE', 'PlanifiedTitle', 'VARCHAR', true, 255, null); + $this->addColumn('PLANIFIED_DESCRIPTION', 'PlanifiedDescription', 'CLOB', false, null, null); + $this->addColumn('PLANIFIED_FREQUENCY', 'PlanifiedFrequency', 'VARCHAR', true, 255, null); + $this->addColumn('PLANIFIED_FREQUENCY_INTERVAL', 'PlanifiedFrequencyInterval', 'INTEGER', true, null, null); + $this->addColumn('PLANIFIED_CYCLE', 'PlanifiedCycle', 'INTEGER', true, null, null); + $this->addColumn('PLANIFIED_ACTUAL_CYCLE', 'PlanifiedActualCycle', 'INTEGER', true, null, 0); + $this->addColumn('PLANIFIED_MIN_AMOUNT', 'PlanifiedMinAmount', 'DECIMAL', false, 16, 0); + $this->addColumn('PLANIFIED_MAX_AMOUNT', 'PlanifiedMaxAmount', 'DECIMAL', false, 16, 0); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + $this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0); + $this->addColumn('VERSION_CREATED_AT', 'VersionCreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('VERSION_CREATED_BY', 'VersionCreatedBy', 'VARCHAR', false, 100, null); + $this->addColumn('ID_VERSION', 'IdVersion', 'INTEGER', false, null, 0); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('PaypalOrder', '\\PayPal\\Model\\PaypalOrder', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \PayPal\Model\PaypalOrderVersion $obj A \PayPal\Model\PaypalOrderVersion object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getVersion())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \PayPal\Model\PaypalOrderVersion object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \PayPal\Model\PaypalOrderVersion) { + $key = serialize(array((string) $value->getId(), (string) $value->getVersion())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \PayPal\Model\PaypalOrderVersion object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 19 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 19 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalOrderVersionTableMap::CLASS_DEFAULT : PaypalOrderVersionTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalOrderVersion object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalOrderVersionTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalOrderVersionTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalOrderVersionTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalOrderVersionTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalOrderVersionTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalOrderVersionTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalOrderVersionTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalOrderVersionTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalOrderVersionTableMap::ID); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PAYMENT_ID); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::AGREEMENT_ID); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::CREDIT_CARD_ID); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::STATE); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::AMOUNT); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::DESCRIPTION); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PAYER_ID); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::TOKEN); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_TITLE); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_DESCRIPTION); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_FREQUENCY_INTERVAL); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_CYCLE); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_ACTUAL_CYCLE); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_MIN_AMOUNT); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::PLANIFIED_MAX_AMOUNT); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::UPDATED_AT); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::VERSION); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::VERSION_CREATED_AT); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::VERSION_CREATED_BY); + $criteria->addSelectColumn(PaypalOrderVersionTableMap::ID_VERSION); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.PAYMENT_ID'); + $criteria->addSelectColumn($alias . '.AGREEMENT_ID'); + $criteria->addSelectColumn($alias . '.CREDIT_CARD_ID'); + $criteria->addSelectColumn($alias . '.STATE'); + $criteria->addSelectColumn($alias . '.AMOUNT'); + $criteria->addSelectColumn($alias . '.DESCRIPTION'); + $criteria->addSelectColumn($alias . '.PAYER_ID'); + $criteria->addSelectColumn($alias . '.TOKEN'); + $criteria->addSelectColumn($alias . '.PLANIFIED_TITLE'); + $criteria->addSelectColumn($alias . '.PLANIFIED_DESCRIPTION'); + $criteria->addSelectColumn($alias . '.PLANIFIED_FREQUENCY'); + $criteria->addSelectColumn($alias . '.PLANIFIED_FREQUENCY_INTERVAL'); + $criteria->addSelectColumn($alias . '.PLANIFIED_CYCLE'); + $criteria->addSelectColumn($alias . '.PLANIFIED_ACTUAL_CYCLE'); + $criteria->addSelectColumn($alias . '.PLANIFIED_MIN_AMOUNT'); + $criteria->addSelectColumn($alias . '.PLANIFIED_MAX_AMOUNT'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_BY'); + $criteria->addSelectColumn($alias . '.ID_VERSION'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalOrderVersionTableMap::DATABASE_NAME)->getTable(PaypalOrderVersionTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalOrderVersionTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalOrderVersionTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalOrderVersionTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalOrderVersion or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalOrderVersion object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalOrderVersion) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalOrderVersionTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(PaypalOrderVersionTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(PaypalOrderVersionTableMap::VERSION, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = PaypalOrderVersionQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalOrderVersionTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalOrderVersionTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_order_version table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalOrderVersionQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalOrderVersion or Criteria object. + * + * @param mixed $criteria Criteria or PaypalOrderVersion object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalOrderVersionTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalOrderVersion object + } + + + // Set the correct dbName + $query = PaypalOrderVersionQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalOrderVersionTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalOrderVersionTableMap::buildTableMap(); diff --git a/Model/Map/PaypalPlanTableMap.php b/Model/Map/PaypalPlanTableMap.php new file mode 100644 index 0000000..fb358f7 --- /dev/null +++ b/Model/Map/PaypalPlanTableMap.php @@ -0,0 +1,456 @@ + array('Id', 'PaypalOrderId', 'PlanId', 'State', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'paypalOrderId', 'planId', 'state', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(PaypalPlanTableMap::ID, PaypalPlanTableMap::PAYPAL_ORDER_ID, PaypalPlanTableMap::PLAN_ID, PaypalPlanTableMap::STATE, PaypalPlanTableMap::CREATED_AT, PaypalPlanTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'PAYPAL_ORDER_ID', 'PLAN_ID', 'STATE', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'paypal_order_id', 'plan_id', 'state', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'PaypalOrderId' => 1, 'PlanId' => 2, 'State' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'paypalOrderId' => 1, 'planId' => 2, 'state' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), + self::TYPE_COLNAME => array(PaypalPlanTableMap::ID => 0, PaypalPlanTableMap::PAYPAL_ORDER_ID => 1, PaypalPlanTableMap::PLAN_ID => 2, PaypalPlanTableMap::STATE => 3, PaypalPlanTableMap::CREATED_AT => 4, PaypalPlanTableMap::UPDATED_AT => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PAYPAL_ORDER_ID' => 1, 'PLAN_ID' => 2, 'STATE' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'paypal_order_id' => 1, 'plan_id' => 2, 'state' => 3, 'created_at' => 4, 'updated_at' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_plan'); + $this->setPhpName('PaypalPlan'); + $this->setClassName('\\PayPal\\Model\\PaypalPlan'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('PAYPAL_ORDER_ID', 'PaypalOrderId', 'INTEGER', 'paypal_order', 'ID', true, null, null); + $this->addColumn('PLAN_ID', 'PlanId', 'VARCHAR', false, 255, null); + $this->addColumn('STATE', 'State', 'VARCHAR', false, 255, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('PaypalOrder', '\\PayPal\\Model\\PaypalOrder', RelationMap::MANY_TO_ONE, array('paypal_order_id' => 'id', ), 'CASCADE', 'RESTRICT'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalPlanTableMap::CLASS_DEFAULT : PaypalPlanTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalPlan object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalPlanTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalPlanTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalPlanTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalPlanTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalPlanTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalPlanTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalPlanTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalPlanTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalPlanTableMap::ID); + $criteria->addSelectColumn(PaypalPlanTableMap::PAYPAL_ORDER_ID); + $criteria->addSelectColumn(PaypalPlanTableMap::PLAN_ID); + $criteria->addSelectColumn(PaypalPlanTableMap::STATE); + $criteria->addSelectColumn(PaypalPlanTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalPlanTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.PAYPAL_ORDER_ID'); + $criteria->addSelectColumn($alias . '.PLAN_ID'); + $criteria->addSelectColumn($alias . '.STATE'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalPlanTableMap::DATABASE_NAME)->getTable(PaypalPlanTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalPlanTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalPlanTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalPlanTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalPlan or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalPlan object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalPlan) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalPlanTableMap::DATABASE_NAME); + $criteria->add(PaypalPlanTableMap::ID, (array) $values, Criteria::IN); + } + + $query = PaypalPlanQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalPlanTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalPlanTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_plan table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalPlanQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalPlan or Criteria object. + * + * @param mixed $criteria Criteria or PaypalPlan object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalPlan object + } + + if ($criteria->containsKey(PaypalPlanTableMap::ID) && $criteria->keyContainsValue(PaypalPlanTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.PaypalPlanTableMap::ID.')'); + } + + + // Set the correct dbName + $query = PaypalPlanQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalPlanTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalPlanTableMap::buildTableMap(); diff --git a/Model/Map/PaypalPlanifiedPaymentI18nTableMap.php b/Model/Map/PaypalPlanifiedPaymentI18nTableMap.php new file mode 100644 index 0000000..b6fad49 --- /dev/null +++ b/Model/Map/PaypalPlanifiedPaymentI18nTableMap.php @@ -0,0 +1,482 @@ + array('Id', 'Locale', 'Title', 'Description', ), + self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', 'description', ), + self::TYPE_COLNAME => array(PaypalPlanifiedPaymentI18nTableMap::ID, PaypalPlanifiedPaymentI18nTableMap::LOCALE, PaypalPlanifiedPaymentI18nTableMap::TITLE, PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION, ), + self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', 'DESCRIPTION', ), + self::TYPE_FIELDNAME => array('id', 'locale', 'title', 'description', ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, 'Description' => 3, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), + self::TYPE_COLNAME => array(PaypalPlanifiedPaymentI18nTableMap::ID => 0, PaypalPlanifiedPaymentI18nTableMap::LOCALE => 1, PaypalPlanifiedPaymentI18nTableMap::TITLE => 2, PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION => 3, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, 'DESCRIPTION' => 3, ), + self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_planified_payment_i18n'); + $this->setPhpName('PaypalPlanifiedPaymentI18n'); + $this->setClassName('\\PayPal\\Model\\PaypalPlanifiedPaymentI18n'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'paypal_planified_payment', 'ID', true, null, null); + $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); + $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); + $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('PaypalPlanifiedPayment', '\\PayPal\\Model\\PaypalPlanifiedPayment', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \PayPal\Model\PaypalPlanifiedPaymentI18n $obj A \PayPal\Model\PaypalPlanifiedPaymentI18n object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \PayPal\Model\PaypalPlanifiedPaymentI18n object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \PayPal\Model\PaypalPlanifiedPaymentI18n) { + $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \PayPal\Model\PaypalPlanifiedPaymentI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalPlanifiedPaymentI18nTableMap::CLASS_DEFAULT : PaypalPlanifiedPaymentI18nTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalPlanifiedPaymentI18n object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalPlanifiedPaymentI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalPlanifiedPaymentI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalPlanifiedPaymentI18nTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalPlanifiedPaymentI18nTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalPlanifiedPaymentI18nTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalPlanifiedPaymentI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalPlanifiedPaymentI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalPlanifiedPaymentI18nTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalPlanifiedPaymentI18nTableMap::ID); + $criteria->addSelectColumn(PaypalPlanifiedPaymentI18nTableMap::LOCALE); + $criteria->addSelectColumn(PaypalPlanifiedPaymentI18nTableMap::TITLE); + $criteria->addSelectColumn(PaypalPlanifiedPaymentI18nTableMap::DESCRIPTION); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.TITLE'); + $criteria->addSelectColumn($alias . '.DESCRIPTION'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME)->getTable(PaypalPlanifiedPaymentI18nTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalPlanifiedPaymentI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalPlanifiedPaymentI18nTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalPlanifiedPaymentI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalPlanifiedPaymentI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalPlanifiedPaymentI18n) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(PaypalPlanifiedPaymentI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(PaypalPlanifiedPaymentI18nTableMap::LOCALE, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = PaypalPlanifiedPaymentI18nQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalPlanifiedPaymentI18nTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalPlanifiedPaymentI18nTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_planified_payment_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalPlanifiedPaymentI18nQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalPlanifiedPaymentI18n or Criteria object. + * + * @param mixed $criteria Criteria or PaypalPlanifiedPaymentI18n object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentI18nTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalPlanifiedPaymentI18n object + } + + + // Set the correct dbName + $query = PaypalPlanifiedPaymentI18nQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalPlanifiedPaymentI18nTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalPlanifiedPaymentI18nTableMap::buildTableMap(); diff --git a/Model/Map/PaypalPlanifiedPaymentTableMap.php b/Model/Map/PaypalPlanifiedPaymentTableMap.php new file mode 100644 index 0000000..3669ba7 --- /dev/null +++ b/Model/Map/PaypalPlanifiedPaymentTableMap.php @@ -0,0 +1,501 @@ + array('Id', 'Frequency', 'FrequencyInterval', 'Cycle', 'MinAmount', 'MaxAmount', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'frequency', 'frequencyInterval', 'cycle', 'minAmount', 'maxAmount', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(PaypalPlanifiedPaymentTableMap::ID, PaypalPlanifiedPaymentTableMap::FREQUENCY, PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL, PaypalPlanifiedPaymentTableMap::CYCLE, PaypalPlanifiedPaymentTableMap::MIN_AMOUNT, PaypalPlanifiedPaymentTableMap::MAX_AMOUNT, PaypalPlanifiedPaymentTableMap::POSITION, PaypalPlanifiedPaymentTableMap::CREATED_AT, PaypalPlanifiedPaymentTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'FREQUENCY', 'FREQUENCY_INTERVAL', 'CYCLE', 'MIN_AMOUNT', 'MAX_AMOUNT', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'frequency', 'frequency_interval', 'cycle', 'min_amount', 'max_amount', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Frequency' => 1, 'FrequencyInterval' => 2, 'Cycle' => 3, 'MinAmount' => 4, 'MaxAmount' => 5, 'Position' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'frequency' => 1, 'frequencyInterval' => 2, 'cycle' => 3, 'minAmount' => 4, 'maxAmount' => 5, 'position' => 6, 'createdAt' => 7, 'updatedAt' => 8, ), + self::TYPE_COLNAME => array(PaypalPlanifiedPaymentTableMap::ID => 0, PaypalPlanifiedPaymentTableMap::FREQUENCY => 1, PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL => 2, PaypalPlanifiedPaymentTableMap::CYCLE => 3, PaypalPlanifiedPaymentTableMap::MIN_AMOUNT => 4, PaypalPlanifiedPaymentTableMap::MAX_AMOUNT => 5, PaypalPlanifiedPaymentTableMap::POSITION => 6, PaypalPlanifiedPaymentTableMap::CREATED_AT => 7, PaypalPlanifiedPaymentTableMap::UPDATED_AT => 8, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'FREQUENCY' => 1, 'FREQUENCY_INTERVAL' => 2, 'CYCLE' => 3, 'MIN_AMOUNT' => 4, 'MAX_AMOUNT' => 5, 'POSITION' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ), + self::TYPE_FIELDNAME => array('id' => 0, 'frequency' => 1, 'frequency_interval' => 2, 'cycle' => 3, 'min_amount' => 4, 'max_amount' => 5, 'position' => 6, 'created_at' => 7, 'updated_at' => 8, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('paypal_planified_payment'); + $this->setPhpName('PaypalPlanifiedPayment'); + $this->setClassName('\\PayPal\\Model\\PaypalPlanifiedPayment'); + $this->setPackage('PayPal.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('FREQUENCY', 'Frequency', 'VARCHAR', true, 255, null); + $this->addColumn('FREQUENCY_INTERVAL', 'FrequencyInterval', 'INTEGER', true, null, null); + $this->addColumn('CYCLE', 'Cycle', 'INTEGER', true, null, null); + $this->addColumn('MIN_AMOUNT', 'MinAmount', 'DECIMAL', false, 16, 0); + $this->addColumn('MAX_AMOUNT', 'MaxAmount', 'DECIMAL', false, 16, 0); + $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, 0); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('PaypalCart', '\\PayPal\\Model\\PaypalCart', RelationMap::ONE_TO_MANY, array('id' => 'planified_payment_id', ), 'CASCADE', 'RESTRICT', 'PaypalCarts'); + $this->addRelation('PaypalPlanifiedPaymentI18n', '\\PayPal\\Model\\PaypalPlanifiedPaymentI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'PaypalPlanifiedPaymentI18ns'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'title, description', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to paypal_planified_payment * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + PaypalCartTableMap::clearInstancePool(); + PaypalPlanifiedPaymentI18nTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? PaypalPlanifiedPaymentTableMap::CLASS_DEFAULT : PaypalPlanifiedPaymentTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (PaypalPlanifiedPayment object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = PaypalPlanifiedPaymentTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = PaypalPlanifiedPaymentTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + PaypalPlanifiedPaymentTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = PaypalPlanifiedPaymentTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + PaypalPlanifiedPaymentTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = PaypalPlanifiedPaymentTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = PaypalPlanifiedPaymentTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + PaypalPlanifiedPaymentTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::ID); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::FREQUENCY); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::FREQUENCY_INTERVAL); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::CYCLE); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::MIN_AMOUNT); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::MAX_AMOUNT); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::POSITION); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::CREATED_AT); + $criteria->addSelectColumn(PaypalPlanifiedPaymentTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.FREQUENCY'); + $criteria->addSelectColumn($alias . '.FREQUENCY_INTERVAL'); + $criteria->addSelectColumn($alias . '.CYCLE'); + $criteria->addSelectColumn($alias . '.MIN_AMOUNT'); + $criteria->addSelectColumn($alias . '.MAX_AMOUNT'); + $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(PaypalPlanifiedPaymentTableMap::DATABASE_NAME)->getTable(PaypalPlanifiedPaymentTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(PaypalPlanifiedPaymentTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new PaypalPlanifiedPaymentTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a PaypalPlanifiedPayment or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PaypalPlanifiedPayment object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \PayPal\Model\PaypalPlanifiedPayment) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + $criteria->add(PaypalPlanifiedPaymentTableMap::ID, (array) $values, Criteria::IN); + } + + $query = PaypalPlanifiedPaymentQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { PaypalPlanifiedPaymentTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { PaypalPlanifiedPaymentTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the paypal_planified_payment table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return PaypalPlanifiedPaymentQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a PaypalPlanifiedPayment or Criteria object. + * + * @param mixed $criteria Criteria or PaypalPlanifiedPayment object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(PaypalPlanifiedPaymentTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from PaypalPlanifiedPayment object + } + + if ($criteria->containsKey(PaypalPlanifiedPaymentTableMap::ID) && $criteria->keyContainsValue(PaypalPlanifiedPaymentTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.PaypalPlanifiedPaymentTableMap::ID.')'); + } + + + // Set the correct dbName + $query = PaypalPlanifiedPaymentQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // PaypalPlanifiedPaymentTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +PaypalPlanifiedPaymentTableMap::buildTableMap(); diff --git a/Model/PaypalCart.php b/Model/PaypalCart.php new file mode 100644 index 0000000..4603a7c --- /dev/null +++ b/Model/PaypalCart.php @@ -0,0 +1,48 @@ +aCart === null && ($this->id !== null)) { + $this->aCart = CartQuery::create()->findPk($this->id, $con); + } + + return $this->aCart; + } + + /** + * Declares an association between this object and a ChildCart object. + * + * @param Cart $cart + * @return \PayPal\Model\PaypalCart The current object (for fluent API support) + * @throws PropelException + */ + public function setCart(Cart $cart = null) + { + if ($cart === null) { + $this->setId(NULL); + } else { + $this->setId($cart->getId()); + } + + $this->aCart = $cart; + + return $this; + } +} diff --git a/Model/PaypalCartQuery.php b/Model/PaypalCartQuery.php new file mode 100644 index 0000000..a73f9fe --- /dev/null +++ b/Model/PaypalCartQuery.php @@ -0,0 +1,21 @@ +aCustomer === null && ($this->id !== null)) { + $this->aCustomer = CustomerQuery::create()->findPk($this->id, $con); + } + + return $this->aCustomer; + } + + /** + * Declares an association between this object and a ChildCustomer object. + * + * @param Customer $customer + * @return \PayPal\Model\PaypalCustomer The current object (for fluent API support) + * @throws PropelException + */ + public function setCustomer(Customer $customer = null) + { + if ($customer === null) { + $this->setId(NULL); + } else { + $this->setId($customer->getId()); + } + + $this->aCustomer = $customer; + + return $this; + } +} diff --git a/Model/PaypalCustomerQuery.php b/Model/PaypalCustomerQuery.php new file mode 100644 index 0000000..cad81bc --- /dev/null +++ b/Model/PaypalCustomerQuery.php @@ -0,0 +1,21 @@ +aOrder === null && ($this->id !== null)) { + $this->aOrder = OrderQuery::create()->findPk($this->id, $con); + } + + return $this->aOrder; + } + + /** + * Declares an association between this object and a ChildOrder object. + * + * @param Order $order + * @return \PayPal\Model\PaypalOrder The current object (for fluent API support) + * @throws PropelException + */ + public function setOrder(Order $order = null) + { + if ($order === null) { + $this->setId(NULL); + } else { + $this->setId($order->getId()); + } + + $this->aOrder = $order; + + return $this; + } +} diff --git a/Model/PaypalOrderQuery.php b/Model/PaypalOrderQuery.php new file mode 100644 index 0000000..0f70b7a --- /dev/null +++ b/Model/PaypalOrderQuery.php @@ -0,0 +1,21 @@ +. */ -/* */ +/* For the full copyright and license information, please view the LICENSE.txt */ +/* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Paypal; +namespace PayPal; -use Paypal\Classes\API\PaypalApiCredentials; -use Paypal\Classes\API\PaypalApiLogManager; -use Paypal\Classes\API\PaypalApiManager; -use Paypal\Classes\NVP\Operations\PaypalNvpOperationsSetExpressCheckout; -use Paypal\Classes\NVP\PaypalNvpMessageSender; +use Monolog\Logger; +use PayPal\Exception\PayPalConnectionException; +use PayPal\Model\PaypalCartQuery; +use PayPal\Model\PaypalPlanifiedPaymentQuery; +use PayPal\Service\Base\PayPalBaseService; +use PayPal\Service\PayPalAgreementService; +use PayPal\Service\PayPalLoggerService; +use PayPal\Service\PayPalPaymentService; use Propel\Runtime\Connection\ConnectionInterface; +use Propel\Runtime\Propel; +use Symfony\Component\Finder\Finder; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\Routing\Router; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Translation\Translator; use Thelia\Install\Database; -use Thelia\Model\CountryQuery; use Thelia\Model\Message; use Thelia\Model\MessageQuery; use Thelia\Model\ModuleImageQuery; use Thelia\Model\Order; -use Thelia\Model\OrderAddressQuery; -use Thelia\Model\OrderQuery; +use Thelia\Model\OrderStatusQuery; use Thelia\Module\AbstractPaymentModule; use Thelia\Tools\URL; -/** - * Class Paypal - * @package Paypal - * @author Thelia - */ -class Paypal extends AbstractPaymentModule +class PayPal extends AbstractPaymentModule { - const DOMAIN = 'paypal'; + /** @var string */ + const DOMAIN_NAME = 'paypal'; + const ROUTER = 'router.paypal'; /** * The confirmation message identifier */ const CONFIRMATION_MESSAGE_NAME = 'paypal_payment_confirmation'; + const RECURSIVE_MESSAGE_NAME = 'paypal_recursive_payment_confirmation'; - public function pay(Order $order) - { - $orderId = $order->getId(); - - /** @var Router $router */ - $router = $this->getContainer()->get('router.paypal'); - - $successUrl = URL::getInstance()->absoluteUrl( - $router->generate('paypal.ok', ['order_id' => $order->getId()]) - ); - - $cancelUrl = URL::getInstance()->absoluteUrl( - $router->generate('paypal.cancel', ['order_id' => $order->getId()]) - ); + const CREDIT_CARD_TYPE_VISA = 'visa'; + const CREDIT_CARD_TYPE_MASTERCARD = 'mastercard'; + const CREDIT_CARD_TYPE_DISCOVER = 'discover'; + const CREDIT_CARD_TYPE_AMEX = 'amex'; - $order = OrderQuery::create()->findPk($orderId); + const PAYPAL_METHOD_PAYPAL = 'paypal'; + const PAYPAL_METHOD_EXPRESS_CHECKOUT = 'express_checkout'; + const PAYPAL_METHOD_CREDIT_CARD = 'credit_card'; + const PAYPAL_METHOD_PLANIFIED_PAYMENT = 'planified_payment'; - $api = new PaypalApiCredentials(); - $redirect_api = new PaypalApiManager(); - $products = array(array()); - $itemIndex = 0; - $logger = new PaypalApiLogManager(); + const PAYPAL_PAYMENT_SERVICE_ID = 'paypal_payment_service'; + const PAYPAL_CUSTOMER_SERVICE_ID = 'paypal_customer_service'; + const PAYPAL_AGREEMENT_SERVICE_ID = 'paypal_agreement_service'; - $send_cart_detail = Paypal::getConfigValue('send_cart_detail', 0); + const PAYMENT_STATE_APPROVED = 'approved'; + const PAYMENT_STATE_CREATED = 'created'; + const PAYMENT_STATE_REFUSED = 'refused'; - if ($send_cart_detail == 1) { - - /* - * Store products into 2d array $products - */ - $products_amount = 0; - - foreach ($order->getOrderProducts() as $product) { - if ($product !== null) { - $amount = floatval($product->getWasInPromo() ? $product->getPromoPrice() : $product->getPrice()); - foreach ($product->getOrderProductTaxes() as $tax) { - $amount += $product->getWasInPromo() ? $tax->getPromoAmount() : $tax->getAmount(); + /** + * Method used by payment gateway. + * + * If this method return a \Thelia\Core\HttpFoundation\Response instance, this response is send to the + * browser. + * + * In many cases, it's necessary to send a form to the payment gateway. On your response you can return this form already + * completed, ready to be sent + * + * @param Order $order + * @return RedirectResponse + * @throws \Exception + */ + public function pay(Order $order) + { + $con = Propel::getConnection(); + $con->beginTransaction(); + + try { + /** @var PayPalPaymentService $payPalService */ + $payPalService = $this->getContainer()->get(self::PAYPAL_PAYMENT_SERVICE_ID); + /** @var PayPalAgreementService $payPalAgreementService */ + $payPalAgreementService = $this->getContainer()->get(self::PAYPAL_AGREEMENT_SERVICE_ID); + + if (null !== $payPalCart = PaypalCartQuery::create()->findOneById($order->getCartId())) { + + if (null !== $payPalCart->getCreditCardId()) { + $payment = $payPalService->makePayment($order, $payPalCart->getCreditCardId()); + + //This payment method does not have a callback URL... So we have to check the payment status + if ($payment->getState() === PayPal::PAYMENT_STATE_APPROVED) { + $event = new OrderEvent($order); + $event->setStatus(OrderStatusQuery::getPaidStatus()->getId()); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + $response = new RedirectResponse(URL::getInstance()->absoluteUrl('/order/placed/' . $order->getId())); + PayPalLoggerService::log( + Translator::getInstance()->trans( + 'Order payed with success with method : %method', + [ + '%method' => self::PAYPAL_METHOD_CREDIT_CARD + ], + self::DOMAIN_NAME + ), + [ + 'order_id' => $order->getId(), + 'customer_id' => $order->getCustomerId() + ], + Logger::INFO + ); + } else { + $response = new RedirectResponse(URL::getInstance()->absoluteUrl('/module/paypal/cancel/' . $order->getId())); + PayPalLoggerService::log( + Translator::getInstance()->trans( + 'Order failed with method : %method', + [ + '%method' => self::PAYPAL_METHOD_CREDIT_CARD + ], + self::DOMAIN_NAME + ), + [ + 'order_id' => $order->getId(), + 'customer_id' => $order->getCustomerId() + ], + Logger::CRITICAL + ); } - $rounded_amounts = round($amount, 2); - $products_amount += $rounded_amounts * $product->getQuantity(); - $products[0][ "NAME" . $itemIndex ] = urlencode($product->getTitle()); - $products[0][ "AMT" . $itemIndex ] = urlencode($rounded_amounts); - $products[0][ "QTY" . $itemIndex ] = urlencode($product->getQuantity()); - $itemIndex ++; - } - } - - /* - * Compute difference between prodcts total and cart amount - * -> get Coupons. - */ - $delta = round($products_amount - $order->getTotalAmount($useless, false), 2); - - if ($delta > 0) { - $products[0][ "NAME" . $itemIndex ] = Translator::getInstance()->trans("Discount"); - $products[0][ "AMT" . $itemIndex ] = - $delta; - $products[0][ "QTY" . $itemIndex ] = 1; - } - } else { - $products[0]["NAME" . $itemIndex] = urlencode(Translator::getInstance()->trans("Order").' '.$orderId); - $products[0]["AMT" . $itemIndex] = round($order->getTotalAmount($useless, false),2); - $products[0]["QTY" . $itemIndex] = 1; - } - - /* - * Create setExpressCheckout request - */ - $setExpressCheckout = new PaypalNvpOperationsSetExpressCheckout( - $api, - round($order->getTotalAmount(), 2), - $order->getCurrency()->getCode(), - $successUrl, - $cancelUrl, - 0, - array( - "L_PAYMENTREQUEST" => $products, - "PAYMENTREQUEST" => array( - array( - "SHIPPINGAMT" => round($order->getPostage(), 2), - "ITEMAMT" => round($order->getTotalAmount($useless, false), 2) - ) - ) - ) - ); - - /* - * Try to get customer's delivery address - */ - if (null !== $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId())) { - /* - * If address is found, set address in setExpressCheckout request - */ - $setExpressCheckout->setCustomerDeliveryAddress( - $address->getLastname(), - $address->getAddress1(), - $address->getAddress2(), - $address->getCity(), - "", // State - $address->getZipcode(), - CountryQuery::create()->findPk($address->getCountryId())->getIsoalpha2() - ); - - /* - * $sender PaypalNvpMessageSender Instance of the class that sends requests - * $response string NVP response of paypal for setExpressCheckout request - * $req array array cast of NVP response - */ - $sender = new PaypalNvpMessageSender($setExpressCheckout, self::isSandboxMode()); - - $response = $sender->send(); - - if ($response) { - $responseData = PaypalApiManager::nvpToArray($response); - - $logger->logTransaction($responseData); - /* - * if setExpressCheckout is correct, store values in the session & redirect to paypal checkout page - * else print error. ( return $this->render ... ) - */ - if (isset($responseData['ACK']) && $responseData['ACK'] === "Success" - && - isset($responseData['TOKEN']) && ! empty($responseData['TOKEN']) - ) { - $sess = $this->getRequest()->getSession(); - $sess->set("Paypal.token", $responseData['TOKEN']); - - return new RedirectResponse( - $redirect_api->getExpressCheckoutUrl($responseData['TOKEN']) + } elseif (null !== $planifiedPayment = PaypalPlanifiedPaymentQuery::create()->findOneById($payPalCart->getPlanifiedPaymentId())) { + //Agreement Payment + $agreement = $payPalAgreementService->makeAgreement($order, $planifiedPayment); + $response = new RedirectResponse($agreement->getApprovalLink()); + PayPalLoggerService::log( + Translator::getInstance()->trans( + 'Order created with success in PayPal with method : %method', + [ + '%method' => self::PAYPAL_METHOD_PLANIFIED_PAYMENT + ], + self::DOMAIN_NAME + ), + [ + 'order_id' => $order->getId(), + 'customer_id' => $order->getCustomerId() + ], + Logger::INFO + ); + } else { + //Classic Payment + $payment = $payPalService->makePayment($order); + $response = new RedirectResponse($payment->getApprovalLink()); + PayPalLoggerService::log( + Translator::getInstance()->trans( + 'Order created with success in PayPal with method : %method', + [ + '%method' => self::PAYPAL_METHOD_PAYPAL + ], + self::DOMAIN_NAME + ), + [ + 'order_id' => $order->getId(), + 'customer_id' => $order->getCustomerId() + ], + Logger::INFO ); } + } else { - $logger->getLogger()->error( + //Classic Payment + $payment = $payPalService->makePayment($order); + $response = new RedirectResponse($payment->getApprovalLink()); + PayPalLoggerService::log( Translator::getInstance()->trans( - "Failed to get a valid Paypal response. Please try again", - [], - self::DOMAIN - ) + 'Order created with success in PayPal with method : %method', + [ + '%method' => self::PAYPAL_METHOD_PAYPAL + ], + self::DOMAIN_NAME + ), + [ + 'order_id' => $order->getId(), + 'customer_id' => $order->getCustomerId() + ], + Logger::INFO ); + + //Future Payment NOT OPERATIONNEL IN PAYPAL API REST YET ! + //$payment = $payPalService->makePayment($order, null, null, true); + //$response = new RedirectResponse($payment->getApprovalLink()); } - } else { - $logger->getLogger()->error( - Translator::getInstance()->trans( - "Failed to get customer delivery address", - [], - self::DOMAIN - ) + + $con->commit(); + + return $response; + } catch (PayPalConnectionException $e) { + $con->rollBack(); + + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::CRITICAL ); + throw $e; + } catch(\Exception $e) { + $con->rollBack(); + + + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::CRITICAL + ); + throw $e; } - - // Failure ! - return new RedirectResponse( - $this->getPaymentFailurePageUrl( - $orderId, - // Pas de point final, sinon 404 ! - Translator::getInstance()->trans( - "Sorry, something did not worked with Paypal. Please try again, or use another payment type", - [], - self::DOMAIN - ) - ) - ); } + /** + * + * This method is call on Payment loop. + * + * If you return true, the payment method will de display + * If you return false, the payment method will not be display + * + * @return boolean + */ public function isValidPayment() { - $valid = false; + $isValid = false; // Check if total order amount is within the module's limits $order_total = $this->getCurrentOrderTotalAmount(); @@ -241,9 +256,9 @@ public function isValidPayment() $cartItemCount = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->countCartItems(); if ($cartItemCount <= Paypal::getConfigValue('cart_item_count', 9)) { - $valid = true; + $isValid = true; - if (Paypal::isSandboxMode()) { + if (PayPalBaseService::isSandboxMode()) { // In sandbox mode, check the current IP $raw_ips = explode("\n", Paypal::getConfigValue('allowed_ip_list', '')); @@ -255,16 +270,33 @@ public function isValidPayment() $client_ip = $this->getRequest()->getClientIp(); - $valid = in_array($client_ip, $allowed_client_ips); + $isValid = in_array($client_ip, $allowed_client_ips); } } } - return $valid; + return $isValid; } + /** + * if you want, you can manage stock in your module instead of order process. + * Return false to decrease the stock when order status switch to pay + * + * @return bool + */ + public function manageStockOnCreation() + { + return false; + } + + /** + * @param \Propel\Runtime\Connection\ConnectionInterface $con + */ public function postActivation(ConnectionInterface $con = null) { + $database = new Database($con); + $database->insertSql(null, array(__DIR__ . "/Config/create.sql")); + // Setup some default values at first install if (null === self::getConfigValue('minimum_amount', null)) { self::setConfigValue('minimum_amount', 0); @@ -289,6 +321,23 @@ public function postActivation(ConnectionInterface $con = null) ; } + if (null === MessageQuery::create()->findOneByName(self::RECURSIVE_MESSAGE_NAME)) { + $message = new Message(); + + $message + ->setName(self::RECURSIVE_MESSAGE_NAME) + ->setHtmlTemplateFileName('paypal-recursive-payment-confirmation.html') + ->setTextTemplateFileName('paypal-recursive-payment-confirmation.txt') + ->setLocale('en_US') + ->setTitle('Paypal payment confirmation') + ->setSubject('Payment of order {$order_ref}') + ->setLocale('fr_FR') + ->setTitle('Confirmation de paiement par Paypal') + ->setSubject('Confirmation du paiement de votre commande {$order_ref}') + ->save() + ; + } + /* Deploy the module's image */ $module = $this->getModuleModel(); @@ -299,55 +348,25 @@ public function postActivation(ConnectionInterface $con = null) public function update($currentVersion, $newVersion, ConnectionInterface $con = null) { - if (null === self::getConfigValue('login', null)) { - $database = new Database($con); - - $statement = $database->execute('select * from paypal_config'); - - while ($statement && $config = $statement->fetchObject()) { - switch($config->name) { - case 'login_sandbox': - Paypal::setConfigValue('sandbox_login', $config->value); - break; - - case 'password_sandbox': - Paypal::setConfigValue('sandbox_password', $config->value); - break; - - case 'signature_sandbox': - Paypal::setConfigValue('sandbox_signature', $config->value); - break; - - default: - Paypal::setConfigValue($config->name, $config->value); - break; - } + $finder = (new Finder()) + ->files() + ->name('#.*?\.sql#') + ->sortByName() + ->in(__DIR__ . DS . 'Config' . DS . 'Update') + ; + + $database = new Database($con); + + /** @var \Symfony\Component\Finder\SplFileInfo $updateSQLFile */ + foreach ($finder as $updateSQLFile) { + if (version_compare($currentVersion, str_replace('.sql', '', $updateSQLFile->getFilename()), '<')) { + $database->insertSql( + null, + [ + $updateSQLFile->getPathname() + ] + ); } } - - parent::update($currentVersion, $newVersion, $con); - } - - public static function isSandboxMode() - { - return 1 == intval(self::getConfigValue('sandbox')); - } - - public function destroy(ConnectionInterface $con = null, $deleteModuleData = false) - { - if ($deleteModuleData) { - MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)->delete(); - } - } - - /** - * if you want, you can manage stock in your module instead of order process. - * Return false to decrease the stock when order status switch to pay - * - * @return bool - */ - public function manageStockOnCreation() - { - return false; } } diff --git a/README.md b/README.md old mode 100755 new mode 100644 index de5541b..a54d4c7 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ### Manually -* Copy the module into ```/local/modules/``` directory and be sure that the name of the module is ```Paypal```. +* Copy the module into ```/local/modules/``` directory and be sure that the name of the module is ```PayPal```. * Activate it in your thelia administration panel ### Composer @@ -16,7 +16,7 @@ Add it in your main thelia composer.json file ``` -composer require thelia/paypal-module:~2.0.0 +composer require thelia/paypal-module:~3.0.0 ``` ## II) How to use @@ -26,7 +26,3 @@ of paypal module. Enter your paypal login informations and save. Don't forget to do some fake orders in sandbox mode ( check "Active sandbox mode" box in tab Configure sandbox in the configuration page, and save ). -## III) Integration - -There is an integration example in the directory /templates/frontOffice/deufault -You must do a page containing a internal error message called gotopaypalfail.html and a order cancel page called ordercanacled.html diff --git a/Service/Base/PayPalBaseService.php b/Service/Base/PayPalBaseService.php new file mode 100644 index 0000000..381a0a3 --- /dev/null +++ b/Service/Base/PayPalBaseService.php @@ -0,0 +1,414 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Service\Base; + +use Monolog\Logger; +use PayPal\Api\Amount; +use PayPal\Api\FuturePayment; +use PayPal\Api\Payer; +use PayPal\Api\PayerInfo; +use PayPal\Api\ShippingAddress; +use PayPal\Api\Transaction; +use PayPal\Auth\OAuthTokenCredential; +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalOrderEvent; +use PayPal\Model\PaypalCart; +use PayPal\Model\PaypalCartQuery; +use PayPal\Model\PaypalOrder; +use PayPal\Model\PaypalPlanifiedPayment; +use PayPal\PayPal; +use PayPal\Rest\ApiContext; +use PayPal\Service\PayPalLoggerService; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Routing\RouterInterface; +use Thelia\Core\Event\Cart\CartRestoreEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\HttpFoundation\Session\Session; +use Thelia\Core\Translation\Translator; +use Thelia\Model\Cart; +use Thelia\Model\Country; +use Thelia\Model\Currency; +use Thelia\Model\Order; +use Thelia\Model\OrderAddressQuery; + +class PayPalBaseService +{ + /** @var EventDispatcherInterface */ + protected $dispatcher; + + /** @var RequestStack */ + protected $requestStack; + + /** @var RouterInterface */ + protected $router; + + /** @var OAuthTokenCredential */ + protected $authTokenCredential; + + /** + * PayPalBaseService constructor. + * @param EventDispatcherInterface $dispatcher + * @param RequestStack $requestStack + * @param RouterInterface $router + */ + public function __construct(EventDispatcherInterface $dispatcher, RequestStack $requestStack, RouterInterface $router) + { + $this->dispatcher = $dispatcher; + $this->requestStack = $requestStack; + $this->router = $router; + + $this->authTokenCredential = new OAuthTokenCredential(self::getLogin(), self::getPassword()); + } + + /** + * @param Order $order + * @param string|null $creditCardId + * @param PaypalPlanifiedPayment $planifiedPayment + * @return PayPalOrderEvent + */ + public function generatePayPalOrder(Order $order, $creditCardId = null, PaypalPlanifiedPayment $planifiedPayment = null) + { + $payPalOrder = new PaypalOrder(); + $payPalOrder + ->setId($order->getId()) + ->setAmount($order->getTotalAmount()) + ; + + if (null !== $creditCardId) { + $payPalOrder->setCreditCardId($creditCardId); + } + + if (null !== $planifiedPayment) { + /** @var \Thelia\Model\Lang $lang */ + $lang = $this->requestStack->getCurrentRequest()->getSession()->get('thelia.current.lang'); + $planifiedPayment->getTranslation($lang->getLocale()); + + $payPalOrder + ->setPlanifiedTitle($planifiedPayment->getTitle()) + ->setPlanifiedDescription($planifiedPayment->getDescription()) + ->setPlanifiedFrequency($planifiedPayment->getFrequency()) + ->setPlanifiedFrequencyInterval($planifiedPayment->getFrequencyInterval()) + ->setPlanifiedCycle($planifiedPayment->getCycle()) + ->setPlanifiedMinAmount($planifiedPayment->getMinAmount()) + ->setPlanifiedMaxAmount($planifiedPayment->getMaxAmount()) + ; + } + + $payPalOrderEvent = new PayPalOrderEvent($payPalOrder); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_ORDER_CREATE, $payPalOrderEvent); + + return $payPalOrderEvent; + } + + /** + * @param PaypalOrder $payPalOrder + * @param $state + * @param string|null $paymentId + * @param string|null $agreementId + * @return PayPalOrderEvent + */ + public function updatePayPalOrder(PaypalOrder $payPalOrder, $state, $paymentId = null, $agreementId = null) + { + $payPalOrder->setState($state); + + if (null !== $paymentId) { + $payPalOrder->setPaymentId($paymentId); + } + + if (null !== $agreementId) { + $payPalOrder->setAgreementId($agreementId); + } + + $payPalOrderEvent = new PayPalOrderEvent($payPalOrder); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_ORDER_UPDATE, $payPalOrderEvent); + + return $payPalOrderEvent; + } + + /** + * @return PaypalCart + */ + public function getCurrentPayPalCart() + { + /** @var Session $session */ + $session = $this->requestStack->getCurrentRequest()->getSession(); + $cart = $session->getSessionCart($this->dispatcher); + + if (null === $cart) { + $cartEvent = new CartRestoreEvent(); + $this->dispatcher->dispatch(TheliaEvents::CART_RESTORE_CURRENT, $cartEvent); + + $cart = $cartEvent->getCart(); + } + + if (null === $payPalCart = PaypalCartQuery::create()->findOneById($cart->getId())) { + $payPalCart = new PaypalCart(); + $payPalCart->setId($cart->getId()); + } + + return $payPalCart; + } + + /** + * @param string $method + * @param array $fundingInstruments + * @param PayerInfo $payerInfo + * @return Payer + */ + public static function generatePayer($method = PayPal::PAYPAL_METHOD_PAYPAL, $fundingInstruments = [], PayerInfo $payerInfo = null) + { + $payer = new Payer(); + $payer->setPaymentMethod($method); + + // Never set empty instruments when communicating with PayPal + if (count($fundingInstruments) > 0) { + $payer->setFundingInstruments($fundingInstruments); + } + + if (null !== $payerInfo) { + $payer->setPayerInfo($payerInfo); + } + + return $payer; + } + + public static function generatePayerInfo($data = []) + { + $payerInfo = new PayerInfo($data); + + return $payerInfo; + } + + public static function generateShippingAddress(Order $order) + { + if (null !== $orderAddress = OrderAddressQuery::create()->findOneById($order->getDeliveryOrderAddressId())) { + $shippingAddress = new ShippingAddress(); + + if (null !== $state = $orderAddress->getState()) { + $payPalState = $state->getIsocode(); + } else { + $payPalState = 'CA'; + } + + $shippingAddress + ->setLine1($orderAddress->getAddress1()) + ->setCity($orderAddress->getCity()) + ->setPostalCode($orderAddress->getZipcode()) + ->setCountryCode($orderAddress->getCountry()->getIsoalpha2()) + ->setState($payPalState) + ; + + if (null !== $orderAddress->getAddress2()) { + + if (null !== $orderAddress->getAddress3()) { + $shippingAddress->setLine2($orderAddress->getAddress2() . ' ' . $orderAddress->getAddress3()); + } else { + $shippingAddress->setLine2($orderAddress->getAddress2()); + } + } elseif (null !== $orderAddress->getAddress3()) { + $shippingAddress->setLine2($orderAddress->getAddress3()); + } + + if (null !== $orderAddress->getStateId()) { + //$shippingAddress->setState($orderAddress->getState()->getIsocode()); + } + + return $shippingAddress; + } else { + $message = Translator::getInstance()->trans( + 'Order address no found to generate PayPal shipping address', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + } + + /** + * @param Order $order + * @param Currency $currency + * @return Amount + */ + public function generateAmount(Order $order, Currency $currency) + { + // Specify the payment amount. + $amount = new Amount(); + $amount->setCurrency($currency->getCode()); + $amount->setTotal($order->getTotalAmount()); + + return $amount; + } + + /** + * @param Cart $cart + * @param Currency $currency + * @return Amount + */ + public function generateAmountFromCart(Cart $cart, Currency $currency) + { + // Specify the payment amount. + $amount = new Amount(); + $amount->setCurrency($currency->getCode()); + $amount->setTotal($cart->getTaxedAmount(Country::getDefaultCountry())); + + return $amount; + } + + /** + * @param Amount $amount + * @param string $description + * @return Transaction + */ + public function generateTransaction(Amount $amount, $description = '') + { + // ###Transaction + // A transaction defines the contract of a + // payment - what is the payment for and who + // is fulfilling it. Transaction is created with + // a `Payee` and `Amount` types + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription($description); + + return $transaction; + } + + public function getAccessToken() + { + $config = self::getApiContext()->getConfig(); + $accessToken = $this->authTokenCredential->getAccessToken($config); + + return $accessToken; + } + + public function getRefreshToken() + { + $refreshToken = FuturePayment::getRefreshToken($this->getAccessToken(), self::getApiContext()); + + return $refreshToken; + } + + /** + * SDK Configuration + * + *@return ApiContext + */ + public static function getApiContext() + { + $apiContext = new ApiContext(); + + // Alternatively pass in the configuration via a hashmap. + // The hashmap can contain any key that is allowed in + // sdk_config.ini + $apiContext->setConfig([ + 'acct1.ClientId' => self::getLogin(), + 'acct1.ClientSecret' => self::getPassword(), + 'http.ConnectionTimeOut' => 30, + 'http.Retry' => 1, + 'mode' => self::getMode(), + 'log.LogEnabled' => true, + 'log.FileName' => '../log/PayPal.log', + 'log.LogLevel' => 'INFO', + 'cache.enabled' => true, + 'cache.FileName' => '../cache/prod/PayPal.cache', + 'http.headers.PayPal-Partner-Attribution-Id' => 'Thelia_Cart', + ]); + + return $apiContext; + } + + /** + * @return string + */ + public static function getLogin() + { + if (PayPal::getConfigValue('sandbox') == 1) { + $login = PayPal::getConfigValue('sandbox_login'); + } else { + $login = PayPal::getConfigValue('login'); + } + + return $login; + } + + /** + * @return string + */ + public static function getPassword() + { + if (PayPal::getConfigValue('sandbox') == 1) { + $password = PayPal::getConfigValue('sandbox_password'); + } else { + $password = PayPal::getConfigValue('password'); + } + + return $password; + } + + /** + * @return string + */ + public static function getMerchantId() + { + if (PayPal::getConfigValue('sandbox') == 1) { + $login = PayPal::getConfigValue('sandbox_merchant_id'); + } else { + $login = PayPal::getConfigValue('merchant_id'); + } + + return $login; + } + + /** + * @return string + */ + public static function getMode() + { + if (PayPal::getConfigValue('sandbox') == 1) { + $mode = 'sandbox'; + } else { + $mode = 'live'; + } + + return $mode; + } + + public static function isSandboxMode() + { + if (self::getMode() === 'live') { + return false; + } else { + return true; + } + } +} diff --git a/Service/PayPalAgreementService.php b/Service/PayPalAgreementService.php new file mode 100644 index 0000000..aae137e --- /dev/null +++ b/Service/PayPalAgreementService.php @@ -0,0 +1,940 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Service; + +use Monolog\Logger; +use PayPal\Api\Agreement; +use PayPal\Api\AgreementStateDescriptor; +use PayPal\Api\ChargeModel; +use PayPal\Api\CreditCard; +use PayPal\Api\CreditCardToken; +use PayPal\Api\Currency; +use PayPal\Api\FundingInstrument; +use PayPal\Api\MerchantPreferences; +use PayPal\Api\Patch; +use PayPal\Api\PatchRequest; +use PayPal\Api\Payer; +use PayPal\Api\PaymentDefinition; +use PayPal\Api\Plan; +use PayPal\Common\PayPalModel; +use PayPal\Event\PayPalEvents; +use PayPal\Event\PayPalOrderEvent; +use PayPal\Event\PayPalPlanEvent; +use PayPal\Exception\PayPalConnectionException; +use PayPal\Model\PaypalOrder; +use PayPal\Model\PaypalOrderQuery; +use PayPal\Model\PaypalPlan; +use PayPal\Model\PaypalPlanifiedPayment; +use PayPal\Model\PaypalPlanQuery; +use PayPal\PayPal; +use PayPal\Service\Base\PayPalBaseService; +use Symfony\Component\Routing\Router; +use Thelia\Core\Translation\Translator; +use Thelia\Model\CurrencyQuery; +use Thelia\Model\Order; +use Thelia\Model\OrderProduct; +use Thelia\Model\OrderProductQuery; +use Thelia\Model\OrderProductTax; +use Thelia\Model\OrderProductTaxQuery; +use Thelia\Tools\URL; + +class PayPalAgreementService extends PayPalBaseService +{ + const PLAN_TYPE_FIXED = 'FIXED'; + const PLAN_TYPE_INFINITE = 'INFINITE'; + + const PAYMENT_TYPE_REGULAR = 'REGULAR'; + const PAYMENT_TYPE_TRIAL = 'TRIAL'; + + const CHARGE_TYPE_SHIPPING = 'SHIPPING'; + const CHARGE_TYPE_TAX = 'TAX'; + + const PAYMENT_FREQUENCY_DAY = 'DAY'; + const PAYMENT_FREQUENCY_WEEK = 'WEEK'; + const PAYMENT_FREQUENCY_MONTH = 'MONTH'; + const PAYMENT_FREQUENCY_YEAR = 'YEAR'; + + const FAIL_AMOUNT_ACTION_CONTINUE = 'CONTINUE'; + const FAIL_AMOUNT_ACTION_CANCEL = 'CANCEL'; + + const MAX_API_LENGHT = 128; + + /** + * @param Order $order + * @param PaypalPlanifiedPayment $planifiedPayment + * @param null $description + * @return Agreement + * @throws PayPalConnectionException + * @throws \Exception + */ + public function makeAgreement(Order $order, PaypalPlanifiedPayment $planifiedPayment, $description = null) + { + //Sadly, this description can NOT be null + if (null === $description) { + $description = 'Thelia order ' . $order->getId(); + } + + $payPalOrderEvent = $this->generatePayPalOrder($order, null, $planifiedPayment); + + $merchantPreferences = $this->createMerchantPreferences($order); + $chargeModel = $this->createChargeModel($order); + + $totalAmount = $order->getTotalAmount(); + $cycleAmount = round($totalAmount / $planifiedPayment->getCycle(), 2); + + $paymentDefinition = $this->createPaymentDefinition( + $order, + 'payment definition for order ' . $order->getId(), + [$chargeModel], + $cycleAmount, + self::PAYMENT_TYPE_REGULAR, + $planifiedPayment->getFrequency(), + $planifiedPayment->getFrequencyInterval(), + $planifiedPayment->getCycle() + ); + + $plan = $this->generateBillingPlan($order, 'plan for order ' . $order->getId(), $merchantPreferences, [$paymentDefinition]); + $plan = $this->createBillingPlan($order, $plan); + $plan = $this->activateBillingPlan($order, $plan); + + $newPlan = new Plan(); + $newPlan->setId($plan->getId()); + + // There is no Billing agreement possible with credit card + $agreement = $this->createBillingAgreementWithPayPal($order, $newPlan, 'agreement ' . $order->getId(), $description); + + //We must update concerned order_product price... order discount... order postage... PayPal will create one invoice each cycle + $this->updateTheliaOrderForCycle($order, $planifiedPayment->getCycle(), $cycleAmount); + + $this->updatePayPalOrder($payPalOrderEvent->getPayPalOrder(), $agreement->getState(), null, $agreement->getId()); + + return $agreement; + } + + public function updateTheliaOrderForCycle(Order $order, $cycle, $cycleAmount) + { + //Be sure that there is no rounding price lost with this method + $moneyLeft = $cycleAmount; + + $newPostage = round($order->getPostage() / $cycle, 2); + $newPostageTax = round($order->getPostageTax() / $cycle, 2); + $newDiscount = round($order->getDiscount() / $cycle, 2); + + $moneyLeft -= ($newPostage + $newPostageTax + $newDiscount); + $orderProducts = OrderProductQuery::create()->filterByOrderId($order->getId())->find(); + + /** @var \Thelia\Model\OrderProduct $orderProduct */ + foreach ($orderProducts as $orderProduct) { + $newPrice = round($orderProduct->getPrice() / $cycle, 2); + $newPromoPrice = round($orderProduct->getPrice() / $cycle, 2); + + if ($orderProduct->getWasInPromo()) { + $moneyLeft -= $newPromoPrice; + } else { + $moneyLeft -= $newPrice; + } + + $orderProduct + ->setPrice($newPrice) + ->setPromoPrice($newPromoPrice) + ->save() + ; + $taxes = OrderProductTaxQuery::create()->filterByOrderProductId($orderProduct->getId())->find(); + + /** @var \Thelia\Model\OrderProductTax $tax */ + foreach ($taxes as $tax) { + $newAmount = round($tax->getAmount() / $cycle, 2); + $newPromoAmount = round($tax->getPromoAmount() / $cycle, 2); + + if ($orderProduct->getWasInPromo()) { + $moneyLeft -= $newPromoAmount; + } else { + $moneyLeft -= $newAmount; + } + + $tax + ->setAmount($newAmount) + ->setPromoAmount($newPromoAmount) + ->save() + ; + } + } + + //Normally, $moneyLeft == 0 here. But in case of rouding price, adjust the rounding in the postage column + $newPostage += $moneyLeft; + + $order + ->setPostage($newPostage) + ->setPostageTax($newPostageTax) + ->setDiscount($newDiscount) + ->save() + ; + + return $order; + } + + /** + * @param $billingPlanId + * @return Plan + */ + public function getBillingPlan($billingPlanId) + { + $plan = Plan::get($billingPlanId, self::getApiContext()); + + return $plan; + } + + /** + * @param Order $order + * @param Plan $plan + * @return Plan + */ + public function activateBillingPlan(Order $order, Plan $plan) + { + $patch = new Patch(); + + $value = new PayPalModel('{ + "state":"ACTIVE" + }'); + + $patch + ->setOp('replace') + ->setPath('/') + ->setValue($value) + ; + + $patchRequest = new PatchRequest(); + $patchRequest->addPatch($patch); + + $plan->update($patchRequest, self::getApiContext()); + $plan = $this->getBillingPlan($plan->getId()); + + if (null === $payPalPlan = PaypalPlanQuery::create() + ->filterByPaypalOrderId($order->getId()) + ->filterByPlanId($plan->getId()) + ->findOne()) { + $payPalPlan = new PaypalPlan(); + $payPalPlan + ->setPaypalOrderId($order->getId()) + ->setPlanId($plan->getId()) + ; + } + + $payPalPlan->setState($plan->getState()); + $payPalPlanEvent = new PayPalPlanEvent($payPalPlan); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_PLAN_UPDATE, $payPalPlanEvent); + + return $plan; + } + + /** + * @param $token + * @param null $orderId + * @return Agreement + * @throws PayPalConnectionException + * @throws \Exception + */ + public function activateBillingAgreementByToken($token, $orderId = null) + { + $agreement = new Agreement(); + + try { + $agreement->execute($token, self::getApiContext()); + + return $this->getBillingAgreement($agreement->getId()); + } catch (PayPalConnectionException $e) { + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $orderId + ], + Logger::CRITICAL + ); + throw $e; + } catch (\Exception $e) { + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $orderId + ], + Logger::CRITICAL + ); + throw $e; + } + } + + /** + * @param Order $order + * @param $name + * @param $merchantPreferences + * @param array $paymentDefinitions + * @param string $description + * @param string $type + * @return Plan + * @throws \Exception + */ + public function generateBillingPlan(Order $order, $name, $merchantPreferences, $paymentDefinitions = [], $description = '', $type = self::PLAN_TYPE_FIXED) + { + if (!in_array($type, self::getAllowedPlanType())) { + $message = Translator::getInstance()->trans( + 'Invalid type send to generate billing plan', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + if (!is_array($paymentDefinitions) || count($paymentDefinitions) <= 0) { + $message = Translator::getInstance()->trans( + 'Invalid number of payment definition send to generate billing plan', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + $plan = new Plan(); + $plan + ->setName(substr($name, 0, self::MAX_API_LENGHT)) + ->setDescription(substr($description, 0, self::MAX_API_LENGHT)) + ->setType($type) + ->setPaymentDefinitions($paymentDefinitions) + ->setMerchantPreferences($merchantPreferences) + ; + + return $plan; + } + + /** + * @param Plan $plan + * @return bool + */ + public function deleteBillingPlan(Plan $plan) + { + $isDeleted = $plan->delete(self::getApiContext()); + + return $isDeleted; + } + + /** + * @param int $pageSize + * @return \PayPal\Api\PlanList + */ + public function listBillingPlans($pageSize = 2) + { + $planList = Plan::all(['page_size' => $pageSize], self::getApiContext()); + + return $planList; + } + + /** + * @param Order $order + * @param Plan $plan + * @return Plan + * @throws PayPalConnectionException + * @throws \Exception + */ + public function createBillingPlan(Order $order, Plan $plan) + { + try { + $plan = $plan->create(self::getApiContext()); + + if (null === $payPalPlan = PaypalPlanQuery::create() + ->filterByPaypalOrderId($order->getId()) + ->filterByPlanId($plan->getId()) + ->findOne()) { + $payPalPlan = new PaypalPlan(); + $payPalPlan + ->setPaypalOrderId($order->getId()) + ->setPlanId($plan->getId()) + ; + } + + $payPalPlan->setState($plan->getState()); + $payPalPlanEvent = new PayPalPlanEvent($payPalPlan); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_PLAN_CREATE, $payPalPlanEvent); + + return $plan; + } catch (PayPalConnectionException $e) { + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::CRITICAL + ); + throw $e; + } catch (\Exception $e) { + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::CRITICAL + ); + throw $e; + } + } + + /** + * @param Order $order + * @param Plan $plan + * @param $creditCardId + * @param $name + * @param $description + * @return Agreement + */ + public function createBillingAgreementWithCreditCard(Order $order, Plan $plan, $creditCardId, $name, $description) + { + $creditCardToken = new CreditCardToken(); + $creditCardToken->setCreditCardId($creditCardId); + + $fundingInstrument = new FundingInstrument(); + //$fundingInstrument->setCreditCardToken($creditCardToken); + + $card = new CreditCard(); + $card + ->setType('visa') + ->setNumber('4491759698858890') + ->setExpireMonth('12') + ->setExpireYear('2017') + ->setCvv2('128') + ; + $fundingInstrument->setCreditCard($card); + + $payer = self::generatePayer( + PayPal::PAYPAL_METHOD_CREDIT_CARD, + [$fundingInstrument], + self::generatePayerInfo(['email' => $order->getCustomer()->getEmail()]) + ); + + $agreement = $this->generateAgreement($order, $plan, $payer, $name, $description); + + $agreement = $agreement->create(self::getApiContext()); + + return $agreement; + } + + /** + * @param Order $order + * @param Plan $plan + * @param $name + * @param $description + * @return Agreement + */ + public function createBillingAgreementWithPayPal(Order $order, Plan $plan, $name, $description) + { + $payer = self::generatePayer(PayPal::PAYPAL_METHOD_PAYPAL); + + $agreement = $this->generateAgreement($order, $plan, $payer, $name, $description); + + $agreement = $agreement->create(self::getApiContext()); + + return $agreement; + } + + /** + * @param $agreementId + * @return Agreement + */ + public function getBillingAgreement($agreementId) + { + $agreement = Agreement::get($agreementId, self::getApiContext()); + + return $agreement; + } + + /** + * @param $agreementId + * @param array $params + * @return \PayPal\Api\AgreementTransactions + */ + public function getBillingAgreementTransactions($agreementId, $params = []) + { + if (is_array($params) || count($params) == 0) { + $params = [ + 'start_date' => date('Y-m-d', strtotime('-15 years')), + 'end_date' => date('Y-m-d', strtotime('+5 days')) + ]; + } + + $agreementTransactions = Agreement::searchTransactions($agreementId, $params, self::getApiContext()); + + return $agreementTransactions; + } + + /** + * @param Agreement $agreement + * @param string $note + * @return Agreement + */ + public function suspendBillingAgreement(Agreement $agreement, $note = 'Suspending the agreement') + { + //Create an Agreement State Descriptor, explaining the reason to suspend. + $agreementStateDescriptor = new AgreementStateDescriptor(); + $agreementStateDescriptor->setNote($note); + + $agreement->suspend($agreementStateDescriptor, self::getApiContext()); + + $agreement = $this->getBillingAgreement($agreement->getId()); + + return $agreement; + } + + /** + * @param Agreement $agreement + * @param string $note + * @return Agreement + */ + public function reActivateBillingAgreement(Agreement $agreement, $note = 'Reactivating the agreement') + { + //Create an Agreement State Descriptor, explaining the reason to re activate. + $agreementStateDescriptor = new AgreementStateDescriptor(); + $agreementStateDescriptor->setNote($note); + + $agreement->reActivate($agreementStateDescriptor, self::getApiContext()); + + $agreement = $this->getBillingAgreement($agreement->getId()); + + return $agreement; + } + + /** + * @param Order $order + * @param $name + * @param array $chargeModels + * @param null $cycleAmount + * @param string $type + * @param string $frequency + * @param int $frequencyInterval + * @param int $cycles + * @return PaymentDefinition + * @throws \Exception + */ + public function createPaymentDefinition(Order $order, $name, $chargeModels = [], $cycleAmount = null, $type = self::PAYMENT_TYPE_REGULAR, $frequency = self::PAYMENT_FREQUENCY_DAY, $frequencyInterval = 1, $cycles = 1) + { + if (!in_array($type, self::getAllowedPaymentType())) { + $message = Translator::getInstance()->trans( + 'Invalid payment type send to create payment definition', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + if (!in_array($frequency, self::getAllowedPaymentFrequency())) { + $message = Translator::getInstance()->trans( + 'Invalid payment frequency send to create payment definition', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + if (!is_array($chargeModels) || count($chargeModels) <= 0) { + $message = Translator::getInstance()->trans( + 'Invalid number of charge models send to create payment definition', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + $paymentDefinition = new PaymentDefinition(); + + if (null === $cycleAmount) { + $totalAmount = $order->getTotalAmount(); + $cycleAmount = round($totalAmount / $cycles, 2); + } + + $paymentDefinition + ->setName(substr($name, 0, self::MAX_API_LENGHT)) + ->setType($type) + ->setFrequency($frequency) + ->setFrequencyInterval($frequencyInterval) + ->setCycles($cycles) + ->setAmount(new Currency(['value' => $cycleAmount, 'currency' => self::getOrderCurrencyCode($order)])) + ->setChargeModels($chargeModels) + ; + + return $paymentDefinition; + } + + /** + * @param Order $order + * @param int $chargeAmount + * @param string $type + * @return ChargeModel + * @throws \Exception + */ + public function createChargeModel(Order $order, $chargeAmount = 0, $type = self::CHARGE_TYPE_SHIPPING) + { + if (!in_array($type, self::getAllowedChargeType())) { + $message = Translator::getInstance()->trans( + 'Invalid charge type send to create charge model', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + $chargeModel = new ChargeModel(); + $chargeModel + ->setType($type) + ->setAmount(new Currency(['value' => $chargeAmount, 'currency' => self::getOrderCurrencyCode($order)])) + ; + + return $chargeModel; + } + + /** + * @param Order $order + * @param bool $autoBillAmount + * @param string $failAction + * @param int $maxFailAttempts + * @param int $feeAmount + * @return MerchantPreferences + * @throws \Exception + */ + public function createMerchantPreferences(Order $order, $autoBillAmount = false, $failAction = self::FAIL_AMOUNT_ACTION_CONTINUE, $maxFailAttempts = 0, $feeAmount = 0) + { + if (!in_array($failAction, self::getAllowedFailedAction())) { + $message = Translator::getInstance()->trans( + 'Invalid fail action send to create merchant preference', + [], + PayPal::DOMAIN_NAME + ); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::ERROR + ); + throw new \Exception($message); + } + + $merchantPreferences = new MerchantPreferences(); + + $urlOk = URL::getInstance()->absoluteUrl( + $this->router->generate( + "paypal.agreement.ok", + [ + 'orderId' => $order->getId() + ], + Router::ABSOLUTE_URL + ) + ); + $urlKo = URL::getInstance()->absoluteUrl( + $this->router->generate( + "paypal.agreement.ko", + [ + 'orderId' => $order->getId() + ], + Router::ABSOLUTE_URL + ) + ); + + if ($autoBillAmount) { + $autoBillAmountStr = 'YES'; + } else { + $autoBillAmountStr = 'NO'; + } + + $merchantPreferences + ->setReturnUrl($urlOk) + ->setCancelUrl($urlKo) + ->setAutoBillAmount($autoBillAmountStr) + ->setInitialFailAmountAction($failAction) + ->setMaxFailAttempts($maxFailAttempts) + ->setSetupFee(new Currency(['value' => $feeAmount, 'currency' => self::getOrderCurrencyCode($order)])) + ; + + return $merchantPreferences; + } + + /** + * @param Order $order + * @return Order + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function duplicateOrder(Order $order) + { + $today = new \Datetime; + $newOrder = new Order(); + $newOrder + ->setCustomerId($order->getCustomerId()) + ->setInvoiceOrderAddressId($order->getInvoiceOrderAddressId()) + ->setDeliveryOrderAddressId($order->getDeliveryOrderAddressId()) + ->setInvoiceDate($today->format('Y-m-d H:i:s')) + ->setCurrencyId($order->getCurrencyId()) + ->setCurrencyRate($order->getCurrencyRate()) + ->setDeliveryRef($order->getDeliveryRef()) + ->setInvoiceRef($order->getInvoiceRef()) + ->setDiscount($order->getDiscount()) + ->setPostage($order->getPostage()) + ->setPostageTax($order->getPostageTax()) + ->setPostageTaxRuleTitle($order->getPostageTaxRuleTitle()) + ->setPaymentModuleId($order->getPaymentModuleId()) + ->setDeliveryModuleId($order->getDeliveryModuleId()) + ->setStatusId($order->getStatusId()) + ->setLangId($order->getLangId()) + ->setCartId($order->getCartId()) + ->save() + ; + + $orderProducts = OrderProductQuery::create()->filterByOrderId($order->getId())->find(); + + /** @var \Thelia\Model\OrderProduct $orderProduct */ + foreach ($orderProducts as $orderProduct) { + $newOrderProduct = new OrderProduct(); + $newOrderProduct + ->setOrderId($newOrder->getId()) + ->setProductRef($orderProduct->getProductRef()) + ->setProductSaleElementsRef($orderProduct->getProductSaleElementsRef()) + ->setProductSaleElementsId($orderProduct->getProductSaleElementsId()) + ->setTitle($orderProduct->getTitle()) + ->setChapo($orderProduct->getChapo()) + ->setDescription($orderProduct->getDescription()) + ->setPostscriptum($orderProduct->getPostscriptum()) + ->setQuantity($orderProduct->getQuantity()) + ->setPrice($orderProduct->getPrice()) + ->setPromoPrice($orderProduct->getPromoPrice()) + ->setWasNew($orderProduct->getWasNew()) + ->setWasInPromo($orderProduct->getWasInPromo()) + ->setWeight($orderProduct->getWeight()) + ->setEanCode($orderProduct->getEanCode()) + ->setTaxRuleTitle($orderProduct->getTaxRuleTitle()) + ->setTaxRuleDescription($orderProduct->getTaxRuleDescription()) + ->setParent($orderProduct->getParent()) + ->setVirtual($orderProduct->getVirtual()) + ->setVirtualDocument($orderProduct->getVirtualDocument()) + ->save() + ; + + $orderProductTaxes = OrderProductTaxQuery::create()->filterByOrderProductId($orderProduct->getId())->find(); + + /** @var \Thelia\Model\OrderProductTax $orderProductTax */ + foreach ($orderProductTaxes as $orderProductTax) { + + $newOrderProductTax = new OrderProductTax(); + $newOrderProductTax + ->setOrderProductId($newOrderProduct->getId()) + ->setTitle($orderProductTax->getTitle()) + ->setDescription($orderProductTax->getDescription()) + ->setAmount($orderProductTax->getAmount()) + ->setPromoAmount($orderProductTax->getPromoAmount()) + ->save() + ; + } + } + + if (null !== $payPalOrder = PaypalOrderQuery::create()->findOneById($order->getId())) { + $newPayPalOrder = new PaypalOrder(); + $newPayPalOrder + ->setId($newOrder->getId()) + ->setPaymentId($payPalOrder->getPaymentId()) + ->setAgreementId($payPalOrder->getAgreementId()) + ->setCreditCardId($payPalOrder->getCreditCardId()) + ->setState($payPalOrder->getState()) + ->setAmount($payPalOrder->getAmount()) + ->setDescription($payPalOrder->getDescription()) + ->setPayerId($payPalOrder->getPayerId()) + ->setToken($payPalOrder->getToken()) + ; + $newPayPalOrderEvent = new PayPalOrderEvent($newPayPalOrder); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_ORDER_CREATE, $newPayPalOrderEvent); + + $payPalPlans = PaypalPlanQuery::create()->filterByPaypalOrderId($payPalOrder->getId()); + + /** @var \PayPal\Model\PaypalPlan $payPalPlan */ + foreach ($payPalPlans as $payPalPlan) { + + $newPayPalPlan = new PaypalPlan(); + $newPayPalPlan + ->setPaypalOrderId($newPayPalOrderEvent->getPayPalOrder()->getId()) + ->setPlanId($payPalPlan->getPlanId()) + ->setState($payPalPlan->getState()) + ; + + $newPayPalPlanEvent = new PayPalPlanEvent($newPayPalPlan); + $this->dispatcher->dispatch(PayPalEvents::PAYPAL_PLAN_CREATE, $newPayPalPlanEvent); + } + } + + return $newOrder; + } + + /** + * @param Order $order + * @param Plan $plan + * @param Payer $payer + * @param $name + * @param string $description + * @return Agreement + * @throws \Exception + */ + public function generateAgreement(Order $order, Plan $plan, Payer $payer, $name, $description = '') + { + $agreement = new Agreement(); + $agreement + ->setName($name) + ->setDescription($description) + ->setStartDate((new \Datetime)->format('Y-m-d\TG:i:s\Z')) + ->setPlan($plan) + ; + + //Add Payer to Agreement + $agreement + ->setPayer($payer) + ->setShippingAddress(self::generateShippingAddress($order)) + ; + + return $agreement; + } + + /** + * @param Order $order + * @return string + */ + public static function getOrderCurrencyCode(Order $order) + { + if (null === $currency = CurrencyQuery::create()->findOneById($order->getCurrencyId())) { + $currency = \Thelia\Model\Currency::getDefaultCurrency(); + } + + return $currency->getCode(); + } + + /** + * @return array + */ + public static function getAllowedPlanType() + { + return [ + self::PLAN_TYPE_FIXED, + self::PLAN_TYPE_INFINITE + ]; + } + + /** + * @return array + */ + public static function getAllowedPaymentType() + { + return [ + self::PAYMENT_TYPE_REGULAR, + self::PAYMENT_TYPE_TRIAL + ]; + } + + /** + * @return array + */ + public static function getAllowedChargeType() + { + return [ + self::CHARGE_TYPE_SHIPPING, + self::CHARGE_TYPE_TAX + ]; + } + + /** + * @return array + */ + public static function getAllowedPaymentFrequency() + { + return [ + self::PAYMENT_FREQUENCY_DAY => self::PAYMENT_FREQUENCY_DAY, + self::PAYMENT_FREQUENCY_WEEK => self::PAYMENT_FREQUENCY_WEEK, + self::PAYMENT_FREQUENCY_MONTH => self::PAYMENT_FREQUENCY_MONTH, + self::PAYMENT_FREQUENCY_YEAR => self::PAYMENT_FREQUENCY_YEAR + ]; + } + + /** + * @return array + */ + public static function getAllowedFailedAction() + { + return [ + self::FAIL_AMOUNT_ACTION_CANCEL, + self::FAIL_AMOUNT_ACTION_CONTINUE + ]; + } +} diff --git a/Service/PayPalCustomerService.php b/Service/PayPalCustomerService.php new file mode 100644 index 0000000..d3707b4 --- /dev/null +++ b/Service/PayPalCustomerService.php @@ -0,0 +1,164 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Service; + +use Monolog\Logger; +use PayPal\Api\OpenIdSession; +use PayPal\Api\OpenIdTokeninfo; +use PayPal\Api\OpenIdUserinfo; +use PayPal\Model\PaypalCustomer; +use PayPal\Model\PaypalCustomerQuery; +use PayPal\Service\Base\PayPalBaseService; +use Thelia\Core\Security\SecurityContext; + +/** + * Class PayPalCustomerService + * @package PayPal\Service + */ +class PayPalCustomerService +{ + /** @var SecurityContext */ + protected $securityContext; + + /** + * PayPalService constructor. + * @param SecurityContext $securityContext + */ + public function __construct(SecurityContext $securityContext) + { + $this->securityContext = $securityContext; + } + + /** + * @param $authorizationCode + * @return OpenIdUserinfo + * @throws \Exception + */ + public function getUserInfoWithAuthorizationCode($authorizationCode) + { + try { + $accessToken = OpenIdTokeninfo::createFromAuthorizationCode( + ['code' => $authorizationCode], + null, + null, + PayPalBaseService::getApiContext() + ); + + return $this->getUserInfo($accessToken->getAccessToken()); + } catch (\Exception $ex) { + PayPalLoggerService::log($ex->getMessage(), [], Logger::ERROR); + throw $ex; + } + } + + /** + * @param $accessToken + * @return OpenIdUserinfo + */ + public function getUserInfo($accessToken) + { + $params = array('access_token' => $accessToken); + $userInfo = OpenIdUserinfo::getUserinfo($params, PayPalBaseService::getApiContext()); + + return $userInfo; + } + + /** + * @return PaypalCustomer + */ + public function getCurrentPayPalCustomer() + { + $payPalCustomer = new PaypalCustomer(); + + if (null !== $customer = $this->securityContext->getCustomerUser()) { + + $payPalCustomer = PaypalCustomerQuery::create()->findOneById($customer->getId()); + + } + + return $payPalCustomer; + } + + /** + * @param $refreshToken + * @return OpenIdTokeninfo + * @throws \Exception + */ + public function generateAccessTokenFromRefreshToken($refreshToken) + { + try { + $tokenInfo = new OpenIdTokeninfo(); + $tokenInfo = $tokenInfo->createFromRefreshToken(['refresh_token' => $refreshToken], PayPalBaseService::getApiContext()); + + return $tokenInfo; + } catch (\Exception $ex) { + PayPalLoggerService::log($ex->getMessage(), [], Logger::ERROR); + throw $ex; + } + } + + /** + * @param $refreshToken + * @return OpenIdUserinfo + * @throws \Exception + */ + public function getUserInfoWithRefreshToken($refreshToken) + { + try { + $tokenInfo = $this->generateAccessTokenFromRefreshToken($refreshToken); + + return $this->getUserInfo($tokenInfo->getAccessToken()); + } catch (\Exception $ex) { + PayPalLoggerService::log($ex->getMessage(), [], Logger::ERROR); + throw $ex; + } + } + + /** + * @return string + */ + public function getUrlToRefreshToken() + { + //Get Authorization URL returns the redirect URL that could be used to get user's consent + $redirectUrl = OpenIdSession::getAuthorizationUrl( + 'http://25b3ee89.ngrok.io/', + [ + 'openid', + 'profile', + 'address', + 'email', + 'phone', + 'https://uri.paypal.com/services/paypalattributes', + 'https://uri.paypal.com/services/expresscheckout', + 'https://uri.paypal.com/services/invoicing' + ], + null, + null, + null, + PayPalBaseService::getApiContext() + ); + + return $redirectUrl; + } +} diff --git a/Service/PayPalLoggerService.php b/Service/PayPalLoggerService.php new file mode 100644 index 0000000..5af391d --- /dev/null +++ b/Service/PayPalLoggerService.php @@ -0,0 +1,133 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Service; + +use Monolog\Logger; +use MySQLHandler\MySQLHandler; +use PayPal\Model\Map\PaypalLogTableMap; +use PayPal\Model\PaypalLogQuery; +use PayPal\PayPal; +use Propel\Runtime\Propel; +use Thelia\Install\Database; + +/** + * Class PayPalLoggerService + * @package PayPal\Service + */ +class PayPalLoggerService +{ + /** + * @param $message + * @param array $params + * @param int $level + */ + public static function log($message, $params = [], $level = Logger::DEBUG) + { + $staticParams = self::getStaticParams(); + + $logger = new Logger(PayPal::getModuleCode()); + + //Create MysqlHandler + $database = new Database(Propel::getConnection()); + $mySQLHandler = new MySQLHandler( + $database->getConnection(), + PaypalLogTableMap::TABLE_NAME, + array_keys($staticParams), + $level + ); + + $logger->pushHandler($mySQLHandler); + + //Now you can use the logger, and further attach additional information + switch ($level) { + case Logger::DEBUG: + $logger->addDebug($message, array_merge($staticParams, $params)); + break; + + case Logger::INFO: + $logger->addInfo($message, array_merge($staticParams, $params)); + break; + + case Logger::NOTICE: + $logger->addNotice($message, array_merge($staticParams, $params)); + break; + + case Logger::WARNING: + $logger->addWarning($message, array_merge($staticParams, $params)); + break; + + case Logger::ERROR: + $logger->addError($message, array_merge($staticParams, $params)); + break; + + case Logger::CRITICAL: + $logger->addCritical($message, array_merge($staticParams, $params)); + break; + + case Logger::ALERT: + $logger->addAlert($message, array_merge($staticParams, $params)); + break; + + case Logger::EMERGENCY: + $logger->addEmergency($message, array_merge($staticParams, $params)); + break; + + default: + $logger->addDebug($message, array_merge($staticParams, $params)); + break; + } + + } + + /** + * @return array + * @throws \Propel\Runtime\Exception\PropelException + */ + public static function getStaticParams() + { + $psr3Fields = ['channel', 'level', 'message', 'time']; + $payPalLogFields = PaypalLogTableMap::getFieldNames(PaypalLogTableMap::TYPE_FIELDNAME); + $readableDate = new \Datetime(); + + $staticParams = []; + foreach ($payPalLogFields as $fieldName) { + + // Do not interpret psr3 fields + if (in_array($fieldName, $psr3Fields)) { + continue; + } + + if (in_array($fieldName, ['created_at', 'updated_at'])) { + $staticParams[$fieldName] = $readableDate->format('Y-m-d H:i:s'); + } elseif (in_array($fieldName, ['id'])) { + $lastId = PaypalLogQuery::create()->count(); + $staticParams[$fieldName] = $lastId + 1; + } else { + $staticParams[$fieldName] = null; + } + } + + return $staticParams; + } +} diff --git a/Service/PayPalPaymentService.php b/Service/PayPalPaymentService.php new file mode 100644 index 0000000..9826ade --- /dev/null +++ b/Service/PayPalPaymentService.php @@ -0,0 +1,411 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace PayPal\Service; + +use Monolog\Logger; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\CreditCardToken; +use PayPal\Api\Details; +use PayPal\Api\FundingInstrument; +use PayPal\Api\FuturePayment; +use PayPal\Api\OpenIdTokeninfo; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\PaymentExecution; +use PayPal\Api\RedirectUrls; +use PayPal\Api\Transaction; +use PayPal\Exception\PayPalConnectionException; +use PayPal\PayPal; +use PayPal\Service\Base\PayPalBaseService; +use Thelia\Core\Translation\Translator; +use Thelia\Model\Cart; +use Thelia\Model\Currency; +use Thelia\Model\CurrencyQuery; +use Thelia\Model\Order; +use Thelia\Tools\URL; + + +/** + * Class PayPalPaymentService + * @package PayPal\Service + */ +class PayPalPaymentService extends PayPalBaseService +{ + /** + * Create a payment using a previously obtained + * credit card id. The corresponding credit + * card is used as the funding instrument. + * + * @param Order $order + * @param bool $future + * @param string|null $creditCardId + * @param string|null $description + * @return Payment + */ + public function makePayment(Order $order, $creditCardId = null, $description = null, $future = false) + { + $payPalOrderEvent = $this->generatePayPalOrder($order); + + if (null !== $creditCardId) { + $creditCardToken = new CreditCardToken(); + $creditCardToken->setCreditCardId($creditCardId); + + $fundingInstrument = new FundingInstrument(); + $fundingInstrument->setCreditCardToken($creditCardToken); + + $payer = self::generatePayer(PayPal::PAYPAL_METHOD_CREDIT_CARD, [$fundingInstrument]); + } else { + $payer = self::generatePayer(); + } + + // Specify the payment amount. + if (null === $currency = CurrencyQuery::create()->findOneById($order->getCurrencyId())) { + $currency = Currency::getDefaultCurrency(); + } + + $amount = $this->generateAmount($order, $currency); + + $transaction = $this->generateTransaction($amount, $description); + + $payment = $this->generatePayment($order, $payer, $transaction, $future); + + $this->updatePayPalOrder($payPalOrderEvent->getPayPalOrder(), $payment->getState(), $payment->getId()); + + return $payment; + } + + public function makePaymentFromCart(Cart $cart, $description = null, $future = false, $fromCartView = true) + { + $payer = self::generatePayer(); + + // Specify the payment amount. + if (null === $currency = CurrencyQuery::create()->findOneById($cart->getCurrencyId())) { + $currency = Currency::getDefaultCurrency(); + } + + $amount = $this->generateAmountFromCart($cart, $currency); + + $transaction = $this->generateTransaction($amount, $description); + + $payment = $this->generatePaymentFromCart($cart, $payer, $transaction, $future, $fromCartView); + + //$this->updatePayPalOrder($payPalOrderEvent->getPayPalOrder(), $payment->getState(), $payment->getId()); + + return $payment; + } + + /** + * Completes the payment once buyer approval has been + * obtained. Used only when the payment method is 'paypal' + * + * @param string $paymentId id of a previously created + * payment that has its payment method set to 'paypal' + * and has been approved by the buyer. + * + * @param string $payerId PayerId as returned by PayPal post + * buyer approval. + * + * @return Payment + */ + public function executePayment($paymentId, $payerId, Details $details = null) + { + $payment = $this->getPaymentDetails($paymentId); + $paymentExecution = new PaymentExecution(); + $paymentExecution->setPayerId($payerId); + + if (null !== $details) { + $amount = new Amount(); + $totalDetails = (float)$details->getShipping() + (float)$details->getTax() + (float)$details->getSubtotal(); + $amount + ->setCurrency('EUR') + ->setTotal($totalDetails) + ->setDetails($details) + ; + + $transaction = new Transaction(); + $transaction->setAmount($amount); + + $paymentExecution->addTransaction($transaction); + } + + $payment = $payment->execute($paymentExecution, self::getApiContext()); + + return $payment; + } + + public function createDetails($shipping = 0, $shippingTax = 0, $subTotal = 0) + { + $details = new Details(); + $details + ->setShipping($shipping) + ->setTax($shippingTax) + ->setSubtotal($subTotal) + ; + + return $details; + } + + /** + * Retrieves the payment information based on PaymentID from Paypal APIs + * + * @param $paymentId + * + * @return Payment + */ + public function getPaymentDetails($paymentId) + { + $payment = Payment::get($paymentId, self::getApiContext()); + + return $payment; + } + + /** + * @param $authorizationCode + * @return OpenIdTokeninfo + * @throws PayPalConnectionException + */ + public function generateAccessToken($authorizationCode) + { + try { + // Obtain Authorization Code from Code, Client ID and Client Secret + $accessToken = OpenIdTokeninfo::createFromAuthorizationCode( + ['code' => $authorizationCode], + null, + null, + self::getApiContext() + ); + + return $accessToken; + } catch (PayPalConnectionException $ex) { + PayPalLoggerService::log($ex->getMessage(), [], Logger::ERROR); + throw $ex; + } + } + + /** + * @param $type + * @param $number + * @param $expireMonth + * @param $expireYear + * @param $cvv2 + * @return string + * @throws \Exception + */ + public function getPayPalCreditCardId($type, $number, $expireMonth, $expireYear, $cvv2) + { + try { + $card = new CreditCard(); + $card->setType($type); + $card->setNumber((int)$number); + $card->setExpireMonth((int)$expireMonth); + $card->setExpireYear((int)$expireYear); + $card->setCvv2($cvv2); + + $card->create(self::getApiContext()); + + return $card->getId(); + } catch (\Exception $e) { + PayPalLoggerService::log($e->getMessage(), [], Logger::ERROR); + throw new \Exception(Translator::getInstance()->trans('Credit card is invalid', [], PayPal::DOMAIN_NAME)); + } + } + + /** + * @param Order $order + * @param Payer $payer + * @param Transaction $transaction + * @param bool $future + * @return FuturePayment|Payment + * @throws PayPalConnectionException + * @throws \Exception + */ + public function generatePayment(Order $order, Payer $payer, Transaction $transaction, $future = false) + { + if ($future) { + $payment = new FuturePayment(); + $payment->setIntent('authorize'); + } else { + $payment = new Payment(); + $payment->setIntent('sale'); + } + + $payment + ->setRedirectUrls($this->getRedirectUrls($order)) + ->setPayer($payer) + ->setTransactions([$transaction]) + ; + + $clientMetadataId = '123123456'; + + try { + + if ($future) { + + //$authorizationCode = self::getAuthorizationCode(); + $refreshToken = $this->getRefreshToken(); + //$refreshToken = FuturePayment::getRefreshToken($this->getAuthorizationCode(), self::getApiContext()); + $payment->updateAccessToken($refreshToken, self::getApiContext()); + $payment->create(self::getApiContext(), $clientMetadataId); + + } else { + $payment->create(self::getApiContext()); + } + + return $payment; + + } catch (PayPalConnectionException $e) { + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::CRITICAL + ); + throw $e; + } catch (\Exception $e) { + PayPalLoggerService::log( + $e->getMessage(), + [ + 'customer_id' => $order->getCustomerId(), + 'order_id' => $order->getId() + ], + Logger::CRITICAL + ); + throw $e; + } + } + + /** + * @param Cart $cart + * @param Payer $payer + * @param Transaction $transaction + * @param bool $future + * @return FuturePayment|Payment + * @throws PayPalConnectionException + * @throws \Exception + */ + public function generatePaymentFromCart(Cart $cart, Payer $payer, Transaction $transaction, $future = false, $fromCartView = true) + { + if ($future) { + $payment = new FuturePayment(); + $payment->setIntent('authorize'); + } else { + $payment = new Payment(); + $payment->setIntent('sale'); + } + + if ($fromCartView) { + $payment->setRedirectUrls($this->getRedirectCartUrls($cart)); + } else { + $payment->setRedirectUrls($this->getRedirectInvoiceUrls($cart)); + } + $payment + ->setPayer($payer) + ->setTransactions([$transaction]) + ; + + $clientMetadataId = '123123456'; + + try { + + if ($future) { + + //$authorizationCode = self::getAuthorizationCode(); + $refreshToken = $this->getRefreshToken(); + //$refreshToken = FuturePayment::getRefreshToken($this->getAuthorizationCode(), self::getApiContext()); + $payment->updateAccessToken($refreshToken, self::getApiContext()); + $payment->create(self::getApiContext(), $clientMetadataId); + + } else { + $payment->create(self::getApiContext()); + } + + return $payment; + + } catch (PayPalConnectionException $e) { + $message = sprintf('url : %s. data : %s. message : %s', $e->getUrl(), $e->getData(), $e->getMessage()); + PayPalLoggerService::log( + $message, + [], + Logger::CRITICAL + ); + throw $e; + } catch (\Exception $e) { + PayPalLoggerService::log( + $e->getMessage(), + [], + Logger::CRITICAL + ); + throw $e; + } + } + + /** + * @param Order $order + * @return RedirectUrls + */ + public function getRedirectUrls(Order $order) + { + $redirectUrls = new RedirectUrls(); + $urlOk = URL::getInstance()->absoluteUrl('/module/paypal/ok/' . $order->getId()); + $urlCancel = URL::getInstance()->absoluteUrl('/module/paypal/cancel/' . $order->getId()); + $redirectUrls->setReturnUrl($urlOk); + $redirectUrls->setCancelUrl($urlCancel); + + return $redirectUrls; + } + + /** + * @param Cart $cart + * @return RedirectUrls + */ + public function getRedirectCartUrls(Cart $cart) + { + $redirectUrls = new RedirectUrls(); + $urlOk = URL::getInstance()->absoluteUrl('/module/paypal/express/checkout/ok/' . $cart->getId()); + $urlCancel = URL::getInstance()->absoluteUrl('/module/paypal/express/checkout/ko/' . $cart->getId()); + $redirectUrls->setReturnUrl($urlOk); + $redirectUrls->setCancelUrl($urlCancel); + + return $redirectUrls; + } + + /** + * @param Cart $cart + * @return RedirectUrls + */ + public function getRedirectInvoiceUrls(Cart $cart) + { + $redirectUrls = new RedirectUrls(); + $urlOk = URL::getInstance()->absoluteUrl('/module/paypal/invoice/express/checkout/ok/' . $cart->getId()); + $urlCancel = URL::getInstance()->absoluteUrl('/module/paypal/invoice/express/checkout/ko/' . $cart->getId()); + $redirectUrls->setReturnUrl($urlOk); + $redirectUrls->setCancelUrl($urlCancel); + + return $redirectUrls; + } +} diff --git a/composer.json b/composer.json index b4276bd..065dd7f 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,13 @@ { - "name": "thelia/paypal-module", - "type": "thelia-module", - "license": "LGPL V3", - "description": "Paypal module for Thelia ecommerce solution", - "authors": [ - { - "name": "Thelia", - "email": "info@thelia.net", - "homepage": "https://github.com/thelia-modules" - } - ], - "require": { - "thelia/installer": "~1.0" - }, - "extra": { - "installer-name": "Paypal" - } -} + "name": "your-vendor/pay-pal-module", + "license": "LGPL-3.0+", + "type": "thelia-module", + "require": { + "thelia/installer": "~1.1", + "paypal/rest-api-sdk-php": "~1.7.0", + "wazaari/monolog-mysql": "^1.0" + }, + "extra": { + "installer-name": "PayPal" + } +} \ No newline at end of file diff --git a/templates/backOffice/default/assets/paypal_agreement.jpeg b/templates/backOffice/default/assets/paypal_agreement.jpeg new file mode 100644 index 0000000..eaa3af2 Binary files /dev/null and b/templates/backOffice/default/assets/paypal_agreement.jpeg differ diff --git a/templates/backOffice/default/assets/paypal_conf1.png b/templates/backOffice/default/assets/paypal_conf1.png new file mode 100644 index 0000000..7904991 Binary files /dev/null and b/templates/backOffice/default/assets/paypal_conf1.png differ diff --git a/templates/backOffice/default/assets/paypal_conf2.png b/templates/backOffice/default/assets/paypal_conf2.png new file mode 100644 index 0000000..47dad7a Binary files /dev/null and b/templates/backOffice/default/assets/paypal_conf2.png differ diff --git a/templates/backOffice/default/assets/paypal_conf3.png b/templates/backOffice/default/assets/paypal_conf3.png new file mode 100644 index 0000000..e7546de Binary files /dev/null and b/templates/backOffice/default/assets/paypal_conf3.png differ diff --git a/templates/backOffice/default/assets/paypal_webhook.png b/templates/backOffice/default/assets/paypal_webhook.png new file mode 100644 index 0000000..419d33c Binary files /dev/null and b/templates/backOffice/default/assets/paypal_webhook.png differ diff --git a/templates/backOffice/default/paypal/form/create-or-update-planified-payment-form.html b/templates/backOffice/default/paypal/form/create-or-update-planified-payment-form.html new file mode 100644 index 0000000..454fa4f --- /dev/null +++ b/templates/backOffice/default/paypal/form/create-or-update-planified-payment-form.html @@ -0,0 +1,38 @@ +{render_form_field field="locale"} +
+
+ {intl l="Global informations of this planified payment" d="paypal.bo.default"} +
+
+
+
+ {render_form_field field="title"} +
+
+
+
+ {render_form_field field="description"} +
+
+
+
+ {render_form_field field="frequency_interval"} +
+
+ {render_form_field field="frequency"} +
+
+ {render_form_field field="cycle"} +
+
+ +
+
+ {render_form_field field="min_amount"} +
+
+ {render_form_field field="max_amount"} +
+
+
+
\ No newline at end of file diff --git a/templates/backOffice/default/paypal/includes/paypal-log-row-js.html b/templates/backOffice/default/paypal/includes/paypal-log-row-js.html new file mode 100644 index 0000000..c4fef9f --- /dev/null +++ b/templates/backOffice/default/paypal/includes/paypal-log-row-js.html @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/templates/backOffice/default/paypal/includes/paypal-log-row.html b/templates/backOffice/default/paypal/includes/paypal-log-row.html new file mode 100644 index 0000000..7d7acd7 --- /dev/null +++ b/templates/backOffice/default/paypal/includes/paypal-log-row.html @@ -0,0 +1,20 @@ +getHook()} style="cursor: pointer;"{/if}> + + {format_date date=$CREATE_DATE} + + {if $log->getHook()} + {$log->getHook()} ({intl l="See webhook details" d="paypal.bo.default"}) + + {else} + {$log->getMessage() nofilter} + {/if} + + {$log->getCustomerId()} + getOrderId()}">{$log->getOrderId()} + + {$log->getHook()} + + {intl l="critical_{$log->getLevel()}" d="paypal.bo.default"} + \ No newline at end of file diff --git a/templates/backOffice/default/paypal/menu/menu.html b/templates/backOffice/default/paypal/menu/menu.html new file mode 100644 index 0000000..213691f --- /dev/null +++ b/templates/backOffice/default/paypal/menu/menu.html @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/templates/backOffice/default/paypal/module-configuration.html b/templates/backOffice/default/paypal/module-configuration.html index a6811b1..0010438 100644 --- a/templates/backOffice/default/paypal/module-configuration.html +++ b/templates/backOffice/default/paypal/module-configuration.html @@ -1,120 +1,215 @@
-
-
-
- {intl d='paypal.bo.default' l="Paypal Configuration"} -
-
+
+
-
-
-
- {form name="paypal.form.configure"} - - {form_hidden_fields form=$form} + {include file="paypal/menu/menu.html" selectedMenu="general"} - {include file = "includes/inner-form-toolbar.html" - hide_flags = true - page_url = "{url path='/admin/module/Paypal'}" - close_url = "{url path='/admin/modules'}" - } +
+ +
- {if $form_error} -
-
-
{$form_error_message}
-
+ {form name="paypal_form_configure"} + + {form_hidden_fields form=$form} +
+
+ {include file = "includes/inner-form-toolbar.html" + hide_flags = true + page_url = "{url path='/admin/module/Paypal'}" + close_url = "{url path='/admin/modules'}" + }
- {/if} - +
-

{intl d='paypal.bo.default' l="Paypal Production parameters"}

+
+

+ 1 + {intl l="SandBox configuration" d="paypal.bo.default"} + +

+
+
+
+ Payment configuration +
+
+
+
+ + {custom_render_form_field form=$form field="sandbox"} + + {$label} + {/custom_render_form_field} + + {render_form_field form=$form field="sandbox_login" value=$sandbox_login} + {render_form_field form=$form field="sandbox_password" value=$sandbox_password} + {render_form_field form=$form field="sandbox_merchant_id" value=$sandbox_merchant_id} - {render_form_field form=$form field="login" value=$login} - {render_form_field form=$form field="password" value=$password} - {render_form_field form=$form field="signature" value=$signature} + {render_form_field form=$form field="allowed_ip_list" value=$allowed_ip_list} +
+
+
+
+

+  {intl l="Help" d="paypal.bo.default"} : {intl l="Configuration" d="paypal.bo.default"} +

+ - {intl l="Log In on developer.paypal.com" d="paypal.bo.default"}
+ - {intl l="Create REST API apps here" d="paypal.bo.default"}
+ - {intl l="Click on Create App" d="paypal.bo.default"}
+ - {intl l="Fill the fields : App Name & Sandbox developer account" d="paypal.bo.default"}
+ - {intl l="Click on Create App" d="paypal.bo.default"}
+ - {intl l="Copy & Paste the Client ID in the form below" d="paypal.bo.default"}
+ - {intl l="Copy & Paste the Client SECRET in the form below" d="paypal.bo.default"}
+ - {intl l="In SANDBOX WEBHOOKS" d="paypal.bo.default"} :
+ -     {intl l="Add Webhook" d="paypal.bo.default"}
+ -         {url path="/module/paypal/webhook/all/events"}
+ - {intl l="In SANDBOX APP SETTINGS" d="paypal.bo.default"} :
+ -     {intl l="Return URL" d="paypal.bo.default"}
+ -         {navigate to="index"}
+ -         {url path="/module/paypal/login/ok"}
+ -         {url path="/module/paypal/agreement/ok"}
+ -         {url path="/module/paypal/agreement/ko"}
+ -
+ - {intl l="Check" d="paypal.bo.default"} {intl l="Accept payments" d="paypal.bo.default"} 
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Future Payments" d="paypal.bo.default"}
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Billing agreements" d="paypal.bo.default"}
+ - {intl l="Check" d="paypal.bo.default"} {intl l="Invoicing" d="paypal.bo.default"} 
+ - {intl l="Check" d="paypal.bo.default"} {intl l="Payouts" d="paypal.bo.default"} 
+ - {intl l="Check" d="paypal.bo.default"} {intl l="PayPal Here" d="paypal.bo.default"} 
+ - {intl l="Check" d="paypal.bo.default"} {intl l="Log In with PayPal" d="paypal.bo.default"} 
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Personal Information" d="paypal.bo.default"}
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Address Information" d="paypal.bo.default"}
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Account Information" d="paypal.bo.default"}
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Use Seamless Checkout" d="paypal.bo.default"}
+ -     {intl l="Check" d="paypal.bo.default"} {intl l="Allow the customers who haven't yet confirmed their email address with PayPal, to log in to your app" d="paypal.bo.default"}
+ - {intl l="That's it !" d="paypal.bo.default"}
+
+
-
-

{intl d='paypal.bo.default' l="Paypal Sandbox parameters"}

- - {custom_render_form_field form=$form field="sandbox"} - - {$label} - {/custom_render_form_field} - - {render_form_field form=$form field="sandbox_login" value=$sandbox_login} - {render_form_field form=$form field="sandbox_password" value=$sandbox_password} - {render_form_field form=$form field="sandbox_signature" value=$sandbox_signature} - - {render_form_field form=$form field="allowed_ip_list" value=$allowed_ip_list} +
+

+ 2 + {intl l="Production configuration" d="paypal.bo.default"} +

+
+
+
+ Payment configuration +
+
+
+
+ {render_form_field form=$form field="login" value=$login} + {render_form_field form=$form field="password" value=$password} + {render_form_field form=$form field="merchant_id" value=$merchant_id} +
+
-
-

{intl d='paypal.bo.default' l="Payment configuration"}

+

+ 3 + {intl l="Payment configuration" d="paypal.bo.default"} +

- {custom_render_form_field form=$form field="send_confirmation_message_only_if_paid"} - - {$label} - {/custom_render_form_field} +
+
+ Payment configuration +
+
+ {custom_render_form_field form=$form field="method_paypal"} + + {$label} + {/custom_render_form_field} - {custom_render_form_field form=$form field="send_payment_confirmation_message"} - - {$label} - {/custom_render_form_field} + {custom_render_form_field form=$form field="method_paypal_with_in_context"} + + {$label} + {/custom_render_form_field} -
- - {intl d='paypal.bo.default' l='You can edit the payment confirmation email sent to the customer after a successful payment.' url={url path="/admin/configuration/messages"}} -
+ {custom_render_form_field form=$form field="method_express_checkout"} + + {$label} + {/custom_render_form_field} - {custom_render_form_field form=$form field="minimum_amount"} -
- - {currency attr='symbol'} -
- {/custom_render_form_field} + {custom_render_form_field form=$form field="method_credit_card"} + + {$label} + {/custom_render_form_field} - {custom_render_form_field form=$form field="maximum_amount"} -
- - {currency attr='symbol'} -
- {/custom_render_form_field} +
+ + {intl d='paypal.bo.default' l='This method works only with PayPal PRO UK account. Please contact PayPal to upgrade your account if you need this service. For more informations, go here'} +
+ + {custom_render_form_field form=$form field="method_planified_payment"} + + {$label} + {/custom_render_form_field} + +
+ + {intl d='paypal.bo.default' l='This method use PayPal webhooks and works only in HTTPS !'} +
+ +
+ + {intl d='paypal.bo.default' l='You can add some planified payment here.' url={url path="/admin/module/paypal/configure/planified"}} +
+ + {custom_render_form_field form=$form field="send_confirmation_message_only_if_paid"} + + {$label} + {/custom_render_form_field} + + {custom_render_form_field form=$form field="send_payment_confirmation_message"} + + {$label} + {/custom_render_form_field} + + {custom_render_form_field form=$form field="send_recursive_message"} + + {$label} + {/custom_render_form_field} + +
+ + {intl d='paypal.bo.default' l='You can edit the payment confirmation email sent to the customer after a successful payment.' url={url path="/admin/configuration/messages"}} +
- {render_form_field form=$form field="cart_item_count" value=$cart_item_count} + {custom_render_form_field form=$form field="minimum_amount"} +
+ + {currency attr='symbol'} +
+ {/custom_render_form_field} - {custom_render_form_field form=$form field="send_cart_detail"} - - {$label} - {/custom_render_form_field} + {custom_render_form_field form=$form field="maximum_amount"} +
+ + {currency attr='symbol'} +
+ {/custom_render_form_field} + + {render_form_field form=$form field="cart_item_count" value=$cart_item_count} +
+
+
+
+
+
+ {include file = "includes/inner-form-toolbar.html" + hide_flags = true + page_url = "{url path='/admin/module/Paypal'}" + close_url = "{url path='/admin/modules'}" + }
{/form}
- -
-
-

- - {intl d='paypal.bo.default' l="Paypal responses history"} -

-
-
-
- {$trace_content nofilter} -
-
- -
\ No newline at end of file diff --git a/templates/backOffice/default/paypal/order-edit-js.html b/templates/backOffice/default/paypal/order-edit-js.html new file mode 100644 index 0000000..3a1e2f3 --- /dev/null +++ b/templates/backOffice/default/paypal/order-edit-js.html @@ -0,0 +1 @@ +{include file = "paypal/includes/paypal-log-row-js.html"} \ No newline at end of file diff --git a/templates/backOffice/default/paypal/payment-information.html b/templates/backOffice/default/paypal/payment-information.html new file mode 100644 index 0000000..52fda46 --- /dev/null +++ b/templates/backOffice/default/paypal/payment-information.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + {loop name="paypal_log" type="paypal_log" backend_context=true order_id=$order_id order="date-reverse"} + {include file = "paypal/includes/paypal-log-row.html"} + {/loop} + +
{intl l='Date' d="paypal.bo.default"}{intl l='Details' d="paypal.bo.default"}{intl l="Customer ID" d="paypal.bo.default"}{intl l="Order ID" d="paypal.bo.default"}{intl l="Webhook" d="paypal.bo.default"}{intl l="Level" d="paypal.bo.default"}
\ No newline at end of file diff --git a/templates/backOffice/default/paypal/paypal-log.html b/templates/backOffice/default/paypal/paypal-log.html new file mode 100644 index 0000000..3285c43 --- /dev/null +++ b/templates/backOffice/default/paypal/paypal-log.html @@ -0,0 +1,105 @@ +{extends file="admin-layout.tpl"} + +{block name="main-content"} + +
+
+
+ + {include file="paypal/menu/menu.html" selectedMenu="log"} + +
+ +
+
+
+ +

+ 1 + {intl l="Automatic PayPal logs" d="paypal.bo.default"} +

+ +
+
+

+  {intl l="Help" d="paypal.bo.default"} : +

+
+ {intl l="This is where we log all the transactions made with PayPal. PayPal webhooks also automatically feed these logs." d="paypal.bo.default"} +
{intl l="This informations can be found directly in concerned order details." d="paypal.bo.default"} +
+
+
+
+ Payment configuration +
+
+
+ + + {$page = $smarty.get.page|default:1} + {$limit = $smarty.get.limit|default:100} + +
+
+
+ + + + + + + + + + + + + + {loop name="paypal_log" type="paypal_log" backend_context=true order="date-reverse" page=$page limit=$limit} + {include file = "paypal/includes/paypal-log-row.html"} + {/loop} + + + + + + +
{intl l='Date' d="paypal.bo.default"}{intl l='Details' d="paypal.bo.default"}{intl l="Customer ID" d="paypal.bo.default"}{intl l="Order ID" d="paypal.bo.default"}{intl l="Webhook" d="paypal.bo.default"}{intl l="Level" d="paypal.bo.default"}
+ {include + file = "includes/pagination.html" + loop_ref = "paypal_log" + max_page_count = $limit + page_url = {url path="/admin/module/paypal/configure/log"} + } +
+
+
+
+
+
+
+
+
+
+
+{/block} + +{block name="javascript-initialization"} + {include file = "paypal/includes/paypal-log-row-js.html"} +{/block} \ No newline at end of file diff --git a/templates/backOffice/default/paypal/planified-payment-edit.html b/templates/backOffice/default/paypal/planified-payment-edit.html new file mode 100644 index 0000000..9ecd9fa --- /dev/null +++ b/templates/backOffice/default/paypal/planified-payment-edit.html @@ -0,0 +1,86 @@ +{extends file="admin-layout.tpl"} + +{block name="no-return-functions"} +{$admin_current_location = 'module'} +{/block} + +{block name="page-title"}{intl l='Edit planified payment' d="paypal.bo.default"}{/block} + +{block name="main-content"} +
+
+ {loop name="paypal_planified_payment" type="paypal_planified_payment" id=$planifiedPaymentId backend_context=true} + + + +
+
+ +
+
+ {intl l='Edit planified payment %title' d="paypal.bo.default" title=$planifiedPayment->getTitle()} +
+
+ + + +
+ +
+ +
+ + {form name="paypal_planified_payment_update_form"} +
getId()}" {form_enctype} class="clearfix"> + + {include file="includes/inner-form-toolbar.html" hide_flags=true close_url={url path="/admin/module/paypal/configure/planified"}} + + + + {* Be sure to get the planified payment ID, even if the form could not be validated *} + + + {form_hidden_fields} + + {render_form_field field="id"} + + {render_form_field field="success_url" value={url path="/admin/module/paypal/configure/planified"}} + + {if $form_error} +
{$form_error_message}
+ {/if} + +
+ {include file = "paypal/form/create-or-update-planified-payment-form.html"} +
+ + {include + file="includes/inner-form-toolbar.html" + hide_submit_buttons = false + hide_flags = true + + close_url={url path="/admin/module/paypal/configure/planified"} + } + + {intl l='Planified payment created on %date_create. Last modification: %date_change' d="paypal.bo.default" date_create={format_date date=$CREATE_DATE} date_change={format_date date=$UPDATE_DATE} } +
+ {/form} +
+
+
+
+
+ {/loop} +
+
+{/block} \ No newline at end of file diff --git a/templates/backOffice/default/paypal/planified-payment.html b/templates/backOffice/default/paypal/planified-payment.html new file mode 100644 index 0000000..2bf98c4 --- /dev/null +++ b/templates/backOffice/default/paypal/planified-payment.html @@ -0,0 +1,185 @@ +{extends file="admin-layout.tpl"} + +{block name="main-content"} + +
+
+
+ + {include file="paypal/menu/menu.html" selectedMenu="planifiedPayment"} + +
+ +
+
+
+

+ 1 + {intl l="Planified payment configuration" d="paypal.bo.default"} +

+ +
+
+

+  {intl l="Help" d="paypal.bo.default"} : +

+
+ {intl l="This feature uses PayPal's Billing Plan and Agreement. It allows debiting a client recursively directly from PayPal." d="paypal.bo.default"} +
{intl l="These planned payments will appear in step 4 of the purchase tunnel when selecting the payment method." d="paypal.bo.default"} +
+
+
+
+ Payment configuration +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + {loop name="paypal_planified_payment" type="paypal_planified_payment" backend_context=true order=$order} + + + + + + + + {/loop} + {elseloop rel="paypal_planified_payment"} + + + + {/elseloop} + +
+ {intl l="List of planified payments" d="paypal.bo.default"} + + + +
+ {intl l='Title' d="paypal.bo.default"} + + {intl l='Details' d="paypal.bo.default"} +
+ {$planifiedPayment->getTitle()} ;
+ {$planifiedPayment->getDescription()} +
+ {intl l='Frequency interval' d="paypal.bo.default"} : {$planifiedPayment->getFrequencyInterval()}
+ {intl l='Frequency' d="paypal.bo.default"} : {$planifiedPayment->getFrequency()}
+ {intl l='Cycle' d="paypal.bo.default"} : {$planifiedPayment->getCycle()}
+ {intl l='Min amount' d="paypal.bo.default"} : {if $planifiedPayment->getMinAmount() > 0}{format_money number=$planifiedPayment->getMinAmount()}{else}{intl l='None' d="paypal.bo.default"}{/if}
+ {intl l='Max amount' d="paypal.bo.default"} : {if $planifiedPayment->getMaxAmount() > 0}{format_money number=$planifiedPayment->getMaxAmount()}{else}{intl l='None' d="paypal.bo.default"}{/if}
+
+ +
+
+ {intl l="No planified payment has been created yet. Click the + button to create one." d="paypal.bo.default"} +
+
+
+
+
+
+
+
+
+
+
+
+ + {* Adding a new planified payment *} + {form name="paypal_planified_payment_create_form"} + + {* Capture the dialog body, to pass it to the generic dialog *} + {capture "creation_dialog"} + {form_hidden_fields} + + {include file = "paypal/form/create-or-update-planified-payment-form.html"} + + {render_form_field field="success_url" value={url path='/admin/module/paypal/configure/planified'}} + {/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "creation_dialog" + dialog_title = {intl l="Create a new planified payment" d="paypal.bo.default"} + dialog_body = {$smarty.capture.creation_dialog nofilter} + + dialog_ok_label = {intl l="Create this planified payment" d="paypal.bo.default"} + + form_action = {url path='/admin/module/paypal/configure/planified/create'} + form_enctype = {form_enctype} + form_error_message = $form_error_message + } + {/form} + + {* Delete confirmation dialog *} + {capture "delete_dialog"} + + {/capture} + + {include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "delete_dialog" + dialog_title = {intl l="Delete planified payment" d="paypal.bo.default"} + dialog_message = {intl l="Do you really want to delete this planified payment ?" d="paypal.bo.default"} + + form_action = {token_url path='/admin/module/paypal/configure/planified/create/delete'} + form_content = {$smarty.capture.delete_dialog nofilter} + } +{/block} + +{block name="javascript-initialization"} + +{/block} \ No newline at end of file diff --git a/templates/email/default/paypal-payment-confirmation.html b/templates/email/default/paypal-payment-confirmation.html old mode 100644 new mode 100755 index 06b34ea..43c199b --- a/templates/email/default/paypal-payment-confirmation.html +++ b/templates/email/default/paypal-payment-confirmation.html @@ -6,10 +6,10 @@ {block name="pre-header"}{/block} {* Subject *} -{block name="email-subject"}{intl d='paypal.email.default' l="Payment of your order %ref" ref={$order_ref}}{/block} +{block name="email-subject"}{intl d='paypal.mail.default' l="Payment of your order %ref" ref={$order_ref}}{/block} {* Title *} -{block name="email-title"}{intl d='paypal.email.default' l="The payment of your order %ref is confirmed" ref={$order_ref}}{/block} +{block name="email-title"}{intl d='paypal.mail.default' l="The payment of your order %ref is confirmed" ref={$order_ref}}{/block} {* Content *} {block name="email-content"} diff --git a/templates/email/default/paypal-payment-confirmation.txt b/templates/email/default/paypal-payment-confirmation.txt old mode 100644 new mode 100755 diff --git a/templates/email/default/paypal-recursive-payment-confirmation.html b/templates/email/default/paypal-recursive-payment-confirmation.html new file mode 100755 index 0000000..43c199b --- /dev/null +++ b/templates/email/default/paypal-recursive-payment-confirmation.html @@ -0,0 +1,23 @@ +{extends file="email-layout.tpl"} + +{* Do not provide a "Open in browser" link *} +{block name="browser"}{/block} +{* No pre-header *} +{block name="pre-header"}{/block} + +{* Subject *} +{block name="email-subject"}{intl d='paypal.mail.default' l="Payment of your order %ref" ref={$order_ref}}{/block} + +{* Title *} +{block name="email-title"}{intl d='paypal.mail.default' l="The payment of your order %ref is confirmed" ref={$order_ref}}{/block} + +{* Content *} +{block name="email-content"} +

+ + {intl l="View this order in your account at %shop_name" shop_name={config key="store_name"}} + +

+

{intl d='paypal.email.default' l='Thank you again for your purchase.'}

+

{intl d='paypal.email.default' l='The %store_name team.' store_name={config key="store_name"}}

+{/block} diff --git a/templates/email/default/paypal-recursive-payment-confirmation.txt b/templates/email/default/paypal-recursive-payment-confirmation.txt new file mode 100755 index 0000000..491fe8b --- /dev/null +++ b/templates/email/default/paypal-recursive-payment-confirmation.txt @@ -0,0 +1,9 @@ +{intl d='paypal.email.default' l='Dear customer'}, + +{intl d='paypal.email.default' l='This is a confirmation of the payment of your order %ref via Paypal on our shop.' ref=$order_ref} + +{intl d='paypal.email.default' l='Your invoice is now available in your customer account at %url.'} url={config key="url_site"}} + +{intl d='paypal.email.default' l='Thank you again for your purchase.'} + +{intl d='paypal.email.default' l='The %store_name team.' store_name={config key="store_name"}} \ No newline at end of file diff --git a/templates/frontOffice/default/assets/cards-logo.jpg b/templates/frontOffice/default/assets/cards-logo.jpg new file mode 100644 index 0000000..962e7d3 Binary files /dev/null and b/templates/frontOffice/default/assets/cards-logo.jpg differ diff --git a/templates/frontOffice/default/assets/ntimes-cards-logo.png b/templates/frontOffice/default/assets/ntimes-cards-logo.png new file mode 100644 index 0000000..efef888 Binary files /dev/null and b/templates/frontOffice/default/assets/ntimes-cards-logo.png differ diff --git a/templates/frontOffice/default/assets/paypal-logo.png b/templates/frontOffice/default/assets/paypal-logo.png new file mode 100644 index 0000000..aab877a Binary files /dev/null and b/templates/frontOffice/default/assets/paypal-logo.png differ diff --git a/templates/frontOffice/default/paypal/cart-bottom.html b/templates/frontOffice/default/paypal/cart-bottom.html new file mode 100644 index 0000000..7c8ef99 --- /dev/null +++ b/templates/frontOffice/default/paypal/cart-bottom.html @@ -0,0 +1,11 @@ +
+ + diff --git a/templates/frontOffice/default/paypal/form/extra-credit-card.html b/templates/frontOffice/default/paypal/form/extra-credit-card.html new file mode 100644 index 0000000..edfd5bb --- /dev/null +++ b/templates/frontOffice/default/paypal/form/extra-credit-card.html @@ -0,0 +1,85 @@ +
+ label}checked{/if}/> + + CB / VISA / Mastercard + + +
\ No newline at end of file diff --git a/templates/frontOffice/default/paypal/form/extra-paypal.html b/templates/frontOffice/default/paypal/form/extra-paypal.html new file mode 100644 index 0000000..9ef809a --- /dev/null +++ b/templates/frontOffice/default/paypal/form/extra-paypal.html @@ -0,0 +1,17 @@ +
+ {if $method_paypal_with_in_context} + label}checked{/if}/> + + {else} + label}checked{/if}/> + + {/if} + + +
\ No newline at end of file diff --git a/templates/frontOffice/default/paypal/form/extra-planified-payment.html b/templates/frontOffice/default/paypal/form/extra-planified-payment.html new file mode 100644 index 0000000..dccbed5 --- /dev/null +++ b/templates/frontOffice/default/paypal/form/extra-planified-payment.html @@ -0,0 +1,26 @@ +{assign var="methodName" value=$name} +{form_field field='paypal_planified_payment'} + {if count($choices) > 0} +
+ label}checked{/if}/> + + +
+ {/if} +{/form_field} + diff --git a/templates/frontOffice/default/paypal/login-bottom.html b/templates/frontOffice/default/paypal/login-bottom.html new file mode 100644 index 0000000..5710a61 --- /dev/null +++ b/templates/frontOffice/default/paypal/login-bottom.html @@ -0,0 +1,16 @@ +
+ + + +
\ No newline at end of file diff --git a/templates/frontOffice/default/paypal/order-delivery-bottom-js.html b/templates/frontOffice/default/paypal/order-delivery-bottom-js.html new file mode 100644 index 0000000..cc14715 --- /dev/null +++ b/templates/frontOffice/default/paypal/order-delivery-bottom-js.html @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/templates/frontOffice/default/paypal/order-delivery-bottom.html b/templates/frontOffice/default/paypal/order-delivery-bottom.html new file mode 100644 index 0000000..00d5b4c --- /dev/null +++ b/templates/frontOffice/default/paypal/order-delivery-bottom.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/templates/frontOffice/default/paypal/order-invoice-bottom.html b/templates/frontOffice/default/paypal/order-invoice-bottom.html new file mode 100644 index 0000000..e6b444a --- /dev/null +++ b/templates/frontOffice/default/paypal/order-invoice-bottom.html @@ -0,0 +1,11 @@ + + + diff --git a/templates/frontOffice/default/paypal/order-invoice-js.html b/templates/frontOffice/default/paypal/order-invoice-js.html new file mode 100644 index 0000000..98a4a49 --- /dev/null +++ b/templates/frontOffice/default/paypal/order-invoice-js.html @@ -0,0 +1,58 @@ + \ No newline at end of file diff --git a/templates/frontOffice/default/paypal/order-invoice-payment-extra.html b/templates/frontOffice/default/paypal/order-invoice-payment-extra.html new file mode 100644 index 0000000..3e394be --- /dev/null +++ b/templates/frontOffice/default/paypal/order-invoice-payment-extra.html @@ -0,0 +1,21 @@ +{form name="thelia.order.payment"} + +{/form} \ No newline at end of file diff --git a/templates/frontOffice/default/paypal/order-placed-additional-payment-info.html b/templates/frontOffice/default/paypal/order-placed-additional-payment-info.html new file mode 100644 index 0000000..9ce0fb2 --- /dev/null +++ b/templates/frontOffice/default/paypal/order-placed-additional-payment-info.html @@ -0,0 +1,6 @@ +{loop type="paypal_order" name="paypal_order" id=$placed_order_id limit=1} + {if $paypal_order->getPlanifiedCycle() > 0} + {intl l="Planified payment" d="paypal.fo.default"} :  + {intl l="Payment in %x times every %frequency_interval %frequency" x=$paypal_order->getPlanifiedCycle() frequency_interval=$paypal_order->getPlanifiedFrequencyInterval() frequency="{intl l=$paypal_order->getPlanifiedFrequency() d="paypal.fo.default"}" d="paypal.fo.default"} + {/if} +{/loop} \ No newline at end of file diff --git a/templates/pdf/default/paypal/after-payment-module.html b/templates/pdf/default/paypal/after-payment-module.html new file mode 100644 index 0000000..d08b5e8 --- /dev/null +++ b/templates/pdf/default/paypal/after-payment-module.html @@ -0,0 +1,6 @@ +{loop type="paypal_order" name="paypal_order" id=$order limit=1} + {if $paypal_order->getPlanifiedCycle() > 0} + {intl l="Planified payment" d="paypal.pdf.default"} :  + {intl l="Payment in %x times every %frequency_interval %frequency" x=$paypal_order->getPlanifiedCycle() frequency_interval=$paypal_order->getPlanifiedFrequencyInterval() frequency="{intl l=$paypal_order->getPlanifiedFrequency() d="paypal.pdf.default"}" d="paypal.pdf.default"} + {/if} +{/loop} \ No newline at end of file