本文整理汇总了PHP中CakeTime::fromString方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeTime::fromString方法的具体用法?PHP CakeTime::fromString怎么用?PHP CakeTime::fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeTime
的用法示例。
在下文中一共展示了CakeTime::fromString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ageFromBirthdate
/**
* Calculates the current age of someone born on $birthdate.
* Source: stackoverflow.com/questions/3776682/php-calculate-age
* @param sing $birthdate The birthdate.
* @return integer The calculated age.
* @access public
* @static
*/
public static function ageFromBirthdate($birthdate)
{
// convert to format: YYYY-MM-DD
$clean_birthdate = date('Y-m-d', CakeTime::fromString($birthdate));
if (CakeTime::isFuture($clean_birthdate)) {
throw new OutOfRangeException("Birthdate is in the future: {$clean_birthdate}", BedrockTime::EXCEPTION_CODE_FUTURE_BIRTHDATE);
}
//explode the date to get month, day and year
$parts = explode('-', $clean_birthdate);
//get age from date or birthdate
$age = intval(date('md', date('U', mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]))) > date('md') ? date('Y') - $parts[0] - 1 : date('Y') - $parts[0]);
return $age;
}
示例2: checkFutureDate
/**
* checkFutureDate
* Custom Validation Rule: Ensures a selected date is either the
* present day or in the future.
*
* @param array $check Contains the value passed from the view to be validated
* @return bool True if in the past or today, False otherwise
*/
public function checkFutureDate($check)
{
$value = array_values($check);
return CakeTime::fromString($this->data[$this->alias]['document_date']) <= CakeTime::fromString($value[0]);
}
示例3: _validate
protected function _validate()
{
$now = time();
$data = $this->request->data;
$this->Provider->isOK = false;
// Check consumer key
if (empty($data['oauth_consumer_key'])) {
return $this->Provider->reason = 'Missing consumer key.';
}
// Check all required launch parameters
if (empty($data['lti_message_type']) or !array_key_exists($data['lti_message_type'], $this->Provider->messageTypes)) {
return $this->Provider->reason = 'Invalid or missing lti_message_type parameter.';
}
if (empty($data['lti_version']) or !in_array($data['lti_version'], $this->Provider->LTI_VERSIONS)) {
return $this->Provider->reason = 'Invalid or missing lti_version parameter.';
}
switch ($data['lti_message_type']) {
case 'ContentItemSelectionRequest':
if (empty($data['content_item_return_url']) or !(strlen(trim($data['content_item_return_url'])) > 0)) {
return $this->Provider->reason = 'Missing content_item_return_url parameter.';
}
if (!empty($data['accept_media_types']) and strlen(trim($data['accept_media_types'])) > 0) {
$mediaTypes = array_filter(explode(',', str_replace(' ', '', $data['accept_media_types'])), 'strlen');
$mediaTypes = array_unique($mediaTypes);
}
if (empty($mediaTypes)) {
return $this->Provider->reason = 'No accept_media_types found.';
}
$this->Provider->mediaTypes = $mediaTypes;
if (!empty($data['accept_presentation_document_targets']) and strlen(trim($data['accept_presentation_document_targets'])) > 0) {
$documentTargets = array_filter(explode(',', str_replace(' ', '', $data['accept_presentation_document_targets'])), 'strlen');
$documentTargets = array_unique($documentTargets);
}
if (empty($documentTargets)) {
return $this->Provider->reason = 'Missing or empty accept_presentation_document_targets parameter.';
}
foreach ($documentTargets as $documentTarget) {
if (!in_array($documentTarget, ['embed', 'frame', 'iframe', 'window', 'popup', 'overlay', 'none'])) {
return $this->Provider->reason = 'Invalid value in accept_presentation_document_targets parameter: ' . $documentTarget;
}
}
$this->Provider->documentTargets = $documentTargets;
if (!empty($data['accept_unsigned']) and !in_array($data['accept_unsigned'], ['true', 'false'])) {
return $this->Provider->reason = 'Invalid value for accept_unsigned parameter: ' . $data['accept_unsigned'];
}
if (!empty($data['accept_multiple']) and !in_array($data['accept_multiple'], ['true', 'false'])) {
return $this->Provider->reason = 'Invalid value for accept_multiple parameter: ' . $data['accept_multiple'];
}
if (!empty($data['accept_copy_advice']) and !in_array($data['accept_copy_advice'], ['true', 'false'])) {
return $this->Provider->reason = 'Invalid value for accept_copy_advice parameter: ' . $data['accept_copy_advice'];
}
if (!empty($data['auto_create']) and !in_array($data['auto_create'], ['true', 'false'])) {
return $this->Provider->reason = 'Invalid value for auto_create parameter: ' . $data['auto_create'];
}
if (!empty($data['can_confirm']) and !in_array($data['can_confirm'], ['true', 'false'])) {
return $this->Provider->reason = 'Invalid value for can_confirm parameter: ' . $data['can_confirm'];
}
break;
case 'basic-lti-launch-request':
case 'DashboardRequest':
if (empty($data['resource_link_id']) or !(strlen(trim($data['resource_link_id'])) > 0)) {
return $this->Provider->reason = 'Missing resource link ID.';
}
// fall through
// fall through
default:
if (!empty($data['launch_presentation_document_target']) and !in_array($data['launch_presentation_document_target'], ['embed', 'frame', 'iframe', 'window', 'popup', 'overlay'])) {
return $this->Provider->reason = 'Invalid value for launch_presentation_document_target parameter: ' . $data['launch_presentation_document_target'];
}
break;
}
#
### Get the consumer
#
$this->loadModel('Lti.Consumer');
$this->Consumer->id = $data['oauth_consumer_key'];
$this->Consumer->read();
if (empty($this->Consumer->consumer_key)) {
return $this->Provider->reason = 'Invalid consumer key.';
}
if ($this->Consumer->protect) {
if (empty($data['tool_consumer_instance_guid'])) {
return $this->Provider->reason = 'A tool consumer GUID must be included in the launch request.';
}
if (empty($this->Consumer->consumer_guid) or !($this->Consumer->consumer_guid == $data['tool_consumer_instance_guid'])) {
return $this->Provider->reason = 'Request is from an invalid tool consumer.';
}
}
if (!$this->Consumer->enabled) {
return $this->Provider->reason = 'Tool consumer has not been enabled by the tool provider.';
}
if (!empty($this->Consumer->enable_from) and CakeTime::fromString($this->Consumer->enable_from) > $now) {
return $this->Provider->reason = 'Tool consumer access is not yet available. It will be available from ' . $this->Consumer->enable_from;
}
if (!empty($this->Consumer->enable_until) and CakeTime::fromString($this->Consumer->enable_until) <= $now) {
return $this->Provider->reason = 'Tool consumer access expired on ' . $this->Consumer->enable_until;
}
#
### Validate message parameter constraints
#
//.........这里部分代码省略.........
示例4: checkPastDate
/**
* checkPastDate
* Custom Validation Rule: Ensures a selected date is either the
* present day or in the past.
*
* @param array $check Contains the value passed from the view to be validated
* @return bool True if in the past or today, False otherwise
*/
public function checkPastDate($check)
{
$value = array_values($check);
return CakeTime::fromString($value[0]) <= CakeTime::fromString(date(Configure::read('databaseDateFormat')));
}
示例5: compareDates
function compareDates($data)
{
return CakeTime::fromString($data['close_date']) > CakeTime::fromString($this->data[$this->alias]['open_date']);
}
示例6: checkPastDate
/**
* checkPastDate
* Custom Validation Rule: Ensures a selected date is either the
* present day or in the past.
*
* @param array $check Contains the value passed from the view to be validated
* @return bool True if in the past or today, False otherwise
*/
public function checkPastDate($check)
{
$value = array_values($check);
return CakeTime::fromString($value['0']) <= CakeTime::fromString(date('Y-m-d'));
}
示例7: fromString
/**
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
*
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
*
* @return string Parsed timestamp
* @see CakeTime::fromString()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function fromString($dateString, $timezone = NULL)
{
return $this->_engine->fromString($dateString, $timezone);
}
示例8: checkPastDate
/**
* checkPastDate
* Custom Validation Rule: Ensures a selected date is either the
* present day or in the past.
*
* @param array $check Contains the value passed from the view to be validated
* @return bool True if in the past or today, False otherwise
*/
public function checkPastDate($data, $key)
{
return CakeTime::fromString($data[$key]) <= CakeTime::fromString(date(Configure::read('databaseDateFormat')));
}
示例9: analysis
//.........这里部分代码省略.........
$this->Session->setFlash("Your predictions are being processed, we will send you an email when the analysis finish", 'success');
return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis'));
}
} else {
if (isset($this->request->data['Participant']['results_File']['size']) && $this->request->data['Participant']['results_File']['size'] > 0) {
if ($this->request->data['Participant']['results_File']['size'] > $this->filesize2bytes(Configure::read('max_file_size'))) {
$this->Session->setFlash("The file can not be more than " . Configure::read('max_file_size'));
return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis'));
}
/* ============================================= */
/* =====================Results================= */
/* ============================================= */
$file = new File($this->request->data['Participant']['results_File']['tmp_name']);
if ($file->readable()) {
$content = $file->read();
$file->close();
$content = $this->decrypt($content);
$results = json_decode(trim($content), true);
// debug($results);
if (!empty($results)) {
$projects = $this->getParticipantProjects($email, $code, $results['project_id']);
if (!empty($projects)) {
$goldenSet = $this->Participant->GoldenProject->find('first', array('recursive' => -1, 'fields' => array('user_id', 'round_id'), 'conditions' => array('project_id' => $results['project_id'])));
if (!empty($goldenSet)) {
$isModified = !$this->Participant->PredictionFile->hasAny(array('participant_id' => $results['Participant']['id'], 'modified' => $results['date']));
$results['Participant']['isModified'] = $isModified;
$results['Golden']['user_id'] = $goldenSet['GoldenProject']['user_id'];
$results['Golden']['round_id'] = $goldenSet['GoldenProject']['round_id'];
$this->Session->write("analysisResults", $results);
$this->redirect(array('action' => 'results'));
} else {
$this->Session->setFlash("This golden set have been deleted");
}
} else {
$this->Session->setFlash("This file does not correspond to your credentials");
}
} else {
$this->Session->setFlash("This file is corrupted");
}
} else {
$this->Session->setFlash("This file is corrupted");
}
} else {
if (empty($projects)) {
$this->Session->setFlash("You are not in any project");
} else {
$this->Session->setFlash("One team prediction file or one result file is needed");
}
}
}
} else {
$cookie = $this->Cookie->read('participantData');
if (isset($cookie)) {
if (isset($cookie['email']) && $cookie['code']) {
$this->request->data['Participant']['email'] = $cookie['email'];
$this->request->data['Participant']['code'] = $cookie['code'];
$this->request->data['Participant']['remember_me'] = true;
if (isset($cookie['project_id'])) {
$this->request->data['Project']['Project'] = $cookie['project_id'];
}
$projects = $this->getParticipantProjects($cookie['email'], $cookie['code']);
if (empty($projects)) {
$this->Cookie->destroy('participantData');
}
} else {
$this->Cookie->destroy('participantData');
}
}
$this->loadModel('Post');
$this->Post->recursive = -1;
$this->Post->contain(false, array('User' => array('username', 'surname', 'full_name', 'image', 'image_type', 'id')));
$this->Post->paginate = array('limit' => 5, 'order' => array('modified' => 'DESC'));
$this->set("posts", $this->paginate($this->Post));
}
$this->set('projects', $projects);
App::uses('CakeTime', 'Utility');
$finalDate = Configure::read('final_date_to_upload_tasks');
$startDate = Configure::read('initial_date_to_upload_tasks');
$isEnd = CakeTime::isPast($finalDate);
$isFuture = CakeTime::isFuture($startDate);
$isThisWeek = CakeTime::isThisWeek($finalDate);
$isToday = CakeTime::isTomorrow(CakeTime::fromString($finalDate));
$finalDate = CakeTime::format($finalDate, "%B %e, %Y");
$startDate = CakeTime::format($startDate, "%B %e, %Y");
$this->set('isEnd', $isEnd);
$this->set('isFuture', $isFuture);
$this->set('isThisWeek', $isThisWeek);
$this->set('isToday', $isToday);
$this->set('finalDate', $finalDate);
$this->set('startDate', $startDate);
//// $key = "xVO5JLSLOTpKX4YRyFpJXNYb1STQK26mHAzgNK6bwS697XzK8ZE5kEA8R7gajaI9fE6HfemeLhg28nqbGTmh5Dv5uKydSOoM4BHlQ43mvH4h0Jl3xFDcv95fRnY9wYAluS1WFi9QOLc2JDUOsN3ggNzypHuZcPaAjBklfsNH98qkX5brqEnfMUubPOUCtpTEUmtvVNq2oTGKSArEuSuuKRnMHtlbKvl4XbaAUvSfajF4DtHwLa2qaWU6pNXLHf16";
//// $key = "FFF3454D1E9CCDE00101010101010101";
// $value = "63612bb6b56ef964bc2a6add5e0697deadde735fd4ca966d7b762f61b2b4cb14a14500";
//// $value = base64_decode($value);
//// debug($value);
//// $result = Security::rijndael($value, $key, 'decrypt');
// $result = $this->decrypt($value);
//// $resultE = Security::rijndael($value, $key, 'encrypt');
// $this->set(compact('result', 'resultE'));
}