Exemple #1
0
 /**
  * Sets up the Relation definitions on this BO.
  *
  * @since 1.0
  */
 private function setupRels()
 {
     // set up MANY-TO-MANY relation person2rights
     $this->members->setRelatedClass('Alpha\\Model\\Person', 'left');
     $this->members->setRelatedClassDisplayField('email', 'left');
     $this->members->setRelatedClass('Alpha\\Model\\Rights', 'right');
     $this->members->setRelatedClassDisplayField('name', 'right');
     $this->members->setRelationType('MANY-TO-MANY');
     $this->members->setValue($this->getOID());
 }
Exemple #2
0
 /**
  * Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition.
  *
  * @since 1.0
  */
 public function testGetRelatedClassDisplayFieldValueFail()
 {
     try {
         $this->rel1->setRelatedClass('NotThere');
         $this->rel1->setRelatedClassDisplayField('someField');
         $value = $this->rel1->getRelatedClassDisplayFieldValue();
         $this->fail('Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition');
     } catch (\Exception $e) {
         $this->assertEquals('The class [NotThere] is not defined anywhere!', $e->getMessage(), 'Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition');
     }
 }
Exemple #3
0
 /**
  * constructor for the class.
  *
  * @since 1.0
  */
 public function __construct()
 {
     self::$logger = new Logger('ArticleComment');
     // ensure to call the parent constructor
     parent::__construct();
     $this->articleOID = new Relation();
     $this->articleOID->setRelatedClass('Alpha\\Model\\Article');
     $this->articleOID->setRelatedClassField('OID');
     $this->articleOID->setRelatedClassDisplayField('description');
     $this->articleOID->setRelationType('MANY-TO-ONE');
     $this->content = new Text();
     $this->content->setAllowHTML(false);
 }
Exemple #4
0
 /**
  * Constructor for the class.
  *
  * @since 1.0
  */
 public function __construct()
 {
     self::$logger = new Logger('ArticleVote');
     // ensure to call the parent constructor
     parent::__construct();
     $this->articleOID = new Relation();
     $this->articleOID->setRelatedClass('Alpha\\Model\\Article');
     $this->articleOID->setRelatedClassField('OID');
     $this->articleOID->setRelatedClassDisplayField('description');
     $this->articleOID->setRelationType('MANY-TO-ONE');
     $this->personOID = new Relation();
     $this->personOID->setRelatedClass('Alpha\\Model\\Person');
     $this->personOID->setRelatedClassField('OID');
     $this->personOID->setRelatedClassDisplayField('email');
     $this->personOID->setRelationType('MANY-TO-ONE');
     $this->score = new Integer();
 }
Exemple #5
0
 /**
  * Sets up the Relation definitions on this record object.
  *
  * @since 2.0
  */
 protected function setupRels()
 {
     $this->comments->setValue($this->OID);
     $this->comments->setRelatedClass('Alpha\\Model\\ArticleComment');
     $this->comments->setRelatedClassField('articleOID');
     $this->comments->setRelatedClassDisplayField('content');
     $this->comments->setRelationType('ONE-TO-MANY');
     $this->votes->setValue($this->OID);
     $this->votes->setRelatedClass('Alpha\\Model\\ArticleVote');
     $this->votes->setRelatedClassField('articleOID');
     $this->votes->setRelatedClassDisplayField('score');
     $this->votes->setRelationType('ONE-TO-MANY');
     $this->tags->setRelatedClass('Alpha\\Model\\Tag');
     $this->tags->setRelatedClassField('taggedOID');
     $this->tags->setRelatedClassDisplayField('content');
     $this->tags->setRelationType('ONE-TO-MANY');
     $this->tags->setTaggedClass(get_class($this));
     $this->tags->setValue($this->OID);
 }
Exemple #6
0
 /**
  * Testing the getRelatedObject method.
  *
  * @since 1.2.1
  */
 public function testGetRelatedObject()
 {
     $oneToOneRel = new Relation();
     $oneToOneRel->setRelatedClass('Alpha\\Model\\Person');
     $oneToOneRel->setRelatedClassField('OID');
     $oneToOneRel->setRelatedClassDisplayField('displayName');
     $oneToOneRel->setRelationType('ONE-TO-ONE');
     $oneToOneRel->setValue($this->person->getOID());
     $this->assertEquals($this->person->getDisplayName(), $oneToOneRel->getRelatedObject()->get('displayName'), 'testing the getRelatedObject method');
 }
Exemple #7
0
 /**
  * Sets up the Relation definitions on this BO.
  *
  * @since 1.0
  */
 protected function setupRels()
 {
     // set up MANY-TO-MANY relation person2rights
     if (isset($this->rights)) {
         $this->rights->setRelatedClass('Alpha\\Model\\Person', 'left');
         $this->rights->setRelatedClassDisplayField('email', 'left');
         $this->rights->setRelatedClass('Alpha\\Model\\Rights', 'right');
         $this->rights->setRelatedClassDisplayField('name', 'right');
         $this->rights->setRelationType('MANY-TO-MANY');
         $this->rights->setValue($this->getID());
     }
     if (isset($this->actions)) {
         $this->actions->setValue($this->OID);
         $this->actions->setRelatedClass('Alpha\\Model\\ActionLog');
         $this->actions->setRelatedClassField('created_by');
         $this->actions->setRelatedClassDisplayField('message');
         $this->actions->setRelationType('ONE-TO-MANY');
     }
 }
Exemple #8
0
    /**
     * Returns the HTML for the record selector that will appear in a pop-up window.
     *
     * @param string $fieldname  The hidden HTML form field in the parent to pass values back to.
     * @param array  $lookupOIDs An optional array of related look-up OIDs, only required for rendering MANY-TO-MANY rels
     *
     * @since 1.0
     *
     * @return string
     */
    public function renderSelector($fieldname, $lookupOIDs = array())
    {
        self::$logger->debug('>>renderSelector(fieldname=[' . $fieldname . '], lookupOIDs=[' . var_export($lookupOIDs, true) . '])');
        $config = ConfigProvider::getInstance();
        $html = '<script language="JavaScript">
            var selectedOIDs = new Object();

            function toggelOID(oid, displayValue, isSelected) {
                if(isSelected)
                    selectedOIDs[oid] = displayValue;
                else
                    delete selectedOIDs[oid];
            }

            function setParentFieldValues() {
                var OIDs;
                var displayValues;

                for(key in selectedOIDs) {
                    if(OIDs == null)
                        OIDs = key;
                    else
                        OIDs = OIDs + \',\' + key;

                    if(displayValues == null)
                        displayValues = selectedOIDs[key];
                    else
                        displayValues = displayValues + \'\\n\' + selectedOIDs[key];
                }

                if(OIDs == null) {
                    document.getElementById(\'' . $fieldname . '\').value = "00000000000";
                    document.getElementById(\'' . $fieldname . '_display\').value = "";
                }else{
                    document.getElementById(\'' . $fieldname . '\').value = OIDs;
                    document.getElementById(\'' . $fieldname . '_display\').value = displayValues;
                }
            }

            </script>';
        if ($this->relationObject->getRelationType() == 'MANY-TO-MANY') {
            $classNameLeft = $this->relationObject->getRelatedClass('left');
            $classNameRight = $this->relationObject->getRelatedClass('right');
            if ($this->accessingClassName == $classNameLeft) {
                $tmpObject = new $classNameRight();
                $fieldName = $this->relationObject->getRelatedClassDisplayField('right');
                $fieldLabel = $tmpObject->getDataLabel($fieldName);
                $oidLabel = $tmpObject->getDataLabel('OID');
                $objects = $tmpObject->loadAll(0, 0, 'OID', 'ASC', true);
                self::$logger->debug('[' . count($objects) . '] related [' . $classNameLeft . '] objects loaded');
            } else {
                $tmpObject = new $classNameLeft();
                $fieldName = $this->relationObject->getRelatedClassDisplayField('left');
                $fieldLabel = $tmpObject->getDataLabel($fieldName);
                $oidLabel = $tmpObject->getDataLabel('OID');
                $objects = $tmpObject->loadAll(0, 0, 'OID', 'ASC', true);
                self::$logger->debug('[' . count($objects) . '] related [' . $classNameLeft . '] objects loaded');
            }
            $html .= '<table cols="3" class="table table-bordered">';
            $html .= '<tr>';
            $html .= '<th>' . $oidLabel . '</th>';
            $html .= '<th>' . $fieldLabel . '</th>';
            $html .= '<th>Connect?</th>';
            $html .= '</tr>';
            foreach ($objects as $obj) {
                $html .= '<tr>';
                $html .= '<td width="20%">';
                $html .= $obj->getOID();
                $html .= '</td>';
                $html .= '<td width="60%">';
                $html .= $obj->get($fieldName);
                $html .= '</td>';
                $html .= '<td width="20%">';
                if (in_array($obj->getOID(), $lookupOIDs)) {
                    $this->onloadJS .= 'toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',true);';
                    $html .= '<input name = "' . $obj->getOID() . '" type="checkbox" checked onclick="toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',this.checked);"/>';
                } else {
                    $html .= '<input name = "' . $obj->getOID() . '" type="checkbox" onclick="toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',this.checked);"/>';
                }
                $html .= '</td>';
                $html .= '</tr>';
            }
            $html .= '</table>';
        } else {
            $className = $this->relationObject->getRelatedClass();
            $tmpObject = new $className();
            $label = $tmpObject->getDataLabel($this->relationObject->getRelatedClassDisplayField());
            $oidLabel = $tmpObject->getDataLabel('OID');
            $objects = $tmpObject->loadAll(0, 0, 'OID', 'DESC');
            $html = '<table cols="3" width="100%" class="bordered">';
            $html .= '<tr>';
            $html .= '<th>' . $oidLabel . '</th>';
            $html .= '<th>' . $label . '</th>';
            $html .= '<th>Connect?</th>';
            $html .= '</tr>';
            foreach ($objects as $obj) {
                $html .= '<tr>';
                $html .= '<td width="20%">';
                $html .= $obj->getOID();
                $html .= '</td>';
                $html .= '<td width="60%">';
                $html .= $obj->get($this->relationObject->getRelatedClassDisplayField());
                $html .= '</td>';
                $html .= '<td width="20%">';
                if ($obj->getOID() == $this->relationObject->getValue()) {
                    $html .= '<img src="' . $config->get('app.url') . '/images/icons/accept_ghost.png"/>';
                } else {
                    $tmp = new Button("document.getElementById('" . $fieldname . "').value = '" . $obj->getOID() . "'; document.getElementById('" . $fieldname . "_display').value = '" . $obj->get($this->relationObject->getRelatedClassDisplayField()) . "'; \$('[Id=" . $fieldname . "_display]').blur(); window.jQuery.dialog.close();", '', 'selBut', $config->get('app.url') . '/images/icons/accept.png');
                    $html .= $tmp->render();
                }
                $html .= '</td>';
                $html .= '</tr>';
            }
            $html .= '</table>';
        }
        $html .= '<script type="text/javascript">' . '$(document).ready(function() {';
        $html .= $this->onloadJS;
        $html .= '});</script>';
        self::$logger->debug('<<renderSelector[html]');
        return $html;
    }
 /**
  * Handles get requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  *
  * @throws Alpha\Exception\ResourceNotFoundException
  */
 public function doGet($request)
 {
     self::$logger->debug('>>doGet(request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     $relationObject = new Relation();
     $body = '';
     try {
         $relationType = $params['relationType'];
         $ActiveRecordOID = $params['ActiveRecordOID'];
         $field = $params['field'];
     } catch (\Exception $e) {
         self::$logger->error('Required param missing for RecordSelectorController controller[' . $e->getMessage() . ']');
         throw new ResourceNotFoundException('File not found');
     }
     if ($relationType == 'MANY-TO-MANY') {
         try {
             $relatedClassLeft = urldecode($params['relatedClassLeft']);
             $relatedClassLeftDisplayField = $params['relatedClassLeftDisplayField'];
             $relatedClassRight = urldecode($params['relatedClassRight']);
             $relatedClassRightDisplayField = $params['relatedClassRightDisplayField'];
             $accessingClassName = urldecode($params['accessingClassName']);
             $lookupOIDs = $params['lookupOIDs'];
         } catch (\Exception $e) {
             self::$logger->error('Required param missing for RecordSelectorController controller[' . $e->getMessage() . ']');
             throw new ResourceNotFoundException('File not found');
         }
         $relationObject->setRelatedClass($relatedClassLeft, 'left');
         $relationObject->setRelatedClassDisplayField($relatedClassLeftDisplayField, 'left');
         $relationObject->setRelatedClass($relatedClassRight, 'right');
         $relationObject->setRelatedClassDisplayField($relatedClassRightDisplayField, 'right');
         $relationObject->setRelationType($relationType);
         $relationObject->setValue($ActiveRecordOID);
         $recSelector = new RecordSelector($relationObject, '', $field, $accessingClassName);
         $body .= $recSelector->renderSelector($field, explode(',', $lookupOIDs));
     } else {
         try {
             $relatedClass = urldecode($params['relatedClass']);
             $relatedClassField = $params['relatedClassField'];
             $relatedClassDisplayField = $params['relatedClassDisplayField'];
         } catch (\Exception $e) {
             self::$logger->error('Required param missing for RecordSelectorController controller[' . $e->getMessage() . ']');
             throw new ResourceNotFoundException('File not found');
         }
         $relationObject->setRelatedClass($relatedClass);
         $relationObject->setRelatedClassField($relatedClassField);
         $relationObject->setRelatedClassDisplayField($relatedClassDisplayField);
         $relationObject->setRelationType($relationType);
         $relationObject->setValue($ActiveRecordOID);
         $recSelector = new RecordSelector($relationObject);
         $body .= $recSelector->renderSelector($field);
     }
     self::$logger->debug('<<__doGet');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }