Example #1
0
 /**
  * Has the Page (or optionally one of it's fields) changed since it was loaded?
  *
  * Assumes that Pages has turned on this Page's change tracking with a call to setTrackChanges(). 
  * Pages that are new (i.e. don't yet exist in the DB) always return true. 
  * 
  * @param string $what If specified, only checks the given property for changes rather than the whole page. 
  * @return bool 
  *
  */
 public function isChanged($what = '')
 {
     if ($this->isNew()) {
         return true;
     }
     if (parent::isChanged($what)) {
         return true;
     }
     $changed = false;
     if ($what) {
         $value = $this->get($what);
         if (is_object($value) && $value instanceof Wire) {
             $changed = $value->isChanged();
         }
     } else {
         foreach ($this->data as $key => $value) {
             if (is_object($value) && $value instanceof Wire) {
                 $changed = $value->isChanged();
             }
             if ($changed) {
                 break;
             }
         }
     }
     return $changed;
 }