public function testSomeFunctions() { $test = new Article(); $wrapped = new MongoDocumentWrapper($test, $this->dm); $wrapped->populate(array('title' => 'test')); $this->assertEquals('test', $wrapped->getPropertyValue('title')); $this->assertFalse($wrapped->hasValidIdentifier()); }
/** * {@inheritDoc} */ public function childCount($node = null, $direct = false) { $meta = $this->getClassMetadata(); if (is_object($node)) { if (!$node instanceof $meta->name) { throw new InvalidArgumentException("Node is not related to this repository"); } $wrapped = new MongoDocumentWrapper($node, $this->dm); if (!$wrapped->hasValidIdentifier()) { throw new InvalidArgumentException("Node is not managed by UnitOfWork"); } } $qb = $this->getChildrenQueryBuilder($node, $direct); $qb->count(); return (int) $qb->getQuery()->execute(); }
/** * Loads all translations with all translatable * fields from the given entity * * @param object $document * @return array list of translations in locale groups */ public function findTranslations($document) { $result = array(); $wrapped = new MongoDocumentWrapper($document, $this->dm); if ($wrapped->hasValidIdentifier()) { $documentId = $wrapped->getIdentifier(); $translationMeta = $this->getClassMetadata(); $qb = $this->createQueryBuilder(); $q = $qb->field('foreignKey')->equals($documentId)->field('objectClass')->equals($wrapped->getMetadata()->name)->sort('locale', 'asc')->getQuery(); $q->setHydrate(false); $data = $q->execute(); if ($data instanceof Cursor) { $data = $data->toArray(); } if ($data && is_array($data) && count($data)) { foreach ($data as $row) { $result[$row['locale']][$row['field']] = $row['content']; } } } return $result; }
/** * Loads all translations with all translatable * fields from the given entity * * @param object $document * * @return array list of translations in locale groups */ public function findTranslations($document) { $result = array(); $wrapped = new MongoDocumentWrapper($document, $this->dm); if ($wrapped->hasValidIdentifier()) { $documentId = $wrapped->getIdentifier(); $translationMeta = $this->getClassMetadata(); // table inheritance support $config = $this->getTranslatableListener()->getConfiguration($this->dm, get_class($document)); $translationClass = isset($config['translationClass']) ? $config['translationClass'] : $translationMeta->rootDocumentName; $qb = $this->dm->createQueryBuilder($translationClass); $q = $qb->field('foreignKey')->equals($documentId)->field('objectClass')->equals($wrapped->getMetadata()->rootDocumentName)->field('content')->exists(true)->notEqual(null)->sort('locale', 'asc')->getQuery(); $q->setHydrate(false); $data = $q->execute(); if ($data instanceof Cursor) { $data = $data->toArray(); } if ($data && is_array($data) && count($data)) { foreach ($data as $row) { $result[$row['locale']][$row['field']] = $row['content']; } } } return $result; }