コード例 #1
0
 public function getDashletFields()
 {
     $fields = parent::getDashletFields();
     $all = PostTag::get()->map('Title', 'Title')->toArray();
     $fields->insertAfter(MultiValueTextField::create('FilterTags', 'Tags to filter by', $all), 'Title');
     return $fields;
 }
コード例 #2
0
 /**
  * Tag this post with a particular tag
  * 
  * @param string $tag
  */
 public function tag($tags, $clearExisting = false)
 {
     if (!is_array($tags)) {
         $tags = array($tags);
     }
     if ($clearExisting) {
         $this->Tags()->removeAll();
     }
     $created = array();
     foreach ($tags as $tag) {
         if (!preg_match('/[a-z0-9_-]/i', $tag)) {
             continue;
         }
         $existing = PostTag::get()->filter(array('Title' => $tag))->first();
         if (!$existing) {
             $existing = PostTag::create();
             $existing->Title = $tag;
             $existing->write();
         }
         $this->Tags()->add($existing, array('Tagged' => date('Y-m-d H:i:s')));
         $created[] = $existing;
     }
     return $created;
 }