/** * See if a term or set of terms is in this set of terms * * @param mixed $tags. A string containing a string or a comma separated list of strings, * or an array of strings, Terms, or a Term subclass * @return boolean. Whether the tag(s) is in the current set of tags. */ public function has($tags) { if (is_string($tags) || is_array($tags) && is_string($tags[0])) { $tags = (array) Terms::parse($tags); } $diff = array_diff($tags, (array) $this); foreach ($tags as $tag) { if (in_array($tag, $diff)) { return false; } } return true; }
/** * function __set * Overrides QueryRecord __set to implement custom object properties * @param string Name of property to return * @return mixed The requested field value */ public function __set( $name, $value ) { switch ( $name ) { case 'pubdate': case 'updated': case 'modified': if ( !( $value instanceOf HabariDateTime ) ) { $value = HabariDateTime::date_create( $value ); } break; case 'tags': if ( $value instanceof Terms ) { return $this->tags_object = $value; } elseif ( is_array( $value ) ) { return $this->tags_object = new Terms($value); } else { return $this->tags_object = Terms::parse( $value, 'Term', Tags::vocabulary() ); } case 'status': return $this->setstatus( $value ); } return parent::__set( $name, $value ); }
/** * Save the tags associated to this object into the terms and object_terms tables * * @param Array $tags strings. The tag names to associate to the object * @param Integer $object_id. The id of the object being tagged * @param String $object_type. The name of the type of the object being tagged. Defaults to post * * @return boolean. Whether the associating succeeded or not. true */ public static function save_associations($terms, $object_id, $object_type = 'post') { if (!$terms instanceof Terms) { $terms = Terms::parse($terms, 'Tag', Tags::vocabulary()); } return self::vocabulary()->set_object_terms($object_type, $object_id, $terms); }
/** * Process categories when the publish form is received * **/ public function action_publish_post($post, $form) { if ($post->content_type == Post::type(self::$content_type)) { $categories = array(); // $categories = $this->parse_categories( $form->categories->value ); $categories = Terms::parse($form->categories->value, 'Term', $this->vocabulary); $this->vocabulary->set_object_terms('post', $post->id, $categories); } }