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\Collection\CategoryCollection;
 15: use rsanchez\Deep\Repository\CategoryFieldRepository;
 16: use rsanchez\Deep\Repository\ChannelRepository;
 17: use rsanchez\Deep\Model\JoinableTrait;
 18: 
 19: /**
 20:  * Model for the categories table
 21:  */
 22: class Category extends Model
 23: {
 24:     use JoinableTrait;
 25: 
 26:     /**
 27:      * {@inheritdoc}
 28:      *
 29:      * @var string
 30:      */
 31:     protected $table = 'categories';
 32: 
 33:     /**
 34:      * {@inheritdoc}
 35:      *
 36:      * @var string
 37:      */
 38:     protected $primaryKey = 'cat_id';
 39: 
 40:     /**
 41:      * Whether to build the collection as a nested set
 42:      * @var boolean
 43:      */
 44:     protected $nested = false;
 45: 
 46:     /**
 47:      * Collection of child categories
 48:      * @var \rsanchez\Deep\Collection\NestedCategoryCollection
 49:      */
 50:     protected $childCategoryCollection;
 51: 
 52:     /**
 53:      * Global Category Field Repository
 54:      * @var \rsanchez\Deep\Repository\CategoryFieldRepository
 55:      */
 56:     protected static $categoryFieldRepository;
 57: 
 58:     /**
 59:      * Global Channel Repository
 60:      * @var \rsanchez\Deep\Repository\ChannelRepository
 61:      */
 62:     protected static $channelRepository;
 63: 
 64:     /**
 65:      * Get child categories
 66:      * NOTE: this will be empty unless you call scopeNested
 67:      * @return \rsanchez\Deep\Collection\CategoryCollection
 68:      */
 69:     public function getChildrenAttribute()
 70:     {
 71:         if (is_null($this->childCategoryCollection)) {
 72:             $this->childCategoryCollection = new CategoryCollection();
 73:         }
 74: 
 75:         return $this->childCategoryCollection;
 76:     }
 77: 
 78:     /**
 79:      * Check if the child collection is empty
 80:      * @return boolean
 81:      */
 82:     public function hasChildren()
 83:     {
 84:         return ! $this->children->isEmpty();
 85:     }
 86: 
 87:     /**
 88:      * Set the global CategoryFieldRepository
 89:      * @param  \rsanchez\Deep\Repository\CategoryFieldRepository $categoryFieldRepository
 90:      * @return void
 91:      */
 92:     public static function setCategoryFieldRepository(CategoryFieldRepository $categoryFieldRepository)
 93:     {
 94:         self::$categoryFieldRepository = $categoryFieldRepository;
 95:     }
 96: 
 97:     /**
 98:      * Set the global ChannelRepository
 99:      * @param  \rsanchez\Deep\Repository\ChannelRepository $channelRepository
100:      * @return void
101:      */
102:     public static function setChannelRepository(ChannelRepository $channelRepository)
103:     {
104:         self::$channelRepository = $channelRepository;
105:     }
106: 
107:     /**
108:      * Join with category_data
109:      *
110:      * @param  \Illuminate\Database\Eloquent\Builder $query;
111:      * @return \Illuminate\Database\Eloquent\Builder
112:      */
113:     public function scopeWithFields(Builder $query)
114:     {
115:         return $this->requireTable($query, 'category_field_data');
116:     }
117: 
118:     /**
119:      * {@inheritdoc}
120:      */
121:     protected static function joinTables()
122:     {
123:         return array(
124:             'category_field_data' => function ($query) {
125:                 $query->join('category_field_data', 'category_field_data.cat_id', '=', 'categories.cat_id');
126:             },
127:         );
128:     }
129: 
130:     /**
131:      * Define the entries Eloquent relationship
132:      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
133:      */
134:     public function entries()
135:     {
136:         return $this->belongsToMany('\\rsanchez\\Deep\\Model\\Title', 'category_posts', 'entry_id', 'cat_id');
137:     }
138: 
139:     /**
140:      * Alias custom field names
141:      *
142:      * {@inheritdoc}
143:      */
144:     public function getAttribute($name)
145:     {
146:         if (! isset($this->attributes[$name]) && self::$categoryFieldRepository->hasField($name)) {
147:             $name = 'field_id_'.self::$categoryFieldRepository->getFieldId($name);
148:         }
149: 
150:         return parent::getAttribute($name);
151:     }
152: 
153:     /**
154:      * {@inheritdoc}
155:      */
156:     public function attributesToArray()
157:     {
158:         $array = parent::attributesToArray();
159: 
160:         foreach ($array as $key => $value) {
161:             if (strncmp($key, 'field_id_', 9) === 0) {
162:                 $id = substr($key, 9);
163: 
164:                 if (self::$categoryFieldRepository->hasFieldId($id)) {
165:                     $array[self::$categoryFieldRepository->getFieldName($id)] = $value;
166:                 }
167: 
168:                 unset($array[$key]);
169:             }
170:         }
171: 
172:         return $array;
173:     }
174: 
175:     /**
176:      * {@inheritdoc}
177:      *
178:      * @param  array                                        $models
179:      * @return \rsanchez\Deep\Collection\CategoryCollection
180:      */
181:     public function newCollection(array $models = array())
182:     {
183:         if ($this->nested) {
184:             $collection = new CategoryCollection();
185: 
186:             $modelsByKey = array();
187:             $childrenByParentId = array();
188: 
189:             foreach ($models as $model) {
190:                 $modelsByKey[$model->cat_id] = $model;
191: 
192:                 if ($model->parent_id) {
193:                     if (isset($modelsByKey[$model->parent_id])) {
194:                         $modelsByKey[$model->parent_id]->children->push($model);
195:                     } else {
196:                         $childrenByParentId[$model->parent_id][] = $model;
197:                     }
198:                 } else {
199:                     if (isset($childrenByParentId[$model->cat_id])) {
200:                         foreach ($childrenByParentId[$model->cat_id] as $child) {
201:                             $model->children->push($child);
202:                         }
203: 
204:                         unset($childrenByParentId[$model->cat_id]);
205:                     }
206: 
207:                     $collection->push($model);
208:                 }
209:             }
210: 
211:             $this->nested = false;
212: 
213:             return $collection;
214:         }
215: 
216:         return new CategoryCollection($models);
217:     }
218: 
219:     /**
220:      * Filter by Category ID
221:      *
222:      * @param  \Illuminate\Database\Eloquent\Builder $query
223:      * @param  dynamic  string                       $categoryId
224:      * @return \Illuminate\Database\Eloquent\Builder
225:      */
226:     public function scopeCategoryId(Builder $query, $categoryId)
227:     {
228:         $categoryIds = array_slice(func_get_args(), 1);
229: 
230:         return $query->whereIn('categories.cat_id', $categoryIds);
231:     }
232: 
233:     /**
234:      * Filter by not Category ID
235:      *
236:      * @param  \Illuminate\Database\Eloquent\Builder $query
237:      * @param  dynamic  string                       $categoryId
238:      * @return \Illuminate\Database\Eloquent\Builder
239:      */
240:     public function scopeNotCategoryId(Builder $query, $categoryId)
241:     {
242:         $categoryIds = array_slice(func_get_args(), 1);
243: 
244:         return $query->whereNotIn('categories.cat_id', $categoryIds);
245:     }
246: 
247:     /**
248:      * Filter by Category Name
249:      *
250:      * @param  \Illuminate\Database\Eloquent\Builder $query
251:      * @param  dynamic  string                       $categoryName
252:      * @return \Illuminate\Database\Eloquent\Builder
253:      */
254:     public function scopeCategoryName(Builder $query, $categoryName)
255:     {
256:         $categoryNames = array_slice(func_get_args(), 1);
257: 
258:         return $query->whereIn('categories.cat_name', $categoryNames);
259:     }
260: 
261:     /**
262:      * Filter by not Category Name
263:      *
264:      * @param  \Illuminate\Database\Eloquent\Builder $query
265:      * @param  dynamic  string                       $categoryName
266:      * @return \Illuminate\Database\Eloquent\Builder
267:      */
268:     public function scopeNotCategoryName(Builder $query, $categoryName)
269:     {
270:         $categoryNames = array_slice(func_get_args(), 1);
271: 
272:         return $query->whereNotIn('categories.cat_name', $categoryNames);
273:     }
274: 
275:     /**
276:      * Filter by Category Group
277:      *
278:      * @param  \Illuminate\Database\Eloquent\Builder $query
279:      * @param  dynamic  string                       $groupId
280:      * @return \Illuminate\Database\Eloquent\Builder
281:      */
282:     public function scopeCategoryGroup(Builder $query, $groupId)
283:     {
284:         $groupIds = array_slice(func_get_args(), 1);
285: 
286:         return $query->whereIn('categories.group_id', $groupIds);
287:     }
288: 
289:     /**
290:      * Filter by Not Category Group
291:      *
292:      * @param  \Illuminate\Database\Eloquent\Builder $query
293:      * @param  dynamic  string                       $groupId
294:      * @return \Illuminate\Database\Eloquent\Builder
295:      */
296:     public function scopeNotCategoryGroup(Builder $query, $groupId)
297:     {
298:         $groupIds = array_slice(func_get_args(), 1);
299: 
300:         return $query->whereNotIn('categories.group_id', $groupIds);
301:     }
302: 
303:     /**
304:      * Filter by Category ID string parameter
305:      *
306:      * @param  \Illuminate\Database\Eloquent\Builder $query
307:      * @param  string                                $string
308:      * @return \Illuminate\Database\Eloquent\Builder
309:      */
310:     public function scopeCategoryIdString(Builder $query, $string)
311:     {
312:         return $this->scopeArrayFromString($query, $string, 'CategoryId');
313:     }
314: 
315:     /**
316:      * Filter by Category Group string parameter
317:      *
318:      * @param  \Illuminate\Database\Eloquent\Builder $query
319:      * @param  string                                $string
320:      * @return \Illuminate\Database\Eloquent\Builder
321:      */
322:     public function scopeCategoryGroupString(Builder $query, $string)
323:     {
324:         return $this->scopeArrayFromString($query, $string, 'CategoryGroup');
325:     }
326: 
327:     /**
328:      * Filter by Category Name string parameter
329:      *
330:      * @param  \Illuminate\Database\Eloquent\Builder $query
331:      * @param  string                                $string
332:      * @return \Illuminate\Database\Eloquent\Builder
333:      */
334:     public function scopeCategoryNameString(Builder $query, $string)
335:     {
336:         return $this->scopeArrayFromString($query, $string, 'CategoryName');
337:     }
338: 
339:     /**
340:      * Limit the number of results
341:      *
342:      * @param  \Illuminate\Database\Eloquent\Builder $query
343:      * @param  int                                   $limit
344:      * @return \Illuminate\Database\Eloquent\Builder
345:      */
346:     public function scopeLimit(Builder $query, $limit)
347:     {
348:         return $query->take($limit);
349:     }
350: 
351:     /**
352:      * Offset the results
353:      *
354:      * @param  \Illuminate\Database\Eloquent\Builder $query
355:      * @param  int                                   $offset
356:      * @return \Illuminate\Database\Eloquent\Builder
357:      */
358:     public function scopeOffset(Builder $query, $offset)
359:     {
360:         return $query->skip($offset);
361:     }
362: 
363:     /**
364:      * Parents only, no sub categories
365:      *
366:      * @param  \Illuminate\Database\Eloquent\Builder $query
367:      * @param  bool                                  $parentsOnly
368:      * @return \Illuminate\Database\Eloquent\Builder
369:      */
370:     public function scopeParentOnly(Builder $query, $parentsOnly = true)
371:     {
372:         return $parentsOnly ? $query->where('parent_id', 0) : $query;
373:     }
374: 
375:     /**
376:      * Parents only string parameter
377:      *
378:      * @param  \Illuminate\Database\Eloquent\Builder $query
379:      * @param  string                                $string
380:      * @return \Illuminate\Database\Eloquent\Builder
381:      */
382:     public function scopeParentOnlyString(Builder $query, $string)
383:     {
384:         return $this->scopeParentOnly($query, $string === 'yes');
385:     }
386: 
387:     /**
388:      * Filter by Channel Name
389:      *
390:      * @param  \Illuminate\Database\Eloquent\Builder $query
391:      * @param  dynamic  string                       $channelName
392:      * @return \Illuminate\Database\Eloquent\Builder
393:      */
394:     public function scopeChannel(Builder $query, $channelName)
395:     {
396:         $channelNames = array_slice(func_get_args(), 1);
397: 
398:         $channels = self::$channelRepository->getChannelsByName($channelNames);
399: 
400:         $groupIds = array();
401: 
402:         $channels->each(function ($channel) use (&$groupIds) {
403:             $groupIds += $channel->cat_group;
404:         });
405: 
406:         if ($groupIds) {
407:             array_unshift($groupIds, $query);
408: 
409:             call_user_func_array(array($this, 'scopeCategoryGroup'), $groupIds);
410:         }
411: 
412:         return $query;
413:     }
414: 
415:     /**
416:      * Filter by not Channel Name
417:      *
418:      * @param  \Illuminate\Database\Eloquent\Builder $query
419:      * @param  dynamic  string                       $channelName
420:      * @return \Illuminate\Database\Eloquent\Builder
421:      */
422:     public function scopeNotChannel(Builder $query, $channelName)
423:     {
424:         $channelNames = array_slice(func_get_args(), 1);
425: 
426:         $channels = self::$channelRepository->getChannelsByName($channelNames);
427: 
428:         $groupIds = array();
429: 
430:         $channels->each(function ($channel) use (&$groupIds) {
431:             $groupIds += $channel->cat_group;
432:         });
433: 
434:         if ($groupIds) {
435:             array_unshift($groupIds, $query);
436: 
437:             call_user_func_array(array($this, 'scopeNotCategoryGroup'), $groupIds);
438:         }
439: 
440:         return $query;
441:     }
442: 
443:     /**
444:      * Filter by Channel string parameter
445:      *
446:      * @param  \Illuminate\Database\Eloquent\Builder $query
447:      * @param  string                                $string
448:      * @return \Illuminate\Database\Eloquent\Builder
449:      */
450:     public function scopeChannelString(Builder $query, $string)
451:     {
452:         return $this->scopeArrayFromString($query, $string, 'Channel');
453:     }
454: 
455:     /**
456:      * Filter by Channel Name
457:      *
458:      * @param  \Illuminate\Database\Eloquent\Builder $query
459:      * @param  dynamic  string                       $channelName
460:      * @return \Illuminate\Database\Eloquent\Builder
461:      */
462:     public function scopeEntryChannel(Builder $query, $channelName)
463:     {
464:         $channelNames = array_slice(func_get_args(), 1);
465: 
466:         $channels = self::$channelRepository->getChannelsByName($channelNames);
467: 
468:         $channelIds = array();
469: 
470:         $channels->each(function ($channel) use (&$channelIds) {
471:             $channelIds[] = $channel->channel_id;
472:         });
473: 
474:         if ($channelIds) {
475:             $query->whereHas('entries', function ($q) use ($channelIds) {
476:                 $q->whereIn('channel_titles.channel_id', $channelIds);
477:             });
478:         }
479: 
480:         return $query;
481:     }
482: 
483:     /**
484:      * Filter by not Channel Name
485:      *
486:      * @param  \Illuminate\Database\Eloquent\Builder $query
487:      * @param  dynamic  string                       $channelName
488:      * @return \Illuminate\Database\Eloquent\Builder
489:      */
490:     public function scopeNotEntryChannel(Builder $query, $channelName)
491:     {
492:         $channelNames = array_slice(func_get_args(), 1);
493: 
494:         $channels = self::$channelRepository->getChannelsByName($channelNames);
495: 
496:         $channelIds = array();
497: 
498:         $channels->each(function ($channel) use (&$channelIds) {
499:             $channelIds[] = $channel->channel_id;
500:         });
501: 
502:         if ($channelIds) {
503:             $query->whereHas('entries', function ($q) use ($channelIds) {
504:                 $q->whereNotIn('channel_titles.channel_id', $channelIds);
505:             });
506:         }
507: 
508:         return $query;
509:     }
510: 
511:     /**
512:      * Filter by Channel string parameter
513:      *
514:      * @param  \Illuminate\Database\Eloquent\Builder $query
515:      * @param  string                                $string
516:      * @return \Illuminate\Database\Eloquent\Builder
517:      */
518:     public function scopeEntryChannelString(Builder $query, $string)
519:     {
520:         return $this->scopeArrayFromString($query, $string, 'EntryChannel');
521:     }
522: 
523:     /**
524:      * Filter by categories with no entries
525:      *
526:      * @return \Illuminate\Database\Eloquent\Builder $query
527:      * @param  boolean                               $showEmpty
528:      * @return \Illuminate\Database\Eloquent\Builder
529:      */
530:     public function scopeShowEmpty(Builder $query, $showEmpty = true)
531:     {
532:         return $showEmpty ? $query : $query->whereHas('entries');
533:     }
534: 
535:     /**
536:      * Show empty string parameter
537:      *
538:      * @param  \Illuminate\Database\Eloquent\Builder $query
539:      * @param  string                                $string
540:      * @return \Illuminate\Database\Eloquent\Builder
541:      */
542:     public function scopeShowEmptyString(Builder $query, $string)
543:     {
544:         return $this->scopeShowEmpty($query, $string === 'yes');
545:     }
546: 
547:     /**
548:      * Filter by expired entries
549:      *
550:      * @return \Illuminate\Database\Eloquent\Builder $query
551:      * @param  boolean                               $showExpired
552:      * @return \Illuminate\Database\Eloquent\Builder
553:      */
554:     public function scopeShowExpired(Builder $query, $showExpired = true)
555:     {
556:         if ($showExpired) {
557:             return $query;
558:         }
559: 
560:         $prefix = $query->getQuery()->getConnection()->getTablePrefix();
561: 
562:         return $query->whereHas('entries', function ($q) {
563:             $q->whereRaw(
564:                 "(`{$prefix}channel_titles`.`expiration_date` = '' OR  `{$prefix}channel_titles`.`expiration_date` > NOW())"
565:             );
566:         });
567:     }
568: 
569:     /**
570:      * Show expired string parameter
571:      *
572:      * @param  \Illuminate\Database\Eloquent\Builder $query
573:      * @param  string                                $string
574:      * @return \Illuminate\Database\Eloquent\Builder
575:      */
576:     public function scopeShowExpiredString(Builder $query, $string)
577:     {
578:         return $this->scopeShowExpired($query, $string === 'yes');
579:     }
580: 
581:     public function scopeShowFutureEntries(Builder $query, $showFutureEntries = true)
582:     {
583:         if ($showFutureEntries) {
584:             return $query;
585:         }
586: 
587:         $prefix = $query->getQuery()->getConnection()->getTablePrefix();
588: 
589:         return $query->whereHas('entries', function ($q) {
590:             $q->whereRaw(
591:                 "(`{$prefix}channel_titles`.`expiration_date` = '' OR  `{$prefix}channel_titles`.`expiration_date` > NOW())"
592:             );
593:         });
594:     }
595: 
596:     /**
597:      * Show empty string parameter
598:      *
599:      * @param  \Illuminate\Database\Eloquent\Builder $query
600:      * @param  string                                $string
601:      * @return \Illuminate\Database\Eloquent\Builder
602:      */
603:     public function scopeShowFutureEntriesString(Builder $query, $string)
604:     {
605:         return $this->scopeShowFutureEntries($query, $string === 'yes');
606:     }
607: 
608:     /**
609:      * Filter by Entry Status
610:      *
611:      * @param  \Illuminate\Database\Eloquent\Builder $query
612:      * @param  dynamic  string                       $status
613:      * @return \Illuminate\Database\Eloquent\Builder
614:      */
615:     public function scopeStatus(Builder $query, $status)
616:     {
617:         $statuses = array_slice(func_get_args(), 1);
618: 
619:         return $query->whereHas('entries', function ($q) use ($statuses) {
620:             return $q->whereIn('status', $statuses);
621:         });
622:     }
623: 
624:     /**
625:      * Filter by Not Entry Status
626:      *
627:      * @param  \Illuminate\Database\Eloquent\Builder $query
628:      * @param  dynamic  string                       $status
629:      * @return \Illuminate\Database\Eloquent\Builder
630:      */
631:     public function scopeNotStatus(Builder $query, $status)
632:     {
633:         $statuses = array_slice(func_get_args(), 1);
634: 
635:         return $query->whereHas('entries', function ($q) use ($statuses) {
636:             return $q->whereNotIn('status', $statuses);
637:         });
638:     }
639: 
640:     /**
641:      * Filter by Status string parameter
642:      *
643:      * @param  \Illuminate\Database\Eloquent\Builder $query
644:      * @param  string                                $string
645:      * @return \Illuminate\Database\Eloquent\Builder
646:      */
647:     public function scopeStatusString(Builder $query, $string)
648:     {
649:         return $this->scopeArrayFromString($query, $string, 'Status');
650:     }
651: 
652:     /**
653:      * Apply a single parameter
654:      *
655:      * @param  \Illuminate\Database\Eloquent\Builder $query
656:      * @param  string                                $key   snake_cased parameter name
657:      * @param  string                                $value scope parameters in string form, eg. 1|2|3
658:      * @return \Illuminate\Database\Eloquent\Builder
659:      */
660:     public function scopeTagparam(Builder $query, $key, $value)
661:     {
662:         /**
663:          * A map of parameter names => model scopes
664:          * @var array
665:          */
666:         static $parameterMap = array(
667:             'show' => 'categoryIdString',
668:             'category_name' => 'categoryNameString',
669:             'category_group' => 'categoryGroupString',
670:             'channel' => 'channelString',
671:             'limit' => 'limit',
672:             'offset' => 'offset',
673:             'parent_only' => 'parentOnlyString',
674:             //'restrict_channel' => 'restrictChannel',
675:             'show_empty' => 'showEmptyString',
676:             'show_expired' => 'showExpiredString',
677:             'show_future_entries' => 'showFutureEntriesString',
678:             'status' => 'statusString',
679:             'style' => 'styleString',
680:         );
681: 
682:         if (! array_key_exists($key, $parameterMap)) {
683:             return $query;
684:         }
685: 
686:         $method = 'scope'.ucfirst($parameterMap[$key]);
687: 
688:         return $this->$method($query, $value);
689:     }
690: 
691:     /**
692:      * Apply an array of parameters
693:      *
694:      * @param  \Illuminate\Database\Eloquent\Builder $query
695:      * @param  array                                 $parameters
696:      * @return \Illuminate\Database\Eloquent\Builder
697:      */
698:     public function scopeTagparams(Builder $query, array $parameters)
699:     {
700:         $showEmpty = ! isset($parameters['show_empty']) || $parameters['show_empty'] === 'yes';
701:         $restrictChannel = ! isset($parameters['restrict_channel']) || $parameters['restrict_channel'] === 'yes';
702: 
703:         if ($showEmpty) {
704:             unset($parameters['status'], $parameters['show_expired'], $parameters['show_future_entries']);
705:         } else {
706:             if ($restrictChannel && isset($parameters['channel'])) {
707:                 $query->entryChannelString($parameters['channel']);
708:             }
709:         }
710: 
711:         // because you're so special
712:         if (! empty($parameters['orderby'])) {
713:             $directions = isset($parameters['sort']) ? explode('|', $parameters['sort']) : null;
714: 
715:             foreach (explode('|', $parameters['orderby']) as $i => $column) {
716:                 $direction = isset($directions[$i]) ? $directions[$i] : 'asc';
717:                 $query->orderBy($column, $direction);
718:             }
719:         }
720: 
721:         foreach ($parameters as $key => $value) {
722:             $this->scopeTagparam($query, $key, $value);
723:         }
724: 
725:         return $query;
726:     }
727: 
728:     public function scopeStyleString(Builder $query, $string)
729:     {
730:         return $string === 'nested' ? $this->scopeNested($query) : $query;
731:     }
732: 
733:     /**
734:      * Order by Category Nesting
735:      *
736:      * @param  \Illuminate\Database\Eloquent\Builder $query
737:      * @return \Illuminate\Database\Eloquent\Builder
738:      */
739:     public function scopeNested(Builder $query)
740:     {
741:         $this->nested = true;
742: 
743:         return $query;
744:     }
745: 
746:     /**
747:      * Call the specified scope, exploding a pipe-delimited string into an array
748:      * Calls the not version of the scope if the string begins with not
749:      * eg  'not 4|5|6'
750:      *
751:      * @param \Illuminate\Database\Eloquent\Builder $query
752:      * @param string                                $string ex '4|5|6' 'not 4|5|6'
753:      * @param string                                $scope  the name of the scope, ex. AuthorId
754:      */
755:     protected function scopeArrayFromString(Builder $query, $string, $scope)
756:     {
757:         if ($not = strncmp($string, 'not ', 4) === 0) {
758:             $string = substr($string, 4);
759:         }
760: 
761:         $args = explode('|', $string);
762: 
763:         $method = 'scope'.$scope;
764: 
765:         if ($not && method_exists($this, 'scopeNot'.$scope)) {
766:             $method = 'scopeNot'.$scope;
767:         }
768: 
769:         array_unshift($args, $query);
770: 
771:         return call_user_func_array(array($this, $method), $args);
772:     }
773: 
774:     /**
775:      * Get all the category custom fields
776:      *
777:      * @return \rsanchez\Deep\Collection\FieldCollection
778:      */
779:     public function getFields()
780:     {
781:         return self::$categoryFieldRepository->getFields();
782:     }
783: }
784: 
API documentation generated by ApiGen 2.8.0