/** * 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()); }
/** * Testing that the display field value of the related class is accessed correctly. * * @since 1.0 */ public function testSetRelatedClassDisplayFieldPass() { try { $this->rel1->setRelatedClass('Alpha\\Model\\Person'); // assuming here that user #1 is the default Administrator account $this->rel1->setValue(1); $this->rel1->setRelatedClassDisplayField('state'); $this->assertEquals('Active', $this->rel1->getRelatedClassDisplayFieldValue(), 'Testing that the display field value of the related class is accessed correctly'); } catch (AlphaException $e) { $this->fail('Testing that the display field value of the related class is accessed correctly'); } }
/** * 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); }
/** * 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'); }
/** * 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'); } }
/** * 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')); }