当前位置: 首页>>代码示例>>PHP>>正文


PHP Tinebase_DateTime::compare方法代码示例

本文整理汇总了PHP中Tinebase_DateTime::compare方法的典型用法代码示例。如果您正苦于以下问题:PHP Tinebase_DateTime::compare方法的具体用法?PHP Tinebase_DateTime::compare怎么用?PHP Tinebase_DateTime::compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tinebase_DateTime的用法示例。


在下文中一共展示了Tinebase_DateTime::compare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _checkDeadline

 /**
  * checks deadline of record
  * 
  * @param Timetracker_Model_Timesheet $_record
  * @param boolean $_throwException
  * @return void
  * @throws Timetracker_Exception_Deadline
  */
 protected function _checkDeadline(Timetracker_Model_Timesheet $_record, $_throwException = TRUE)
 {
     // get timeaccount
     $timeaccount = Timetracker_Controller_Timeaccount::getInstance()->get($_record->timeaccount_id);
     if (isset($timeaccount->deadline) && $timeaccount->deadline == Timetracker_Model_Timeaccount::DEADLINE_LASTWEEK) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Check if deadline is exceeded for timeaccount ' . $timeaccount->title);
         }
         // it is only on monday allowed to add timesheets for last week
         $date = new Tinebase_DateTime();
         $date->setTime(0, 0, 0);
         $dayOfWeek = $date->get('w');
         if ($dayOfWeek >= 2) {
             // only allow to add ts for this week
             $date->sub($dayOfWeek, Tinebase_DateTime::MODIFIER_DAY);
         } else {
             // only allow to add ts for last week
             $date->sub($dayOfWeek + 7, Tinebase_DateTime::MODIFIER_DAY);
         }
         // convert start date to Tinebase_DateTime
         $startDate = new Tinebase_DateTime($_record->start_date);
         if ($date->compare($startDate) >= 0) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deadline exceeded: ' . $startDate . ' < ' . $date);
             }
             if ($this->checkRight(Timetracker_Acl_Rights::MANAGE_TIMEACCOUNTS, FALSE) || Timetracker_Model_TimeaccountGrants::hasGrant($_record->timeaccount_id, Tinebase_Model_Grants::GRANT_ADMIN)) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' User with admin / manage all rights is allowed to save Timesheet even if it exceeds the deadline.');
                 }
             } else {
                 if ($_throwException) {
                     throw new Timetracker_Exception_Deadline();
                 }
             }
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Valid date: ' . $startDate . ' >= ' . $date);
             }
         }
     }
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:49,代码来源:Timesheet.php

示例2: diff

 /**
  * returns a Tinebase_Record_Diff record with differences to the given record
  * 
  * @param Tinebase_Record_Interface $_record record for comparison
  * @param array $omitFields omit fields (for example modlog fields)
  * @return Tinebase_Record_Diff|NULL
  */
 public function diff($_record, $omitFields = array())
 {
     if (!$_record instanceof Tinebase_Record_Abstract) {
         return $_record;
     }
     $result = new Tinebase_Record_Diff(array('id' => $this->getId(), 'model' => get_class($_record)));
     $diff = array();
     foreach (array_keys($this->_validators) as $fieldName) {
         if (in_array($fieldName, $omitFields)) {
             continue;
         }
         $ownField = $this->__get($fieldName);
         $recordField = $_record->{$fieldName};
         if ($fieldName == 'customfields' && is_array($ownField) && is_array($recordField)) {
             // special handling for customfields, remove empty customfields from array
             foreach (array_keys($recordField, '', true) as $key) {
                 unset($recordField[$key]);
             }
             foreach (array_keys($ownField, '', true) as $key) {
                 unset($ownField[$key]);
             }
         }
         if (in_array($fieldName, $this->_datetimeFields)) {
             if ($ownField instanceof DateTime && $recordField instanceof DateTime) {
                 /** @var Tinebase_DateTime $recordField */
                 if (!$ownField instanceof Tinebase_DateTime) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Convert ' . $fieldName . ' to Tinebase_DateTime to make sure we have the compare() method');
                     }
                     $ownField = new Tinebase_DateTime($ownField);
                 }
                 if ($ownField->compare($recordField) === 0) {
                     continue;
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' datetime for field ' . $fieldName . ' is not equal: ' . $ownField->getIso() . ' != ' . $recordField->getIso());
                     }
                 }
             } else {
                 if (!$recordField instanceof DateTime && $ownField == $recordField) {
                     continue;
                 }
             }
         } else {
             if ($fieldName == $this->_identifier && $this->getId() == $_record->getId()) {
                 continue;
             } else {
                 if ($ownField instanceof Tinebase_Record_Abstract || $ownField instanceof Tinebase_Record_RecordSet) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Doing subdiff for field ' . $fieldName);
                     }
                     $subdiff = $ownField->diff($recordField);
                     if (is_object($subdiff) && !$subdiff->isEmpty()) {
                         $diff[$fieldName] = $subdiff;
                     }
                     continue;
                 } else {
                     if ($recordField instanceof Tinebase_Record_Abstract && is_scalar($ownField)) {
                         // maybe we have the id of the record -> just compare the id
                         if ($recordField->getId() == $ownField) {
                             continue;
                         } else {
                             $recordField = $recordField->getId();
                         }
                     } else {
                         if ($ownField == $recordField) {
                             continue;
                         } else {
                             if (empty($ownField) && empty($recordField)) {
                                 continue;
                             } else {
                                 if (empty($ownField) && $recordField instanceof Tinebase_Record_RecordSet && count($recordField) == 0 || empty($recordField) && $ownField instanceof Tinebase_Record_RecordSet && count($ownField) == 0) {
                                     continue;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Found diff for ' . $fieldName . '(this/other):' . print_r($ownField, true) . '/' . print_r($recordField, true));
         }
         $diff[$fieldName] = $recordField;
     }
     $result->diff = $diff;
     return $result;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:95,代码来源:Abstract.php


注:本文中的Tinebase_DateTime::compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。