コード例 #1
0
ファイル: Util.php プロジェクト: atoledov/siglab
 public static function generateFilesImport(IConnection $connect, $objCampaign, $folioID, $path_file, $fileType = "BOTH", $create_dir = false)
 {
     try {
         global $arrayDefaultHeadFieldAltitude, $servers_altitude, $database;
         $arrayFileDAT = array();
         $arrayFileTYP = array();
         if ($create_dir) {
             mkdir($path_file);
         }
         $nameFile = $objCampaign->getShortName() . "_" . $folioID;
         $rs = Customfields::getCustomFieldsListCustom($connect, $objCampaign->getCode(), 'cxc_estado=' . BLOCK_FIELD_PROTOCOL);
         while (@($field = $connect->getRows($rs))) {
             $fields_custom[$field['campo']] = array("type" => $field['tipo'], "length" => $field['longitud']);
         }
         foreach ($fields_custom as $name => $attribs) {
             switch (strtolower(trim($attribs['type']))) {
                 case 'date':
                     $arrayFileDAT[] = "DATE_FORMAT(custom.{$name},'%Y-%m-%d') ";
                     $arrayFileTYP[] = "{$name}     {$attribs['type']}";
                     break;
                 case 'datetime':
                     $arrayFileDAT[] = "DATE_FORMAT(custom.{$name},'%Y-%m-%d %T') ";
                     $arrayFileTYP[] = "{$name}      {$attribs['type']}";
                     break;
                 case 'time':
                     $arrayFileDAT[] = "custom.{$name} ";
                     $arrayFileTYP[] = "{$name}      {$attribs['type']}";
                     break;
                 case 'int':
                     $arrayFileDAT[] = "custom.{$name}";
                     $arrayFileTYP[] = "{$name}      number(10,0)";
                     break;
                 case 'double':
                     $arrayFileDAT[] = "custom.{$name}";
                     $arrayFileTYP[] = "{$name}      number(10,2)";
                     break;
                 case 'varchar':
                     $arrayFileDAT[] = "custom.{$name}";
                     $arrayFileTYP[] = "{$name}      char({$attribs['length']})";
                     break;
                 default:
                     $arrayFileDAT[] = "custom.{$name}";
                     $arrayFileTYP[] = "{$name}      {$attribs['type']}({$attribs['length']})";
                     break;
             }
             $i++;
         }
         //Generando file .dat
         if ($fileType == "DAT" || $fileType == "BOTH") {
             $rsData = CampaignData::getDataForFileDat($connect, $folioID, $arrayFileDAT, $objCampaign->getShortName(), "SE");
             $file = $path_file . DIRECTORY_SEPARATOR . $nameFile . ".dat";
             $pointer = fopen($file, "w+");
             if ($pointer !== FALSE) {
                 while ($field = $connect->getRows($rsData)) {
                     foreach ($field as $value) {
                         fputs($pointer, $value . "|");
                     }
                     fputs($pointer, chr(13) . chr(10));
                 }
                 fclose($pointer);
             } else {
                 throw new MyException("Error no se pudo crear archivo .DAT");
             }
         }
         //Generando file .typ
         if ($fileType == "TYP" || $fileType == "BOTH") {
             $file = $path_file . DIRECTORY_SEPARATOR . $nameFile . ".typ";
             $pointer = fopen($file, "w+");
             if ($pointer === FALSE) {
                 throw new MyException("Error no se pudo crear archivo .TYP");
             }
             $i = 0;
             $arrayHeadLength = array();
             if (strtolower(COUNTRY_KEY) == 'ec') {
                 $serverAtt = trim($objCampaign->getServerAltitude()) == "" ? SERVER_NORMAL : trim($objCampaign->getServerAltitude());
                 $connectSQL = Util::createConnection(ENGINE_SQLSERVER, $database[$servers_altitude["{$serverAtt}"]['altitude']]);
                 $connectSQL->connect();
                 $rsDataAltitude = Altitude::getTableSchemaTypeData($connectSQL, $objCampaign->getShortName());
                 while ($data = $connectSQL->getRows($rsDataAltitude)) {
                     $arrayHeadLength[$data['columna']]['tipo'] = $data['type'];
                     $arrayHeadLength[$data['columna']]['longitud'] = $data['longitud'];
                 }
             }
             foreach ($arrayDefaultHeadFieldAltitude as $key => $value) {
                 if ($i != 0) {
                     fputs($pointer, chr(13) . chr(10));
                 } else {
                     $i = 1;
                 }
                 if (startsWith("*", $value)) {
                     $value = str_replace("*", "", $value);
                     if ($arrayHeadLength[$value]['tipo'] == 'varchar') {
                         $value = $value . "    char({$arrayHeadLength[$value]['longitud']})";
                     }
                 }
                 fputs($pointer, $value);
             }
             fputs($pointer, chr(13) . chr(10));
             $i = 0;
             foreach ($arrayFileTYP as $value) {
                 if ($i != 0) {
                     fputs($pointer, chr(13) . chr(10));
                 } else {
                     $i = 1;
                 }
                 fputs($pointer, $value);
             }
             fclose($pointer);
         }
         return $nameFile;
     } catch (MyException $ex) {
         throw $ex;
     }
 }
コード例 #2
0
 public function addCampaignData()
 {
     $form_values = $this->form_values;
     $campaign_data = new CampaignData();
     $campaign_id = $this->_em->find('Campaigns', $form_values['campaign_id']);
     $campaign_data->setCampaign($campaign_id);
     $item_id = $this->_em->find('ItemPackSizes', $form_values['item_id']);
     $campaign_data->setItemPackSize($item_id);
     list($warehouse_id, $location_id) = explode("_", $form_values['wh_id']);
     $wh_id = $this->_em->find('Warehouses', $warehouse_id);
     $campaign_data->setWarehouse($wh_id);
     $loc_id = $this->_em->find('Locations', $location_id);
     $campaign_data->setUnionCouncil($loc_id);
     $campaign_data->setCampaignDay($form_values['campaign_day']);
     $campaign_data->setDailyTarget($form_values['daily_target']);
     $campaign_data->setHouseholdVisited($form_values['household_visited']);
     $campaign_data->setMultipleFamilyHousehold($form_values['multiple_family_household']);
     $campaign_data->setTargetAgeSixMonths($form_values['target_age_six_months']);
     $campaign_data->setTargetAgeSixtyMonths($form_values['target_age_sixty_months']);
     $campaign_data->setTotalCoverage($form_values['total_coverage']);
     $campaign_data->setRefusalCovered($form_values['refusal_covered']);
     $campaign_data->setCoverageMobileChildren($form_values['coverage_mobile_children']);
     $campaign_data->setCoverageNotAccessible($form_values['coverage_not_accessible']);
     $campaign_data->setRecordNotAccessible($form_values['record_not_accessible']);
     $campaign_data->setRecordRefusal($form_values['record_refusal']);
     $campaign_data->setReportedWithWeakness($form_values['reported_with_weakness']);
     $campaign_data->setZeroDoses($form_values['zero_dose']);
     $campaign_data->setTeamsReported($form_values['teams_reported']);
     $campaign_data->setInaccessibleCoverage($form_values['inaccessible_coverage']);
     $campaign_data->setVialsGiven($form_values['vials_given']);
     $campaign_data->setVialsUsed($form_values['vials_used']);
     $campaign_data->setVialsReturned($form_values['vials_returned']);
     $campaign_data->setVialsExpired($form_values['vials_expired']);
     $campaign_data->setReconSyrWasted($form_values['recon_syr_wasted']);
     $campaign_data->setAdSyrWasted($form_values['ad_syr_wasted']);
     $user_id = $this->_em->find('Users', $this->_identity->getIdentity());
     $campaign_data->setCreatedDate(App_Tools_Time::now());
     $campaign_data->setCreatedBy($user_id);
     $campaign_data->setModifiedBy($user_id);
     $campaign_data->setModifiedDate(App_Tools_Time::now());
     $dist_id = $this->_em->find('Locations', $form_values['district_id']);
     $campaign_data->setDistrict($dist_id);
     $this->_em->persist($campaign_data);
     $this->_em->flush();
     $last_id_camp_data = $campaign_data->getPkId();
     /* $camp_targets = new CampaignTargets();
        $camp_targets->setCampaign($campaign_id);
        $camp_targets->setDailyTarget($form_values['daily_target']);
        //$camp_targets->setLocation();
        $camp_targets->setCreatedDate(new \DateTime(date("Y-m-d")));
        $camp_targets->setCreatedBy($user_id);
        $this->_em->persist($camp_targets);
        $this->_em->flush();
        $last_id_camp_target = $camp_targets->getPkId(); */
     /* $camp_data_update = $this->_table->find($last_id_camp_data);
        $camp_data_update->setCampaignTarget($last_id_camp_target);
        $this->_em->persist($camp_data_update);
        $this->_em->flush(); */
 }