예제 #1
0
 protected function setValuesArray($valuesArray)
 {
     $this->valuesArray = $valuesArray;
     //      if(!isset($valuesArray["attribute_metadata"])) {
     //       throw new Exception("Unable to initialize item without metadata");
     //      }
     $this->initializeBaseFields($valuesArray);
     $cachedAttributeMetadata = array();
     foreach ($valuesArray as $key => $value) {
         if (preg_match('/^' . preg_quote("_ca_attribute_") . "/", $key)) {
             $va_tmp = explode('attribute_', $key);
             $elementId = $va_tmp[1];
             $this->addAttributeMetadata($elementId, $valuesArray["attribute_metadata"][$elementId]);
             $this->setAttributeValue($elementId, $value);
         }
     }
     //read attribute extended values
     if (isset($valuesArray["extended_values"]) && is_array($valuesArray["extended_values"])) {
         $attritbutes = $valuesArray["extended_values"];
         foreach ($attritbutes as $key => $attributevalues) {
             foreach ($attributevalues as $attribute) {
                 $this->addAttributeExtendedValue($key, array_pop($attribute['opa_values']));
             }
         }
     }
     if (isset($valuesArray["relationships"]) && is_array($valuesArray["relationships"])) {
         //read relations data and wrap it into Relationship.php array()
         $relations = $valuesArray["relationships"];
         foreach ($relations as $key => $value) {
             $relationship = new Relationship(array('relation_id' => $value["relation_id"], 'related_object_type' => $value["related_object_type"], 'item_info_service' => $this->itemInfoController));
             if (isset($value["displayname"])) {
                 $displayname = $value["displayname"];
             } elseif (isset($value['name_singular'])) {
                 $displayname = $value['name_singular'];
             } elseif (isset($value["name"])) {
                 $displayname = $value["name"];
             } else {
                 $displayname = '';
             }
             $relationship->setDisplayName($displayname);
             $relationship->setRelationshipTypeId($value["relationship_type_id"]);
             $relationship->setRelationshipTypeName($value["relationship_type_name"]);
             $relationship->setRelatedObjectId($value);
             $this->addRelation($relationship);
         }
     }
     if (isset($valuesArray["labels"]) && is_array($valuesArray["labels"])) {
         $labels = $valuesArray["labels"];
         foreach ($labels as $lang) {
             foreach ($lang as $id => $value) {
                 $label_id = $id;
                 if (isset($value['label_id'])) {
                     $label_id = $value['label_id'];
                 }
                 if (isset($value['name'])) {
                     $name = $value['name'];
                 } elseif (isset($value['name_plural'])) {
                     $name = $value['name_plural'];
                 }
                 $label = new Label(array('label_id' => $label_id, 'locale' => $value['locale_language'], 'is_preferred' => $value['is_preferred'], 'value' => $name));
                 $this->addLabel($label);
             }
         }
     }
     if (isset($valuesArray["tags"]) && is_array($valuesArray["tags"])) {
         foreach ($valuesArray["tags"] as $tag_array) {
             if (!isset($tag_array["moderated_by_user_id"]) || $tag_array["moderated_by_user_id"] == null || ($tag_array["moderated_by_user_id"] = '')) {
                 // comment has not been moderated yet
             } else {
                 $newtag = new Tag(array('tag_id' => $tag_array["tag_id"], 'locale_id' => $tag_array["locale_id"], 'values' => $tag_array));
                 $this->addTag($newtag);
             }
         }
     }
     if (isset($valuesArray["rating"]) && is_array($valuesArray["rating"])) {
         $this->setTotalNumberOfVotes($valuesArray["rating"]["total"]);
         $this->setAverageRating($valuesArray["rating"]["average"]);
     }
     if (isset($valuesArray["comments"]) && is_array($valuesArray["comments"])) {
         foreach ($valuesArray["comments"] as $comment_arr) {
             if (!isset($comment_arr["moderated_by_user_id"]) || $comment_arr["moderated_by_user_id"] == null || ($comment_arr["moderated_by_user_id"] = '')) {
                 // comment has not been moderated yet
             } else {
                 $newcomment = new Comment(array('comment_id' => $comment_arr["comment_id"], 'locale_id' => $comment_arr["locale_id"], 'values' => $comment_arr));
                 $this->addComment($newcomment);
             }
         }
     }
     if (isset($valuesArray["hierarchy"]) && is_array($valuesArray["hierarchy"])) {
         $ancestors = array();
         $ancestorArr = $valuesArray['hierarchy']['ancestors'];
         foreach ($ancestorArr as $k => $a) {
             $options = array('idno' => $a['idno'], 'parent_id' => $a['parent_id'], 'item_info_controller' => $this->itemInfoController, 'table' => $this->getTable());
             $ancestor = new BasicNode($a['id'], $options);
             $labelArr = $a['label'];
             while (count($labelArr) == 1) {
                 $labelArr = array_pop($labelArr);
             }
             $label_id = 0;
             if (isset($labelArr['label_id'])) {
                 $label_id = $labelArr['label_id'];
             }
             if (isset($labelArr['name'])) {
                 $name = $labelArr['name'];
             } elseif (isset($labelArr['name_plural'])) {
                 $name = $labelArr['name_plural'];
             }
             $label = new Label(array('label_id' => $label_id, 'locale' => $labelArr['locale_language'], 'is_preferred' => $labelArr['is_preferred'], 'value' => $name));
             $ancestor->addLabel($label);
             $ancestors[$a['id']] = $ancestor;
         }
         foreach ($ancestors as $item) {
             $parentId = $item->getParentId();
             if (isset($parentId) && $parentId != null) {
                 $item->setAncestor($ancestors[$parentId]);
             }
         }
         $parentId = $this->getParentId();
         if (isset($parentId) && $parentId != null) {
             $this->setAncestor($ancestors[$parentId]);
         }
         $childArr = $valuesArr['hierarchy']['children'];
         foreach ($childArr as $k => $c) {
             $options = array('idno' => $c['idno'], 'parent_id' => $c['parent_id'], 'item_info_controller' => $this->itemInfoController, 'table' => $this->getTable());
             $child = new BasicNode($c['id'], $options);
             $labelArr = $c['label'];
             while (count($labelArr) == 1) {
                 $labelArr = array_pop($labelArr);
             }
             $label_id = 0;
             if (isset($labelArr['label_id'])) {
                 $label_id = $labelArr['label_id'];
             }
             if (isset($labelArr['name'])) {
                 $name = $labelArr['name'];
             } elseif (isset($labelArr['name_plural'])) {
                 $name = $labelArr['name_plural'];
             }
             $label = new Label(array('label_id' => $label_id, 'locale' => $labelArr['locale_language'], 'is_preferred' => $labelArr['is_preferred'], 'value' => $name));
             $child->addLabel($label);
             $this->addChild($child);
         }
     }
 }