Beispiel #1
0
 /**
  * After creating a new Article, tokenize the description field to form a set
  * of automated tags and save them.
  *
  * @since 1.0
  */
 protected function after_save_callback()
 {
     if ($this->getVersion() == 1 && $this->tags instanceof \Alpha\Model\Type\Relation) {
         // update the empty tags values to reference this OID
         $this->tags->setValue($this->OID);
         foreach ($this->taggedAttributes as $tagged) {
             $tags = Tag::tokenize($this->get($tagged), 'Alpha\\Model\\Article', $this->getOID());
             foreach ($tags as $tag) {
                 try {
                     $tag->save();
                 } catch (ValidationException $e) {
                     /*
                      * The unique key has most-likely been violated because this BO is already tagged with this
                      * value, so we can ignore in this case.
                      */
                 }
             }
         }
     }
     $this->setupRels();
 }
Beispiel #2
0
 /**
  * Test to ensure that the duplicated value "unittestarticle" is only converted to a Tag once by Tag::tokenize.
  *
  * @since 1.0
  */
 public function testTokenizeNoDuplicates()
 {
     $tags = Tag::tokenize($this->article->get('description'), 'Article', $this->article->getOID());
     $count = 0;
     foreach ($tags as $tag) {
         if ($tag->get('content') == 'unittestarticle') {
             ++$count;
         }
     }
     $this->assertEquals(1, $count, 'Test to ensure that the duplicated value "unittestarticle" is only converted to a Tag once by Tag::tokenize');
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function index($sourceObject)
 {
     $taggedAttributes = $sourceObject->getTaggedAttributes();
     foreach ($taggedAttributes as $tagged) {
         $tags = Tag::tokenize($sourceObject->get($tagged), get_class($sourceObject), $sourceObject->getOID());
         foreach ($tags as $tag) {
             try {
                 $tag->save();
             } catch (ValidationException $e) {
                 /*
                  * The unique key has most-likely been violated because this BO is already tagged with this
                  * value, so we can ignore in this case.
                  */
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Regenerates the tags on the supplied list of active records.
  *
  * @param array $records
  *
  * @since 1.0
  */
 private function regenerateTagsOnRecords($records)
 {
     foreach ($records as $record) {
         foreach ($record->get('taggedAttributes') as $tagged) {
             $tags = Tag::tokenize($record->get($tagged), get_class($record), $record->getOID());
             foreach ($tags as $tag) {
                 try {
                     $tag->save();
                 } catch (ValidationException $e) {
                     /*
                      * The unique key has most-likely been violated because this record is already tagged with this
                      * value, so we can ignore in this case.
                      */
                 }
             }
         }
     }
 }