- Timestamp:
- 03/10/10 14:23:54 (11 years ago)
- Location:
- trunk/server/www/app
- Files:
-
- 8 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/www/app/config/sql/schema.php
r297 r314 1 1 <?php 2 2 /* SVN FILE: $Id$ */ 3 /* App schema generated on: 2010-0 2-22 13:02:55 : 1266842515*/3 /* App schema generated on: 2010-03-10 12:03:56 : 1268219576*/ 4 4 class AppSchema extends CakeSchema { 5 5 var $name = 'App'; … … 15 15 'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'), 16 16 'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40), 17 'icon' => array('type' => 'string', 'null' => false, 'default' => NULL), 17 18 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 18 19 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), -
trunk/server/www/app/controllers/applications_controller.php
r234 r314 20 20 21 21 /** 22 * The application controller22 * The applications controller 23 23 */ 24 24 class ApplicationsController extends AppController 25 25 { 26 /** @var void Turn on scaffolding */ 27 public $scaffold; 26 /** @var array The components this controller uses */ 27 public $components = array('AuthCert'); 28 29 /** @var array The helpers this controller uses */ 30 public $helpers = array('Html', 'Form'); 31 32 /** 33 * Make a list of all images 34 */ 35 private function _getImages() 36 { 37 $images = glob(WWW_ROOT . 'img/icons/applications/*.*'); 38 foreach ($images as &$image) { 39 $image = basename($image); 40 } 41 42 return array_combine($images, $images); 43 } 44 45 /** 46 * Show the index of all applications 47 */ 48 public function admin_index() { 49 $this->Application->recursive = 0; 50 $this->set('applications', $this->paginate()); 51 } 52 53 /** 54 * View a single application 55 * @param string $id The application ID 56 */ 57 public function admin_view($id = null) { 58 if (!$id) { 59 $this->Session->setFlash(__('Invalid Application.', true)); 60 $this->redirect(array('action'=>'index')); 61 } 62 $this->set('application', $this->Application->read(null, $id)); 63 } 64 65 /** 66 * Add a new application 67 */ 68 public function admin_add() { 69 if (!empty($this->data)) { 70 $this->Application->create(); 71 if ($this->Application->save($this->data)) { 72 $this->Session->setFlash(__('The Application has been saved', true)); 73 $this->redirect(array('action'=>'index')); 74 } else { 75 $this->Session->setFlash(__('The Application could not be saved. Please, try again.', true)); 76 } 77 } 78 79 $doctypes = $this->Application->Doctype->find('list'); 80 $images = $this->_getImages(); 81 82 $this->set(compact('doctypes', 'images')); 83 $this->render('admin_edit'); 84 } 85 86 /** 87 * Edit an applications 88 * @param string $id The application ID 89 */ 90 public function admin_edit($id = null) { 91 if (!$id && empty($this->data)) { 92 $this->Session->setFlash(__('Invalid Application', true)); 93 $this->redirect(array('action'=>'index')); 94 } 95 96 if (!empty($this->data)) { 97 if ($this->Application->save($this->data)) { 98 $this->Session->setFlash(__('The Application has been saved', true)); 99 $this->redirect(array('action'=>'index')); 100 } else { 101 $this->Session->setFlash(__('The Application could not be saved. Please, try again.', true)); 102 } 103 } 104 105 if (empty($this->data)) { 106 $this->data = $this->Application->read(null, $id); 107 } 108 109 $doctypes = $this->Application->Doctype->find('list'); 110 $images = $this->_getImages(); 111 112 $this->set(compact('doctypes', 'images')); 113 } 114 115 /** 116 * Delete an application 117 * @param string $id The application ID 118 */ 119 public function admin_delete($id = null) { 120 if (!$id && empty($this->data)) { 121 $this->Session->setFlash(__('Invalid id for Application', true)); 122 $this->redirect(array('action'=>'index')); 123 } 124 125 if (!empty($this->data)) { 126 // Migrate application 127 $success = ( 128 $this->Application->migrate($this->data['Application']['id'], $this->data['Application']['new_id']) 129 && $this->Application->del($id) 130 ); 131 132 if ($success) { 133 $this->Session->setFlash(__('Application deleted', true)); 134 $this->redirect(array('action'=>'index')); 135 } 136 } 137 138 if (empty($this->data)) { 139 $this->data = $this->Application->read(null, $id); 140 } 141 142 143 $applications = $this->Application->find('list'); 144 if (isset($applications[$id])) { 145 unset($applications[$id]); 146 } 147 148 $this->set(compact('applications')); 149 } 150 28 151 } 29 30 152 ?> -
trunk/server/www/app/models/application.php
r234 r314 27 27 { 28 28 /** @var string Each application has many instances (workers) running on factories */ 29 public $hasMany = 'Worker';29 public $hasMany = array('Worker', 'Job'); 30 30 31 31 /** @var string Every application supports a certain ODF doctype */ … … 34 34 /** @var string the default order */ 35 35 public $order = 'Application.name ASC'; 36 37 /** 38 * Migrate one application to another 39 * @param string $from_id The ID to migrate 40 * @param string $to_id The ID to migrate to 41 * @return boolean Success 42 */ 43 public function migrate($from_id, $to_id) 44 { 45 if (!$from_id || !$to_id) { 46 return false; 47 } 48 49 $this->Job->updateAll( 50 array('Job.application_id' => "'" . $to_id . "'"), 51 array('Job.application_id' => $from_id) 52 ); 53 54 $this->Worker->updateAll( 55 array('Worker.application_id' => "'" . $to_id . "'"), 56 array('Worker.application_id' => $from_id) 57 ); 58 59 return true; 60 } 36 61 } 37 62
Note: See TracChangeset
for help on using the changeset viewer.