public function tearDown() { if ($this->object_mono instanceof databox_field) { $this->object_mono->delete(); } if ($this->object_multi instanceof databox_field) { $this->object_multi->delete(); } $extra = $this->databox->get_meta_structure()->get_element_by_name('Bonoboyoyo'); if ($extra instanceof databox_field) { $extra->delete(); } parent::tearDown(); }
/** * @todo move this function to caption_record * @param Array $params An array containing three keys : meta_struct_id (int) , meta_id (int or null) and value (Array) * @param databox $databox * @return record_adapter * @throws Exception * @throws Exception_InvalidArgument */ protected function set_metadata(array $params, databox $databox) { $mandatoryParams = ['meta_struct_id', 'meta_id', 'value']; foreach ($mandatoryParams as $param) { if (!array_key_exists($param, $params)) { throw new Exception_InvalidArgument(sprintf('Invalid metadata, missing key %s', $param)); } } if (!is_scalar($params['value'])) { throw new Exception('Metadata value should be scalar'); } $databox_field = $databox->get_meta_structure()->get_element($params['meta_struct_id']); $caption_field = new caption_field($this->app, $databox_field, $this); $vocab = $vocab_id = null; if (isset($params['vocabularyId']) && $databox_field->getVocabularyControl()) { try { $vocab = $databox_field->getVocabularyControl(); $vocab_id = $params['vocabularyId']; $vocab->validate($vocab_id); } catch (\Exception $e) { $vocab = $vocab_id = null; } } if (trim($params['meta_id']) !== '') { $tmp_val = trim($params['value']); $caption_field_value = $caption_field->get_value($params['meta_id']); if ($tmp_val === '') { $caption_field_value->delete(); unset($caption_field_value); } else { $caption_field_value->set_value($params['value']); if ($vocab && $vocab_id) { $caption_field_value->setVocab($vocab, $vocab_id); } } } else { $caption_field_value = caption_Field_Value::create($this->app, $databox_field, $this, $params['value'], $vocab, $vocab_id); } return $this; }
/** * @param \databox $databox * @return array */ private function retrieveDataboxFieldOrderings(\databox $databox) { $publicOrder = []; $businessOrder = []; foreach ($databox->get_meta_structure() as $field) { $fieldName = $field->get_name(); if (!$field->isBusiness()) { $publicOrder[] = $fieldName; } $businessOrder[] = $fieldName; } return ['public' => $publicOrder, 'business' => $businessOrder]; }
/** * * @param \Alchemy\Phrasea\Application $app * @param databox $databox * @param string $name * @param bool $multi * * @return self * * @throws \Exception_InvalidArgument */ public static function create(Application $app, databox $databox, $name, $multi) { $sorter = 0; $sql = 'SELECT (MAX(sorter) + 1) as sorter FROM metadatas_structure'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($row) { $sorter = max(1, (int) $row['sorter']); } $sql = "INSERT INTO metadatas_structure\n (`id`, `name`, `src`, `readonly`, `required`, `indexable`, `type`, `tbranch`,\n `thumbtitle`, `multi`, `business`, `aggregable`,\n `report`, `sorter`, `separator`)\n VALUES (null, :name, '', 0, 0, 1, 'string', '',\n null, :multi,\n 0, 0, 1, :sorter, '')"; $name = self::generateName($name); if ($name === '') { throw new \Exception_InvalidArgument(); } $multi = $multi ? 1 : 0; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute([':name' => $name, ':sorter' => $sorter, ':multi' => $multi]); $id = $databox->get_connection()->lastInsertId(); $stmt->closeCursor(); $databox->delete_data_from_cache(databox::CACHE_META_STRUCT); return $databox->get_meta_structure()->get_element($id); }