Exemple #1
0
 public function edit($akID = 0)
 {
     if ($this->post('akID')) {
         $akID = $this->post('akID');
     }
     $key = FileAttributeKey::getByID($akID);
     if (!is_object($key) || $key->isAttributeKeyInternal()) {
         $this->redirect('/dashboard/files/attributes');
     }
     $type = $key->getAttributeType();
     $this->set('key', $key);
     $this->set('type', $type);
     if ($this->isPost()) {
         $cnt = $type->getController();
         $cnt->setAttributeKey($key);
         $e = $cnt->validateKey($this->post());
         if ($e->has()) {
             $this->set('error', $e);
         } else {
             $type = AttributeType::getByID($this->post('atID'));
             $key->update($this->post());
             $this->redirect('/dashboard/files/attributes', 'attribute_updated');
         }
     }
 }
Exemple #2
0
 public function edit($akID = 0)
 {
     if ($this->post('akID')) {
         $akID = $this->post('akID');
     }
     $key = FileAttributeKey::getByID($akID);
     $type = $key->getAttributeType();
     $this->set('key', $key);
     $this->set('type', $type);
     if ($this->isPost()) {
         $cnt = $type->getController();
         $cnt->setAttributeKey($key);
         $e = $cnt->validateKey($this->post());
         if ($e->has()) {
             $this->set('error', $e);
         } else {
             $type = AttributeType::getByID($this->post('atID'));
             $args = array('akHandle' => $this->post('akHandle'), 'akName' => $this->post('akName'), 'akIsSearchable' => $this->post('akIsSearchable'), 'akIsSearchableIndexed' => $this->post('akIsSearchableIndexed'), 'akIsAutoCreated' => 0, 'akIsEditable' => 1);
             $key->update($this->post());
             $this->redirect('/dashboard/files/attributes', 'attribute_updated');
         }
     }
 }
Exemple #3
0
	/** 
	 * @access private 
	 */
	public function get($akID) {
		return FileAttributeKey::getByID($akID);
	}
Exemple #4
0
	protected function upgradeFileAttributes() {
		$messages = array();
		$db = Loader::db();
		$r = $db->Execute('select _FileAttributeKeys.* from _FileAttributeKeys order by fakID asc');
		while ($row = $r->FetchRow()) {
			$cleanHandle = preg_replace("/[^A-Za-z0-9\_]/",'',$row['akHandle']); // remove spaces, chars that'll mess up our index tables
			$existingAKID = $db->GetOne('select akID from AttributeKeys where akHandle = ?',  array($cleanHandle) );
			if ($existingAKID < 1) {
				$args = array(
					'akHandle' => $cleanHandle,
					'akIsSearchable' => $row['akSearchable'],
					'akIsAutoCreated' => $row['akIsImporterAttribute'],
					'akIsEditable' => $row['akIsEditable'],
					'akName' => $row['akName']			
				);
				$sttype = $row['akType'];
				switch($row['akType']) {
					case 'SELECT':
					case 'SELECT_ADD':
						if ($row['akAllowOtherValues']) {
							$args['akSelectAllowMultipleValues'] = 1;
						}
						$sttype = 'SELECT';
						break;
					case 'SELECT_MULTIPLE':
						$sttype = 'SELECT';
						$args['akSelectAllowMultipleValues'] = 1;
						if ($row['akAllowOtherValues']) {
							$args['akSelectAllowMultipleValues'] = 1;
						}
						break;
				}
				
				$type = AttributeType::getByHandle(strtolower($sttype));
				$ak = FileAttributeKey::add($type, $args);
				if ($sttype == 'SELECT') {
					$selectOptions = explode("\n", $row['akValues']);
					foreach($selectOptions as $so) {
						if ($so != '') {
							SelectAttributeTypeOption::add($ak, $so);
						}
					}
				}
			} else {
				$ak = FileAttributeKey::getByID($existingAKID);
			}
			
			$r2 = $db->Execute('select * from _FileAttributeValues where fakID = ? and isImported = 0', $row['fakID']);
			while ($row2 = $r2->FetchRow()) {
				$f = File::getByID($row2['fID']);
				$fv = $f->getVersion($row2['fvID']);
				$value = $row2['value'];
				if ($row['akType'] == 'SELECT' || $row['akType'] == 'SELECT_MULTIPLE' || $row['akType'] == 'SELECT_ADD') {
					$value = explode("\n", $value);					
				}
				$fv->setAttribute($ak, $value);
				unset($f);
				unset($fv);

				$db->Execute('update _FileAttributeValues set isImported = 1 where fakID = ? and fvID = ? and fID = ?', array($row['fakID'], $row2['fvID'], $row2['fID']));
				$this->incrementImported();
			}
			
			unset($ak);
			unset($row2);
			$r2->Close();
			unset($r2);
		}
		
		unset($row);
		$r->Close();
		unset($r);
		return $messages;
	}