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 Brickrouge\Element;
 15 
 16 class PopNode extends \Brickrouge\Widget
 17 {
 18     const T_CONSTRUCTOR = '#popnode-constructor';
 19 
 20     static protected function add_assets(\Brickrouge\Document $document)
 21     {
 22         parent::add_assets($document);
 23 
 24         $document->css->add(DIR . 'public/module.css');
 25         $document->js->add(DIR . 'public/module.js');
 26     }
 27 
 28     public function __construct(array $attributes=[])
 29     {
 30         parent::__construct('div', $attributes + [
 31 
 32             self::T_CONSTRUCTOR => 'nodes',
 33 
 34             'placeholder' => 'Sélectionner un enregistrement',
 35             'class' => 'spinner',
 36             'data-adjust' => 'adjust-node',
 37             'tabindex' => 0
 38 
 39         ]);
 40     }
 41 
 42     protected function alter_dataset(array $dataset)
 43     {
 44         return parent::alter_dataset($dataset + [
 45 
 46             'constructor' => $this[self::T_CONSTRUCTOR],
 47             'placeholder' => $this['placeholder']
 48 
 49         ]);
 50     }
 51 
 52     protected function render_inner_html()
 53     {
 54         global $core;
 55 
 56         $rc = parent::render_inner_html();
 57 
 58         $constructor = $this[self::T_CONSTRUCTOR];
 59         $value = $this['value'] ?: $this[self::DEFAULT_VALUE];
 60         $record = null;
 61 
 62         if ($value)
 63         {
 64             $model = $core->models[$constructor];
 65 
 66             try
 67             {
 68                 $record = is_numeric($value) ? $model[$value] : $this->getEntry($model, $value);
 69             }
 70             catch (\Exception $e)
 71             {
 72                 \ICanBoogie\log_error('Missing record %nid', [ '%nid' => $value ]);
 73             }
 74         }
 75 
 76         if (!$record)
 77         {
 78             $this->add_class('placeholder');
 79             $value = null;
 80         }
 81 
 82         $rc .= new Element('input', [ 'type' => 'hidden', 'name' => $this['name'], 'value' => $value ]);
 83 
 84         $placeholder = $this['placeholder'];
 85 
 86         if ($placeholder)
 87         {
 88             $rc .= '<em class="spinner-placeholder">' . \ICanBoogie\escape($placeholder) . '</em>';
 89         }
 90 
 91         $rc .= '<span class="spinner-content">' . $this->getPreview($record) . '</span>';
 92 
 93         return $rc;
 94     }
 95 
 96     protected function getEntry($model, $value)
 97     {
 98         return $model->where('title = ? OR slug = ?', $value, $value)->order('created_at DESC')->one;
 99     }
100 
101     protected function getPreview($entry)
102     {
103         if (!$entry)
104         {
105             return '';
106         }
107 
108         $title = $entry->title;
109         $label = \ICanBoogie\shorten($title, 32, .75, $shortened);
110 
111         $rc  = '<span class="title"' . ($shortened ? ' title="' . \Brickrouge\escape($title) . '"' : '') . '>';
112         $rc .= \Brickrouge\escape($label) . '</span>';
113 
114         return $rc;
115     }
116 }
Autodoc API documentation generated by ApiGen 2.8.0