465
public function setBusiness($business=null, $type="default") {
466
if (isset($this->_snapshot)) {return false;}
467
$this->removeBusinessList($type);
468
$this->addBusiness($business, $type);
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);
478
$relationship->getBusiness()->delete();
480
$relationship->delete();
484
public function removeBusinessList($type=null) {
485
if (isset($this->_snapshot)) {return false;}
487
return BusinessGroup::deleteAll(null, $this->id, $type);
490
public function addBusiness($business=null, $type="default") {
491
if (isset($this->_snapshot)) {return false;}
492
if (isset($business)) {
496
$list = is_array($business) ? $business : array($business);
498
foreach ($list as $item) {
499
if (is_object($item) && !$item->id) {
502
$id = is_object($item) ? $item->id : $item;
503
$relationship = $this->getBusinessGroup($id, $type);
504
$relationship->deleted = false;
505
$relationship->save();
510
public function getBusiness($type="default") {
511
if (isset($this->_cache["Business"]) && isset($this->_cache["Business"][$type])) {
512
$business = $this->_cache["Business"][$type];
514
$business = new Business($this->getBusinessId($type));
516
$this->_cache["Business"][$type] = $business;
517
return $this->_cache["Business"][$type];
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(",") . ")");
525
public function getBusinessId($type="default") {
526
return $this->getBusinessIds($type)->get(0);
528
public function getBusinessIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
529
$db = Database::getInstance();
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;
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) : "")
554
while ($db->getRecord()) {
555
$ids[] = $db->record["entity_id"];
558
return new Collection($ids);
561
public function setContact($contact=null, $type="default") {
562
if (isset($this->_snapshot)) {return false;}
563
$this->removeContactList($type);
564
$this->addContact($contact, $type);
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);
574
$relationship->getContact()->delete();
576
$relationship->delete();
580
public function removeContactList($type=null) {
581
if (isset($this->_snapshot)) {return false;}
583
return ContactGroup::deleteAll(null, $this->id, $type);
586
public function addContact($contact=null, $type="default") {
587
if (isset($this->_snapshot)) {return false;}
588
if (isset($contact)) {
592
$list = is_array($contact) ? $contact : array($contact);
594
foreach ($list as $item) {
595
if (is_object($item) && !$item->id) {
598
$id = is_object($item) ? $item->id : $item;
599
$relationship = $this->getContactGroup($id, $type);
600
$relationship->deleted = false;
601
$relationship->save();
606
public function getContact($type="default") {
607
if (isset($this->_cache["Contact"]) && isset($this->_cache["Contact"][$type])) {
608
$contact = $this->_cache["Contact"][$type];
610
$contact = new Contact($this->getContactId($type));
612
$this->_cache["Contact"][$type] = $contact;
613
return $this->_cache["Contact"][$type];
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(",") . ")");
621
public function getContactId($type="default") {
622
return $this->getContactIds($type)->get(0);
624
public function getContactIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
625
$db = Database::getInstance();
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;
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) : "")
650
while ($db->getRecord()) {
651
$ids[] = $db->record["person_entity_id"];
654
return new Collection($ids);
657
public function setContent($content=null, $type="default") {
658
if (isset($this->_snapshot)) {return false;}
659
$this->removeContentList($type);
660
$this->addContent($content, $type);
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);
670
$relationship->getContent()->delete();
672
$relationship->delete();
676
public function removeContentList($type=null) {
677
if (isset($this->_snapshot)) {return false;}
679
return ContentGroup::deleteAll(null, $this->id, $type);
682
public function addContent($content=null, $type="default") {
683
if (isset($this->_snapshot)) {return false;}
684
if (isset($content)) {
688
$list = is_array($content) ? $content : array($content);
690
foreach ($list as $item) {
691
if (is_object($item) && !$item->id) {
694
$id = is_object($item) ? $item->id : $item;
695
$relationship = $this->getContentGroup($id, $type);
696
$relationship->deleted = false;
697
$relationship->save();
702
public function getContent($type="default") {
703
if (isset($this->_cache["Content"]) && isset($this->_cache["Content"][$type])) {
704
$content = $this->_cache["Content"][$type];
706
$content = new Content($this->getContentId($type));
708
$this->_cache["Content"][$type] = $content;
709
return $this->_cache["Content"][$type];
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(",") . ")");
717
public function getContentId($type="default") {
718
return $this->getContentIds($type)->get(0);
720
public function getContentIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
721
$db = Database::getInstance();
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;
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) : "")
746
while ($db->getRecord()) {
747
$ids[] = $db->record["id"];
750
return new Collection($ids);
753
public function setOrgposition($orgposition=null, $type="default") {
754
if (isset($this->_snapshot)) {return false;}
755
$this->removeOrgpositionList($type);
756
$this->addOrgposition($orgposition, $type);
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);
766
$relationship->getOrgposition()->delete();
768
$relationship->delete();
772
public function removeOrgpositionList($type=null) {
773
if (isset($this->_snapshot)) {return false;}
775
return GroupOrgposition::deleteAll($this->id, null, $type);
778
public function addOrgposition($orgposition=null, $type="default") {
779
if (isset($this->_snapshot)) {return false;}
780
if (isset($orgposition)) {
784
$list = is_array($orgposition) ? $orgposition : array($orgposition);
786
foreach ($list as $item) {
787
if (is_object($item) && !$item->id) {
790
$id = is_object($item) ? $item->id : $item;
791
$relationship = $this->getGroupOrgposition($id, $type);
792
$relationship->deleted = false;
793
$relationship->save();
798
public function getOrgposition($type="default") {
799
if (isset($this->_cache["Orgposition"]) && isset($this->_cache["Orgposition"][$type])) {
800
$orgposition = $this->_cache["Orgposition"][$type];
802
$orgposition = new Orgposition($this->getOrgpositionId($type));
804
$this->_cache["Orgposition"][$type] = $orgposition;
805
return $this->_cache["Orgposition"][$type];
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(",") . ")");
813
public function getOrgpositionId($type="default") {
814
return $this->getOrgpositionIds($type)->get(0);
816
public function getOrgpositionIds($type=null, $order=null, $where=null, $limit=null, $offset=0, $primary=false) {
817
$db = Database::getInstance();
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;
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) : "")
842
while ($db->getRecord()) {
843
$ids[] = $db->record["id"];
846
return new Collection($ids);
849
449
public function setResource($resource=null, $type="default") {
850
450
if (isset($this->_snapshot)) {return false;}
851
451
$this->removeResourceList($type);