~vcs-imports/helix/helix

« back to all changes in this revision

Viewing changes to trunk/modules/Core/Generated/Objects/GroupTable.php

  • Committer: damianobrien
  • Date: 2015-07-08 19:49:46 UTC
  • Revision ID: svn-v4:05b9009a-c606-4cef-bdc0-1359a4facf5f::421
changed collection->add call to collection->append in the generator

Show diffs side-by-side

added added

removed removed

Lines of Context:
428
428
                return $this->groupTypeId;
429
429
        }
430
430
 
431
 
        public function getBusinessGroup($businessId, $type="default") {
432
 
                return new BusinessGroup(null, $businessId, $this->id, BusinessGroup::typeId($type));
433
 
        }
434
 
 
435
 
        public function getGroupOrgposition($orgpositionId, $type="default") {
436
 
                return new GroupOrgposition(null, $this->id, $orgpositionId, GroupOrgposition::typeId($type));
437
 
        }
438
 
 
439
 
        public function getContentGroup($contentId, $type="default") {
440
 
                return new ContentGroup(null, $contentId, $this->id, ContentGroup::typeId($type));
441
 
        }
442
 
 
443
 
        public function getContactGroup($contactId, $type="default") {
444
 
                return new ContactGroup(null, $contactId, $this->id, ContactGroup::typeId($type));
445
 
        }
446
 
 
447
431
        public function getGroupResource($resourceId, $type="default") {
448
432
                return new GroupResource(null, $this->id, $resourceId, GroupResource::typeId($type));
449
433
        }
462
446
                }
463
447
        }
464
448
 
465
 
        public function setBusiness($business=null, $type="default") {
466
 
                if (isset($this->_snapshot)) {return false;}
467
 
                $this->removeBusinessList($type);
468
 
                $this->addBusiness($business, $type);
469
 
                return $this;
470
 
        }
471
 
        public function removeBusiness($business, $type="default", $deleteObject=true) {
472
 
                if (isset($this->_snapshot)) {return false;}
473
 
                $list = is_array($business) ? $business : array($business);
474
 
                foreach ($list as $item) {
475
 
                        $id = is_object($item) ? $item->id : $item;
476
 
                        $relationship = $this->getBusinessGroup($id, $type);
477
 
                        if ($deleteObject) {
478
 
                                $relationship->getBusiness()->delete();
479
 
                        }
480
 
                        $relationship->delete();
481
 
                }
482
 
                return $this;
483
 
        }
484
 
        public function removeBusinessList($type=null) {
485
 
                if (isset($this->_snapshot)) {return false;}
486
 
                if ($this->id>0) {
487
 
                        return BusinessGroup::deleteAll(null, $this->id, $type);
488
 
                }
489
 
        }
490
 
        public function addBusiness($business=null, $type="default") {
491
 
                if (isset($this->_snapshot)) {return false;}
492
 
                if (isset($business)) {
493
 
                        if (!$this->id) {
494
 
                                $this->save();
495
 
                        }
496
 
                        $list = is_array($business) ? $business : array($business);
497
 
                        $order = 0;
498
 
                        foreach ($list as $item) {
499
 
                                if (is_object($item) && !$item->id) {
500
 
                                        $item->save();
501
 
                                }
502
 
                                $id = is_object($item) ? $item->id : $item;
503
 
                                $relationship = $this->getBusinessGroup($id, $type);
504
 
                                $relationship->deleted = false;
505
 
                                $relationship->save();
506
 
                        }
507
 
                }
508
 
                return $this;
509
 
        }
510
 
        public function getBusiness($type="default") {
511
 
                if (isset($this->_cache["Business"]) && isset($this->_cache["Business"][$type])) {
512
 
                        $business = $this->_cache["Business"][$type];
513
 
                } else {
514
 
                        $business = new Business($this->getBusinessId($type));
515
 
                }
516
 
                $this->_cache["Business"][$type] = $business;
517
 
                return $this->_cache["Business"][$type];
518
 
        }
519
 
        public function getBusinessList($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
520
 
                $db = Database::getInstance();
521
 
                $ids = $this->getBusinessIds($type, $order, $where, $limit, $offset, $primary);
522
 
                $list = $ids->count()===0 ? new Collection() : Business::objects($order, "{$db->le}business{$db->le}.{$db->re}entity_id{$db->re} IN (" . $ids->join(",") . ")");
523
 
                return $list;
524
 
        }
525
 
        public function getBusinessId($type="default") {
526
 
                return $this->getBusinessIds($type)->get(0);
527
 
        }
528
 
        public function getBusinessIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
529
 
                $db = Database::getInstance();
530
 
                $ids = array();
531
 
                
532
 
                if (isset($this->_snapshot)) {
533
 
                        $date = $this->_snapshot;
534
 
                        $condition = " {$db->le}business{$db->re}.{$db->le}tdate{$db->re} IS NOT NULL AND {$db->le}business{$db->re}.{$db->le}fdate{$db->re}<={$db->queryValue($date)} AND {$db->queryValue($date)}<={$db->le}business{$db->re}.{$db->le}tdate{$db->re} ";
535
 
                        $where = isset($where) ? "{$where} AND ({$condition})" : $condition;
536
 
                }
537
 
                
538
 
                $query = implode(NL, array(
539
 
                        "SELECT {$db->le}business{$db->re}.{$db->le}entity_id{$db->re} ",
540
 
                        "FROM {$db->le}business{$db->re} ",
541
 
                        "INNER JOIN {$db->le}business_group{$db->re} ON {$db->le}business_group{$db->re}.{$db->le}business_entity_id{$db->re}={$db->le}business{$db->re}.{$db->le}entity_id{$db->re} ",
542
 
                        "       AND {$db->le}business_group{$db->re}.{$db->le}deleted{$db->re}=0 ",
543
 
                        "       AND {$db->le}business{$db->re}.{$db->le}deleted{$db->re}=0 ",
544
 
                        "       AND {$db->le}business_group{$db->re}.{$db->le}group_id{$db->re}={$db->queryValue($this->id)} ",
545
 
                        (isset($type) ? "       AND {$db->le}business_group{$db->re}.{$db->le}business_group_type_id{$db->re}=" . $db->queryValue(BusinessGroup::typeId($type)) . " " : ""),
546
 
                        ($primary ? "   AND {$db->le}business_group{$db->re}.{$db->le}primary{$db->re}=1 " : ""),
547
 
                        (isset($where) ? " WHERE {$where} " : ""),
548
 
                        (isset($order) ? " ORDER BY {$order}" : ""),
549
 
                        (isset($limit) ? $db::limitOffsetString($limit,$offset) : "")
550
 
                ));
551
 
                
552
 
                $db->query($query);
553
 
                
554
 
                while ($db->getRecord()) {
555
 
                        $ids[] = $db->record["entity_id"];
556
 
                }
557
 
                
558
 
                return new Collection($ids);
559
 
        }
560
 
 
561
 
        public function setContact($contact=null, $type="default") {
562
 
                if (isset($this->_snapshot)) {return false;}
563
 
                $this->removeContactList($type);
564
 
                $this->addContact($contact, $type);
565
 
                return $this;
566
 
        }
567
 
        public function removeContact($contact, $type="default", $deleteObject=true) {
568
 
                if (isset($this->_snapshot)) {return false;}
569
 
                $list = is_array($contact) ? $contact : array($contact);
570
 
                foreach ($list as $item) {
571
 
                        $id = is_object($item) ? $item->id : $item;
572
 
                        $relationship = $this->getContactGroup($id, $type);
573
 
                        if ($deleteObject) {
574
 
                                $relationship->getContact()->delete();
575
 
                        }
576
 
                        $relationship->delete();
577
 
                }
578
 
                return $this;
579
 
        }
580
 
        public function removeContactList($type=null) {
581
 
                if (isset($this->_snapshot)) {return false;}
582
 
                if ($this->id>0) {
583
 
                        return ContactGroup::deleteAll(null, $this->id, $type);
584
 
                }
585
 
        }
586
 
        public function addContact($contact=null, $type="default") {
587
 
                if (isset($this->_snapshot)) {return false;}
588
 
                if (isset($contact)) {
589
 
                        if (!$this->id) {
590
 
                                $this->save();
591
 
                        }
592
 
                        $list = is_array($contact) ? $contact : array($contact);
593
 
                        $order = 0;
594
 
                        foreach ($list as $item) {
595
 
                                if (is_object($item) && !$item->id) {
596
 
                                        $item->save();
597
 
                                }
598
 
                                $id = is_object($item) ? $item->id : $item;
599
 
                                $relationship = $this->getContactGroup($id, $type);
600
 
                                $relationship->deleted = false;
601
 
                                $relationship->save();
602
 
                        }
603
 
                }
604
 
                return $this;
605
 
        }
606
 
        public function getContact($type="default") {
607
 
                if (isset($this->_cache["Contact"]) && isset($this->_cache["Contact"][$type])) {
608
 
                        $contact = $this->_cache["Contact"][$type];
609
 
                } else {
610
 
                        $contact = new Contact($this->getContactId($type));
611
 
                }
612
 
                $this->_cache["Contact"][$type] = $contact;
613
 
                return $this->_cache["Contact"][$type];
614
 
        }
615
 
        public function getContactList($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
616
 
                $db = Database::getInstance();
617
 
                $ids = $this->getContactIds($type, $order, $where, $limit, $offset, $primary);
618
 
                $list = $ids->count()===0 ? new Collection() : Contact::objects($order, "{$db->le}contact{$db->le}.{$db->re}person_entity_id{$db->re} IN (" . $ids->join(",") . ")");
619
 
                return $list;
620
 
        }
621
 
        public function getContactId($type="default") {
622
 
                return $this->getContactIds($type)->get(0);
623
 
        }
624
 
        public function getContactIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
625
 
                $db = Database::getInstance();
626
 
                $ids = array();
627
 
                
628
 
                if (isset($this->_snapshot)) {
629
 
                        $date = $this->_snapshot;
630
 
                        $condition = " {$db->le}contact{$db->re}.{$db->le}tdate{$db->re} IS NOT NULL AND {$db->le}contact{$db->re}.{$db->le}fdate{$db->re}<={$db->queryValue($date)} AND {$db->queryValue($date)}<={$db->le}contact{$db->re}.{$db->le}tdate{$db->re} ";
631
 
                        $where = isset($where) ? "{$where} AND ({$condition})" : $condition;
632
 
                }
633
 
                
634
 
                $query = implode(NL, array(
635
 
                        "SELECT {$db->le}contact{$db->re}.{$db->le}person_entity_id{$db->re} ",
636
 
                        "FROM {$db->le}contact{$db->re} ",
637
 
                        "INNER JOIN {$db->le}contact_group{$db->re} ON {$db->le}contact_group{$db->re}.{$db->le}contact_person_entity_id{$db->re}={$db->le}contact{$db->re}.{$db->le}person_entity_id{$db->re} ",
638
 
                        "       AND {$db->le}contact_group{$db->re}.{$db->le}deleted{$db->re}=0 ",
639
 
                        "       AND {$db->le}contact{$db->re}.{$db->le}deleted{$db->re}=0 ",
640
 
                        "       AND {$db->le}contact_group{$db->re}.{$db->le}group_id{$db->re}={$db->queryValue($this->id)} ",
641
 
                        (isset($type) ? "       AND {$db->le}contact_group{$db->re}.{$db->le}contact_group_type_id{$db->re}=" . $db->queryValue(ContactGroup::typeId($type)) . " " : ""),
642
 
                        ($primary ? "   AND {$db->le}contact_group{$db->re}.{$db->le}primary{$db->re}=1 " : ""),
643
 
                        (isset($where) ? " WHERE {$where} " : ""),
644
 
                        (isset($order) ? " ORDER BY {$order}" : ""),
645
 
                        (isset($limit) ? $db::limitOffsetString($limit,$offset) : "")
646
 
                ));
647
 
                
648
 
                $db->query($query);
649
 
                
650
 
                while ($db->getRecord()) {
651
 
                        $ids[] = $db->record["person_entity_id"];
652
 
                }
653
 
                
654
 
                return new Collection($ids);
655
 
        }
656
 
 
657
 
        public function setContent($content=null, $type="default") {
658
 
                if (isset($this->_snapshot)) {return false;}
659
 
                $this->removeContentList($type);
660
 
                $this->addContent($content, $type);
661
 
                return $this;
662
 
        }
663
 
        public function removeContent($content, $type="default", $deleteObject=true) {
664
 
                if (isset($this->_snapshot)) {return false;}
665
 
                $list = is_array($content) ? $content : array($content);
666
 
                foreach ($list as $item) {
667
 
                        $id = is_object($item) ? $item->id : $item;
668
 
                        $relationship = $this->getContentGroup($id, $type);
669
 
                        if ($deleteObject) {
670
 
                                $relationship->getContent()->delete();
671
 
                        }
672
 
                        $relationship->delete();
673
 
                }
674
 
                return $this;
675
 
        }
676
 
        public function removeContentList($type=null) {
677
 
                if (isset($this->_snapshot)) {return false;}
678
 
                if ($this->id>0) {
679
 
                        return ContentGroup::deleteAll(null, $this->id, $type);
680
 
                }
681
 
        }
682
 
        public function addContent($content=null, $type="default") {
683
 
                if (isset($this->_snapshot)) {return false;}
684
 
                if (isset($content)) {
685
 
                        if (!$this->id) {
686
 
                                $this->save();
687
 
                        }
688
 
                        $list = is_array($content) ? $content : array($content);
689
 
                        $order = 0;
690
 
                        foreach ($list as $item) {
691
 
                                if (is_object($item) && !$item->id) {
692
 
                                        $item->save();
693
 
                                }
694
 
                                $id = is_object($item) ? $item->id : $item;
695
 
                                $relationship = $this->getContentGroup($id, $type);
696
 
                                $relationship->deleted = false;
697
 
                                $relationship->save();
698
 
                        }
699
 
                }
700
 
                return $this;
701
 
        }
702
 
        public function getContent($type="default") {
703
 
                if (isset($this->_cache["Content"]) && isset($this->_cache["Content"][$type])) {
704
 
                        $content = $this->_cache["Content"][$type];
705
 
                } else {
706
 
                        $content = new Content($this->getContentId($type));
707
 
                }
708
 
                $this->_cache["Content"][$type] = $content;
709
 
                return $this->_cache["Content"][$type];
710
 
        }
711
 
        public function getContentList($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
712
 
                $db = Database::getInstance();
713
 
                $ids = $this->getContentIds($type, $order, $where, $limit, $offset, $primary);
714
 
                $list = $ids->count()===0 ? new Collection() : Content::objects($order, "{$db->le}content{$db->le}.{$db->re}id{$db->re} IN (" . $ids->join(",") . ")");
715
 
                return $list;
716
 
        }
717
 
        public function getContentId($type="default") {
718
 
                return $this->getContentIds($type)->get(0);
719
 
        }
720
 
        public function getContentIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
721
 
                $db = Database::getInstance();
722
 
                $ids = array();
723
 
                
724
 
                if (isset($this->_snapshot)) {
725
 
                        $date = $this->_snapshot;
726
 
                        $condition = " {$db->le}content{$db->re}.{$db->le}tdate{$db->re} IS NOT NULL AND {$db->le}content{$db->re}.{$db->le}fdate{$db->re}<={$db->queryValue($date)} AND {$db->queryValue($date)}<={$db->le}content{$db->re}.{$db->le}tdate{$db->re} ";
727
 
                        $where = isset($where) ? "{$where} AND ({$condition})" : $condition;
728
 
                }
729
 
                
730
 
                $query = implode(NL, array(
731
 
                        "SELECT {$db->le}content{$db->re}.{$db->le}id{$db->re} ",
732
 
                        "FROM {$db->le}content{$db->re} ",
733
 
                        "INNER JOIN {$db->le}content_group{$db->re} ON {$db->le}content_group{$db->re}.{$db->le}content_id{$db->re}={$db->le}content{$db->re}.{$db->le}id{$db->re} ",
734
 
                        "       AND {$db->le}content_group{$db->re}.{$db->le}deleted{$db->re}=0 ",
735
 
                        "       AND {$db->le}content{$db->re}.{$db->le}deleted{$db->re}=0 ",
736
 
                        "       AND {$db->le}content_group{$db->re}.{$db->le}group_id{$db->re}={$db->queryValue($this->id)} ",
737
 
                        (isset($type) ? "       AND {$db->le}content_group{$db->re}.{$db->le}content_group_type_id{$db->re}=" . $db->queryValue(ContentGroup::typeId($type)) . " " : ""),
738
 
                        ($primary ? "   AND {$db->le}content_group{$db->re}.{$db->le}primary{$db->re}=1 " : ""),
739
 
                        (isset($where) ? " WHERE {$where} " : ""),
740
 
                        (isset($order) ? " ORDER BY {$order}" : ""),
741
 
                        (isset($limit) ? $db::limitOffsetString($limit,$offset) : "")
742
 
                ));
743
 
                
744
 
                $db->query($query);
745
 
                
746
 
                while ($db->getRecord()) {
747
 
                        $ids[] = $db->record["id"];
748
 
                }
749
 
                
750
 
                return new Collection($ids);
751
 
        }
752
 
 
753
 
        public function setOrgposition($orgposition=null, $type="default") {
754
 
                if (isset($this->_snapshot)) {return false;}
755
 
                $this->removeOrgpositionList($type);
756
 
                $this->addOrgposition($orgposition, $type);
757
 
                return $this;
758
 
        }
759
 
        public function removeOrgposition($orgposition, $type="default", $deleteObject=true) {
760
 
                if (isset($this->_snapshot)) {return false;}
761
 
                $list = is_array($orgposition) ? $orgposition : array($orgposition);
762
 
                foreach ($list as $item) {
763
 
                        $id = is_object($item) ? $item->id : $item;
764
 
                        $relationship = $this->getGroupOrgposition($id, $type);
765
 
                        if ($deleteObject) {
766
 
                                $relationship->getOrgposition()->delete();
767
 
                        }
768
 
                        $relationship->delete();
769
 
                }
770
 
                return $this;
771
 
        }
772
 
        public function removeOrgpositionList($type=null) {
773
 
                if (isset($this->_snapshot)) {return false;}
774
 
                if ($this->id>0) {
775
 
                        return GroupOrgposition::deleteAll($this->id, null, $type);
776
 
                }
777
 
        }
778
 
        public function addOrgposition($orgposition=null, $type="default") {
779
 
                if (isset($this->_snapshot)) {return false;}
780
 
                if (isset($orgposition)) {
781
 
                        if (!$this->id) {
782
 
                                $this->save();
783
 
                        }
784
 
                        $list = is_array($orgposition) ? $orgposition : array($orgposition);
785
 
                        $order = 0;
786
 
                        foreach ($list as $item) {
787
 
                                if (is_object($item) && !$item->id) {
788
 
                                        $item->save();
789
 
                                }
790
 
                                $id = is_object($item) ? $item->id : $item;
791
 
                                $relationship = $this->getGroupOrgposition($id, $type);
792
 
                                $relationship->deleted = false;
793
 
                                $relationship->save();
794
 
                        }
795
 
                }
796
 
                return $this;
797
 
        }
798
 
        public function getOrgposition($type="default") {
799
 
                if (isset($this->_cache["Orgposition"]) && isset($this->_cache["Orgposition"][$type])) {
800
 
                        $orgposition = $this->_cache["Orgposition"][$type];
801
 
                } else {
802
 
                        $orgposition = new Orgposition($this->getOrgpositionId($type));
803
 
                }
804
 
                $this->_cache["Orgposition"][$type] = $orgposition;
805
 
                return $this->_cache["Orgposition"][$type];
806
 
        }
807
 
        public function getOrgpositionList($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
808
 
                $db = Database::getInstance();
809
 
                $ids = $this->getOrgpositionIds($type, $order, $where, $limit, $offset, $primary);
810
 
                $list = $ids->count()===0 ? new Collection() : Orgposition::objects($order, "{$db->le}orgposition{$db->le}.{$db->re}id{$db->re} IN (" . $ids->join(",") . ")");
811
 
                return $list;
812
 
        }
813
 
        public function getOrgpositionId($type="default") {
814
 
                return $this->getOrgpositionIds($type)->get(0);
815
 
        }
816
 
        public function getOrgpositionIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
817
 
                $db = Database::getInstance();
818
 
                $ids = array();
819
 
                
820
 
                if (isset($this->_snapshot)) {
821
 
                        $date = $this->_snapshot;
822
 
                        $condition = " {$db->le}orgposition{$db->re}.{$db->le}tdate{$db->re} IS NOT NULL AND {$db->le}orgposition{$db->re}.{$db->le}fdate{$db->re}<={$db->queryValue($date)} AND {$db->queryValue($date)}<={$db->le}orgposition{$db->re}.{$db->le}tdate{$db->re} ";
823
 
                        $where = isset($where) ? "{$where} AND ({$condition})" : $condition;
824
 
                }
825
 
                
826
 
                $query = implode(NL, array(
827
 
                        "SELECT {$db->le}orgposition{$db->re}.{$db->le}id{$db->re} ",
828
 
                        "FROM {$db->le}orgposition{$db->re} ",
829
 
                        "INNER JOIN {$db->le}group_orgposition{$db->re} ON {$db->le}group_orgposition{$db->re}.{$db->le}orgposition_id{$db->re}={$db->le}orgposition{$db->re}.{$db->le}id{$db->re} ",
830
 
                        "       AND {$db->le}group_orgposition{$db->re}.{$db->le}deleted{$db->re}=0 ",
831
 
                        "       AND {$db->le}orgposition{$db->re}.{$db->le}deleted{$db->re}=0 ",
832
 
                        "       AND {$db->le}group_orgposition{$db->re}.{$db->le}group_id{$db->re}={$db->queryValue($this->id)} ",
833
 
                        (isset($type) ? "       AND {$db->le}group_orgposition{$db->re}.{$db->le}group_orgposition_type_id{$db->re}=" . $db->queryValue(GroupOrgposition::typeId($type)) . " " : ""),
834
 
                        ($primary ? "   AND {$db->le}group_orgposition{$db->re}.{$db->le}primary{$db->re}=1 " : ""),
835
 
                        (isset($where) ? " WHERE {$where} " : ""),
836
 
                        (isset($order) ? " ORDER BY {$order}" : ""),
837
 
                        (isset($limit) ? $db::limitOffsetString($limit,$offset) : "")
838
 
                ));
839
 
                
840
 
                $db->query($query);
841
 
                
842
 
                while ($db->getRecord()) {
843
 
                        $ids[] = $db->record["id"];
844
 
                }
845
 
                
846
 
                return new Collection($ids);
847
 
        }
848
 
 
849
449
        public function setResource($resource=null, $type="default") {
850
450
                if (isset($this->_snapshot)) {return false;}
851
451
                $this->removeResourceList($type);
1089
689
        public function getDescendants() {
1090
690
                $descendants = new Collection();
1091
691
                foreach ($this->getChildren() as $child) {
1092
 
                        $descendants->add($child);
 
692
                        $descendants->append($child);
1093
693
                        if ($child->hasChildren()) {
1094
 
                                $descendants->add($child->getDescendants());
 
694
                                $descendants->append($child->getDescendants());
1095
695
                        }
1096
696
                }
1097
697
                return $descendants;
1102
702
                $child = $this;
1103
703
                while ($child->isChild()) {
1104
704
                        $parent = $child->getParent();
1105
 
                        $ancestors->add($parent);
 
705
                        $ancestors->append($parent);
1106
706
                        $child = $parent;
1107
707
                }
1108
708
                return $ancestors;