Example #1
0
 public function slug($slug = null)
 {
     if (func_num_args() > 0) {
         $this->slug = isset($slug) ? strtolower(\Coast\str_slugify(iconv('utf-8', 'ascii//translit//ignore', $slug))) : $slug;
         return $this;
     }
     return $this->slug;
 }
Example #2
0
 public function tagsText($tagsText = null)
 {
     if (func_num_args() > 0) {
         if (!isset($tagsText)) {
             $this->tags->clear();
             return $this;
         }
         $split = explode(',', $tagsText);
         $names = [];
         foreach ($split as $name) {
             $names[strtolower(\Coast\str_slugify(iconv('utf-8', 'ascii//translit//ignore', $name)))] = trim($name);
         }
         $tags = Wrapper::$em->__invoke('core_tag')->all(['slugs' => array_keys($names)]);
         foreach ($tags as $tag) {
             if (isset($names[$tag->slug])) {
                 unset($names[$tag->slug]);
             }
         }
         foreach ($names as $slug => $name) {
             $tag = new Tag();
             $tag->fromArray(['name' => $name]);
             $tags[] = $tag;
         }
         foreach ($tags as $tag) {
             if (!$this->tags->contains($tag)) {
                 $this->tags->add($tag);
             }
         }
         foreach ($this->tags as $tag) {
             if (!in_array($tag, $tags, true)) {
                 $this->tags->removeElement($tag);
             }
         }
         return $this;
     }
     return implode(', ', array_map(function ($tag) {
         return $tag->name;
     }, $this->tags->toArray()));
 }
Example #3
0
function str_camel_upper($string)
{
    return \str_replace(' ', null, \ucwords(\Coast\str_slugify($string, ' ')));
}