| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Calendars_Html_Admin_Controller_Index |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
SH4_Calendars_Query $query, |
| 8 |
SH4_Calendars_Command $command, |
| 9 |
HC3_Post $post |
| 10 |
) |
| 11 |
{ |
| 12 |
$this->query = $hooks->wrap($query); |
| 13 |
$this->command = $hooks->wrap($command); |
| 14 |
$this->post = $hooks->wrap($post); |
| 15 |
$this->self = $hooks->wrap($this); |
| 16 |
} |
| 17 |
|
| 18 |
public function execute() |
| 19 |
{ |
| 20 |
$action = $this->post->get('action'); |
| 21 |
$ids = $this->post->get('id'); |
| 22 |
|
| 23 |
if( ! is_array($ids) ){ |
| 24 |
$ids = explode( ':', $ids ); |
| 25 |
} |
| 26 |
|
| 27 |
$filter = $this->post->get('filter'); |
| 28 |
if( $filter ){ |
| 29 |
$calendarId = $this->post->get('calendar'); |
| 30 |
return $this->self->executeFilter( $calendarId ); |
| 31 |
} |
| 32 |
|
| 33 |
if( ('archive' == $action) && $ids ){ |
| 34 |
$this->self->executeArchive( $ids ); |
| 35 |
|
| 36 |
$msg = '__Calendar Archived__'; |
| 37 |
if( count($ids) > 1 ){ |
| 38 |
$msg .= ' (' . count($ids) . ')'; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
if( ('restore' == $action) && $ids ){ |
| 43 |
$this->self->executeRestore( $ids ); |
| 44 |
|
| 45 |
$msg = '__Calendar Restored__'; |
| 46 |
if( count($ids) > 1 ){ |
| 47 |
$msg .= ' (' . count($ids) . ')'; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
if( ('delete' == $action) && $ids ){ |
| 52 |
$this->self->executeDelete( $ids ); |
| 53 |
|
| 54 |
$msg = '__Calendar Deleted__'; |
| 55 |
if( count($ids) > 1 ){ |
| 56 |
$msg .= ' (' . count($ids) . ')'; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
$return = array( 'admin/calendars', $msg ); |
| 61 |
return $return; |
| 62 |
} |
| 63 |
|
| 64 |
public function executeFilter( $calendarId ) |
| 65 |
{ |
| 66 |
$params = array(); |
| 67 |
$params['admin/calendar'] = $calendarId ? $calendarId : NULL; |
| 68 |
|
| 69 |
$return = array( array('admin/calendars', $params), NULL ); |
| 70 |
return $return; |
| 71 |
} |
| 72 |
|
| 73 |
public function executeDelete( $ids ) |
| 74 |
{ |
| 75 |
if( ! is_array($ids) ){ |
| 76 |
$ids = array($ids); |
| 77 |
} |
| 78 |
|
| 79 |
foreach( $ids as $id ){ |
| 80 |
$model = $this->query->findById( $id ); |
| 81 |
$this->command->delete( $model ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public function executeArchive( $ids ) |
| 86 |
{ |
| 87 |
if( ! is_array($ids) ){ |
| 88 |
$ids = array($ids); |
| 89 |
} |
| 90 |
|
| 91 |
foreach( $ids as $id ){ |
| 92 |
$model = $this->query->findById( $id ); |
| 93 |
$this->command->archive( $model ); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
public function executeRestore( $ids ) |
| 98 |
{ |
| 99 |
if( ! is_array($ids) ){ |
| 100 |
$ids = array($ids); |
| 101 |
} |
| 102 |
|
| 103 |
foreach( $ids as $id ){ |
| 104 |
$model = $this->query->findById( $id ); |
| 105 |
$this->command->restore( $model ); |
| 106 |
} |
| 107 |
} |
| 108 |
} |