本文整理汇总了PHP中CommonFunctions::IsValidId方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonFunctions::IsValidId方法的具体用法?PHP CommonFunctions::IsValidId怎么用?PHP CommonFunctions::IsValidId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonFunctions
的用法示例。
在下文中一共展示了CommonFunctions::IsValidId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIsValidId
/**
* Test isValidId() method
*/
public function testIsValidId()
{
$this->assertFalse(CommonFunctions::IsValidId(-1));
$this->assertFalse(CommonFunctions::IsValidId("-1"));
$this->assertTrue(CommonFunctions::IsValidId(0));
$this->assertTrue(CommonFunctions::IsValidId("0"));
$this->assertTrue(CommonFunctions::IsValidId("000"));
$this->assertFalse(CommonFunctions::IsValidId(null));
$this->assertFalse(CommonFunctions::IsValidId(""));
$this->assertFalse(CommonFunctions::IsValidId("asdf"));
$this->assertFalse(CommonFunctions::IsValidId("'-+'"));
$this->assertFalse(CommonFunctions::IsValidId("2.11"));
$this->assertFalse(CommonFunctions::IsValidId("2.00"));
$this->assertFalse(CommonFunctions::IsValidId("0.00"));
$this->assertFalse(CommonFunctions::IsValidId("0.10"));
// Try scientific notation. Shouldn't work
$this->assertFalse(CommonFunctions::IsValidId("2e5"));
// Valid numbers
$this->assertTrue(CommonFunctions::IsValidId(100));
$this->assertTrue(CommonFunctions::IsValidId("100"));
$this->assertTrue(CommonFunctions::IsValidId(3));
$this->assertTrue(CommonFunctions::IsValidId("03"));
$this->assertTrue(CommonFunctions::IsValidId("031"));
// With Prefixes
$this->assertTrue(CommonFunctions::IsValidId('LOC101', 'LOC'));
$this->assertFalse(CommonFunctions::IsValidId('LOC101', 'EMP'));
$this->assertFalse(CommonFunctions::IsValidId('101', 'LOC'));
$this->assertFalse(CommonFunctions::IsValidId('LOCA1', 'LOC'));
$this->assertFalse(CommonFunctions::IsValidId('LOC', 'LOC'));
$this->assertTrue(CommonFunctions::IsValidId('EMP010', 'EMP'));
}
示例2: validateTimeEvent
/**
* Validates the timeevent against the given timesheet.
*
* @param TimeEvent $timeEvent Time event to validate
* @param Timesheet $timesheet Time sheet
* @return mixed true if validate success, error string if not.
*/
public function validateTimeEvent($timeEvent, $timesheet)
{
$eventStartTime = $timeEvent->getStartTime();
$eventEndTime = $timeEvent->getEndTime();
$eventStart = strtotime($eventStartTime);
$eventEnd = strtotime($eventEndTime);
$periodStartDate = $timesheet->getStartDate();
$periodEndDate = $timesheet->getEndDate();
$periodStart = strtotime($periodStartDate);
$periodEnd = strtotime($periodEndDate);
$periodEnd = strtotime("+1 day", $periodEnd);
// strtotime returns false (-1 before php 5.1.0) on error
if (!($periodStart > 0) || !($periodEnd > 0) || $periodStart >= $periodEnd) {
return self::INVALID_TIMESHEET_PERIOD_ERROR;
}
$reportedDate = $timeEvent->getReportedDate();
$reported = strtotime($reportedDate);
$eventId = $timeEvent->getTimeEventId();
$newEvent = empty($eventId);
if (!CommonFunctions::IsValidId($timeEvent->getProjectId())) {
return self::ProjectNotSpecified_ERROR;
}
if (!CommonFunctions::IsValidId($timeEvent->getActivityId())) {
return self::ActivityNotSpecified_ERROR;
}
if (!empty($eventStartTime) && !($eventStart > 0)) {
return self::InvalidStartTime_ERROR;
}
if (!empty($eventEndTime) && !($eventEnd > 0)) {
return self::InvalidEndTime_ERROR;
}
if (empty($reportedDate)) {
return self::ReportedDateNotSpecified_ERROR;
} else {
if (!($reported > 0)) {
return self::InvalidReportedDate_ERROR;
}
}
$duration = $timeEvent->getDuration();
$duration = $duration === "" ? null : $duration;
// 0 not allowed for duration in last row.
if (!is_null($duration) && ($duration < 0 || $newEvent && $duration == 0)) {
return self::InvalidDuration_ERROR;
}
// Validate period/interval
if (empty($eventStartTime) && empty($eventEndTime) && !empty($duration)) {
// reported date + duration
if ($reported < $periodStart || $reported + $duration > $periodEnd) {
return self::EVENT_OUTSIDE_PERIOD_FAILURE;
}
} else {
if (!empty($eventStartTime) && empty($eventEndTime) && is_null($duration)) {
// start time only
if ($eventStart < $periodStart || $eventStart > $periodEnd) {
return self::EVENT_OUTSIDE_PERIOD_FAILURE;
}
} else {
if (!empty($eventStartTime) && !empty($eventEndTime)) {
if (!empty($duration) && $newEvent) {
return self::NotAllowedToSpecifyDurationAndInterval_ERROR;
}
// start and end time
if ($eventStart >= $eventEnd) {
return self::ZeroOrNegativeIntervalSpecified_ERROR;
}
if ($eventStart < $periodStart || $eventEnd > $periodEnd) {
return self::EVENT_OUTSIDE_PERIOD_FAILURE;
}
$timeEvent->setDuration($eventEnd - $eventStart);
} else {
if (!empty($eventStartTime) && !empty($duration) && empty($eventEndTime)) {
// start time and duration
if ($eventStart < $periodStart || $eventStart + $duration > $periodEnd) {
return self::EVENT_OUTSIDE_PERIOD_FAILURE;
}
$timeEvent->setEndTime(date("Y-m-d H:i", $eventStart + $duration));
} else {
return self::NoValidDurationOrInterval_ERROR;
}
}
}
}
return true;
}