Source for file access.php

Documentation is available at access.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  model
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. /**
  12.  * FrameworkOnFramework model behavior class to filter front-end access to items
  13.  * based on the viewing access levels.
  14.  *
  15.  * @package  FrameworkOnFramework
  16.  * @since    2.1
  17.  */
  18. {
  19.     /**
  20.      * This event runs after we have built the query used to fetch a record
  21.      * list in a model. It is used to apply automatic query filters.
  22.      *
  23.      * @param   FOFModel        &$model  The model which calls this event
  24.      * @param   JDatabaseQuery  &$query  The model which calls this event
  25.      *
  26.      * @return  void 
  27.      */
  28.     public function onAfterBuildQuery(&$model&$query)
  29.     {
  30.         // This behavior only applies to the front-end.
  31.         if (!FOFPlatform::getInstance()->isFrontend())
  32.         {
  33.             return;
  34.         }
  35.  
  36.         // Get the name of the access field
  37.         $table $model->getTable();
  38.         $accessField $table->getColumnAlias('access');
  39.  
  40.         // Make sure the field actually exists
  41.         if (!in_array($accessField$table->getKnownFields()))
  42.         {
  43.             return;
  44.         }
  45.  
  46.         $model->applyAccessFiltering(null);
  47.     }
  48.  
  49.     /**
  50.      * The event runs after FOFModel has called FOFTable and retrieved a single
  51.      * item from the database. It is used to apply automatic filters.
  52.      *
  53.      * @param   FOFModel  &$model   The model which was called
  54.      * @param   FOFTable  &$record  The record loaded from the databae
  55.      *
  56.      * @return  void 
  57.      */
  58.     public function onAfterGetItem(&$model&$record)
  59.     {
  60.         if ($record instanceof FOFTable)
  61.         {
  62.             $fieldName $record->getColumnAlias('access');
  63.  
  64.             // Make sure the field actually exists
  65.             if (!in_array($fieldName$record->getKnownFields()))
  66.             {
  67.                 return;
  68.             }
  69.  
  70.             // Get the user
  71.             $user FOFPlatform::getInstance()->getUser();
  72.  
  73.             // Filter by authorised access levels
  74.             if (!in_array($record->$fieldName$user->getAuthorisedViewLevels()))
  75.             {
  76.                 $record null;
  77.             }
  78.         }
  79.     }
  80. }

Documentation generated on Tue, 19 Nov 2013 14:53:15 +0100 by phpDocumentor 1.4.3