| 564 | | if(@array_key_exists("conditions", $parameters)) |
| 565 | | $additional_conditions = $parameters['conditions']; |
| 566 | | elseif($parameters[0] != "") |
| 567 | | $additional_conditions = $parameters[0]; |
| 568 | | |
| 569 | | if(@array_key_exists("order", $parameters)) |
| | 565 | if(@array_key_exists("conditions", $parameters)) { |
| | 566 | $additional_conditions = " AND (".$parameters['conditions'].")"; |
| | 567 | } elseif($parameters[0] != "") { |
| | 568 | $additional_conditions = " AND (".$parameters[0].")"; |
| | 569 | } |
| | 570 | if(@array_key_exists("order", $parameters)) { |
| 604 | | $object = new $other_class_name(); |
| 605 | | |
| 606 | | # Prepare the join table name primary keys (fields) to do the join on |
| 607 | | if(is_null($join_table)) { |
| 608 | | $join_table = $this->get_join_table_name($this->table_name, $other_table_name); |
| | 604 | $other_class_object = new $other_class_name(); |
| | 605 | |
| | 606 | # If finder_sql is specified just use it instead of determining the joins/sql |
| | 607 | if(!is_null($finder_sql)) { |
| | 608 | $conditions = $finder_sql; |
| | 609 | $order = null; |
| | 610 | $limit = null; |
| | 611 | $joins = null; |
| | 612 | } else { |
| | 613 | # Prepare the join table name primary keys (fields) to do the join on |
| | 614 | if(is_null($join_table)) { |
| | 615 | $join_table = $this->get_join_table_name($this->table_name, $other_table_name); |
| | 616 | } |
| | 617 | |
| | 618 | # Primary keys |
| | 619 | $this_primary_key = $this->primary_keys[0]; |
| | 620 | $other_primary_key = $other_class_object->primary_keys[0]; |
| | 621 | |
| | 622 | # Foreign keys |
| | 623 | if(is_null($this_foreign_key)) { |
| | 624 | $this_foreign_key = Inflector::singularize($this->table_name)."_".$this_primary_key; |
| | 625 | } |
| | 626 | if(is_null($other_foreign_key)) { |
| | 627 | $other_foreign_key = Inflector::singularize($other_table_name)."_".$other_primary_key; |
| | 628 | } |
| | 629 | |
| | 630 | # Primary key value |
| | 631 | $this_primary_key_value = is_numeric($this->$this_primary_key) ? $this->$this_primary_key : "'".$this->$this_primary_key."'"; |
| | 632 | |
| | 633 | # Set up the SQL segments |
| | 634 | $conditions = "{$join_table}.{$this_foreign_key} = {$this_primary_key_value}".$additional_conditions; |
| | 635 | $joins = "LEFT JOIN {$join_table} ON {$other_table_name}.{$other_primary_key} = {$join_table}.{$other_foreign_key}"; |
| 611 | | # Primary keys |
| 612 | | $this_primary_key = $this->primary_keys[0]; |
| 613 | | $other_primary_key = $object->primary_keys[0]; |
| 614 | | |
| 615 | | # Foreign keys |
| 616 | | $this_foreign_key = ($this_primary_key != 'id') ? $this_primary_key : Inflector::singularize($this->table_name)."_id"; |
| 617 | | $other_foreign_key = ($other_primary_key != 'id') ? $other_primary_key : Inflector::singularize($other_table_name)."_id"; |
| 618 | | |
| 619 | | # Primary key value |
| 620 | | $this_primary_key_value = is_numeric($this->$this_primary_key) ? $this->$this_primary_key : "'".$this->$this_primary_key."'"; |
| 621 | | |
| 622 | | # Set up the SQL segments |
| 623 | | $conditions = "{$join_table}.{$this_foreign_key} = {$this_primary_key_value}"; |
| 624 | | $joins .= "LEFT JOIN {$join_table} ON {$other_table_name}.{$other_primary_key} = {$join_table}.{$other_foreign_key}"; |
| 625 | | |
| 641 | | if (!is_null($parameters)) { |
| 642 | | //echo "<pre>";print_r($parameters); |
| 643 | | if(@array_key_exists("conditions", $parameters)) |
| 644 | | $additional_conditions = $parameters['conditions']; |
| 645 | | elseif($parameters[0] != "") |
| 646 | | $additional_conditions = $parameters[0]; |
| 647 | | |
| 648 | | if(@array_key_exists("order", $parameters)) |
| | 653 | if (is_array($parameters)) { |
| | 654 | if(@array_key_exists("conditions", $parameters)) { |
| | 655 | $additional_conditions = " AND (".$parameters['conditions'].")"; |
| | 656 | } elseif($parameters[0] != "") { |
| | 657 | $additional_conditions = " AND (".$parameters[0].")"; |
| | 658 | } |
| | 659 | if(@array_key_exists("order", $parameters)) { |
| 657 | | |
| 658 | | if(@array_key_exists("joins", $parameters)) |
| 659 | | $additional_joins = $parameters['joins']; |
| 660 | | elseif($parameters[3] != "") |
| 661 | | $additional_joins = $parameters[3]; |
| 662 | | |
| 663 | | if(!empty($additional_conditions)) |
| 664 | | $conditions .= " AND (" . $additional_conditions . ")"; |
| 665 | | if(!empty($additional_joins)) |
| 666 | | $joins .= " " . $additional_joins; |
| 667 | | |
| | 668 | } |
| | 669 | if(@array_key_exists("foreign_key", $parameters)) { |
| | 670 | $foreign_key = $parameters['foreign_key']; |
| | 671 | } |
| 682 | | if(@array_key_exists("foreign_key", $parameters)) { |
| 683 | | $foreign_key = $parameters['foreign_key']; |
| 684 | | } else { |
| 685 | | $foreign_key = Inflector::singularize($this->table_name)."_id"; |
| 686 | | } |
| 687 | | if(count($other_class_object->primary_keys) == 1) { |
| 688 | | $id = $other_class_object->primary_keys[0]; |
| 689 | | } else { |
| 690 | | $id = "id"; |
| 691 | | } |
| 692 | | $id_value = $this->$id; |
| 693 | | if(is_numeric($id_value)) { |
| 694 | | $conditions = "$foreign_key={$id_value}"; |
| 695 | | } else { |
| 696 | | $conditions = "$foreign_key='{$id_value}'"; |
| 697 | | } |
| 698 | | |
| | 689 | # If finder_sql is specified just use it instead of determining the association |
| | 690 | if(!is_null($finder_sql)) { |
| | 691 | $conditions = $finder_sql; |
| | 692 | $order = null; |
| | 693 | $limit = null; |
| | 694 | $joins = null; |
| | 695 | } else { |
| | 696 | # This class primary key |
| | 697 | $this_primary_key = $this->primary_keys[0]; |
| | 698 | |
| | 699 | if(!$foreign_key) { |
| | 700 | # this should end up being like user_id or account_id but if you specified |
| | 701 | # a primaray key other than 'id' it will be like user_field |
| | 702 | $foreign_key = Inflector::singularize($this->table_name)."_".$this_primary_key; |
| | 703 | } |
| | 704 | |
| | 705 | $foreign_key_value = $this->$this_primary_key; |
| | 706 | $conditions = is_numeric($foreign_key_value) ? |
| | 707 | "$foreign_key = {$foreign_key_value}" : |
| | 708 | "$foreign_key = '{$foreign_key_value}'" . $additional_conditions; |
| | 709 | } |
| | 710 | |
| 712 | | if(@array_key_exists("class_name", $parameters)) { |
| 713 | | $other_object_name = $parameters['class_name']; |
| 714 | | } |
| | 724 | |
| | 725 | # Use any passed-in parameters |
| | 726 | if (is_array($parameters)) { |
| | 727 | //echo "<pre>";print_r($parameters); |
| | 728 | if(@array_key_exists("conditions", $parameters)) { |
| | 729 | $additional_conditions = " AND (".$parameters['conditions'].")"; |
| | 730 | } elseif($parameters[0] != "") { |
| | 731 | $additional_conditions = " AND (".$parameters[0].")"; |
| | 732 | } |
| | 733 | if(@array_key_exists("order", $parameters)) { |
| | 734 | $order = $parameters['order']; |
| | 735 | } elseif($parameters[1] != "") { |
| | 736 | $order = $parameters[1]; |
| | 737 | } |
| | 738 | if(@array_key_exists("foreign_key", $parameters)) { |
| | 739 | $foreign_key = $parameters['foreign_key']; |
| | 740 | } |
| | 741 | if(@array_key_exists("class_name", $parameters)) { |
| | 742 | $other_object_name = $parameters['class_name']; |
| | 743 | } |
| | 744 | } |
| | 745 | |
| 726 | | if(count($other_class_object->primary_keys) == 1) { |
| 727 | | $id = $other_class_object->primary_keys[0]; |
| 728 | | } else { |
| 729 | | $id = "id"; |
| 730 | | } |
| 731 | | $id_value = $this->$id; |
| 732 | | if(is_numeric($id_value)) { |
| 733 | | $conditions = "$foreign_key={$id_value}"; |
| 734 | | } else { |
| 735 | | $conditions = "$foreign_key='{$id_value}'"; |
| 736 | | } |
| | 754 | if(!$foreign_key){ |
| | 755 | $foreign_key = Inflector::singularize($this->table_name)."_".$this_primary_key; |
| | 756 | } |
| | 757 | |
| | 758 | $foreign_key_value = $this->$this_primary_key; |
| | 759 | $conditions = is_numeric($foreign_key_value) ? |
| | 760 | "{$foreign_key} = {$foreign_key_value}" : |
| | 761 | "{$foreign_key} = '{$foreign_key_value}'"; |
| 758 | | if(@array_key_exists("class_name", $parameters)) { |
| 759 | | $other_object_name = $parameters['class_name']; |
| 760 | | } |
| | 783 | |
| | 784 | # Use any passed-in parameters |
| | 785 | if (is_array($parameters)) { |
| | 786 | //echo "<pre>";print_r($parameters); |
| | 787 | if(@array_key_exists("conditions", $parameters)) { |
| | 788 | $additional_conditions = $parameters['conditions']; |
| | 789 | } elseif($parameters[0] != "") { |
| | 790 | $additional_conditions = $parameters[0]; |
| | 791 | } |
| | 792 | if(@array_key_exists("order", $parameters)) { |
| | 793 | $order = $parameters['order']; |
| | 794 | } elseif($parameters[1] != "") { |
| | 795 | $order = $parameters[1]; |
| | 796 | } |
| | 797 | if(@array_key_exists("foreign_key", $parameters)) { |
| | 798 | $foreign_key = $parameters['foreign_key']; |
| | 799 | } |
| | 800 | if(@array_key_exists("class_name", $parameters)) { |
| | 801 | $other_object_name = $parameters['class_name']; |
| | 802 | } |
| | 803 | } |
| | 804 | |
| 772 | | if(count($other_class_object->primary_keys) == 1) { |
| 773 | | $id = $other_class_object->primary_keys[0]; |
| 774 | | } else { |
| 775 | | $id = "id"; |
| 776 | | } |
| 777 | | $foreign_key_value = $this->$foreign_key; |
| 778 | | if(is_numeric($foreign_key_value)) { |
| 779 | | $conditions = "$id = $foreign_key_value"; |
| 780 | | } else { |
| 781 | | $conditions = "$id = '$foreign_key_value'"; |
| 782 | | } |
| | 817 | $other_primary_key_value = $this->$foreign_key; |
| | 818 | $conditions = is_numeric($other_primary_key_value) ? |
| | 819 | "{$other_primary_key} = {$other_primary_key_value}" : |
| | 820 | "{$other_primary_key} = '{$other_primary_key_value}'"; |