예제 #1
0
 /**
  * @brief Returns the last modified time of the record.
  *
  * @return long Unix timestamp marking the last time the record was modified.
  *
  * @since 0.8
  *
  * @section Synopsis
  *
  * This method will first check to see if the delegate class implements a method
  * named getLastModified() and return its result.  If none can be found it will 
  * attempt to guess which field is used to store the last modified date 
  * (based on the Dataface_Table::getLastUpdatedField() method).  Otherwise it will
  * simply return 0.
  *
  * This method is used throughout Xataface to mark the modification times of records.
  *
  * @see http://www.xataface.com/wiki/Delegate_class_methods
  * @see http://xataface.com/documentation/tutorial/getting_started/delegate_classes
  * @see Dataface_Table::getLastUpdatedField()
  */
 function getLastModified()
 {
     if ($res = $this->callDelegateFunction('getLastModified')) {
         return $res;
     } else {
         if ($lastModifiedField = $this->_table->getLastUpdatedField()) {
             if (strcasecmp($this->_table->getType($lastModifiedField), 'timestamp') === 0) {
                 $date = $this->val($lastModifiedField);
                 return strtotime($date['year'] . '-' . $date['month'] . '-' . $date['day'] . ' ' . $date['hours'] . ':' . $date['minutes'] . ':' . $date['seconds']);
             }
             $strtime = $this->strval($lastModifiedField);
             if ($strtime) {
                 return strtotime($strtime);
             }
         }
     }
     if (!isset($this->pouch['__mtime'])) {
         $sql = "select mtime from dataface__record_mtimes where recordhash='" . addslashes(md5($this->getId())) . "'";
         try {
             try {
                 $res = df_q($sql);
             } catch (Exception $ex) {
                 Dataface_IO::createRecordMtimes();
                 $res = df_q($sql);
             }
             list($mtime) = xf_db_fetch_row($res);
             @xf_db_free_result($res);
             $this->pouch['__mtime'] = intval($mtime);
         } catch (Exception $ex) {
             error_log("Failed SQL query {$sql}");
             $this->pouch['__mtime'] = 0;
         }
     }
     return $this->pouch['__mtime'];
 }