Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AdjustNode
  • ConfigOperation
  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • ExportBlock
  • ExportOperation
  • Helpers
  • Hooks
  • ImportOperation
  • ManageBlock
  • Model
  • Module
  • Node
  • OfflineOperation
  • OnlineOperation
  • PopNode
  • QueryOperationOperation
  • SaveOperation
  • TitleSlugCombo
  • Update20131208
  • Update20140405
  • ViewProvider

Functions

  • slugize
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Nodes;
 13 
 14 use ICanBoogie\ActiveRecord\Query;
 15 use ICanBoogie\Event;
 16 use ICanBoogie\Exception;
 17 use ICanBoogie\HTTP\HTTPError;
 18 use ICanBoogie\HTTP\NotFound;
 19 
 20 class ViewProvider extends \Icybee\Modules\Views\ActiveRecordProvider
 21 {
 22     /**
 23      * @throws a HTTPException with code 404 if no record matching the conditions could be found
 24      * and the view is of type "view".
 25      *
 26      * @throws a HTTPException with code 401 if the record is offline and user don't have access
 27      * permission and the view is of type "view".
 28      */
 29     public function __invoke()
 30     {
 31         global $core;
 32 
 33         $rc = parent::__invoke();
 34 
 35         if ($rc instanceof Node)
 36         {
 37             if (!$rc)
 38             {
 39                 throw new NotFound('The requested record was not found.');
 40             }
 41 
 42             if (!$rc->is_online)
 43             {
 44                 if (!$core->user->has_permission(\ICanBoogie\Module::PERMISSION_ACCESS, $rc->constructor))
 45                 {
 46                     throw new HTTPError('The requested record requires authentication.', 401);
 47                 }
 48 
 49                 $rc->title .= ' ✎';
 50             }
 51 
 52             $page = isset($core->request->context->page) ? $core->request->context->page : null;
 53 
 54             if ($page)
 55             {
 56                 $page->title = $rc->title;
 57 
 58                 if ($this->view->type == 'view')
 59                 {
 60                     $page->node = $rc;
 61                 }
 62             }
 63         }
 64 
 65         return $rc;
 66     }
 67 
 68     /**
 69      * Returns the conditions unaltered.
 70      */
 71     protected function alter_conditions(array $conditions)
 72     {
 73         return $conditions;
 74     }
 75 
 76     /**
 77      * Alters the query to search for records from the same constructor, a similar site and a
 78      * similar language.
 79      *
 80      * The method also alters the query if the `nid` or `slug` conditions are defined.
 81      *
 82      * Finaly if the return type is RETURN_MANY the query is altered to search for online nodes
 83      * only.
 84      */
 85     protected function alter_query(Query $query, array $conditions)
 86     {
 87         $query->own->similar_site->similar_language;
 88 
 89         if (isset($conditions['nid']))
 90         {
 91             $query->filter_by_nid($conditions['nid']);
 92         }
 93         else if (isset($conditions['slug']))
 94         {
 95             $query->filter_by_slug($conditions['slug']);
 96         }
 97 
 98         if ($this->returns == self::RETURNS_MANY)
 99         {
100             $query->filter_by_is_online(true);
101         }
102 
103         return parent::alter_query($query, $conditions)->order('created_at DESC');
104     }
105 
106     /**
107      * Returns the rendering context unaltered.
108      */
109     protected function alter_context(\BlueTihi\Context $context, Query $query, array $conditions)
110     {
111         return $context;
112     }
113 }
Autodoc API documentation generated by ApiGen 2.8.0