PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/mybase/controllers/ProjectController.php

https://github.com/besters/My-Base
PHP | 93 lines | 67 code | 26 blank | 0 comment | 6 complexity | a7b1f92118bc696531b8122af78f3355 MD5 | raw file
  1. <?php
  2. class Mybase_ProjectController extends Unodor_Controller_Action
  3. {
  4. public function init()
  5. {
  6. $this->_model = new Model_Project();
  7. parent::init();
  8. }
  9. public function indexAction()
  10. {
  11. $result = $this->_model->getProjectsList();
  12. $this->view->project = $result;
  13. }
  14. public function newAction()
  15. {
  16. $this->_form = new Mybase_Form_Project();
  17. $session = new Zend_Session_Namespace('Zend_Auth');
  18. $this->_form->populate(array('iduser' => $session->storage->iduser));
  19. $this->view->form = $this->_form;
  20. $formData = $this->getRequest()->getPost();
  21. if($this->_request->isPost()){
  22. if($this->_form->isValid($formData)){
  23. $lastInsertId = $this->_model->save($formData);
  24. $acl = new Model_Acl;
  25. if(isset($formData['img'])){
  26. $account = new Model_Account();
  27. if(!is_dir(ROOT_PATH . '/public/files/' . $account->getId()))
  28. mkdir(ROOT_PATH . '/public/files/' . $account->getId());
  29. mkdir(ROOT_PATH . '/public/files/' . $account->getId() . '/' . $lastInsertId . '/');
  30. rename(ROOT_PATH . '/public/files/tmp/' . $formData['img'], ROOT_PATH . '/public/files/' . $account->getId() . '/' . $lastInsertId . '/' . $formData['img']);
  31. }
  32. $acl->createDefault($lastInsertId, $formData['iduser']);
  33. $this->_flash('New project has been successfully created', 'done');
  34. return $this->_redirect('/' . $lastInsertId . '/team');
  35. }else{
  36. $this->_flash('Formulář není vyplněn správně', 'error', false);
  37. $this->_form->populate($formData);
  38. }
  39. }
  40. }
  41. public function uploadAction()
  42. {
  43. $this->disableMvc(true, true);
  44. $account = new Model_Account();
  45. $adapter = new Zend_File_Transfer_Adapter_Http();
  46. if(!is_dir(ROOT_PATH . '/public/files/tmp/'))
  47. mkdir(ROOT_PATH . '/public/files/tmp/');
  48. $adapter->setDestination(ROOT_PATH . '/public/files/tmp/');
  49. $info = $adapter->getFileInfo();
  50. $ex = explode('.', $info['Filedata']['name']);
  51. $fileType = $ex[count($ex) - 1];
  52. $hash = $adapter->getHash('md5');
  53. $tmpFile = $info['Filedata']['destination'] . '/' . $hash . '.' . $fileType;
  54. $adapter->addFilter('Rename', array('target' => $tmpFile, 'overwrite' => true));
  55. if($adapter->receive()){
  56. $img = new Unodor_Image_Resize($tmpFile);
  57. $img->adaptiveResize(50, 50)->save($tmpFile, false);
  58. echo $hash . '.' . $fileType;
  59. }
  60. }
  61. public function checkAction()
  62. {
  63. $this->disableMvc(true, true);
  64. echo true;
  65. return true;
  66. }
  67. }