1: <?php
2:
3: /**
4: * Orchestra: A minimalist object-oriented superset for WordPress using Phalcon.
5: *
6: * This source file is subject to the MIT license that is bundled
7: * with this package in the file LICENSE and is available through
8: * the world-wide-web at the following URI:
9: * http://opensource.org/licenses/MIT
10: *
11: * @copyright Akufen Atelier Creatif
12: * @author Nicholas Charbonneau <nicholas@akufen.ca>
13: * @license http://opensource.org/licenses/MIT
14: * @version 0.1.3
15: * @link https://github.com/akufenstudio/orchestra
16: */
17:
18: namespace Akufen\Orchestra\Mvc\Models;
19:
20: /**
21: * Akufen\Orchestra\Mvc\Models
22: *
23: * A model for WordPress posts
24: *
25: * @package Models
26: * @uses \Akufen\Orchestra\Mvc\Model
27: */
28: class Posts extends \Akufen\Orchestra\Mvc\Model
29: {
30: /**
31: * Initialize a post's source & relationships
32: *
33: * @return void
34: */
35: public function initialize()
36: {
37: global $table_prefix;
38:
39: $this->setSource($table_prefix . 'posts');
40:
41: // Posts belong to an author
42: $this->belongsTo(
43: 'post_author',
44: 'Akufen\Orchestra\Mvc\Models\Users',
45: 'ID',
46: array('alias' => 'postAuthor')
47: );
48:
49: // Posts may have parent posts
50: $this->belongsTo(
51: 'post_parent',
52: 'Akufen\Orchestra\Mvc\Models\Posts',
53: 'ID',
54: array('alias' => 'postParent')
55: );
56:
57: // Posts have many post metas
58: $this->hasMany(
59: 'ID',
60: 'Akufen\Orchestra\Mvc\Models\PostMeta',
61: 'post_id',
62: array('alias' => 'metas')
63: );
64:
65: // Posts have many term relationships
66: $this->hasMany(
67: 'ID',
68: 'Akufen\Orchestra\Mvc\Models\TermRelationships',
69: 'object_id',
70: array('alias' => 'termRelationships')
71: );
72: }
73:
74: /**
75: * Retrieve the post's permalink.
76: *
77: * @return string $permalink The post's permalink.
78: */
79: public function getPermalink()
80: {
81: return get_permalink($this->ID);
82: }
83: }
84: