/** * Install hstore * /usr/share/postgresql/contrib # cat hstore.sql | psql -U pgsql -d onphp **/ public function testHstore() { foreach (DBTestPool::me()->getPool() as $connector => $db) { DBPool::me()->setDefault($db); $properties = array('age' => '23', 'weight' => 80, 'comment' => null); $user = TestUser::create()->setCity($moscow = TestCity::create()->setName('Moscow'))->setCredentials(Credentials::create()->setNickname('fake')->setPassword(sha1('passwd')))->setLastLogin(Timestamp::create(time()))->setRegistered(Timestamp::create(time())->modify('-1 day'))->setProperties(Hstore::make($properties)); $moscow = TestCity::dao()->add($moscow); $user = TestUser::dao()->add($user); Cache::me()->clean(); TestUser::dao()->dropIdentityMap(); $user = TestUser::dao()->getById('1'); $this->assertInstanceOf('Hstore', $user->getProperties()); $this->assertEquals($properties, $user->getProperties()->getList()); $form = TestUser::proto()->makeForm(); $form->get('properties')->setFormMapping(array(Primitive::string('age'), Primitive::integer('weight'), Primitive::string('comment'))); $form->import(array('id' => $user->getId())); $this->assertNotNull($form->getValue('id')); $object = $user; FormUtils::object2form($object, $form); $this->assertInstanceOf('Hstore', $form->getValue('properties')); $this->assertEquals(array_filter($properties), $form->getValue('properties')->getList()); $subform = $form->get('properties')->getInnerForm(); $this->assertEquals($subform->getValue('age'), '23'); $this->assertEquals($subform->getValue('weight'), 80); $this->assertNull($subform->getValue('comment')); $user = new TestUser(); FormUtils::form2object($form, $user, false); $this->assertEquals($user->getProperties()->getList(), array_filter($properties)); } }
public function getValue() { if (!$this->value instanceof Form) { return null; } return Hstore::make($this->value->export()); }
/** When using the form filter **/ public function getDiffAsArray($is_old = true) { if ($is_old) { $hstore = $this->_get('old_value'); } else { $hstore = $this->_get('new_value'); } $diff = new Hstore(); $diff->import($hstore); $tab = $diff->getIterator(); foreach ($tab as $key => $value) { if (preg_match("/_indexed\$/", $key) || preg_match("/_name_ts\$/", $key) || preg_match("/_order_by\$/", $key)) { $tab->offsetUnset($key); } } return $tab; }
public function testRun() { $array = array('1' => 'qqer', 'f' => 'qs34$9&)_@+#qer', 'null' => null); $test = Hstore::make($array); $test2 = Hstore::create($test->toString()); $this->assertEquals($test->toString(), $test2->toString()); $this->assertTrue($test->isExists('null')); $this->assertFalse($test->isExists('notExist')); }
public function getStatus() { $hstore = new Hstore(); $hstore->import($this->_get('status')); return $hstore; }
public function executeEdit(sfWebRequest $request) { $staging = Doctrine::getTable('Staging')->findOneById($request->getParameter('id')); $this->import = Doctrine::getTable('Imports')->find($staging->getImportRef()); if (!Doctrine::getTable('collectionsRights')->hasEditRightsFor($this->getUser(), $this->import->getCollectionRef())) { $this->forwardToSecureAction(); } $this->fields = $staging->getFields(); $form_fields = array(); if ($this->fields) { foreach ($this->fields as $key => $values) { $form_fields[] = $values['fields']; } } if (in_array('taxon_ref', $form_fields)) { $parent = new Hstore(); $parent->import($staging->getTaxonParents()); $taxon_parent = $parent->getArrayCopy(); $taxon_parent[$staging->getTaxonLevelName()] = $staging->getTaxonName(); $this->taxon_level_name = $staging->getTaxonLevelName(); $this->catalogues_taxon = Doctrine::getTable('Taxonomy')->getLevelParents('Taxonomy', $taxon_parent); } if (in_array('litho_ref', $form_fields)) { $parent = new Hstore(); $parent->import($staging->getLithoParents()); $parents = $parent->getArrayCopy(); $parents[$staging->getLithoLevelName()] = $staging->getLithoName(); $this->litho_level_name = $staging->getLithoLevelName(); $this->catalogues_litho = Doctrine::getTable('Lithostratigraphy')->getLevelParents('Lithostratigraphy', $parents); } if (in_array('lithology_ref', $form_fields)) { $parent = new Hstore(); $parent->import($staging->getLithologyParents()); $parents = $parent->getArrayCopy(); $parents[$staging->getLithologyLevelName()] = $staging->getLithologyName(); $this->lithology_level_name = $staging->getLithologyLevelName(); $this->catalogues_lithology = Doctrine::getTable('Lithology')->getLevelParents('Lithology', $parents); } if (in_array('chrono_ref', $form_fields)) { $parent = new Hstore(); $parent->import($staging->getChronoParents()); $parents = $parent->getArrayCopy(); $parents[$staging->getChronoLevelName()] = $staging->getChronoName(); $this->chrono_level_name = $staging->getChronoLevelName(); $this->catalogues_chrono = Doctrine::getTable('Chronostratigraphy')->getLevelParents('Chronostratigraphy', $parents); } if (in_array('mineral_ref', $form_fields)) { $parent = new Hstore(); $parent->import($staging->getMineralParents()); $parents = $parent->getArrayCopy(); $parents[$staging->getMineralLevelName()] = $staging->getMineralName(); $this->mineral_level_name = $staging->getMineralLevelName(); $this->catalogues_mineral = Doctrine::getTable('Mineralogy')->getLevelParents('Mineralogy', $parents); } $this->form = new StagingForm($staging, array('fields' => $form_fields)); }
/** * @return TestUser */ private function spawnUser($options = array()) { $options += array('id' => '77', 'credentials' => Credentials::create(), 'lastLogin' => Timestamp::create('2011-12-31'), 'registered' => Timestamp::create('2011-12-30'), 'strangeTime' => Time::create('01:23:45'), 'city' => null, 'firstOptional' => null, 'secondOptional' => null, 'url' => HttpUrl::create()->parse('https://www.github.com'), 'properties' => Hstore::make(array('a' => 'apple', 'b' => 'bananas')), 'ip' => IpAddress::create('127.0.0.1')); return $this->spawnObject(TestUser::create(), $options); }
/** * This function fill all lithology fields from Staging * $chrono_parent may containt all field referenced in $array_level separated by "," */ public function processWithMineralogyNode($xml_node, $object) { $mineral_parent = new Hstore(); // this array below is a mineral array ! I must change it as soon as I get the good list $array_level = array("phylum", "class", "order", "family", "genus", "sub_genus", "species", "sub_species"); foreach ($xml_node->childNodes as $mineral_node) { // text node doesn't interest us if ($mineral_node->nodeName == "#text") { continue; } // if a node have not more than one child, it's a node without childen if (in_array($mineral_node->nodeName, $array_level)) { $mineral_parent[$mineral_node->nodeName] = $mineral_node->nodeValue; } elseif ($mineral_node->nodeName == 'name') { $object['mineralogy_name'] = $mineral_node->nodeValue; } elseif ($mineral_node->nodeName == 'level') { $object['mineralogy_level_name'] = $mineral_node->nodeValue; } elseif ($mineral_node->nodeName == 'comments') { $this->complex_nodes['comments']['node'] = $mineral_node; $this->complex_nodes['comments']['notion_concerned'] = 'mineralogy'; } elseif ($mineral_node->nodeName == 'properties') { $this->complex_nodes['properties']['node'] = $mineral_node; $this->complex_nodes['properties']['notion_concerned'] = 'mineralogy'; } else { throw new Exception('Unknown node ' . $mineral_node->nodeName . ' in mineralogy'); } } $object['mineralogy_parents'] = $mineral_parent->export(); }
public static function containValueList($field, array $list) { return self::containHstore($field, Hstore::make($list)); }