コード例 #1
0
 /**
  * Hydrates simple form with expression data.
  * 
  * @param Expression|string $expression
  * @param SimpleForm $form
  * @return ExpressionService
  */
 public function hydrateSimpleForm($expression, SimpleForm $form)
 {
     if (!$expression instanceof Expression) {
         $expression = Expression::create($expression);
     }
     if (!$this->isSimpleExpression($expression)) {
         throw new \InvalidArgumentException('Expression is too complex to be rendered by the simple form');
     }
     $hour = $expression->getHour();
     $minute = $expression->getMinute();
     $dayOfMonth = $expression->getDayOfMonth();
     $month = $expression->getMonth();
     $dayOfWeek = $expression->getDayOfWeek();
     $timeFieldset = $form->get('time');
     if ($hour && $minute) {
         if (is_array($hour[0])) {
             // Populate "Every Hour" fieldset
             $timeFieldset->get('picker')->setValue(SimpleForm::EVERY_HOUR);
             $timeFieldset->get(SimpleForm::EVERY_HOUR)->get('step')->setValue($hour[0]['step']);
             $timeFieldset->get(SimpleForm::EVERY_HOUR)->get('minute')->setValue($minute[0]);
         } else {
             // Populate "Specific Time" fieldset
             $timeFieldset->get('picker')->setValue(SimpleForm::SPECIFIC_TIME);
             $timeFieldset->get(SimpleForm::SPECIFIC_TIME)->get('hour')->setValue($hour[0]);
             $timeFieldset->get(SimpleForm::SPECIFIC_TIME)->get('minute')->setValue($minute[0]);
         }
     } elseif ($minute) {
         if (is_array($minute[0])) {
             // Populate "Every Minute" fieldset
             $timeFieldset->get('picker')->setValue(SimpleForm::EVERY_MINUTE);
             $timeFieldset->get(SimpleForm::EVERY_MINUTE)->get('step')->setValue($minute[0]['step']);
         } else {
             // Populate "Every Hour" fieldset
             $timeFieldset->get('picker')->setValue(SimpleForm::EVERY_HOUR);
             $timeFieldset->get(SimpleForm::EVERY_HOUR)->get('step')->setValue(1);
             $timeFieldset->get(SimpleForm::EVERY_HOUR)->get('minute')->setValue($minute[0]);
         }
     } else {
         // Populate "Every Minute" fieldset
         $timeFieldset->get('picker')->setValue(SimpleForm::EVERY_MINUTE);
         $timeFieldset->get(SimpleForm::EVERY_MINUTE)->get('step')->setValue(1);
     }
     $repeatFieldset = $form->get('repeat');
     if ($dayOfMonth) {
         // Populate "Yearly" fieldset
         if ($month) {
             $repeatFieldset->get('picker')->setValue(SimpleForm::YEARLY);
             $repeatFieldset->get(SimpleForm::YEARLY)->get('dayOfMonth')->setValue($dayOfMonth[0]);
             $repeatFieldset->get(SimpleForm::YEARLY)->get('month')->setValue($month[0]);
             // Populate "Monthly" fieldset
         } else {
             $dayOfMonth = $this->_expandRanges($dayOfMonth);
             $repeatFieldset->get('picker')->setValue(SimpleForm::MONTHLY);
             $repeatFieldset->get(SimpleForm::MONTHLY)->get('dayOfMonth')->setValue($dayOfMonth);
         }
     }
     // Populate "Weekly" fieldset
     if ($dayOfWeek) {
         $dayOfWeek = $this->_expandRanges($dayOfWeek);
         $repeatFieldset->get('picker')->setValue(SimpleForm::WEEKLY);
         $repeatFieldset->get(SimpleForm::WEEKLY)->get('dayOfWeek')->setValue($dayOfWeek);
     }
     return $this;
 }
コード例 #2
0
ファイル: index.php プロジェクト: Kingbalou/cronkeep
     } else {
         $app->render(500, array('error' => true, 'msg' => $form->getFormattedMessages()));
     }
 });
 $app->get('/edit-form/:hash', $setupJsonResponse, function ($hash) use($app) {
     $crontab = new Crontab();
     $job = $crontab->findByHash($hash);
     if (!$job) {
         $app->render(404, array('error' => true, 'msg' => 'Cron job no longer exists'));
         $app->stop();
     }
     $expressionService = new ExpressionService();
     // Prepare simple form
     $simpleForm = null;
     if ($expressionService->isSimpleExpression($job->getExpression())) {
         $simpleForm = new AddJob\SimpleForm();
         $simpleForm->get('name')->setValue($job->getComment());
         $simpleForm->get('command')->setValue($job->getCommand());
         $expressionService->hydrateSimpleForm($job->getExpression(), $simpleForm);
     }
     // Prepare advanced form
     $advancedForm = new AddJob\AdvancedForm();
     $advancedForm->get('name')->setValue($job->getComment());
     $advancedForm->get('command')->setValue($job->getCommand());
     $advancedForm->get('expression')->setValue($job->getExpression());
     $app->render(200, array('error' => false, 'html' => $app->config('view')->partial('partials/job-edit-dialog.phtml', array('hash' => $hash, 'simpleForm' => $simpleForm, 'advancedForm' => $advancedForm))));
 });
 /**
  * Runs a cron job in background.
  */
 $app->get('/run/:hash', $setupJsonResponse, function ($hash) use($app) {