コード例 #1
0
ファイル: UserTable.php プロジェクト: kalelc/inventory
 public function save(User $user)
 {
     $data = array('first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'picture' => $user->getPicture(), 'signature' => $user->getSignature(), 'rol' => $user->getRol(), 'password' => $user->getPassword(), 'status' => 0);
     $id = (int) $user->getId();
     unset($data['password']);
     $params = array();
     $params['table'] = $this->tableGateway->getTableName();
     $params['operation'] = 1;
     $params['data'] = json_encode($data);
     if ($id == 0) {
         $this->tableGateway->insert($data);
         $id = $this->tableGateway->getLastInsertValue();
         if ($id) {
             $params['id'] = $id;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             return $id;
         } else {
             return false;
         }
     } else {
         if ($this->get($id)) {
             $params['id'] = $id;
             $params['operation'] = 2;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             $this->tableGateway->update($data, array('id' => $id));
             return $id;
         } else {
             return false;
         }
     }
 }
コード例 #2
0
ファイル: UserController.php プロジェクト: kalelc/inventory
 public function addAction()
 {
     $this->getAuthenticateValidate();
     $form = $this->getServiceLocator()->get("Security\\Form\\UserForm");
     $request = $this->getRequest();
     if ($request->isPost()) {
         $user = new User();
         $adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
         $user->setAdapter($adapter);
         $data = $request->getPost()->toArray();
         $form->setInputFilter($user->getInputFilter());
         $form->setData($data);
         if ($form->isValid()) {
             $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService');
             $fileService->setDestination($this->config['component']['user']['image_path']);
             $fileService->setSize($this->config['file_characteristics']['image']['size']);
             $fileService->setExtension($this->config['file_characteristics']['image']['extension']);
             $picture = $fileService->copy($this->params()->fromFiles('picture'));
             $signature = $fileService->copy($this->params()->fromFiles('signature'));
             $data['picture'] = $picture ? $picture : "";
             $data['signature'] = $signature ? $signature : "";
             $user->exchangeArray($data);
             $this->getUserTable()->save($user);
             return $this->redirect()->toRoute('security/user');
         }
     }
     return array('form' => $form, 'config' => $this->config);
 }