/**
  * Generic logic for setting PMP doc data from a post
  */
 protected function set_doc_data()
 {
     $this->doc->attributes->title = $this->post->post_title;
     $this->doc->attributes->published = date('c', strtotime($this->post->post_date_gmt));
     $this->doc->attributes->itags = array_merge(self::$ITAGS, array("post-id-{$this->post->ID}"));
     // pull collection/group settings based on the TOP-LEVEL post id
     $top_level_id = $this->post->post_parent > 0 ? $this->post->post_parent : $this->post->ID;
     // collections
     $this->doc->links->collection = array();
     $series = pmp_get_collection_override_value($top_level_id, 'series');
     $property = pmp_get_collection_override_value($top_level_id, 'property');
     if (!empty($series)) {
         $this->doc->links->collection[] = $this->get_collection_link($series, 'series');
     }
     if (!empty($property)) {
         $this->doc->links->collection[] = $this->get_collection_link($property, 'property');
     }
     // permissions
     $this->doc->links->permission = array();
     $group = pmp_get_collection_override_value($top_level_id, 'group');
     if (!empty($group)) {
         $this->doc->links->permission[] = $this->get_group_link($group);
     }
 }
Пример #2
0
/**
 * Builds a data structure that describes a select menu for the post based on the $type
 *
 * @param $type (string) The document option to create a select menu for
 * (i.e., 'group', 'property' or 'series').
 * @since 0.3
 */
function _pmp_select_for_post($post, $type)
{
    $ret = array('default_guid' => get_option('pmp_default_' . $type, false), 'type' => $type);
    $sdk = new SDKWrapper();
    $pmp_things = $sdk->query2json('queryDocs', array('profile' => $type, 'writeable' => 'true', 'limit' => 9999));
    $override = pmp_get_collection_override_value($post, $type);
    $options = array();
    // Pad the options with an empty value
    $options[] = array('selected' => selected($override, false, false), 'guid' => '', 'title' => '--- No ' . $type . ' ---');
    if (!empty($pmp_things['items'])) {
        foreach ($pmp_things['items'] as $thing) {
            if (!empty($override)) {
                $selected = selected($override, $thing['attributes']['guid'], false);
            }
            $option = array('selected' => isset($selected) ? $selected : '', 'guid' => $thing['attributes']['guid'], 'title' => $thing['attributes']['title']);
            $options[] = $option;
        }
    }
    $ret['options'] = $options;
    return $ret;
}