示例#1
0
 /**
  * Method for fetching all of the comments for this article.
  *
  * @return array An array of ArticleComment objects
  *
  * @since 1.0
  */
 public function getArticleComments()
 {
     $comments = $this->comments->getRelatedObjects();
     return $comments;
 }
示例#2
0
 /**
  * Renders the text boxes and buttons for the widget, that will appear in user forms.
  *
  * @param bool $expanded Render the related fields in expanded format or not (optional)
  * @param bool $buttons  Render buttons for expanding/contacting the related fields (optional)
  *
  * @return string
  *
  * @since 1.0
  */
 public function render($expanded = false, $buttons = true)
 {
     self::$logger->debug('>>render(expanded=[' . $expanded . '], buttons=[' . $buttons . '])');
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name)) : $this->name;
     $html = '';
     // render text-box for many-to-one relations
     if ($this->relationObject->getRelationType() == 'MANY-TO-ONE') {
         // value to appear in the text-box
         $inputBoxValue = $this->relationObject->getRelatedClassDisplayFieldValue();
         $html .= '<div class="form-group">';
         $html .= '<label for="' . $this->name . '_display">' . $this->label . '</label>';
         $html .= '<input type="text" size="70" class="form-control" name="' . $this->name . '_display" id="' . $this->name . '_display" value="' . $inputBoxValue . '" disabled/>';
         $js = " if(window.jQuery) {\n                        window.jQuery.dialog = new BootstrapDialog({\n                            title: 'Please select',\n                            message: 'Loading...',\n                            onshow: function(dialogRef){\n                                dialogRef.getModalBody().load('" . $config->get('app.url') . "/recordselector/12m/'+document.getElementById('" . $fieldname . "').value+'/" . $this->name . '/' . urlencode($this->relationObject->getRelatedClass()) . '/' . $this->relationObject->getRelatedClassField() . '/' . $this->relationObject->getRelatedClassDisplayField() . "');\n                            },\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                        });\n                        window.jQuery.dialog.open();\n                    }";
         $tmp = new Button($js, 'Select', 'relBut', '', 'glyphicon-check');
         $html .= '<div class="centered lower">' . $tmp->render() . '</div>';
         // hidden field to store the actual value of the relation
         $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="' . $this->relationObject->getValue() . '"/>';
         if ($this->relationObject->getRule() != '') {
             $html .= '<input type="hidden" id="' . $fieldname . '_msg" value="' . $this->relationObject->getHelper() . '"/>';
             $html .= '<input type="hidden" id="' . $fieldname . '_rule" value="' . $this->relationObject->getRule() . '"/>';
         }
         $html .= '</div>';
     }
     // render read-only list for one-to-many relations
     if ($this->relationObject->getRelationType() == 'ONE-TO-MANY') {
         $objects = $this->relationObject->getRelatedObjects();
         if (count($objects) > 0) {
             // render tags differently
             if ($this->name == 'tags' && $this->relationObject->getRelatedClass() == 'TagObject') {
                 $html .= '<p><strong>' . $this->label . ':</strong>';
                 foreach ($objects as $tag) {
                     $html .= ' <a href="' . $config->get('app.url') . '/search/' . $tag->get('content') . '">' . $tag->get('content') . '</a>';
                 }
                 $html .= '</p>';
             } else {
                 $html .= '<div><strong>' . $this->label . ':</strong>';
                 if ($buttons) {
                     $html .= '<div class="spread">';
                     $tmp = new Button("document.getElementById('relation_field_" . $this->name . "').style.display = '';", 'Show', $this->name . 'DisBut', '', 'glyphicon-list');
                     $html .= $tmp->render();
                     $tmp = new Button("document.getElementById('relation_field_" . $this->name . "').style.display = 'none';", 'Hide', $this->name . 'HidBut', '', 'glyphicon-minus');
                     $html .= $tmp->render();
                     $html .= '</div>';
                 }
                 $html .= '</div>';
                 $html .= '<div id="relation_field_' . $this->name . '" style="display:' . ($expanded ? '' : 'none') . ';">';
                 $customViewControllerName = Controller::getCustomControllerName(get_class($objects[0]), 'view');
                 $customEditControllerName = Controller::getCustomControllerName(get_class($objects[0]), 'edit');
                 $request = new Request(array('method' => 'GET'));
                 $URI = $request->getURI();
                 foreach ($objects as $obj) {
                     // check to see if we are in the admin back-end
                     if (mb_strpos($URI, '/tk/') !== false) {
                         $viewURL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($obj) . '&ActiveRecordOID=' . $obj->getOID());
                         $editURL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($obj) . '&ActiveRecordOID=' . $obj->getOID() . '&view=edit');
                     } else {
                         if (isset($customViewControllerName)) {
                             if ($config->get('app.use.mod.rewrite')) {
                                 $viewURL = $config->get('app.url') . $customViewControllerName . '/oid/' . $obj->getOID();
                             } else {
                                 $viewURL = $config->get('app.url') . 'controller/' . $customViewControllerName . '.php?oid=' . $obj->getOID();
                             }
                         } else {
                             $viewURL = $config->get('app.url') . 'alpha/controller/Detail.php?bo=' . get_class($obj) . '&oid=' . $obj->getOID();
                         }
                         if (isset($customEditControllerName)) {
                             if ($config->get('app.use.mod.rewrite')) {
                                 $editURL = $config->get('app.url') . $customEditControllerName . '/oid/' . $obj->getOID();
                             } else {
                                 $editURL = $config->get('app.url') . 'controller/' . $customEditControllerName . '.php?oid=' . $obj->getOID();
                             }
                         } else {
                             $editURL = $config->get('app.url') . 'alpha/controller/Edit.php?bo=' . get_class($obj) . '&oid=' . $obj->getOID();
                         }
                     }
                     /*
                      * If any display headers were set with setRelatedClassHeaderFields, use them otherwise
                      * use the OID of the related class as the only header.
                      */
                     $headerFields = $this->relationObject->getRelatedClassHeaderFields();
                     if (count($headerFields) > 0) {
                         foreach ($headerFields as $field) {
                             $label = $obj->getDataLabel($field);
                             $value = $obj->get($field);
                             if ($field == 'created_by' || $field == 'updated_by') {
                                 $person = new PersonObject();
                                 $person->load($value);
                                 $value = $person->getDisplayName();
                             }
                             $html .= '<em>' . $label . ': </em>' . $value . '&nbsp;&nbsp;&nbsp;&nbsp;';
                         }
                         // if the related BO has been updated, render the update time
                         if ($obj->getCreateTS() != $obj->getUpdateTS()) {
                             try {
                                 $html .= '<em>' . $obj->getDataLabel('updated_ts') . ': </em>' . $obj->get('updated_ts');
                             } catch (IllegalArguementException $e) {
                                 $html .= '<em>Updated: </em>' . $obj->get('updated_ts');
                             }
                         }
                     } else {
                         $html .= '<em>' . $obj->getDataLabel('OID') . ': </em>' . $obj->get('OID');
                     }
                     // ensures that line returns are rendered
                     $value = str_replace("\n", '<br>', $obj->get($this->relationObject->getRelatedClassDisplayField()));
                     $html .= '<p>' . $value . '</p>';
                     $html .= '<div class="centered">';
                     $html .= '<a href="' . $viewURL . '">View</a>';
                     // if the current user owns it, they get the edit link
                     if ($session->get('currentUser') != null && $session->get('currentUser')->getOID() == $obj->getCreatorId()) {
                         $html .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . $editURL . '">Edit</a>';
                     }
                     $html .= '</div>';
                 }
                 $html .= '</div>';
             }
         }
     }
     // render text-box for many-to-many relations
     if ($this->relationObject->getRelationType() == 'MANY-TO-MANY') {
         // value to appear in the text-box
         $inputBoxValue = $this->relationObject->getRelatedClassDisplayFieldValue($this->accessingClassName);
         // replace commas with line returns
         $inputBoxValue = str_replace(',', "\n", $inputBoxValue);
         $html .= '<div class="form-group">';
         $html .= '<label for="' . $this->name . '_display">' . $this->label . '</label>';
         $html .= '<textarea id="' . $this->name . '_display" class="form-control" rows="5" readonly>';
         $html .= $inputBoxValue;
         $html .= '</textarea>';
         $fieldname1 = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name)) : $this->name;
         $fieldname2 = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name . '_OID')) : $this->name . '_OID';
         $js = "if(window.jQuery) {\n                        BootstrapDialog.show({\n                            title: 'Please select',\n                            message: 'Loading...',\n                            onshow: function(dialogRef){\n                                dialogRef.getModalBody().load('" . $config->get('app.url') . "/recordselector/m2m/'+document.getElementById('" . $fieldname2 . "').value+'/" . $this->name . '/' . urlencode($this->relationObject->getRelatedClass('left')) . '/' . $this->relationObject->getRelatedClassDisplayField('left') . '/' . urlencode($this->relationObject->getRelatedClass('right')) . '/' . $this->relationObject->getRelatedClassDisplayField('right') . '/' . urlencode($this->accessingClassName) . "/'+document.getElementById('" . $fieldname1 . "').value);\n                            },\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                                    setParentFieldValues();\n                                    \$('[id=\\'" . $this->name . "_display\\']').blur();\n                                    dialogItself.close();\n                                }\n                            }\n                        ]\n                        });\n                    }";
         $tmp = new Button($js, 'Select', 'relBut', '', 'glyphicon-check');
         $html .= '<div class="centered lower">' . $tmp->render() . '</div>';
         $html .= '</div>';
         // hidden field to store the OID of the current BO
         $html .= '<input type="hidden" name="' . $fieldname2 . '" id="' . $fieldname2 . '" value="' . $this->relationObject->getValue() . '"/>';
         // hidden field to store the OIDs of the related BOs on the other side of the rel (this is what we check for when saving)
         if ($this->relationObject->getSide($this->accessingClassName) == 'left') {
             $lookupOIDs = $this->relationObject->getLookup()->loadAllFieldValuesByAttribute('leftID', $this->relationObject->getValue(), 'rightID', 'DESC');
         } else {
             $lookupOIDs = $this->relationObject->getLookup()->loadAllFieldValuesByAttribute('rightID', $this->relationObject->getValue(), 'leftID', 'DESC');
         }
         $html .= '<input type="hidden" name="' . $fieldname1 . '" id="' . $fieldname1 . '" value="' . implode(',', $lookupOIDs) . '"/>';
     }
     self::$logger->debug('<<__render [html]');
     return $html;
 }