| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright  Copyright (c) Flipbox Digital Limited | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license    https://flipboxfactory.com/software/hubspot/license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @link       https://www.flipboxfactory.com/software/hubspot/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace flipbox\craft\hubspot\cp\controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Craft; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use craft\helpers\ArrayHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use flipbox\craft\hubspot\actions\visitors\Delete; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use flipbox\craft\hubspot\actions\visitors\Update; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use flipbox\craft\hubspot\HubSpot; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author Flipbox Factory <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @since 1.1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class VisitorsController extends AbstractController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function behaviors() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         return ArrayHelper::merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             parent::behaviors(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 'error' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                     'default' => 'visitor' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 'redirect' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                     'only' => ['update', 'delete'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                     'actions' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                         'update' => [200], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                         'delete' => [204] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'flash' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                     'actions' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                         'update' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                             200 => HubSpot::t("HubSpot Visitor updated successfully"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                             400 => HubSpot::t("Failed to updated HubSpot Visitor") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                         'delete' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                             204 => HubSpot::t("HubSpot Visitor deleted successfully"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                             400 => HubSpot::t("Failed to delete HubSpot Visitor") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                         ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param string|null $identifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @throws \yii\base\InvalidConfigException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     public function actionUpdate( | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         string $identifier = null | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         if ($identifier === null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             $identifier = Craft::$app->getRequest()->getParam( | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |                 'identifier', | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 Craft::$app->getRequest()->getParam('id') | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         /** @var Update $action */ | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         return (Craft::createObject([ | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             'class' => Update::class | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         ], [ | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             'update', | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |             $this | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         ]))->runWithParams([ | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |             'identifier' => $identifier | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @param string|null $identifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @throws \yii\base\InvalidConfigException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function actionDelete( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         string $identifier = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         if ($identifier === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             $identifier = Craft::$app->getRequest()->getParam( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 'identifier', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 Craft::$app->getRequest()->getParam('id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         /** @var Delete $action */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return (Craft::createObject([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             'class' => Delete::class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         ], [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             'delete', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ]))->runWithParams([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             'identifier' => $identifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 108 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  |