/** * Test getAccessConstraintsNice of MDResourceConstraint. */ function testGetUseConstraintsNice() { $mdResourceConstraint = array(); $mdResourceConstraint['accessConstraints'] = trim('copyright'); $mdResourceConstraint['useConstraints'] = trim('license'); $mdResourceConstraint['otherConstraints'] = trim('otherRestrictions'); // load the sub-array into the object $item = new MDResourceConstraint(); $item->loadData($mdResourceConstraint); $this->assertEquals($item->getField('useConstraints'), 'license', 'Problem creating the MDResourceConstraint'); //Checking standardprotocol $this->assertEquals($item->getUseConstraintsNice(), 'License', 'initial otherConstraints failed for getUseConstraintsNice(). Value in MDCodeTypes might have changed'); //other protocol $mdResourceConstraint['useConstraints'] = trim('otherRestrictions'); $item = new MDResourceConstraint(); $item->loadData($mdResourceConstraint); $this->assertEquals($item->getUseConstraintsNice(), 'Other restrictions', 'other useConstraints failed for getUseConstraintsNice(). Value in MDCodeTypes might have changed'); // invalid protocol $mdResourceConstraint['useConstraints'] = trim('Some invalid access constraints'); $item = new MDResourceConstraint(); $item->loadData($mdResourceConstraint); $this->assertEquals($item->getUseConstraintsNice(), MDCodeTypes::$default_for_null_value, 'invalid useConstraints falied for getUseConstraintsNice()'); //empty protocol $mdResourceConstraint['useConstraints'] = ''; $item = new MDResourceConstraint(); $item->loadData($mdResourceConstraint); $this->assertEquals($item->getUseConstraintsNice(), MDCodeTypes::$default_for_null_value, 'empty useConstraints failed for getUseConstraintsNice()'); // null protocol $mdResourceConstraint['useConstraints'] = null; $item = new MDResourceConstraint(); $item->loadData($mdResourceConstraint); $this->assertEquals($item->getUseConstraintsNice(), MDCodeTypes::$default_for_null_value, 'null useConstraints failed for getUseConstraintsNice()'); }
/** * This method loads a provided array into the data structure. * It also creates dependencies, such as contact data objects * and populate the values into those objects. * * @param $data array of db-values. */ public function loadData($data) { if ($data == null) { return; } if (!is_array($data)) { return; } foreach ($data as $k => $v) { // store data into this object (no ':" in the string) if (strpos($k, ':') === false) { $this->{$k} = Convert::xml2raw($v); } else { // A ':' is used as a namespace marker. It is used to // create the related data objects, such as MDContacts. $relations = explode(':', $k); $fieldName = array_pop($relations); $relObj = $this; // iterate through the relationships. At the moment, this // loading process just works for 1 level hierarchies. foreach ($relations as $relation) { if ($relation == 'PointOfContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->PointOfContacts()->add($item); } if ($relation == 'MDContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->MDContacts()->add($item); } if ($relation == 'MDResourceConstraints') { // load the sub-array into the MDResourceConstraints object if (is_array($v)) { foreach ($v as $vitem) { $item = new MDResourceConstraint(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceConstraints()->add($item); } } } if ($relation == 'MDResourceFormats') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDResourceFormat(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceFormats()->add($item); } } } if ($relation == 'MDTopicCategory') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDTopicCategory(); $item->loadData($vitem); // add the new MDTopicCategory to the collection class of this // object. $relObj->MDTopicCategory()->add($item); } } } if ($relation == 'MDCitationDates') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDCitationDate(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDCitationDates()->add($item); } } } if ($relation == 'MCPMDCreativeCommons') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new MCPMDCreativeCommons(); $item->loadData($vitem); // add the new MCPMDCreativeCommons to the collection class of this // object. $relObj->MCPMDCreativeCommons()->add($item); } } } if ($relation == 'CIOnlineResources') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new CIOnlineResource(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->CIOnlineResources()->add($item); } } } if ($relation == 'MDHierarchyLevel') { if (is_array($v)) { foreach ($v as $vitem) { $codes = MDCodeTypes::get_scope_codes(); if (isset($codes[$vitem['Value']])) { $item = new MDHierarchyLevel(); $item->loadData($vitem); $relObj->MDHierarchyLevel()->add($item); } } } } if ($relation == 'MDHierarchyLevelName') { if (is_array($v)) { foreach ($v as $vitem) { $item = new MDHierarchyLevelName(); $item->loadData($vitem); $relObj->MDHierarchyLevelName()->add($item); } } } } } } }