コード例 #1
0
ファイル: TagController.php プロジェクト: alphadevx/alpha
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @throws Alpha\Exception\IllegalArguementException
  * @throws Alpha\Exception\FileNotFoundException
  *
  * @since 1.0
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     $config = ConfigProvider::getInstance();
     $body = '';
     // render the tag manager screen
     if (!isset($params['ActiveRecordType']) && !isset($params['ActiveRecordOID'])) {
         $body .= View::displayPageHead($this);
         $message = $this->getStatusMessage();
         if (!empty($message)) {
             $body .= $message;
         }
         $body .= '<h3>Listing active record which are tagged</h3>';
         $ActiveRecordTypes = ActiveRecord::getBOClassNames();
         foreach ($ActiveRecordTypes as $ActiveRecordType) {
             $record = new $ActiveRecordType();
             if ($record->isTagged()) {
                 $tag = new Tag();
                 $count = count($tag->loadAllByAttribute('taggedClass', $ActiveRecordType));
                 $body .= '<h4>' . $record->getFriendlyClassName() . ' record type is tagged (' . $count . ' tags found)</h4>';
                 $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('clearTaggedClass')) : 'clearTaggedClass';
                 $js = "if(window.jQuery) {\n                        BootstrapDialog.show({\n                            title: 'Confirmation',\n                            message: 'Are you sure you want to delete all tags attached to the " . $record->getFriendlyClassName() . " class, and have them re-created?',\n                            buttons: [\n                                {\n                                    icon: 'glyphicon glyphicon-remove',\n                                    label: 'Cancel',\n                                    cssClass: 'btn btn-default btn-xs',\n                                    action: function(dialogItself){\n                                        dialogItself.close();\n                                    }\n                                },\n                                {\n                                    icon: 'glyphicon glyphicon-ok',\n                                    label: 'Okay',\n                                    cssClass: 'btn btn-default btn-xs',\n                                    action: function(dialogItself) {\n                                        \$('[id=\"" . $fieldname . "\"]').attr('value', '" . addslashes($ActiveRecordType) . "');\n                                        \$('#clearForm').submit();\n                                        dialogItself.close();\n                                    }\n                                }\n                            ]\n                        });\n                    }";
                 $button = new Button($js, 'Re-create tags', 'clearBut' . stripslashes($ActiveRecordType));
                 $body .= $button->render();
             }
         }
         ActiveRecord::disconnect();
         $body .= '<form action="' . $request->getURI() . '" method="POST" id="clearForm">';
         $body .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '"/>';
         $body .= View::renderSecurityFields();
         $body .= '</form>';
     } elseif (isset($params['ActiveRecordType']) && $params['ActiveRecordType'] != 'Alpha\\Model\\Tag' && isset($params['ActiveRecordOID'])) {
         // render screen for managing individual tags on a given active record
         $body .= View::displayPageHead($this);
         $message = $this->getStatusMessage();
         if (!empty($message)) {
             $body .= $message;
         }
         $ActiveRecordType = urldecode($params['ActiveRecordType']);
         $ActiveRecordOID = $params['ActiveRecordOID'];
         if (class_exists($ActiveRecordType)) {
             $record = new $ActiveRecordType();
         } else {
             throw new IllegalArguementException('No ActiveRecord available to display tags for!');
         }
         try {
             $record->load($ActiveRecordOID);
             $tags = $record->getPropObject('tags')->getRelatedObjects();
             ActiveRecord::disconnect();
             $body .= '<form action="' . $request->getURI() . '" method="POST" accept-charset="UTF-8">';
             $body .= '<h3>The following tags were found:</h3>';
             foreach ($tags as $tag) {
                 $labels = $tag->getDataLabels();
                 $temp = new StringBox($tag->getPropObject('content'), $labels['content'], 'content_' . $tag->getID(), '');
                 $body .= $temp->render(false);
                 $js = "if(window.jQuery) {\n                        BootstrapDialog.show({\n                            title: 'Confirmation',\n                            message: 'Are you sure you wish to delete this tag?',\n                            buttons: [\n                                {\n                                    icon: 'glyphicon glyphicon-remove',\n                                    label: 'Cancel',\n                                    cssClass: 'btn btn-default btn-xs',\n                                    action: function(dialogItself){\n                                        dialogItself.close();\n                                    }\n                                },\n                                {\n                                    icon: 'glyphicon glyphicon-ok',\n                                    label: 'Okay',\n                                    cssClass: 'btn btn-default btn-xs',\n                                    action: function(dialogItself) {\n                                        \$('[id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID') . "\"]').attr('value', '" . $tag->getID() . "');\n                                        \$('#deleteForm').submit();\n                                        dialogItself.close();\n                                    }\n                                }\n                            ]\n                        });\n                    }";
                 $button = new Button($js, 'Delete', 'delete' . $tag->getID() . 'But');
                 $body .= $button->render();
             }
             $body .= '<h3>Add a new tag:</h3>';
             $temp = new StringBox(new String(), 'New tag', 'NewTagValue', '');
             $body .= $temp->render(false);
             $temp = new Button('submit', 'Save', 'saveBut');
             $body .= $temp->render();
             $body .= '&nbsp;&nbsp;';
             if ($params['ActiveRecordType'] = 'Alpha\\Model\\Article') {
                 $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ArticleController&ActiveRecordType=' . $params['ActiveRecordType'] . '&ActiveRecordOID=' . $params['ActiveRecordOID'] . '&view=edit') . "'", 'Back to record', 'cancelBut');
             } else {
                 $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $params['ActiveRecordType'] . '&ActiveRecordOID=' . $params['ActiveRecordOID'] . '&view=edit') . "'", 'Back to record', 'cancelBut');
             }
             $body .= $temp->render();
             $body .= View::renderSecurityFields();
             $body .= '</form>';
             $body .= View::renderDeleteForm($request->getURI());
         } catch (RecordNotFoundException $e) {
             $msg = 'Unable to load the ActiveRecord of id [' . $params['ActiveRecordOID'] . '], error was [' . $e->getMessage() . ']';
             self::$logger->error($msg);
             throw new FileNotFoundException($msg);
         }
     } else {
         return parent::doGET($request);
     }
     $body .= View::displayPageFoot($this);
     self::$logger->debug('<<doGET');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }