1: <?php
2:
3: 4: 5:
6: class Quform_Admin_Page_Factory
7: {
8: 9: 10:
11: protected $viewFactory;
12:
13: 14: 15:
16: protected $repository;
17:
18: 19: 20:
21: protected $options;
22:
23: 24: 25:
26: protected $license;
27:
28: 29: 30:
31: protected $formFactory;
32:
33: 34: 35:
36: protected $scriptLoader;
37:
38: 39: 40:
41: protected $permissions;
42:
43: 44: 45:
46: protected $builder;
47:
48: 49: 50:
51: protected $themes;
52:
53: 54: 55:
56: protected $entryExporter;
57:
58: 59: 60:
61: protected $uploader;
62:
63: 64: 65:
66: protected $session;
67:
68: 69: 70:
71: protected $migrator;
72:
73: 74: 75:
76: protected $upgrader;
77:
78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93:
94: public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository,
95: Quform_Options $options, Quform_License $license, Quform_Form_Factory $formFactory,
96: Quform_ScriptLoader $scriptLoader, Quform_Permissions $permissions,
97: Quform_Builder $builder, Quform_Themes $themes, Quform_Entry_Exporter $entryExporter,
98: Quform_Uploader $uploader, Quform_Session $session, Quform_Migrator $migrator,
99: Quform_Upgrader $upgrader)
100: {
101: $this->viewFactory = $viewFactory;
102: $this->repository = $repository;
103: $this->options = $options;
104: $this->license = $license;
105: $this->formFactory = $formFactory;
106: $this->scriptLoader = $scriptLoader;
107: $this->permissions = $permissions;
108: $this->builder = $builder;
109: $this->themes = $themes;
110: $this->entryExporter = $entryExporter;
111: $this->uploader = $uploader;
112: $this->session = $session;
113: $this->migrator = $migrator;
114: $this->upgrader = $upgrader;
115: }
116:
117: 118: 119: 120: 121:
122: public function create($page)
123: {
124: $method = 'create' . $page . 'Page';
125:
126: if (method_exists($this, $method)) {
127: return $this->$method();
128: }
129:
130: throw new InvalidArgumentException('Method not found to create page: ' . $page);
131: }
132:
133: 134: 135:
136: protected function createDashboardPage()
137: {
138: return new Quform_Admin_Page_Dashboard($this->viewFactory, $this->repository, $this->options);
139: }
140:
141: 142: 143:
144: protected function createFormsPage()
145: {
146: switch ($this->getSubPage()) {
147: case 'list':
148: default:
149: $page = new Quform_Admin_Page_Forms_List($this->viewFactory, $this->repository, $this->scriptLoader, new Quform_Form_List_Table($this->repository, $this->options));
150: break;
151: case 'add':
152: $page = new Quform_Admin_Page_Forms_Add($this->viewFactory, $this->repository);
153: break;
154: case 'edit':
155: $page = new Quform_Admin_Page_Forms_Edit($this->viewFactory, $this->repository, $this->builder, $this->license, $this->options);
156: break;
157: }
158:
159: return $page;
160: }
161:
162: 163: 164:
165: protected function createEntriesPage()
166: {
167: switch ($this->getSubPage()) {
168: case 'list':
169: default:
170: $page = new Quform_Admin_Page_Entries_List($this->viewFactory, $this->repository, $this->formFactory, $this->options);
171: break;
172: case 'view':
173: $page = new Quform_Admin_Page_Entries_View($this->viewFactory, $this->repository, $this->formFactory, $this->options);
174: break;
175: case 'edit':
176: $page = new Quform_Admin_Page_Entries_Edit($this->viewFactory, $this->repository, $this->formFactory, $this->uploader, $this->session);
177: break;
178: }
179:
180: return $page;
181: }
182:
183: 184: 185:
186: protected function createToolsPage()
187: {
188: switch ($this->getSubPage()) {
189: case 'home':
190: default:
191: $page = new Quform_Admin_Page_Tools_Home($this->viewFactory, $this->repository);
192: break;
193: case 'export.entries':
194: $page = new Quform_Admin_Page_Tools_ExportEntries($this->viewFactory, $this->repository, $this->entryExporter, $this->formFactory);
195: break;
196: case 'export.form':
197: $page = new Quform_Admin_Page_Tools_ExportForm($this->viewFactory, $this->repository);
198: break;
199: case 'import.form':
200: $page = new Quform_Admin_Page_Tools_ImportForm($this->viewFactory, $this->repository);
201: break;
202: case 'migrate':
203: $page = new Quform_Admin_Page_Tools_Migrate($this->viewFactory, $this->repository, $this->migrator);
204: break;
205: case 'uninstall':
206: $page = new Quform_Admin_Page_Tools_Uninstall($this->viewFactory, $this->repository, $this->options, $this->permissions, $this->uploader, $this->session, $this->upgrader);
207: break;
208: }
209:
210: return $page;
211: }
212:
213: 214: 215:
216: protected function createSettingsPage()
217: {
218: return new Quform_Admin_Page_Settings($this->viewFactory, $this->repository, $this->options, $this->license, $this->permissions, $this->scriptLoader);
219: }
220:
221: 222: 223:
224: protected function createHelpPage()
225: {
226: return new Quform_Admin_Page_Help($this->viewFactory, $this->repository);
227: }
228:
229: 230: 231:
232: protected function createPreviewPage()
233: {
234: return new Quform_Admin_Page_Preview($this->viewFactory, $this->repository, $this->options, $this->scriptLoader, $this->themes);
235: }
236:
237: 238: 239: 240: 241:
242: protected function getSubPage()
243: {
244: return Quform::get($_GET, 'sp');
245: }
246: }
247: