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

  • AdjustImage
  • AdjustThumbnail
  • EditBlock
  • GalleryBlock
  • GalleryController
  • Hooks
  • Image
  • ImageUpload
  • ManageBlock
  • Model
  • Module
  • NodeRelation
  • PopImage
  • PopOrUploadImage
  • SaveOperation
  • Thumbnail
  • ThumbnailDecorator
  • ThumbnailOperation
  • UploadImage
  • UploadOperation
 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\Images;
13 
14 use ICanBoogie\ActiveRecord;
15 use ICanBoogie\ActiveRecord\RecordNotFound;
16 
17 class Model extends \Icybee\Modules\Files\Model
18 {
19     static protected $accept = [ '.gif', '.png', '.jpg', '.jpeg' ];
20 
21     public function save(array $properties, $key=null, array $options=[])
22     {
23         if (isset($properties[Image::HTTP_FILE]))
24         {
25             $file = $properties[Image::HTTP_FILE];
26 
27             list($w, $h) = getimagesize($file->pathname);
28 
29             $properties[Image::WIDTH] = $w;
30             $properties[Image::HEIGHT] = $h;
31         }
32 
33         return parent::save($properties, $key, $options + [
34 
35             self::ACCEPT => self::$accept
36 
37         ]);
38     }
39 
40     /**
41      * Includes the images assigned to the records.
42      *
43      * The `image` property of the records is set to the associated image.
44      *
45      * @param array $records The records to alter.
46      *
47      * @return array
48      */
49     public function including_assigned_image(array $records)
50     {
51         $keys = array();
52 
53         foreach ($records as $record)
54         {
55             $keys[] = $record->nid;
56         }
57 
58         if (!$keys)
59         {
60             return $records;
61         }
62 
63         $pairs = ActiveRecord\get_model('registry/node')
64         ->select('targetid, value')
65         ->filter_by_name_and_targetid('image_id', $keys)
66         ->pairs;
67 
68         if (!$pairs)
69         {
70             return $records;
71         }
72 
73         try
74         {
75             $images = $this->find($pairs);
76         }
77         catch (RecordNotFound $e)
78         {
79             $images = $e->records;
80         }
81 
82         foreach ($records as $record)
83         {
84             $nid = $record->nid;
85             $image_key = $pairs[$nid];
86 
87             if (empty($images[$image_key]))
88             {
89                 continue;
90             }
91 
92             $record->image = $images[$image_key];
93         }
94 
95         return $records;
96     }
97 }
Autodoc API documentation generated by ApiGen 2.8.0