public function addAction()
 {
     $request = $this->getRequest();
     $id = $this->params()->fromRoute('id');
     if ($id == '') {
         $customer = new Customer();
         $customerForm = new customerForm();
         if ($request->isPost()) {
             $data = $this->params()->fromPost();
             $file = $request->getFiles()->toArray();
             $size = new Size(array('max' => 2000000));
             //minimum bytes filesize
             $fileUpload = Utility::uploadFile($file);
             $data['avatar'] = $fileUpload['avatar'];
             if (!$fileUpload['status']) {
                 $customerForm->setMessages($fileUpload['error']);
             }
             $customer->setFullname($data['fullname']);
             $customer->setNicename($data['fullname']);
             $customer->setCustomerCode($data['customerCode']);
             $customer->setLevel(1);
             $customer->setPhone($data['phone']);
             $customer->setEmail($data['email']);
             $customer->setAddress($data['address']);
             $customer->setBirthday($data['birthday']);
             $customer->setAvatar($data['avatar']);
             $this->modelCustomer->insert($customer);
         }
         return new ViewModel(array('data' => $customer, 'title' => 'Add Customer ', 'form' => $customerForm));
     } else {
         $event = $this->modelCustomer->findOneBy(array('id' => $id));
         $configForm = new customerForm();
         $configForm->setAttribute('action', '/admin/customer/add/' . $id);
         $configForm->get('id')->setValue($event->getId());
         $configForm->get('fullname')->setValue($event->getFullname());
         $configForm->get('nicename')->setValue($event->getNicename());
         $configForm->get('customerCode')->setValue($event->getCustomerCode());
         $configForm->get('level')->setValue($event->getLevel());
         $configForm->get('phone')->setValue($event->getPhone());
         $configForm->get('email')->setValue($event->getEmail());
         $configForm->get('address')->setValue($event->getAddress());
         $configForm->get('birthday')->setValue($event->getBirthday());
         $configForm->get('avatar')->setValue('');
         $configForm->get('avatar_old')->setValue($event->getAvatar());
         if ($request->isPost()) {
             $file = $request->getFiles()->toArray();
             $data = $this->params()->fromPost();
             if (empty($file['avatar']['name'])) {
                 $data['avatar'] = $data['avatar_old'];
             } else {
                 $fileUpload = Utility::uploadFile($file);
                 if (!$fileUpload['status']) {
                     //  $configForm->setMessages($fileUpload['error']);
                     print_r($fileUpload['error']);
                     die;
                 } else {
                 }
                 $data['avatar'] = $fileUpload['avatar'];
             }
             // $value = $event->getValue();
             $idFormPost = $this->params()->fromPost('id');
             $event = $this->modelCustomer->findOneBy(array('id' => $idFormPost));
             $event->setFullname($data['fullname']);
             $event->setNicename($data['fullname']);
             $event->setCustomerCode($data['customerCode']);
             $event->setLevel($data['level']);
             $event->setPhone($data['phone']);
             $event->setEmail($data['email']);
             $event->setAddress($data['address']);
             $event->setBirthday($data['birthday']);
             $event->setAvatar($data['avatar']);
             $this->modelCustomer->edit($event);
             //update form
             $configForm->get('fullname')->setValue($event->getFullname());
             $configForm->get('nicename')->setValue($event->getNicename());
             $configForm->get('customerCode')->setValue($event->getCustomerCode());
             $configForm->get('level')->setValue($event->getLevel());
             $configForm->get('phone')->setValue($event->getPhone());
             $configForm->get('email')->setValue($event->getEmail());
             $configForm->get('address')->setValue($event->getAddress());
             $configForm->get('birthday')->setValue($event->getBirthday());
             $configForm->get('avatar')->setValue($event->getAvatar());
         }
         return new ViewModel(array('data' => $event, 'title' => 'Edit Customer: ' . $event->getFullname(), 'form' => $configForm));
     }
 }
Beispiel #2
0
 static function createCustomer(array $customer)
 {
     if (is_array($customer) && !empty($customer)) {
         !isset($customer['avatar']) ? $customer['avatar'] = '' : $customer['avatar'];
         !isset($customer['birthday']) ? $customer['birthday'] = '' : $customer['birthday'];
         !isset($customer['customer_code']) ? $customer['customer_code'] = '' : $customer['customer_code'];
         !isset($customer['email']) ? $customer['email'] = '' : $customer['email'];
         $doctrine = self::$servicelocator->get('doctrine');
         $customerModel = new customerModel($doctrine);
         $customerEntity = new Customer();
         $customerEntity->setFullname('hung');
         $customerEntity->setAddress('123');
         $customerEntity->setEmail('123');
         $customerEntity->setPhone('123');
         $customerEntity->setNicename('123');
         $customerEntity->setAvatar('1231');
         $customerEntity->setIsdelete(1);
         $customerEntity->setBirthday('1231');
         $customerEntity->setLevel(1);
         $customerEntity->setCustomerCode(1);
         $save = $customerModel->insert($customerEntity);
         return $save->getId();
     }
     return null;
 }