Esempio n. 1
0
 private function createApplications($provider, $projects, $users, $projectString, $fundraiserString, $dateDemandeString, $amountString, $responseString, $dateResponseString, $reasonString)
 {
     if ($projectString == null) {
         return;
     }
     if ($projectString == '') {
         return;
     }
     if ($fundraiserString == null) {
         return;
     }
     if ($fundraiserString == '') {
         return;
     }
     $projects_keys = explode(', ', $projectString);
     $fundraisers_keys = explode(', ', $fundraiserString);
     preg_match('/\\b\\d{2}[-.]?\\d{2}[-.]?\\d{4}\\b/', $dateDemandeString, $date_keys);
     $response_keys = explode(', ', $responseString);
     $amount_keys = explode(', ', $amountString);
     preg_match('/\\b\\d{2}[-.]?\\d{2}[-.]?\\d{4}\\b/', $dateResponseString, $date_response_keys);
     for ($i = 0; $i < count($projects_keys); $i++) {
         $app = new Application();
         $app->setProvider($provider);
         if (isset($fundraisers_keys[$i])) {
             $app->setFundraiser($users[$fundraisers_keys[$i]]);
         }
         if (isset($projects_keys[$i])) {
             $app->setProject($projects[$projects_keys[$i]]);
         }
         if (isset($date_keys[$i])) {
             $app->setAskDate(\DateTime::createFromFormat('d.m.Y', $date_keys[$i]));
         }
         if (isset($date_response_keys[$i])) {
             $app->setResponseDate(\DateTime::createFromFormat('d.m.Y', $date_response_keys[$i]));
         }
         if (isset($response_keys[$i])) {
             switch ($response_keys[$i]) {
                 case 'NON':
                     $app->setResponse(Application::RESPONSE_NO);
                     break;
                 case 'OUI':
                     $app->setResponse(Application::RESPONSE_YES);
                     break;
                 case 'En attente':
                     $app->setResponse(Application::RESPONSE_WAITING);
                     break;
             }
         }
         $app->setResponseMotivation($reasonString);
         if (isset($amount_keys[$i])) {
             $array = array();
             preg_match_all('!\\d+!', $amount_keys[$i], $array);
             // print_r($array);
             $number = '';
             foreach ($array[0] as $piece) {
                 $number = $number . $piece;
             }
             echo $number . PHP_EOL;
             $app->setAmount(floatval($number));
         }
         $app->setStatus(Application::STATUS_CLOSED);
     }
 }