예제 #1
0
 public function executeAddNewBrand()
 {
     $this->setLayout(false);
     $this->trademarkTypes = UtilsHelper::loadTrademarkTypes();
     if ($brand = Document::getDocumentInstance($this->getRequestParameter('brand_id'))) {
         if (get_class($brand) != 'Brand') {
             $brand = null;
         }
     }
     if (!$brand) {
         $brand = new Brand();
     }
     $ownersArr = array();
     $root = Rootfolder::getRootfolderByModule('clients');
     $owners = Document::getChildrenOf($root->getId(), 'Client');
     foreach ($owners as $ow) {
         $ownersArr[$ow->getId()] = $ow->getLabel();
     }
     $this->ownersArr = $ownersArr;
     $success = false;
     if ($this->getRequestParameter('submit') > '') {
         // check input data
         $request = $this->getRequest();
         $params = $request->getParameterHolder()->getAll();
         //var_dump($params);
         $errors = false;
         $fields = array("label" => 'Наименование', "application_number" => 'Заявка номер', "register_number" => 'Регистров номер', "registration_date" => 'Дата на регистриране', "kind" => 'Тип', "application_date" => 'Дата на заявяване', "expires_on" => 'Срок', "nice_classes" => 'Класове по Ницска класификация', "rights_owner" => 'Притежател', "rights_representative" => 'Представител', "office_of_origin" => 'Държава на регистрация', "designated_contracting_party" => 'Държави в които е в сила');
         foreach ($fields as $fl => $label) {
             $val = trim($params[$fl]);
             if ($val == '') {
                 if ($fl == 'rights_owner') {
                     if ($params['owner'] == '') {
                         $errors = true;
                         $request->setError('err' . $fl, '- ' . $label);
                     }
                 } else {
                     $errors = true;
                     $request->setError('err' . $fl, '- ' . $label);
                 }
             }
         }
         $image = null;
         if ($errors) {
             UtilsHelper::setFlashMsg('Моля, въведете необходимите данни:<br>', UtilsHelper::MSG_ERROR);
         } else {
             if ($request->getFileName('image')) {
                 try {
                     $image = Media::upload('image', 'upload', array('image/gif', 'image/jpeg', 'image/jpg', 'image/png'));
                     //var_dump($image);
                     list($w, $h) = getimagesize($image->getServerAbsoluteUrl());
                     if ($w > $h) {
                         $image->resizeImage("thumbs", null, 105);
                     } else {
                         $image->resizeImage("thumbs", 95);
                     }
                 } catch (Exception $e) {
                     $errors = true;
                     $request->setError('errImage', '- ' . UtilsHelper::Localize('media.' . $e->getMessage()));
                 }
             }
             if ($errors) {
                 // remove uploaded image
                 if ($image) {
                     $image->delete();
                 }
                 UtilsHelper::setFlashMsg('Моля, коригирайте:<br>', UtilsHelper::MSG_ERROR);
             }
         }
         // if everithing is OK
         if (!$errors) {
             //$brand = new Brand();
             $brand->setLabel($params['label']);
             if ($params['owner'] > '') {
                 $brand->setClientId($params['owner']);
                 $client = Document::getDocumentInstance($params['owner']);
                 $brand->setRightsOwner($client->getLabel());
             } else {
                 $val = trim($params['rights_owner']);
                 $client = new Client();
                 $client->setLabel($val);
                 $client->save();
                 $brand->setClientId($client->getId());
                 $this->client = $client;
                 $brand->setRightsOwner($val);
             }
             $brand->setApplicationNumber($params['application_number']);
             $brand->setRegisterNumber($params['register_number']);
             $brand->setRegistrationDate($params['registration_date']);
             $brand->setKind($params['kind']);
             $brand->setApplicationDate($params['application_date']);
             $brand->setStatus($params['status']);
             $brand->setExpiresOn($params['expires_on']);
             $brand->setViennaClasses(str_replace(' ', '', $params['vienna_classes']));
             $brand->setColors($params['colors']);
             $brand->setNiceClasses(str_replace(' ', '', $params['nice_classes']));
             $brand->setRightsOwnerAddress($params['rights_owner_address']);
             $brand->setRightsRepresentative($params['rights_representative']);
             $brand->setRightsRepresentativeAddress($params['rights_representative_address']);
             $brand->setOfficeOfOrigin($params['office_of_origin']);
             $brand->setDesignatedContractingParty($params['designated_contracting_party']);
             if ($image) {
                 $brand->setImage($image->getId());
             }
             $brand->save();
             $success = true;
         }
     }
     $this->brand = $brand;
     $this->success = $success;
 }