summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--readme.md123
-rw-r--r--sources/dhtmlx_scheduler_helper/SchedulerHelper.php (renamed from SchedulerHelper.php)32
-rw-r--r--sources/dhtmlx_scheduler_helper/classes/RecurringType.php (renamed from RecurringType.php)37
-rw-r--r--sources/dhtmlx_scheduler_helper/classes/SchedulerHelperConnector.php (renamed from SchedulerHelperConnector.php)4
-rw-r--r--sources/dhtmlx_scheduler_helper/classes/SchedulerHelperDate.php (renamed from SchedulerDate.php)9
5 files changed, 161 insertions, 44 deletions
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..8929d8b
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,123 @@
+Sheduler Helper for PHP
+========================
+
+### Requirements
+
+ - PHP>=5.4 (PDO~)
+ - MySQL, PostgreSQL, Sqlite and etc.
+
+### Installation
+
+ - composer
+
+ or
+
+ - just download the files from this repository reposetory 'git@github.com:DHTMLX/scheduler-helper-php.git'
+
+ require_once "./SchedulerHelper.php";
+ use Scheduler\Helper;
+
+### How to use
+
+Для создания объекта хелпера необходимо вызвать конструктор класса Scheduler\Helper::Helper([$connectorDataArray]):
+
+```
+ $helper = new Helper(
+ array(
+ "dbsm": "mysql", //Необязательный параметр. По умолчанию установлено "mysql".
+ host: "localhost", //Необязательный параметр. По умолчанию установлено "localhost".
+ "db_name" => "scheduler_helper_db",
+ "user" => "root",
+ "password" => "root",
+ "table_name" => "events_rec" //Имя таблицы в которой хранятся данные повторяющихся событий.
+ )
+ );
+```
+
+В хелпере определены стандартный набор полей для работы с таблицей:
+
+```
+ 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"
+```
+
+Для переопределения и создания новые полей необходимо использовать метод 'setFieldsNames([$fieldsDataArray])':
+
+```
+ $helper->setFieldsNames(array(
+ $helper::FLD_RECURRING_TYPE => "my_recurring_type_field", //Переопределение поля 'FLD_RECURRING_TYPE'.
+ "my_property_field" //Инициализация нового поля.
+ ));
+```
+
+Для сохранения данных в базу необходимо использовать метод 'saveData([dataArray])':
+
+```
+ //Для сохранения данных поля 'FLD_RECURRING_TYPE' вы можете использовать массив данных или строку формата 'week_2_____1,3#10'.
+ $newRecurringTypeArray = array(
+ "each" => "week",
+ "step" => 2,
+ "days_of_week" => "monday,wednesday", //Если поле 'week_number' установлено, то поле 'days_of_week' должно содержать только одно значение.
+ // "week_number" => 2,
+ "repeat" => 10
+ );
+
+ $helper->saveData(array(
+ // $helper::FLD_ID => "20", //Если для сохранения передавать это поле, то данные в базе данных будут обновлены по этому значению, иначе записаны новые.
+ $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), //Для расчета конечной даты повторяющейся серии вы можете использовать функцию 'getRecurringEndDateStr'.
+ $helper::FLD_LENGTH => 500,
+ "my_property_field" => "Any data..." //Новые поля определенные пользователем должны иметь такой вид.
+ ));
+```
+
+Для удаления данных из базы данных необходимо использовать метод 'deleteById([ID])':
+
+```
+ $helper->deleteById(48); //Удалит данные по полю 'FLD_ID'.
+```
+
+Для получения данных повторяющихся событий необходимо использовать метов 'getData([$startDateStr], [$endDateStr])':
+
+```
+ $helper->getData("2015-02-10 09:00:00", "2020-01-02 07:00:00");
+
+ //Функция вернет повторяющиеся события по данному диапозону с учетом исключений серии событий.
+ //Результат имеет вид:
+ //array(
+ // array(
+ // "start_date" => "2015-02-13 00:00:00",
+ // "end_date" => "2015-02-15 00:00:00",
+ // "text" => "Second Friday",
+ // ...
+ // ),
+ // ....
+ //);
+```
+
+
+### License
+
+DHTMLX is published under the GPLv3 license.
+
+License:
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+
+
+Copyright (c) 2015 DHTMLX
diff --git a/SchedulerHelper.php b/sources/dhtmlx_scheduler_helper/SchedulerHelper.php
index 2387dbe..0395b6c 100644
--- a/SchedulerHelper.php
+++ b/sources/dhtmlx_scheduler_helper/SchedulerHelper.php
@@ -1,13 +1,13 @@
<?php
-namespace Scheduler;
-require_once "SchedulerDate.php";
-require_once "SchedulerHelperConnector.php";
-require_once "RecurringType.php";
+namespace DHTMLX_Scheduler;
+require_once "classes/SchedulerHelperDate.php";
+require_once "classes/SchedulerHelperConnector.php";
+require_once "classes/RecurringType.php";
use PDO, Exception;
-abstract class DHelper extends Connector
+abstract class DHelper extends SchedulerHelperConnector
{
const FLD_ID = "id";
const FLD_START_DATE = "start_date";
@@ -203,7 +203,7 @@ class Helper extends DHelper implements IHelper
".$this->getParentIdFieldName()." = '0'
OR (
".$this->getParentIdFieldName()." != '0'
- AND ".$this->getLengthFieldName()." < '".SchedulerDate::getDateTimestamp($startDate)."'
+ AND ".$this->getLengthFieldName()." < '".SchedulerHelperDate::getDateTimestamp($startDate)."'
)
)";
@@ -256,10 +256,10 @@ class Helper extends DHelper implements IHelper
for($i = 0; $i < count($recurringDatesStamps); $i++) {
$preparedEventData = $recurringEventData;
$eventStartDateStamp = $recurringDatesStamps[$i];
- $preparedEventData[$this->getStartDateFieldName()] = date(SchedulerDate::FORMAT_DEFAULT, $eventStartDateStamp);
+ $preparedEventData[$this->getStartDateFieldName()] = date(SchedulerHelperDate::FORMAT_DEFAULT, $eventStartDateStamp);
$eventEndDateStamp = $eventStartDateStamp + $recurringEventData[$this->getLengthFieldName()];
- $preparedEventData[$this->getEndDateFieldName()] = date(SchedulerDate::FORMAT_DEFAULT, $eventEndDateStamp);
+ $preparedEventData[$this->getEndDateFieldName()] = date(SchedulerHelperDate::FORMAT_DEFAULT, $eventEndDateStamp);
if(isset($parentRecurringExceptions[$eventStartDateStamp])) {
$eventExceptionData = $parentRecurringExceptions[$eventStartDateStamp];
@@ -288,16 +288,16 @@ class Helper extends DHelper implements IHelper
$recurringEventsExceptions = $this->_getRecurringEventsExceptions();
$recurringEvents = $this->_getRecurringEventsByInterval($startDate, $endDate);
- $intervalStartDateStamp = SchedulerDate::getDateTimestamp($startDate);
- $intervalEndDateStamp = SchedulerDate::getDateTimestamp($endDate);
+ $intervalStartDateStamp = SchedulerHelperDate::getDateTimestamp($startDate);
+ $intervalEndDateStamp = SchedulerHelperDate::getDateTimestamp($endDate);
for($i = 0; $i < count($recurringEvents); $i++) {
$eventData = $recurringEvents[$i];
//Parse recurring data format.
$recurringTypeData = $eventData[$this->getRecurringTypeFieldName()];
- $recurringStartDateStamp = SchedulerDate::getDateTimestamp($eventData[$this->getStartDateFieldName()]);
- $recurringEndDateStamp = SchedulerDate::getDateTimestamp($eventData[$this->getEndDateFieldName()]);
+ $recurringStartDateStamp = SchedulerHelperDate::getDateTimestamp($eventData[$this->getStartDateFieldName()]);
+ $recurringEndDateStamp = SchedulerHelperDate::getDateTimestamp($eventData[$this->getEndDateFieldName()]);
$recurringTypeObj = new RecurringType($recurringTypeData, $recurringStartDateStamp, $recurringEndDateStamp);
//Get recurring dates by parsed format.
@@ -312,8 +312,8 @@ class Helper extends DHelper implements IHelper
$resultData = array();
for($i = 0; $i < count($recurringData); $i++) {
$recurringEvent = $recurringData[$i];
- $recurringStartDateStamp = SchedulerDate::getDateTimestamp($recurringEvent[$this->getStartDateFieldName()]);
- $recurringEndDateStamp = SchedulerDate::getDateTimestamp($recurringEvent[$this->getEndDateFieldName()]);
+ $recurringStartDateStamp = SchedulerHelperDate::getDateTimestamp($recurringEvent[$this->getStartDateFieldName()]);
+ $recurringEndDateStamp = SchedulerHelperDate::getDateTimestamp($recurringEvent[$this->getEndDateFieldName()]);
if(
(($intervalStartDateStamp <= $recurringStartDateStamp) && ($recurringStartDateStamp <= $intervalEndDateStamp))
@@ -385,7 +385,7 @@ class Helper extends DHelper implements IHelper
* @return int
*/
public function getRecurringEndDateStr($recurringType, $startDateStr, $eventLength) {
- $endDateStamp = RecurringType::getRecurringEndDate($recurringType, SchedulerDate::getDateTimestamp($startDateStr), $eventLength);
- return date(SchedulerDate::FORMAT_DEFAULT, $endDateStamp);
+ $endDateStamp = RecurringType::getRecurringEndDate($recurringType, SchedulerHelperDate::getDateTimestamp($startDateStr), $eventLength);
+ return date(SchedulerHelperDate::FORMAT_DEFAULT, $endDateStamp);
}
} \ No newline at end of file
diff --git a/RecurringType.php b/sources/dhtmlx_scheduler_helper/classes/RecurringType.php
index b5ff1de..b9a08af 100644
--- a/RecurringType.php
+++ b/sources/dhtmlx_scheduler_helper/classes/RecurringType.php
@@ -1,5 +1,5 @@
<?php
-namespace Scheduler;
+namespace DHTMLX_Scheduler;
use Exception;
class RecurringType {
@@ -65,7 +65,6 @@ class RecurringType {
$dataFields = array(
self::FLD_REC_TYPE => "each",
self::FLD_REC_TYPE_STEP => "step",
-// self::FLD_WEEK_DAY => "day_of_week",//ToDo: delete.
self::FLD_WEEK_NUMBER => "week_number",
self::FLD_WEEK_DAYS_LIST => "days_of_week",
self::FLD_REPEAT => "repeat"
@@ -236,21 +235,21 @@ class RecurringType {
if($intervalEndDateStamp > $recurringEndDateStamp)
$intervalEndDateStamp = $recurringEndDateStamp;
- $differenceStartDates = SchedulerDate::differenceBetweenDates($intervalStartDateStamp, $recurringStartDateStamp);
- $differenceEndDates = SchedulerDate::differenceBetweenDates($intervalEndDateStamp, $recurringEndDateStamp);
- $dateUnits = SchedulerDate::$DATE_UNITS;
+ $differenceStartDates = SchedulerHelperDate::differenceBetweenDates($intervalStartDateStamp, $recurringStartDateStamp);
+ $differenceEndDates = SchedulerHelperDate::differenceBetweenDates($intervalEndDateStamp, $recurringEndDateStamp);
+ $dateUnits = SchedulerHelperDate::$DATE_UNITS;
//Add years.
- $recurringInterval["start_date_stamp"] = SchedulerDate::addYears($recurringStartDateStamp, $differenceStartDates[$dateUnits["year"]]);
- $recurringInterval["end_date_stamp"] = SchedulerDate::addYears($recurringEndDateStamp, -$differenceEndDates[$dateUnits["year"]]);
+ $recurringInterval["start_date_stamp"] = SchedulerHelperDate::addYears($recurringStartDateStamp, $differenceStartDates[$dateUnits["year"]]);
+ $recurringInterval["end_date_stamp"] = SchedulerHelperDate::addYears($recurringEndDateStamp, -$differenceEndDates[$dateUnits["year"]]);
//If recurring type is "year" then exit, else add months.
if($this->getRecurringTypeValue() == self::REC_TYPE_YEAR)
return $recurringInterval;
//Add months.
- $recurringInterval["start_date_stamp"] = SchedulerDate::addMonths($recurringInterval["start_date_stamp"], $differenceStartDates[$dateUnits["month"]]);
- $recurringInterval["end_date_stamp"] = SchedulerDate::addMonths($recurringInterval["end_date_stamp"], -$differenceEndDates[$dateUnits["month"]]);
+ $recurringInterval["start_date_stamp"] = SchedulerHelperDate::addMonths($recurringInterval["start_date_stamp"], $differenceStartDates[$dateUnits["month"]]);
+ $recurringInterval["end_date_stamp"] = SchedulerHelperDate::addMonths($recurringInterval["end_date_stamp"], -$differenceEndDates[$dateUnits["month"]]);
return $recurringInterval;
}
@@ -262,9 +261,9 @@ class RecurringType {
*/
private function _getRecurringDayStep($dateStamp, $recurringWeekDay)
{
- $weekDay = SchedulerDate::getDayOfWeek($dateStamp);
+ $weekDay = SchedulerHelperDate::getDayOfWeek($dateStamp);
$dayStep = $recurringWeekDay - $weekDay;
- $dayStep = ($dayStep < 0) ? (SchedulerDate::DAYS_IN_WEEK - (-$dayStep)) : $dayStep;
+ $dayStep = ($dayStep < 0) ? (SchedulerHelperDate::DAYS_IN_WEEK - (-$dayStep)) : $dayStep;
return $dayStep;
}
@@ -282,14 +281,14 @@ class RecurringType {
if($recurringWeekDays) {
for($i = 0; $i < count($recurringWeekDays); $i++) {
$dayStep = $this->_getRecurringDayStep($dateStamp, $recurringWeekDays[$i]);
- array_push($recurringDays, SchedulerDate::addDays($dateStamp, $dayStep));
+ array_push($recurringDays, SchedulerHelperDate::addDays($dateStamp, $dayStep));
}
}
//Else if recurring type has day of week and step for it, then get this day.
elseif($this->getWeekDayValue() && $this->getWeekNumberValue()) {
$dayStep = $this->_getRecurringDayStep($dateStamp, $this->getWeekDayValue());
- $dayStep += (SchedulerDate::DAYS_IN_WEEK * ($this->getWeekNumberValue() - 1));
- array_push($recurringDays, SchedulerDate::addDays($dateStamp, $dayStep));
+ $dayStep += (SchedulerHelperDate::DAYS_IN_WEEK * ($this->getWeekNumberValue() - 1));
+ array_push($recurringDays, SchedulerHelperDate::addDays($dateStamp, $dayStep));
}
//Else return recurring date without change.
else
@@ -333,19 +332,19 @@ class RecurringType {
$recurringTypeStep = $this->getRecurringTypeStepValue();
switch($this->getRecurringTypeValue()) {
case self::REC_TYPE_DAY:
- $currentRecurringStartDateStamp = SchedulerDate::addDays($currentRecurringStartDateStamp, $recurringTypeStep);
+ $currentRecurringStartDateStamp = SchedulerHelperDate::addDays($currentRecurringStartDateStamp, $recurringTypeStep);
break;
case self::REC_TYPE_WEEK:
- $currentRecurringStartDateStamp = SchedulerDate::addWeeks($currentRecurringStartDateStamp, $recurringTypeStep);
+ $currentRecurringStartDateStamp = SchedulerHelperDate::addWeeks($currentRecurringStartDateStamp, $recurringTypeStep);
break;
case self::REC_TYPE_MONTH:
- $currentRecurringStartDateStamp = SchedulerDate::addMonths($currentRecurringStartDateStamp, $recurringTypeStep);
+ $currentRecurringStartDateStamp = SchedulerHelperDate::addMonths($currentRecurringStartDateStamp, $recurringTypeStep);
break;
case self::REC_TYPE_YEAR:
- $currentRecurringStartDateStamp = SchedulerDate::addYears($currentRecurringStartDateStamp, $recurringTypeStep);
+ $currentRecurringStartDateStamp = SchedulerHelperDate::addYears($currentRecurringStartDateStamp, $recurringTypeStep);
break;
}
}
@@ -380,4 +379,4 @@ class RecurringType {
return $maxEndDateStamp;
}
-} \ No newline at end of file
+}
diff --git a/SchedulerHelperConnector.php b/sources/dhtmlx_scheduler_helper/classes/SchedulerHelperConnector.php
index 88e8203..2584bfb 100644
--- a/SchedulerHelperConnector.php
+++ b/sources/dhtmlx_scheduler_helper/classes/SchedulerHelperConnector.php
@@ -1,9 +1,9 @@
<?php
-namespace Scheduler;
+namespace DHTMLX_Scheduler;
use PDO, Exception;
-class Connector
+class SchedulerHelperConnector
{
private $_dbsm, $_host, $_db_name, $_user, $_password, $_table_name;
private $_PDO;
diff --git a/SchedulerDate.php b/sources/dhtmlx_scheduler_helper/classes/SchedulerHelperDate.php
index 52d342f..827e896 100644
--- a/SchedulerDate.php
+++ b/sources/dhtmlx_scheduler_helper/classes/SchedulerHelperDate.php
@@ -1,14 +1,9 @@
<?php
-namespace Scheduler;
+namespace DHTMLX_Scheduler;
use DateTime;
-interface ISchedulerDate
-{
- static public function getDateTimestamp($date);
-}
-
-class SchedulerDate implements ISchedulerDate
+class SchedulerHelperDate
{
const SECONDS_IN_DAY = 86400;
const DAYS_IN_WEEK = 7;