PHP code example of dhtmlx / scheduler-helper

1. Go to this page and download the library: Download dhtmlx/scheduler-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dhtmlx / scheduler-helper example snippets



use DHTMLX_Scheduler\Helper;

  $helper = new Helper(
    array(
      "dbsm" => "mysql", // optional, "mysql" by default
      "host" => "localhost", // optional, "localhost" by default
      "db_name" => "scheduler_helper_db",
      "user" => "root",
      "password" => "root",
      "table_name" => "events_rec" // name of the table that contains data of recurring events 
    )
  );

  helper::FLD_ID => "event_id",
  helper::FLD_START_DATE => "start_date",
  helper::FLD_END_DATE => "end_date",
  helper::FLD_TEXT => "text",
  helper::FLD_RECURRING_TYPE => "rec_type",
  helper::FLD_PARENT_ID => "event_pid",
  helper::FLD_LENGTH => "event_length"

  $helper->setFieldsNames(array(
    $helper::FLD_RECURRING_TYPE => "my_recurring_type_field", // redefining the field 'FLD_RECURRING_TYPE'.
    "my_property_field" // initialization of a new field
  ));

  $helper->setFieldsNames(array(
    $helper::FLD_RECURRING_TYPE => "my_recurring_type_field", // redefining the field 'FLD_RECURRING_TYPE'.
    "my_property_field" // initialization of a new field
  ), true);

  $helper->config["server_date"] = true;

  $helper->config["occurrence_timestamp_in_utc"] = true;

  // To save data of the field 'FLD_RECURRING_TYPE', you can use a data array or a string in the format 'week_2_____1,3#10'.
  $newRecurringTypeArray = array(
    "each" => "week",
    "step" => 2,
    "days_of_week" => "monday,wednesday", // if the field 'week_number' is set, the field 'days_of_week' must contain only one value
  //  "week_number" => 2,
    "repeat" => 10
  );

  $helper->saveData(array(
  //    $helper::FLD_ID => "20", // if you pass this field for saving, data in the database will be updated by this value, otherwise new data will be written
    $helper::FLD_RECURRING_TYPE => $newRecurringTypeArray,
    $helper::FLD_START_DATE => "2015-09-30 00:00:00",
    $helper::FLD_END_DATE => $helper->getRecurringEndDateStr($newRecurringTypeArray, "2015-09-30 00:00:00", 500), // to count the end date of the recurring series, you can use the function 'getRecurringEndDateStr'
    $helper::FLD_LENGTH => 500,
    "my_property_field" => "Any data..." // new fields defined by the user must be presented in this way
  ));

  $helper->deleteById(48); // will delete data by the field 'FLD_ID'.

  $helper->getData("2015-02-10 09:00:00", "2020-01-02 07:00:00");
  
  // The function will return recurring events from the defined range taking into account exclusion of events series
  // The result will look as follows:
  //array(
  //  array(
  //   "start_date" => "2015-02-13 00:00:00",
  //   "end_date" => "2015-02-15 00:00:00",
  //   "text" => "Second Friday",
  //   ...
  //  ),
  //  ....
  //);

    phpunit --bootstrap SchedulerHelper.php tests/SchedulerHelperTest