Пример #1
0
 public function view()
 {
     $ak = $this->loadAttribute();
     if ($this->displayMode == "cloud") {
         $type = $ak->getAttributeType();
         $controller = $type->getController();
         $controller->setAttributeKey($ak);
         $items = $controller->getOptions();
         $options = new SelectAttributeTypeOptionList();
         if ($this->cloudCount > 0 && $items instanceof SelectAttributeTypeOptionList && $items->count()) {
             $i = 1;
             foreach ($items as $item) {
                 $options->add($item);
                 if ($i >= $this->cloudCount) {
                     break;
                 }
                 $i++;
             }
         } else {
             $options = $items;
         }
     } else {
         $c = Page::getCurrentPage();
         $av = $c->getAttributeValueObject($ak);
         $controller = $ak->getController();
         $options = $c->getAttribute($ak->getAttributeKeyHandle());
     }
     if ($this->targetCID > 0) {
         $target = Page::getByID($this->targetCID);
         $this->set('target', $target);
     }
     $this->set('options', $options);
     $this->set('akc', $controller);
     $this->set('ak', $ak);
 }
 public function view()
 {
     $ak = $this->loadAttribute();
     if ($this->displayMode == "cloud") {
         $type = $ak->getAttributeType();
         $controller = $type->getController();
         $controller->setAttributeKey($ak);
         $items = $controller->getOptions();
         $options = new SelectAttributeTypeOptionList();
         if ($this->cloudCount > 0 && $items instanceof SelectAttributeTypeOptionList && $items->count()) {
             $i = 1;
             foreach ($items as $item) {
                 $options->add($item);
                 if ($i >= $this->cloudCount) {
                     break;
                 }
                 $i++;
             }
         } else {
             $options = $items;
         }
     } else {
         $c = Page::getCurrentPage();
         $av = $c->getAttributeValueObject($ak);
         $controller = $ak->getController();
         $options = $c->getAttribute($ak->getAttributeKeyHandle());
     }
     if ($this->targetCID > 0) {
         $target = Page::getByID($this->targetCID);
         $this->set('target', $target);
     }
     // grab selected tag, if we're linking to a page with a tag block on it.
     if (is_array($_REQUEST['akID'])) {
         $res = $_REQUEST['akID'][$ak->getAttributeKeyID()]['atSelectOptionID'][0];
         if (is_numeric($res) && $res > 0) {
             $selectedOptionID = $res;
         }
     }
     $this->set('selectedOptionID', $selectedOptionID);
     $this->set('options', $options);
     $this->set('akc', $controller);
     $this->set('ak', $ak);
 }
Пример #3
0
	public function saveKey($data) {
		$ak = $this->getAttributeKey();
		
		$db = Loader::db();

		$initialOptionSet = $this->getOptions();
		$selectedPostValues = $this->getSelectValuesFromPost();
		
		$akSelectAllowMultipleValues = $data['akSelectAllowMultipleValues'];
		$akSelectAllowOtherValues = $data['akSelectAllowOtherValues'];
		$akSelectOptionDisplayOrder = $data['akSelectOptionDisplayOrder'];
		
		if ($data['akSelectAllowMultipleValues'] != 1) {
			$akSelectAllowMultipleValues = 0;
		}
		if ($data['akSelectAllowOtherValues'] != 1) {
			$akSelectAllowOtherValues = 0;
		}
		if (!in_array($data['akSelectOptionDisplayOrder'], array('display_asc', 'alpha_asc', 'popularity_desc'))) {
			$akSelectOptionDisplayOrder = 'display_asc';
		}
				
		// now we have a collection attribute key object above.
		$db->Replace('atSelectSettings', array(
			'akID' => $ak->getAttributeKeyID(), 
			'akSelectAllowMultipleValues' => $akSelectAllowMultipleValues, 
			'akSelectAllowOtherValues' => $akSelectAllowOtherValues,
			'akSelectOptionDisplayOrder' => $akSelectOptionDisplayOrder
		), array('akID'), true);
		
		// Now we add the options
		$newOptionSet = new SelectAttributeTypeOptionList();
		$displayOrder = 0;
		foreach($selectedPostValues as $option) {
			$opt = $option->saveOrCreate($ak);
			if ($akSelectOptionDisplayOrder == 'display_asc') {
				$opt->setDisplayOrder($displayOrder);
			}
			$newOptionSet->add($opt);
			$displayOrder++;
		}
		
		// Now we remove all options that appear in the 
		// old values list but not in the new
		foreach($initialOptionSet as $iopt) {
			if (!$newOptionSet->contains($iopt)) {
				$iopt->delete();
			}
		}
	}