Source for file enabled.php

Documentation is available at enabled.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.  * that are enabled.
  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 enabled field
  37.         $table $model->getTable();
  38.         $enabledField $table->getColumnAlias('enabled');
  39.  
  40.         // Make sure the field actually exists
  41.         if (!in_array($enabledField$table->getKnownFields()))
  42.         {
  43.             return;
  44.         }
  45.  
  46.         // Filter by enabled fields only
  47.         $db JFactory::getDbo();
  48.         $query->where($db->qn($enabledField' = ' $db->q(1));
  49.     }
  50.  
  51.     /**
  52.      * The event runs after FOFModel has called FOFTable and retrieved a single
  53.      * item from the database. It is used to apply automatic filters.
  54.      *
  55.      * @param   FOFModel  &$model   The model which was called
  56.      * @param   FOFTable  &$record  The record loaded from the databae
  57.      *
  58.      * @return  void 
  59.      */
  60.     public function onAfterGetItem(&$model&$record)
  61.     {
  62.         if ($record instanceof FOFTable)
  63.         {
  64.             $fieldName $record->getColumnAlias('enabled');
  65.  
  66.             // Make sure the field actually exists
  67.             if (!in_array($fieldName$record->getKnownFields()))
  68.             {
  69.                 return;
  70.             }
  71.  
  72.             if ($record->$fieldName != 1)
  73.             {
  74.                 $record null;
  75.             }
  76.         }
  77.     }
  78. }

Documentation generated on Tue, 19 Nov 2013 15:02:29 +0100 by phpDocumentor 1.4.3