Create a new schedule.

@return \Illuminate\Http\JsonResponse
422416
public function store()
    {
        try {
            $schedule = execute(new CreateScheduleCommand(
                Binput::get('name'),
                Binput::get('message', null, false, false),
                Binput::get('status'),
                Binput::get('scheduled_at'),
                Binput::get('completed_at'),
                Binput::get('components', [])
            ));
        } catch (QueryException $e) {
            throw new BadRequestHttpException();
        }

        return $this->item($schedule);
    }
914788
public function evaluateSchedule()
    {
        $this->scheduleModel->reset()
            ->setContactClient($this->contactClient)
            ->setTimezone()
            ->evaluateDay()
            ->evaluateTime()
            ->evaluateExclusions();

        return new \DateTime();
    }
302370
public function make()
    {
        if (is_lumen()) {
            return new \Laravel\Lumen\Http\ResponseFactory();
        }

        return app(\Illuminate\Contracts\Routing\ResponseFactory::class);
    }
345592
public function getSchedule()
    {
        $list = [];

        foreach ($this->schedule as $time => $jobs) {
            foreach ($jobs as $job) {
                $list[$time][] = $job->getId();
            }
        }

        return $list;
    }
833410
public function createRequest() {
        $request = new \Amp\Artax\Request();
        $url = null;
        $request->setMethod('');


        $jsonParams = [];
        $value = $this->getFilteredParameter('scopes');
        $jsonParams['scopes'] = $value;
        $value = $this->getFilteredParameter('add_scopes');
        $jsonParams['add_scopes'] = $value;
        $value = $this->getFilteredParameter('remove_scopes');
        $jsonParams['remove_scopes'] = $value;
        $value = $this->getFilteredParameter('note');
        $jsonParams['note'] = $value;
        $value = $this->getFilteredParameter('note_url');
        $jsonParams['note_url'] = $value;
        $value = $this->getFilteredParameter('fingerprint');
        $jsonParams['fingerprint'] = $value;

        //Parameters are parsed and set, lets prepare the request
        if (count($jsonParams)) {
            $jsonBody = json_encode($jsonParams);
            $request->setHeader("Content-Type", "application/json");
            $request->setBody($jsonBody);
        }
        if ($url == null) {
            $url = "https://api.github.com/authorizations/{id}";
        }
        $request->setUri($url);

        return $request;
    }
766544
public static function create()
    {
        self::$french_calendar    = new FrenchCalendar();
        self::$gregorian_calendar = new GregorianCalendar();
        self::$jewish_calendar    = new JewishCalendar(array(
            JewishCalendar::EMULATE_BUG_54254 => self::shouldEmulateBug54254(),
        ));
        self::$julian_calendar    = new JulianCalendar();
    }
5941
public function getSchedule() {
    // Use cached schedule if already processed.
    if ($this->schedule) {
      return $this->schedule;
    }

    $conf = $this->configFactory->get('openy_group_schedules.settings');
    $days_range = is_numeric($conf->get('days_range')) ? $conf->get('days_range') : 14;

    $filter_date = DrupalDateTime::createFromTimestamp($this->parameters['filter_timestamp'], $this->timezone);
    $current_date = DrupalDateTime::createFromTimestamp(REQUEST_TIME, $this->timezone)->format(GroupexRequestTrait::$dateFilterFormat);
    // Define end date of shown items as 2 weeks.
    $end_date = DrupalDateTime::createFromTimestamp(REQUEST_TIME + 86400 * $days_range, $this->timezone);

    // Prepare classes items.
    $items = [];

    foreach ($this->processedData as $item) {
      // If item date more than 1 week in future skip it.
      $item_date = DrupalDateTime::createFromTimestamp($item->timestamp, $this->timezone);
      if ($item_date > $end_date) {
        continue;
      }
      $class_url_options = $this->parameters;
      // $class_url_options['class'] = $item->class_id; //doesn't exist in API, needs to be added through processData().
      $class_url_options['filter_date'] = $current_date;
      $class_url_options['filter_length'] = 'week';
      $class_url_options['groupex_class'] = 'groupex_table_class_individual';
      $class_url_options['view_mode'] = 'class';
      unset($class_url_options['instructor']);

      $instructor_url_options = $this->parameters;
      $instructor_url_options['filter_date'] = $current_date;
      $instructor_url_options['filter_length'] = 'week';

      $instructor_url_options['instructor'] = $item->instructor;
      // Here we need to remove redundant HTML if exists.
      // Example: Melissa T.<br><span class="fa fa-refresh" aria-hidden="true"></span><span class="sub">Lucy T.</span>
      $pos = strpos($item->instructor, '<span class="sub">');
      if (FALSE !== $pos) {
        $original_instructor = substr_replace($item->instructor, '', 0, $pos);
        $original_instructor = str_replace('<span class="sub">', '', $original_instructor);
        $original_instructor = str_replace('</span>', '', $original_instructor);
        $instructor_url_options['instructor'] = $original_instructor;
      }

      $instructor_url_options['class'] = 'any';
      $instructor_url_options['groupex_class'] = 'groupex_table_instructor_individual';
      unset($instructor_url_options['view_mode']);

      $date_url_options = $this->parameters;
      $date_url_options['filter_date'] = date('m/d/y', strtotime($item->date));
      $date_url_options['filter_length'] = 'day';
      $date_url_options['class'] = 'any';
      $date_url_options['groupex_class'] = 'groupex_table_class';
      unset($date_url_options['instructor']);
      unset($date_url_options['view_mode']);

      $items[$item->id] = [
        '#theme' => isset($this->parameters['groupex_class']) ? $this->parameters['groupex_class'] : 'groupex_class',
        '#class' => [
          'id' => trim($item->id),
          'name' => trim($item->title),
          'group' => trim($item->category),
          'description' => $item->desc,
          'address_1' => $item->address_1,
          'address_2' => trim($item->location),
          'date' => $item->date,
          'studio' => $item->studio,
          'date_short' => date('F, d', strtotime($item->date)),
          'time' => $item->start,
          'duration' => sprintf('%d min', trim($item->length)),
          'instructor' => $item->instructor,
//          'class_id' => $item->class_id, //doesn't exist in API, needs to be added through processData().
          'class_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $class_url_options]),
          'instructor_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $instructor_url_options]),
          'date_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $date_url_options]),
          'calendar' => $item->calendar,
        ],
      ];
    }

    // Pack classes into the schedule.
    $schedule = [];

    // There 3 types of schedules.
    // Day: show classes for single day.
    // Week: show classes for week grouped by day.
    // Location: show classes for 1 day grouped by location.
    $schedule['type'] = isset($this->parameters['filter_length']) ? $this->parameters['filter_length'] : 'day';
    if (!empty($this->parameters['location']) && count($this->parameters['location']) > 1) {
      $schedule['type'] = 'location';
    }
    if (!empty($this->parameters['class']) && is_numeric($this->parameters['class'])) {
      $schedule['type'] = 'week';
    }
    if (!empty($this->parameters['instructor'])) {
      $schedule['type'] = 'instructor';
    }
    switch ($schedule['type']) {
      case 'day':
        $schedule['classes'] = [];
        foreach ($items as $id => $class) {
          $schedule['classes'][] = $class;
          $schedule['title'] = trim($this->enrichedData[$id]->location);
        }
        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location_id = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location_id, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['title'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;

      case 'week':
        $schedule['days'] = [];
        foreach ($items as $id => $class) {
          $schedule['days'][$this->enrichedData[$id]->day]['classes'][] = $class;
          $schedule['days'][$this->enrichedData[$id]->day]['day_short'] = DrupalDateTime::createFromFormat(GroupexRequestTrait::$dateFullFormat, $this->enrichedData[$id]->day, $this->timezone)->format('l, F j');
          $schedule['days'][$this->enrichedData[$id]->day]['date_link'] = $class['#class']['date_link'];
        }
        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['day'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;

      case 'location':
        $schedule['locations'] = [];
        $location_id = NULL;
        $locations_ids = \Drupal::entityQuery('mapping')
          ->condition('type', 'location')
          ->execute();
        $locations = \Drupal::entityManager()->getStorage('mapping')->loadMultiple($locations_ids);
        foreach ($items as $id => $class) {
          $short_location_name = trim($this->enrichedData[$id]->location);
          foreach ($locations as $location) {
            if ($location->get('name')->value == $short_location_name) {
              $field_groupex_id = $location->field_groupex_id->getValue();
              $location_id = isset($field_groupex_id[0]['value']) ? $field_groupex_id[0]['value'] : FALSE;
            }
          }
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $pdf_href = $this->groupexHelper->getPdfLink($location_id, $this->parameters['filter_timestamp'], $category);
          $schedule['locations'][$short_location_name]['classes'][] = $class;
          $schedule['locations'][$short_location_name]['pdf_href'] = $pdf_href;
        }
        $schedule['filter_date'] = date(GroupexRequestTrait::$dateFullFormat, $this->parameters['filter_timestamp']);
        break;

      case 'instructor':
        // Filter classes by instructor.
        $schedule['days'] = [];

        foreach ($items as $id => $class) {
          if ($class['#class']['instructor'] == $this->parameters['instructor']) {
            $class_date = DrupalDateTime::createFromFormat(
              GroupexRequestTrait::$dateFullFormat,
              $this->enrichedData[$id]->day,
              $this->timezone
            );

            $schedule['days'][$this->enrichedData[$id]->day]['classes'][] = $class;
            $schedule['days'][$this->enrichedData[$id]->day]['day_short'] = $class_date->format('l, F j');

            // Adjust query options to fit class date.
            $date_url_options['filter_date'] = $class_date->format(GroupexRequestTrait::$dateFilterFormat);
            $date_url_options['filter_timestamp'] = $class_date->format('U');

            $url = Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $date_url_options]);
            $schedule['days'][$this->enrichedData[$id]->day]['date_link'] = $url;
          }
        }

        $schedule['instructor_location'] = t('Schedule for <span class="name"><span class="icon icon-user"></span>@name</span>', [
          '@name' => reset($schedule['days'])['classes'][0]['#class']['instructor'],
        ]);

        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['day'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;
    }

    $this->schedule = $schedule;
    return $this->schedule;
  }
335936
public function createCustomer()
    {
        $data = [
            "email" => request()->email,
            "first_name" => request()->fname,
            "last_name" => request()->lname,
            "phone" => request()->phone,
            "metadata" => request()->additional_info /* key => value pairs array */

        ];

        $this->setRequestOptions();
        return $this->setHttpResponse('/customer', 'POST', $data)->getResponse();
    }
998583
public static function create()
    {
        $dispatcher = new Dispatcher();
        foreach (static::$_stack as $middleware) {
            $dispatcher->addFilter($middleware);
        }

        return $dispatcher;
    }
1313121
public function getScheduled()
    {
        $items = Auth::user()->items()->scheduled();

        $table = new InventoryScheduled($items);

        return view('mustard::inventory.scheduled', [
            'table' => $table,
            'items' => $table->paginate(),
        ]);
    }
924852
public function addSchedule($scheduleId)
    {
        $schedule = new Schedule($this->customerKey, $this->key);
        $schedule->id = $scheduleId;
        return $schedule;
    }
1182082
public function scheduleNowAction()
    {
        $codes = $this->getMassActionCodes();
        foreach ($codes as $key) {
            Mage::getModel('cron/schedule')
                ->setJobCode($key)
                ->setScheduledReason(Aoe_Scheduler_Model_Schedule::REASON_SCHEDULENOW_WEB)
                ->schedule()
                ->save();

            $this->_getSession()->addSuccess($this->__('Job "%s" has been scheduled.', $key));
        }
        $this->_redirect('*/*/index');
    }
896888
private function jsonManager()
    {
        if($this->jsonManager === null)
            $this->jsonManager = new JsonManager($this, $this->jsonProperty);

        return $this->jsonManager;
    }
1327903
public function add($schedule)
    {
        if (is_array($schedule)) {
            $this->collection[] = new Schedule($schedule);
        } elseif (is_object($schedule) && $schedule instanceof Schedule) {
            $this->collection[] = $schedule;
        }

        return $this;
    }
343064
public function make()
    {
        $this->setDefaultHeaders();

        $startTime = microtime(true);
        $result = $this->httpClient->request($this->getMethod(), $this->getURL(), $this->getPayload());
        $endTime = microtime(true);

        $this->response = new Response();
        $this->response->setExecutionTime(round(($endTime - $startTime), 5))
            ->setStatusCode($result->getStatusCode());

        // set the request ID for remote debugging if it is present            
        if (!empty(($requestID = $result->getHeader('X-Moltin-Request-Id')))) {
            $this->response->setRequestID($requestID[0]);
        }

        $body = json_decode($result->getBody());
        $this->response->setRaw($body)->parse();

        return $this;
    }
549864
public function startup()
    {
        $reflector = new ReflectionClass('Resque');
        $this->_resqueLibrary = dirname(dirname($reflector->getFileName()));

        $reflector = new ReflectionClass('ResqueScheduler\ResqueScheduler');
        $this->_resqueSchedulerLibrary = dirname(dirname(dirname($reflector->getFileName())));

        $this->ResqueStatus = new ResqueStatus(Resque::redis());

        $this->_io->styles('success', ['text' => 'green']);
        $this->_io->styles('bold', ['bold' => true]);
    }
1294897
public function schedule()
    {
        $createdAtTime = $this->getCronTimestamp();
        $scheduledAtTime = $createdAtTime;

        /* @var $schedule Schedule */
        $schedule = $this->scheduleCollection->getNewEmptyItem();
        $schedule->setJobCode(Export::JOB_CODE)
            ->setStatus(Schedule::STATUS_PENDING)
            ->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $createdAtTime))
            ->setScheduledAt(strftime('%Y-%m-%d %H:%M', $scheduledAtTime));

        $schedule->save();

        return $schedule;
    }