PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Controller/ActorsController.php

https://github.com/Wargo/reddevil
PHP | 82 lines | 50 code | 31 blank | 1 comment | 7 complexity | 9e9284c7702372a168f30edcee02d183 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. class ActorsController extends AppController {
  3. function index() {
  4. $actors = $this->Actor->find('all', array(
  5. 'conditions' => array(
  6. 'gender' => 0
  7. //'active' => 1
  8. ),
  9. ));
  10. $title_for_layout = __('Chicas de RedDevilX');
  11. $names = Set::extract('/Actor/name', $actors);
  12. $description_for_layout = implode(', ', $names);
  13. $this->set(compact('actors', 'title_for_layout', 'description_for_layout'));
  14. }
  15. function admin_index() {
  16. $actors = $this->Actor->find('all');
  17. $this->set(compact('actors'));
  18. }
  19. function admin_edit($id = null) {
  20. if ($this->request->data) {
  21. if ($id) {
  22. $this->Actor->id = $id;
  23. } else {
  24. $this->Actor->create();
  25. }
  26. $this->request->data['Actor']['slug'] = ClassRegistry::init('Video')->title2url($this->request->data['Actor']['name']);
  27. $this->Actor->save($this->request->data);
  28. if (!empty($_FILES['data']['name']['Actor']['file'])) {
  29. $aux = explode('-', $this->Actor->id);
  30. $aux = substr($aux[1], 0, 3);
  31. if (!is_dir(APP . 'uploads' . DS . 'img' . DS . 'Actor' . DS . $aux)) {
  32. mkdir(APP . 'uploads' . DS . 'img' . DS . 'Actor' . DS . $aux);
  33. }
  34. exec('rm -f ' . WWW_ROOT . 'img' . DS . 'Actor' . DS . $aux . DS . $this->Actor->id . '*');
  35. move_uploaded_file($_FILES['data']['tmp_name']['Actor']['file'],
  36. APP . 'uploads' . DS . 'img' . DS . 'Actor' . DS . $aux . DS . $this->Actor->id . '.jpg');
  37. }
  38. return $this->redirect('index');
  39. }
  40. if ($id) {
  41. $this->request->data = $this->Actor->findById($id);
  42. }
  43. $this->set(compact('id'));
  44. }
  45. function admin_delete($id = null) {
  46. if ($id) {
  47. $this->Actor->delete($id);
  48. }
  49. return $this->redirect('index');
  50. }
  51. }