예제 #1
0
 public function testGet_databox()
 {
     $this->assertInstanceOf('\\databox', $this->object_mono->get_databox());
     $this->assertEquals(self::$DI['record_1']->get_databox()->get_sbas_id(), $this->object_mono->get_databox()->get_sbas_id());
     $this->assertInstanceOf('\\databox', $this->object_multi->get_databox());
     $this->assertEquals(self::$DI['record_1']->get_databox()->get_sbas_id(), $this->object_multi->get_databox()->get_sbas_id());
 }
예제 #2
0
 /**
  *
  * @return string
  */
 public function highlight_thesaurus()
 {
     $value = $this->getValue();
     $databox = $this->databox_field->get_databox();
     $XPATH_thesaurus = $databox->get_xpath_thesaurus();
     $tbranch = $this->databox_field->get_tbranch();
     if (!$tbranch || !$XPATH_thesaurus) {
         return $value;
     }
     // ---------------- new code ----------------------
     $cleanvalue = str_replace(["[[em]]", "[[/em]]", "'"], ["", "", "'"], $value);
     list($term_noacc, $context_noacc) = $this->splitTermAndContext($cleanvalue);
     $term_noacc = $this->app['unicode']->remove_indexer_chars($term_noacc);
     $context_noacc = $this->app['unicode']->remove_indexer_chars($context_noacc);
     // find all synonyms in all related branches
     $q = "(" . $tbranch . ")//sy[@w='" . $term_noacc . "'";
     if ($context_noacc) {
         $q .= " and @k='" . $context_noacc . "']";
     } else {
         $q .= " and not(@k)]";
     }
     $q .= "/../sy";
     $nodes = $XPATH_thesaurus->query($q);
     // loop on every sy found
     $bestnode = null;
     $bestnote = 0;
     foreach ($nodes as $node) {
         $note = 0;
         $note += $node->getAttribute("lng") == $this->app['locale'] ? 4 : 0;
         $note += $node->getAttribute("w") == $term_noacc ? 2 : 0;
         if ($context_noacc != "") {
             $note += $node->getAttribute("k") == $context_noacc ? 1 : 0;
         }
         if ($note > $bestnote) {
             $bestnode = $node;
         }
     }
     if ($bestnode) {
         list($term, $context) = $this->splitTermAndContext(str_replace(["[[em]]", "[[/em]]"], ["", ""], $value));
         // a value has been found in thesaurus, update value & set the query to bounce to the value
         $this->value = $bestnode->getAttribute('v');
         $this->qjs = $term . ($context ? '[' . $context . ']' : '');
         $this->isThesaurusValue = true;
     } else {
         $this->isThesaurusValue = false;
     }
     return $this;
 }
예제 #3
0
 public static function delete_all_metadatas(Application $app, databox_field $databox_field)
 {
     $connection = $databox_field->get_databox()->get_connection();
     $builder = $connection->createQueryBuilder();
     $builder->select('COUNT(m.id) AS count_id')->from('metadatas', 'm')->where($builder->expr()->eq('m.meta_struct_id', ':meta_struct_id'))->setParameter('meta_struct_id', $databox_field->get_id());
     /** @var Statement $stmt */
     $stmt = $builder->execute();
     $rowcount = $stmt->fetchColumn();
     $stmt->closeCursor();
     unset($stmt);
     $n = 0;
     $increment = 500;
     $builder->select('m.record_id', 'm.id')->setMaxResults($increment);
     while ($n < $rowcount) {
         /** @var Statement $stmt */
         $stmt = $builder->setFirstResult($n)->execute();
         $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($rs as $row) {
             try {
                 $record = $databox_field->get_databox()->get_record($row['record_id']);
                 $caption_field = new caption_field($app, $databox_field, $record);
                 $caption_field->delete();
                 $record->set_metadatas([]);
                 unset($caption_field);
                 unset($record);
             } catch (\Exception $e) {
             }
         }
         $n += $increment;
     }
     return;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function asString()
 {
     return serialize(['id' => $this->databox_field->get_id(), 'sbas_id' => $this->databox_field->get_databox()->get_sbas_id(), 'value' => $this->value]);
 }
예제 #5
0
 public static function delete_all_metadatas(Application $app, databox_field $databox_field)
 {
     $sql = 'SELECT count(id) as count_id FROM metadatas
         WHERE meta_struct_id = :meta_struct_id';
     $stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
     $params = [':meta_struct_id' => $databox_field->get_id()];
     $stmt->execute($params);
     $rowcount = $stmt->rowCount();
     $stmt->closeCursor();
     $n = 0;
     $increment = 500;
     while ($n < $rowcount) {
         $sql = 'SELECT record_id, id FROM metadatas
           WHERE meta_struct_id = :meta_struct_id
           LIMIT ' . $n . ', ' . $increment;
         $params = [':meta_struct_id' => $databox_field->get_id()];
         $stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
         $stmt->execute($params);
         $rowcount = $stmt->rowCount();
         $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         unset($stmt);
         foreach ($rs as $row) {
             try {
                 $record = $databox_field->get_databox()->get_record($row['record_id']);
                 $caption_field = new caption_field($app, $databox_field, $record);
                 $caption_field->delete();
                 $record->set_metadatas([]);
                 $app['phraseanet.SE']->updateRecord($record);
                 unset($caption_field);
                 unset($record);
             } catch (\Exception $e) {
             }
         }
         $n += $increment;
     }
     return;
 }