Example #1
0
 public function getAttributeValue($avID, $method = 'getValue')
 {
     $av = CollectionAttributeValue::getByID($avID);
     if (is_object($av)) {
         $av->setAttributeKey($this);
         $value = $av->{$method}();
         $av->__destruct();
         unset($av);
         return $value;
     }
 }
Example #2
0
 public function getAttributeValueObject($ak, $createIfNotFound = false)
 {
     $db = Loader::db();
     $av = false;
     if (is_string($ak)) {
         $ak = CollectionAttributeKey::getByHandle($ak);
     }
     $v = array($this->getCollectionID(), $this->getVersionID(), $ak->getAttributeKeyID());
     $avID = $db->GetOne('select avID from CollectionAttributeValues where cID = ? and cvID = ? and akID = ?', $v);
     if ($avID > 0) {
         $av = CollectionAttributeValue::getByID($avID);
         if (is_object($av)) {
             $av->setCollection($this);
             $av->setAttributeKey($ak);
         }
     }
     if ($createIfNotFound) {
         $cnt = 0;
         // Is this avID in use ?
         if (is_object($av)) {
             $cnt = $db->GetOne('select count(avID) from CollectionAttributeValues where avID = ?', $av->getAttributeValueID());
         }
         if (!is_object($av) || $cnt > 1) {
             $newAV = $ak->addAttributeValue();
             $av = CollectionAttributeValue::getByID($newAV->getAttributeValueID());
             $av->setCollection($this);
         }
     }
     return $av;
 }