@@ -28,7 +28,7 @@ public function indexAction()
28
28
}
29
29
30
30
$ connection = Mage::helper ('zendesk ' )->getConnectionStatus ();
31
-
31
+
32
32
if (!$ connection ['success ' ]) {
33
33
$ this ->setFlag ('' , 'no-dispatch ' , true );
34
34
Mage::getSingleton ('adminhtml/session ' )->addError ( $ connection ['msg ' ] );
@@ -37,7 +37,7 @@ public function indexAction()
37
37
}
38
38
39
39
Mage::helper ('zendesk ' )->storeDependenciesInCachedRegistry ();
40
-
40
+
41
41
$ this ->_title ($ this ->__ ('Zendesk Dashboard ' ));
42
42
$ this ->loadLayout ();
43
43
$ this ->_setActiveMenu ('zendesk/zendesk_dashboard ' );
@@ -98,7 +98,7 @@ public function authenticateAction()
98
98
99
99
$ user = Mage::getSingleton ('admin/session ' )->getUser ();
100
100
$ name = $ user ->getName ();
101
- $ email = Mage:: getStoreConfig ( ' zendesk/general/email ' );
101
+ $ email = $ user -> getEmail ( );
102
102
$ externalId = $ user ->getId ();
103
103
104
104
$ payload = array (
@@ -107,7 +107,7 @@ public function authenticateAction()
107
107
"name " => $ name ,
108
108
"email " => $ email
109
109
);
110
-
110
+
111
111
// Validate if we need to include external_id param
112
112
$ externalIdEnabled = Mage::helper ('zendesk ' )->isExternalIdEnabled ();
113
113
if ($ externalIdEnabled ) {
@@ -118,14 +118,14 @@ public function authenticateAction()
118
118
119
119
$ jwt = JWT ::encode ($ payload , $ token );
120
120
$ return = $ return_url ? "&return_to= " .$ return_url : "" ;
121
-
121
+
122
122
$ url = "https:// " .$ domain ."/access/jwt?jwt= " . $ jwt . $ return ;
123
123
124
124
Mage::log ('Admin URL: ' . $ url , null , 'zendesk.log ' );
125
125
126
126
$ this ->_redirectUrl ($ url );
127
127
}
128
-
128
+
129
129
/**
130
130
* Wrapper for the existing authenticate action. Mirrors the login/logout actions available for customers.
131
131
*/
@@ -160,7 +160,7 @@ public function createAction()
160
160
if (!$ this ->_domainConfigured ()) {
161
161
return ;
162
162
}
163
-
163
+
164
164
// Check if we have been passed an order ID, in which case we can preload some of the form details
165
165
if ($ orderId = $ this ->getRequest ()->getParam ('order_id ' )) {
166
166
$ order = Mage::getModel ('sales/order ' )->load ($ orderId );
@@ -198,9 +198,9 @@ public function launchAction()
198
198
if (!$ domain ) {
199
199
return ;
200
200
}
201
-
201
+
202
202
$ sso = Mage::getStoreConfig ('zendesk/sso/enabled ' );
203
-
203
+
204
204
if (!$ sso ) {
205
205
$ url = "https:// " .$ domain ;
206
206
} elseif (Mage::helper ('zendesk ' )->isSSOAdminUsersEnabled ()) {
@@ -396,13 +396,13 @@ public function clearLogAction()
396
396
}
397
397
398
398
public function checkOutboundAction ()
399
- {
399
+ {
400
400
$ connection = Mage::helper ('zendesk ' )->getConnectionStatus ();
401
-
401
+
402
402
$ this ->getResponse ()->clearHeaders ()->setHeader ('Content-type ' ,'application/json ' , true );
403
403
$ this ->getResponse ()->setBody (json_encode ($ connection ));
404
- }
405
-
404
+ }
405
+
406
406
/**
407
407
* Loading page block
408
408
*/
@@ -425,16 +425,16 @@ public function loadBlockAction()
425
425
$ this ->getResponse ()->setBody ($ result );
426
426
}
427
427
}
428
-
428
+
429
429
public function getUserAction ()
430
430
{
431
431
$ request = $ this ->getRequest ();
432
432
$ id = $ request ->getParam ('id ' );
433
-
433
+
434
434
$ user = Mage::getModel ('customer/customer ' )->load ($ id );
435
-
435
+
436
436
$ this ->getResponse ()->clearHeaders ()->setHeader ('Content-type ' ,'application/json ' ,true );
437
-
437
+
438
438
if ($ user ->getId ()) {
439
439
$ this ->getResponse ()->setBody (json_encode (array ('success ' =>true , 'usr ' => array (
440
440
'firstname ' => $ user ->getFirstname (),
@@ -445,14 +445,14 @@ public function getUserAction()
445
445
$ this ->getResponse ()->setBody (json_encode (array ('success ' =>false , 'msg ' =>Mage::helper ('zendesk ' )->__ ('User does not exist ' ))));
446
446
}
447
447
}
448
-
448
+
449
449
public function getOrderAction ()
450
450
{
451
451
$ request = $ this ->getRequest ();
452
452
$ id = $ request ->getParam ('id ' );
453
-
453
+
454
454
$ order = Mage::getModel ('sales/order ' )->load ($ id );
455
-
455
+
456
456
$ this ->getResponse ()->clearHeaders ()->setHeader ('Content-type ' ,'application/json ' ,true );
457
457
if ($ order ->getId ()) {
458
458
$ this ->getResponse ()->setBody (json_encode (array ('success ' =>true , 'order ' => array (
@@ -462,16 +462,16 @@ public function getOrderAction()
462
462
$ this ->getResponse ()->setBody (json_encode (array ('success ' =>false , 'msg ' =>Mage::helper ('zendesk ' )->__ ('Order does not exist ' ))));
463
463
}
464
464
}
465
-
465
+
466
466
public function syncAction ()
467
467
{
468
468
$ this ->getResponse ()->clearHeaders ()->setHeader ('Content-type ' ,'application/json ' ,true );
469
469
Mage::log ('Synchronization started ' , null , 'zendesk.log ' );
470
- try {
470
+ try {
471
471
$ user = Mage::getModel ('zendesk/api_users ' )->all ();
472
472
if (is_null ($ user ))
473
473
throw new Exception ("Connection Failed " );
474
-
474
+
475
475
$ data = array ();
476
476
$ data [] = array (
477
477
'user_field ' => array (
@@ -539,14 +539,14 @@ public function syncAction()
539
539
if (!isset ($ response ['active ' ]) || $ response ['active ' ] === false )
540
540
Mage::log ('Unable to create User Field with key ' .$ field ['user_field ' ]['key ' ], null , 'zendesk.log ' );
541
541
}
542
-
542
+
543
543
$ customers = Mage::getModel ('customer/customer ' )->getCollection ();
544
544
$ customers ->addAttributeToSelect (array ('firstname ' , 'lastname ' , 'email ' ));
545
545
foreach ($ customers as $ customer ) {
546
546
Mage::log ('Synchronizing customer with id ' .$ customer ->getId (), null , 'zendesk.log ' );
547
547
Mage::dispatchEvent ('customer_save_commit_after ' , array ('customer ' => $ customer ));
548
548
}
549
-
549
+
550
550
} catch (Exception $ ex ) {
551
551
Mage::log ('Synchronization failed: ' .$ ex ->getMessage (), null , 'zendesk.log ' );
552
552
$ this ->getResponse ()->setBody (json_encode (array ('success ' =>false , 'msg ' =>Mage::helper ('zendesk ' )->__ ('Synchronization failed: ' ).$ ex ->getMessage ())));
@@ -568,12 +568,12 @@ public function bulkDeleteAction()
568
568
}
569
569
$ this ->_redirectReferer ();
570
570
}
571
-
571
+
572
572
public function bulkChangeStatusAction ()
573
573
{
574
574
$ ids = $ this ->getRequest ()->getParam ('id ' );
575
575
$ status = $ this ->getRequest ()->getParam ('status ' );
576
-
576
+
577
577
try {
578
578
$ response = Mage::getModel ('zendesk/api_tickets ' )->updateMany ($ ids , compact ('status ' ));
579
579
$ this ->getMassActionResponse ($ response , $ ids );
@@ -582,12 +582,12 @@ public function bulkChangeStatusAction()
582
582
}
583
583
$ this ->_redirect ('adminhtml/zendesk/ ' );
584
584
}
585
-
585
+
586
586
public function bulkChangePriorityAction ()
587
587
{
588
588
$ ids = $ this ->getRequest ()->getParam ('id ' );
589
589
$ priority = $ this ->getRequest ()->getParam ('priority ' );
590
-
590
+
591
591
try {
592
592
$ response = Mage::getModel ('zendesk/api_tickets ' )->updateMany ($ ids , compact ('priority ' ));
593
593
$ this ->getMassActionResponse ($ response , $ ids );
@@ -596,12 +596,12 @@ public function bulkChangePriorityAction()
596
596
}
597
597
$ this ->_redirect ('adminhtml/zendesk/ ' );
598
598
}
599
-
599
+
600
600
public function bulkChangeTypeAction ()
601
601
{
602
602
$ ids = $ this ->getRequest ()->getParam ('id ' );
603
603
$ type = $ this ->getRequest ()->getParam ('type ' );
604
-
604
+
605
605
try {
606
606
$ response = Mage::getModel ('zendesk/api_tickets ' )->updateMany ($ ids , compact ('type ' ));
607
607
$ this ->getMassActionResponse ($ response , $ ids );
@@ -610,11 +610,11 @@ public function bulkChangeTypeAction()
610
610
}
611
611
$ this ->_redirect ('adminhtml/zendesk/ ' );
612
612
}
613
-
613
+
614
614
public function bulkMarkSpamAction ()
615
615
{
616
616
$ ids = $ this ->getRequest ()->getParam ('id ' );
617
-
617
+
618
618
try {
619
619
$ response = Mage::getModel ('zendesk/api_tickets ' )->bulkMarkAsSpam ($ ids );
620
620
$ message = '%d out of %d ticket(s) were marked as spam. ' ;
@@ -627,34 +627,34 @@ public function bulkMarkSpamAction()
627
627
628
628
public function ticketsAllAction () {
629
629
$ isAjax = Mage::app ()->getRequest ()->isAjax ();
630
-
630
+
631
631
if ($ isAjax ) {
632
632
Mage::helper ('zendesk ' )->storeDependenciesInCachedRegistry ();
633
633
$ this ->getResponse ()->setBody ($ this ->getLayout ()->createBlock ('zendesk/adminhtml_dashboard_tab_tickets_grid_all ' )->toHtml ());
634
634
}
635
635
}
636
-
636
+
637
637
public function ticketsViewAction () {
638
638
$ isAjax = Mage::app ()->getRequest ()->isAjax ();
639
639
640
640
if ($ isAjax ) {
641
641
Mage::helper ('zendesk ' )->storeDependenciesInCachedRegistry ();
642
642
$ viewId = (int ) $ this ->getRequest ()->getParam ('viewid ' );
643
643
Mage::register ('zendesk_tickets_view ' , $ viewId );
644
-
644
+
645
645
$ this ->getResponse ()->setBody ($ this ->getLayout ()->createBlock ('zendesk/adminhtml_dashboard_tab_tickets_grid_view ' )->toHtml ());
646
646
}
647
647
}
648
-
648
+
649
649
protected function getMassActionResponse ($ response , $ ids , $ message = '%d out of %d ticket(s) were updated. ' )
650
650
{
651
651
if (isset ($ response ['job_status ' ]) && isset ($ response ['job_status ' ]['url ' ])) {
652
652
$ job_status = Mage::getModel ('zendesk/api_tickets ' )->getJobStatus ($ response ['job_status ' ]['url ' ]);
653
-
653
+
654
654
$ parsed = array ();
655
655
$ parsed ['errors ' ] = array ();
656
656
$ parsed ['success ' ] = 0 ;
657
-
657
+
658
658
if (isset ($ job_status ['job_status ' ]['results ' ])) {
659
659
foreach ($ job_status ['job_status ' ]['results ' ] as $ result ) {
660
660
if ($ result ['success ' ]) {
@@ -669,8 +669,8 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
669
669
670
670
Mage::getSingleton ('adminhtml/session ' )->addSuccess (
671
671
Mage::helper ('zendesk ' )->__ (
672
- $ message ,
673
- $ parsed ['success ' ],
672
+ $ message ,
673
+ $ parsed ['success ' ],
674
674
count ($ ids )
675
675
)
676
676
);
@@ -688,7 +688,7 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
688
688
);
689
689
}
690
690
}
691
-
691
+
692
692
private function _domainConfigured ()
693
693
{
694
694
$ domain = Mage::getStoreConfig ('zendesk/general/domain ' );
0 commit comments