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

  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • Hooks
  • ManageBlock
  • Model
  • Module
  • SaveOperation
  • ServerName
  • Site
  • StatusOperation
 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\Sites;
13 
14 use ICanBoogie\Errors;
15 use ICanBoogie\I18n\FormattedString;
16 
17 use Icybee\Modules\Sites\Site;
18 
19 /**
20  * Updates the status of a website.
21  */
22 class StatusOperation extends \ICanBoogie\Operation
23 {
24     protected function get_controls()
25     {
26         return array
27         (
28             self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
29         )
30 
31         + parent::get_controls();
32     }
33 
34     protected function validate(Errors $errors)
35     {
36         if ($this->request->is_put)
37         {
38             $status = $this->request['status'];
39 
40             if ($status === null || !in_array($status, array(Site::STATUS_OK, Site::STATUS_UNAVAILABLE, Site::STATUS_UNAUTHORIZED, Site::STATUS_NOT_FOUND)))
41             {
42                 throw new \InvalidArgumentException('Invalid status value.');
43             }
44         }
45 
46         return true;
47     }
48 
49     protected function process()
50     {
51         static $status_names = array
52         (
53             Site::STATUS_OK => 'ok (online)',
54             Site::STATUS_UNAVAILABLE => 'unavailable',
55             Site::STATUS_UNAUTHORIZED => 'unauthorized',
56             Site::STATUS_NOT_FOUND => 'not found (offline)'
57         );
58 
59         if ($this->request->is_put)
60         {
61             $status = $this->request['status'];
62 
63             $record = $this->record;
64             $record->status = $status;
65             $record->save();
66 
67             $this->response->message = new FormattedString('The site %title is now ' . $status_names[$status] . '.', array('title' => $record->title));
68         }
69 
70         return $this->record->status;
71     }
72 }
Autodoc API documentation generated by ApiGen 2.8.0