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

  • Comment
  • ConfigBlock
  • ConfigOperation
  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • Hooks
  • ManageBlock
  • Model
  • Module
  • PatchOperation
  • PreviewOperation
  • SaveOperation
  • SubmitForm
  • Update20131208
  • ViewProvider
  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\Comments;
 13 
 14 use ICanBoogie\ActiveRecord;
 15 use ICanBoogie\ActiveRecord\Query;
 16 use ICanBoogie\DateTime;
 17 
 18 /**
 19  * Comments model.
 20  */
 21 class Model extends ActiveRecord\Model
 22 {
 23     /**
 24      * Adds the `status` and `notify` properties if they are not defined, they default to
 25      * `pending` and `no`.
 26      *
 27      * @throws \InvalidArgumentException if the value of the `notify` property is not one of `no`,
 28      * `yes`, `author` or `done`.
 29      */
 30     public function save(array $properties, $key=null, array $options=array())
 31     {
 32         if (!$key && empty($properties[Comment::CREATED_AT]))
 33         {
 34             $properties[Comment::CREATED_AT] = DateTime::now();
 35         }
 36 
 37         $properties += array
 38         (
 39             Comment::STATUS => 'pending',
 40             Comment::NOTIFY => 'no',
 41             Comment::UPDATED_AT => DateTime::now()
 42         );
 43 
 44         if (!in_array($properties[Comment::NOTIFY], array('no', 'yes', 'author', 'done')))
 45         {
 46             throw new \InvalidArgumentException(\ICanBoogie\format
 47             (
 48                 'Invalid value for property %property: %value', array
 49                 (
 50                     '%property' => Comment::NOTIFY,
 51                     '%value' => $properties[Comment::NOTIFY]
 52                 )
 53             ));
 54         }
 55 
 56         return parent::save($properties, $key, $options);
 57     }
 58 
 59     /**
 60      * Adds a condition on the `status` field, which should equal {@link Comment::STATUS_APPROVED}.
 61      *
 62      * @param Query $query
 63      *
 64      * @return Query
 65      */
 66     protected function scope_approved(Query $query)
 67     {
 68         return $query->filter_by_status(Comment::STATUS_APPROVED);
 69     }
 70 
 71     /**
 72      * Adds a condition on the `status` field, which should equal {@link Comment::STATUS_PENDING}.
 73      *
 74      * @param Query $query
 75      *
 76      * @return Query
 77      */
 78     protected function scope_pending(Query $query)
 79     {
 80         return $query->filter_by_status(Comment::STATUS_PENDING);
 81     }
 82 
 83     /**
 84      * Adds a condition on the `status` field, which should equal {@link Comment::STATUS_SPAM}.
 85      *
 86      * @param Query $query
 87      *
 88      * @return Query
 89      */
 90     protected function scope_spam(Query $query, $approved=true)
 91     {
 92         return $query->filter_by_status(Comment::STATUS_SPAM);
 93     }
 94 
 95     /**
 96      * Finds the nodes the records belong to.
 97      *
 98      * The `node` property of the records is set to the node they belong to.
 99      *
100      * @param array $records
101      *
102      * @return array
103      */
104     public function including_node(array $records)
105     {
106         $keys = array();
107 
108         foreach ($records as $record)
109         {
110             $keys[$record->nid] = $record;
111         }
112 
113         $nodes = ActiveRecord\get_model('nodes')->find_using_constructor(array_keys($keys));
114 
115         foreach ($nodes as $key => $node)
116         {
117             $keys[$key]->node = $node;
118         }
119 
120         return $records;
121     }
122 }
Autodoc API documentation generated by ApiGen 2.8.0