Source for file private.php

Documentation is available at private.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.  * craeted by the currently logged in user only.
  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.         $createdField $table->getColumnAlias('created_by');
  39.  
  40.         // Make sure the access field actually exists
  41.         if (!in_array($createdField$table->getKnownFields()))
  42.         {
  43.             return;
  44.         }
  45.  
  46.         // Get the current user's id
  47.         $user_id FOFPlatform::getInstance()->getUser()->id;
  48.  
  49.         // And filter the query output by the user id
  50.         $db JFactory::getDbo();
  51.  
  52.         $alias $model->getTableAlias();
  53.         $alias $alias $alias '.' '';
  54.  
  55.         $query->where($alias $db->qn($createdField' = ' $db->q($user_id));
  56.     }
  57.  
  58.     /**
  59.      * The event runs after FOFModel has called FOFTable and retrieved a single
  60.      * item from the database. It is used to apply automatic filters.
  61.      *
  62.      * @param   FOFModel  &$model   The model which was called
  63.      * @param   FOFTable  &$record  The record loaded from the databae
  64.      *
  65.      * @return  void 
  66.      */
  67.     public function onAfterGetItem(&$model&$record)
  68.     {
  69.         if ($record instanceof FOFTable)
  70.         {
  71.             $fieldName $record->getColumnAlias('created_by');
  72.  
  73.             // Make sure the field actually exists
  74.             if (!in_array($fieldName$record->getKnownFields()))
  75.             {
  76.                 return;
  77.             }
  78.  
  79.             $user_id FOFPlatform::getInstance()->getUser()->id;
  80.  
  81.             if ($record->$fieldName != $user_id)
  82.             {
  83.                 $record null;
  84.             }
  85.         }
  86.     }
  87. }

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