/**
  * Overrides xPDOObject::remove to cache the menus.
  *
  * {@inheritdoc}
  */
 public function remove(array $ancestors = array()) {
     $removed = parent::remove($ancestors);
     if ($removed && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
         $this->rebuildCache();
     }
     return $removed;
 }
 /**
  * Custom collection loader that forces access policy checking.
  *
  * {@inheritdoc}
  */
 public static function loadCollection(xPDO &$xpdo, $className, $criteria = null, $cacheFlag = true)
 {
     $objCollection = array();
     if (!($className = $xpdo->loadClass($className))) {
         return $objCollection;
     }
     $rows = false;
     $fromCache = false;
     $collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
     if (!is_object($criteria)) {
         $criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
     }
     if (is_object($criteria)) {
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
             $rows = $xpdo->fromCache($criteria, $className);
             $fromCache = is_array($rows) && !empty($rows);
         }
         if (!$fromCache) {
             $rows = xPDOObject::_loadRows($xpdo, $className, $criteria);
         }
         $cacheRows = array();
         if (is_array($rows)) {
             foreach ($rows as $row) {
                 if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) {
                     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) {
                         $cacheRows[] = $row;
                     }
                 }
             }
         } elseif (is_object($rows)) {
             while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
                 if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) {
                     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) {
                         $cacheRows[] = $row;
                     }
                 }
             }
         }
         if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($cacheRows)) {
             $xpdo->toCache($criteria, $cacheRows, $cacheFlag);
         }
     } else {
         $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'modAccessibleObject::loadCollection() - No valid statement could be found in or generated from the given criteria.');
     }
     return $objCollection;
 }
 /**
  * Custom collection loader that forces access policy checking.
  *
  * {@inheritdoc}
  */
 public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
     $objCollection= array ();
     $fromCache = false;
     if (!$className= $xpdo->loadClass($className)) return $objCollection;
     $rows= false;
     $fromCache= false;
     $collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
     if (!is_object($criteria)) {
         $criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag);
     }
     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
         $rows= $xpdo->fromCache($criteria);
         $fromCache = (is_array($rows) && !empty($rows));
     }
     if (!$fromCache && is_object($criteria)) {
         $rows= xPDOObject :: _loadRows($xpdo, $className, $criteria);
     }
     if (is_array ($rows)) {
         foreach ($rows as $row) {
             modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
         }
     } elseif (is_object($rows)) {
         $cacheRows = array();
         while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
             modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
             if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $cacheRows[] = $row;
         }
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $rows =& $cacheRows;
     }
     if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($rows)) {
         $xpdo->toCache($criteria, $rows, $cacheFlag);
     }
     return $objCollection;
 }
    /**
     * Overrides xPDOObject::save to fire modX-specific events.
     *
     * {@inheritDoc}
     */
    public function save($cacheFlag= null) {
        $isNew = $this->isNew();

        if ($this->xpdo instanceof modX) {
            $this->xpdo->invokeEvent('OnContextBeforeSave',array(
                'context' => &$this,
                'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
                'cacheFlag' => $cacheFlag,
            ));
        }

        $saved = parent :: save($cacheFlag);

        if ($saved && $this->xpdo instanceof modX) {
            $this->xpdo->invokeEvent('OnContextSave',array(
                'context' => &$this,
                'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
                'cacheFlag' => $cacheFlag,
            ));
        }
        return $saved;
    }
 public function checkPolicy($criteria, $targets = null, modUser $user = null)
 {
     return parent::checkPolicy($criteria, $targets, $user);
 }