Example #1
0
 public function save(array $data)
 {
     $table = $this->getTable();
     $fields = $table->info(Zend_Db_Table_Abstract::COLS);
     foreach ($data as $field => $value) {
         if (!in_array($field, $fields)) {
             unset($data[$field]);
         }
     }
     $table->insert($data);
     $last_insert_id = $table->lastInsertId();
     $_SESSION["production"]["id"] = $last_insert_id;
     //insert one role for the user in the production
     $data_permission_production["productions_id"] = $last_insert_id;
     $data_permission_production["acl_roles_id"] = $_SESSION['gpms']['storage']->role_id;
     $data_permission_production["acl_users_id"] = $_SESSION['gpms']['storage']->id;
     $model_permission_production = new Production_Model_Permissionproduction();
     $model_permission_production->save($data_permission_production);
     //insert the relation between company and production
     $db = Zend_Registry::get('db');
     $data_company_production["companies_id"] = $_SESSION["company"]["id"];
     $data_company_production["productions_id"] = $last_insert_id;
     $db->insert(companies_has_productions, $data_company_production);
     //        die();
     return $last_insert_id;
 }
 /**
  * AddAction for Permissionproductions
  *
  * @return void
  */
 public function addAction()
 {
     //check if the user select a production
     $this->production = new Zend_Session_Namespace('production');
     if ($this->production->id == null) {
         return $this->_helper->_redirector->gotoSimple('index', 'production', 'production');
     }
     $this->view->headTitle("Add New Permissionproduction", 'APPEND');
     $request = $this->getRequest();
     $form = new Production_Form_Permissionproduction();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $model = new Production_Model_Permissionproduction();
             $data = $form->getValues();
             unset($data["id"]);
             $data["productions_id"] = $_SESSION["production"]["id"];
             $model->save($data);
             return $this->_helper->_redirector->gotoSimple('consult', 'production', 'production');
         }
     } else {
         $form->populate($form->getValues());
     }
     $this->view->form = $form;
 }