Overview

Namespaces

  • rsanchez
    • Deep
      • App
        • EE
        • Laravel
          • Facade
      • Collection
      • Hydrator
      • Model
      • Plugin
      • Relations
      • Repository

Classes

  • AbstractEntity
  • AbstractField
  • AbstractProperty
  • Asset
  • Category
  • CategoryField
  • CategoryPosts
  • Channel
  • Comment
  • Entry
  • Field
  • Fieldtype
  • File
  • GridCol
  • GridRow
  • JoinableScope
  • MatrixCol
  • MatrixRow
  • Member
  • MemberField
  • PlayaEntry
  • RelationshipEntry
  • Site
  • Title
  • UploadPref

Interfaces

  • FileInterface

Traits

  • GlobalAttributeVisibilityTrait
  • JoinableTrait
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Deep
  5:  *
  6:  * @package      rsanchez\Deep
  7:  * @author       Rob Sanchez <info@robsanchez.com>
  8:  */
  9: 
 10: namespace rsanchez\Deep\Model;
 11: 
 12: use Illuminate\Database\Eloquent\Model;
 13: use Illuminate\Database\Eloquent\Builder;
 14: use rsanchez\Deep\Model\Entry;
 15: 
 16: /**
 17:  * {@inheritdoc}
 18:  *
 19:  * Joins with relationships table
 20:  */
 21: class RelationshipEntry extends Entry
 22: {
 23:     /**
 24:      * {@inheritdoc}
 25:      */
 26:     protected $hidden = array('channel', 'site_id', 'forum_topic_id', 'ip_address', 'versioning_enabled', 'parent_id', 'field_id', 'grid_field_id', 'grid_col_id', 'grid_row_id', 'child_id', 'order', 'relationship_id');
 27: 
 28:     /**
 29:      * {@inheritdoc}
 30:      */
 31:     protected $collectionClass = '\\rsanchez\\Deep\\Collection\\RelationshipCollection';
 32: 
 33:     /**
 34:      * {@inheritdoc}
 35:      */
 36:     protected static function joinTables()
 37:     {
 38:         return array_merge(parent::joinTables(), array(
 39:             'relationships' => function ($query) {
 40:                 $query->join('relationships', 'relationships.child_id', '=', 'channel_titles.entry_id');
 41:             },
 42:         ));
 43:     }
 44: 
 45:     /**
 46:      * Filter by Parent Entry ID
 47:      *
 48:      * @param  \Illuminate\Database\Eloquent\Builder $query
 49:      * @param  int|array                             $entryId
 50:      * @return \Illuminate\Database\Eloquent\Builder
 51:      */
 52:     public function scopeParentEntryId(Builder $query, $entryId)
 53:     {
 54:         $entryId = is_array($entryId) ? $entryId : array($entryId);
 55: 
 56:         return $this->requireTable($query, 'relationships', true)->whereIn('relationships.parent_id', $entryId);
 57:     }
 58: 
 59:     /**
 60:      * Get the parents of the specified entry ID
 61:      *
 62:      * @param  \Illuminate\Database\Eloquent\Builder $query
 63:      * @param  int|array                             $entryId
 64:      * @return \Illuminate\Database\Eloquent\Builder
 65:      */
 66:     public function scopeParents(Builder $query, $entryId)
 67:     {
 68:         $entryId = is_array($entryId) ? $entryId : array($entryId);
 69: 
 70:         return $query->join('relationships', 'relationships.parent_id', '=', 'channel_titles.entry_id')
 71:             ->whereIn('relationships.child_id', $entryId)
 72:             ->orderBy('relationships.order', 'asc')
 73:             ->groupBy('relationships.child_id')
 74:             ->groupBy('relationships.field_id')
 75:             ->groupBy('channel_titles.entry_id');
 76:     }
 77: 
 78:     /**
 79:      * Get the siblings of the specified entry ID
 80:      *
 81:      * @param  \Illuminate\Database\Eloquent\Builder $query
 82:      * @param  int|array                             $entryId
 83:      * @return \Illuminate\Database\Eloquent\Builder
 84:      */
 85:     public function scopeSiblings(Builder $query, $entryId)
 86:     {
 87:         $entryId = is_array($entryId) ? $entryId : array($entryId);
 88: 
 89:         $connection = $query->getQuery()->getConnection();
 90:         $tablePrefix = $connection->getTablePrefix();
 91: 
 92:         return $query->join('relationships', 'relationships.child_id', '=', 'channel_titles.entry_id')
 93:             ->join($connection->raw("`{$tablePrefix}relationships` AS `{$tablePrefix}relationships_2`"), 'relationships_2.parent_id', '=', 'relationships.parent_id')
 94:             ->addSelect('*')
 95:             ->addSelect('relationships_2.child_id AS sibling_id')
 96:             ->whereIn('relationships_2.child_id', $entryId)
 97:             ->orderBy('relationships.order', 'asc')
 98:             ->groupBy('relationships_2.child_id')
 99:             ->groupBy('relationships.field_id')
100:             ->groupBy('channel_titles.entry_id');
101:     }
102: }
103: 
API documentation generated by ApiGen 2.8.0