Example #1
0
 public function map(EntityContract $entity, array $data)
 {
     $id = $data['post_parent'];
     $entity->setParent(function () use($id) {
         $parent = null;
         if ($id) {
             $parent = $this->postRepository->postOfId($id);
         }
         return $parent;
     });
     $id = $data['ID'];
     $entity->setCategories(function () use($id) {
         $categories = new Collection();
         foreach (wp_get_post_categories($id) as $termId) {
             $categories->push($this->categoryRepository->categoryOfId($termId));
         }
         return $categories;
     });
     $entity->setTags(function () use($id) {
         $tags = new Collection();
         foreach (wp_get_post_tags($id) as $termId) {
             $tags->push($this->tagRepository->tagOfId($termId));
         }
         return $tags;
     });
 }
Example #2
0
 public function find($args = null)
 {
     if (is_null($args) or is_array($args)) {
         $defaults = $this->newParams();
         $defaults = $defaults instanceof Arrayable ? $defaults->toArray() : $defaults;
         $args = is_array($args) ? array_replace_recursive($defaults, $args) : $defaults;
     }
     $args = $args instanceof Arrayable ? $args->toArray() : $args;
     $users = new Collection();
     foreach (get_users($args) as $user) {
         $users->push($this->userOfId($user->ID));
     }
     return $users;
 }
Example #3
0
 /**
  * Return a collection of terms
  *
  * @param  Fire\Contracts\Foundation\Arrayable|array|null  $args
  * @return Fire\Foundation\Collection
  */
 public function find($args = null)
 {
     if (is_null($args) or is_array($args)) {
         $defaults = $this->newParams();
         $defaults = $defaults instanceof Arrayable ? $defaults->toArray() : $defaults;
         $args = is_array($args) ? array_replace_recursive($defaults, $args) : $defaults;
     }
     $args = $args instanceof Arrayable ? $args->toArray() : $args;
     $terms = new Collection();
     foreach (get_terms($this->taxonomy, $args) as $term) {
         $terms->push($this->termOfId($term->term_id));
     }
     return $terms;
 }
Example #4
0
 public function find($args = null)
 {
     if (is_null($args) or is_array($args)) {
         $defaults = $this->newParams();
         $defaults = $defaults instanceof Arrayable ? $defaults->toArray() : $defaults;
         $args = is_array($args) ? array_replace_recursive($defaults, $args) : $defaults;
     }
     $args = $args instanceof Arrayable ? $args->toArray() : $args;
     $comments = new Collection();
     foreach (get_comments($args) as $comment) {
         $comments->push($this->commentOfId($comment->comment_ID));
     }
     return $comments;
 }
Example #5
0
 /**
  * Set the current entities for use in templates
  */
 protected function setCurrentEntities()
 {
     global $wp_query;
     if ($post = $wp_query->post) {
         if ($post->post_type === PagePostType::TYPE) {
             $this->pageRepository->setCurrentPage($this->pageRepository->pageOfId($post->ID));
         } elseif ($post->post_type === PostPostType::TYPE) {
             $this->postRepository->setCurrentPost($this->postRepository->postOfId($post->ID));
         }
     }
     $collection = new Collection();
     if ($posts = $wp_query->posts) {
         foreach ($posts as $post) {
             $collection->push($this->postRepository->postOfId($post->ID));
         }
     }
     $this->postRepository->setCurrentPosts($collection);
 }