Entity/DocumentRepository.php
changeset 23 b435f8055cb4
parent 18 6f16b9fd6a17
child 27 8551d844b4f3
equal deleted inserted replaced
22:99c15cfe420b 23:b435f8055cb4
   134         throw new \Exception("Unknown accessor $accessor");
   134         throw new \Exception("Unknown accessor $accessor");
   135     }
   135     }
   136     
   136     
   137     function writeDocument($document,  $document_id_column, $fields)
   137     function writeDocument($document,  $document_id_column, $fields)
   138     {
   138     {
   139         # get document from id
   139         // get document from id
       
   140          
   140         $docid = $this->reflectionGetField($document, $document_id_column);
   141         $docid = $this->reflectionGetField($document, $document_id_column);
   141         $baseDocument = $this->findOneByExternalId($docid);
   142         $baseDocument = $this->findOneByExternalId($docid);
   142     
   143     
   143         if(is_null($baseDocument))
   144         if(is_null($baseDocument))
   144         {
   145         {
   145             $baseDocument = new Document();
   146             $baseDocument = new Document();
   146             $baseDocument->setExternalId($docid);
   147             $baseDocument->setExternalId($document);
   147         }
   148         }
   148         
   149         
   149         foreach ($fields as $name => $field_def) {
   150         foreach ($fields as $name => $field_def) {
   150             if(isset($field_def['accessor']))
   151             if(isset($field_def['accessor']))
   151             {
   152             {
   182         {
   183         {
   183             $this->getEntityManager()->remove($baseDocument);
   184             $this->getEntityManager()->remove($baseDocument);
   184         }
   185         }
   185     }
   186     }
   186     
   187     
       
   188     function updateTagsStr($document)
       
   189     {
       
   190         $tags_str = array();
       
   191         foreach($document->getTags() as $tag)
       
   192         {
       
   193             $tags_str[] = $tag->getTag()->getLabel();
       
   194         }
       
   195         
       
   196         $document->setTagsStr(implode(",",$tags_str));
       
   197         
       
   198         $this->getEntityManager()->flush();
       
   199     }
       
   200         
   187 }
   201 }