Пример #1
0
 public function save()
 {
     $empNumber = $this->getValue('EmpID');
     $attachId = $this->getValue('seqNOvc');
     $empAttachment = false;
     if (empty($attachId)) {
         $q = Doctrine_Query::create()->select('MAX(a.attach_id)')->from('EmployeeAttachment a')->where('a.emp_number = ?', $empNumber);
         $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
         if (count($result) != 1) {
             throw new PIMServiceException('MAX(a.attach_id) failed.');
         }
         $attachId = is_null($result[0]['MAX']) ? 1 : $result[0]['MAX'] + 1;
     } else {
         $q = Doctrine_Query::create()->select('a.emp_number, a.attach_id')->from('EmployeeAttachment a')->where('a.emp_number = ?', $empNumber)->andWhere('a.attach_id = ?', $attachId);
         $result = $q->execute();
         if ($result->count() == 1) {
             $empAttachment = $result[0];
         } else {
             throw new PIMServiceException('Invalid attachment');
         }
     }
     //
     // New file upload
     //
     $newFile = false;
     if ($empAttachment === false) {
         $empAttachment = new EmployeeAttachment();
         $empAttachment->emp_number = $empNumber;
         $empAttachment->attach_id = $attachId;
         $newFile = true;
     }
     $commentOnly = $this->getValue('commentOnlyvc');
     if ($newFile || $commentOnly == '0') {
         $file = $this->getValue('ufilevc');
         $tempName = $file->getTempName();
         $empAttachment->size = $file->getSize();
         $empAttachment->filename = $file->getOriginalName();
         $empAttachment->attachment = file_get_contents($tempName);
         $empAttachment->file_type = $file->getType();
         $empAttachment->screen = $this->getValue('screen');
         $empAttachment->attached_by = $this->getOption('loggedInUser');
         $empAttachment->attached_by_name = $this->getOption('loggedInUserName');
         // emp_id and name
     }
     $empAttachment->attached_time = $this->getValue('attached_time');
     $empAttachment->description = null;
     // $this->getValue('txtAttDescvc');
     $empAttachment->save();
 }
Пример #2
0
 /**
  * Save employee contract
  */
 public function updateAttachment()
 {
     $empNumber = $this->getValue('emp_number');
     //$attachId = $this->getValue('seqNO');
     $update = $this->getValue('contract_update');
     $empAttachment = false;
     $file = $this->getValue('contract_file');
     if ($update == self::CONTRACT_DELETE) {
         $q = Doctrine_Query::create()->delete('EmployeeAttachment a')->where('emp_number = ?', $empNumber)->andWhere('screen = ?', "contract");
         $result = $q->execute();
     } else {
         if ($update == self::CONTRACT_UPLOAD || !empty($file)) {
             // find existing
             $q = Doctrine_Query::create()->select('a.emp_number, a.attach_id')->from('EmployeeAttachment a')->where('a.emp_number = ?', $empNumber)->andWhere('screen = ?', "contract");
             $result = $q->execute();
             if ($result->count() == 1) {
                 $empAttachment = $result[0];
             }
             //
             // New file upload
             //
             $newFile = false;
             if ($empAttachment === false) {
                 $empAttachment = new EmployeeAttachment();
                 $empAttachment->emp_number = $empNumber;
                 $q = Doctrine_Query::create()->select('MAX(a.attach_id)')->from('EmployeeAttachment a')->where('a.emp_number = ?', $empNumber);
                 $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
                 if (count($result) != 1) {
                     throw new PIMServiceException('MAX(a.attach_id) failed.');
                 }
                 $attachId = is_null($result[0]['MAX']) ? 1 : $result[0]['MAX'] + 1;
                 $empAttachment->attach_id = $attachId;
                 $newFile = true;
             }
             $tempName = $file->getTempName();
             $empAttachment->size = $file->getSize();
             $empAttachment->filename = $file->getOriginalName();
             $empAttachment->attachment = file_get_contents($tempName);
             $empAttachment->file_type = $file->getType();
             $empAttachment->screen = EmployeeAttachment::SCREEN_JOB_CONTRACT;
             $empAttachment->attached_by = $this->getOption('loggedInUser');
             $empAttachment->attached_by_name = $this->getOption('loggedInUserName');
             $empAttachment->save();
         }
     }
 }