| 
                    1
                 | 
                                    
                                                     | 
                
                 | 
                <?php  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    2
                 | 
                                    
                                                     | 
                
                 | 
                /**  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    3
                 | 
                                    
                                                     | 
                
                 | 
                 * This file is part of the eav package.  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    4
                 | 
                                    
                                                     | 
                
                 | 
                 * @author    Alex Kuperwood <[email protected]>  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    5
                 | 
                                    
                                                     | 
                
                 | 
                 * @copyright 2025 Alex Kuperwood  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    6
                 | 
                                    
                                                     | 
                
                 | 
                 * @license   https://opensource.org/license/mit  The MIT License  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    7
                 | 
                                    
                                                     | 
                
                 | 
                 */  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    8
                 | 
                                    
                                                     | 
                
                 | 
                declare(strict_types=1);  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    9
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    10
                 | 
                                    
                                                     | 
                
                 | 
                namespace Kuperwood\Eav\Model;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    11
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    12
                 | 
                                    
                                                     | 
                
                 | 
                use Kuperwood\Eav\Enum\_GROUP;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    13
                 | 
                                    
                                                     | 
                
                 | 
                use PDO;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    14
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    15
                 | 
                                    
                                                     | 
                
                 | 
                class AttributeGroupModel extends Model  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    16
                 | 
                                    
                                                     | 
                
                 | 
                { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    17
                 | 
                                    
                             1                          | 
                
                 | 
                    public function __construct()  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    18
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    19
                 | 
                                    
                             1                          | 
                
                 | 
                        $this->setTable(_GROUP::table());  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    20
                 | 
                                    
                             1                          | 
                
                 | 
                        $this->setPrimaryKey(_GROUP::ID);  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    21
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    22
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    23
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    24
                 | 
                                    
                             1                          | 
                
                 | 
                    public function create(array $data) : int  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    25
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    26
                 | 
                                    
                             1                          | 
                
                 | 
                        $conn = $this->getNativeConnection();  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    27
                 | 
                                    
                             1                          | 
                
                 | 
                        $sql = sprintf("INSERT INTO %s (%s, %s) values(:sid, :name)", _GROUP::table(), _GROUP::SET_ID, _GROUP::NAME); | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    28
                 | 
                                    
                             1                          | 
                
                 | 
                        $stmt = $conn->prepare($sql);  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    29
                 | 
                                    
                             1                          | 
                
                 | 
                        $stmt->execute(['sid' => $data[_GROUP::SET_ID], 'name' => $data[_GROUP::NAME]]);  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    30
                 | 
                                    
                             1                          | 
                
                 | 
                        return (int) $conn->lastInsertId();  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    31
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                                                            
                                                                
            
                                    
            
            
                | 
                    32
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    33
                 | 
                                    
                             1                          | 
                
                 | 
                    public function checkGroupInAttributeSet(int $setKey, int $groupKey) : bool  | 
            
            
                                                        
            
                                    
            
            
                | 
                    34
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                        
            
                                    
            
            
                | 
                    35
                 | 
                                    
                             1                          | 
                
                 | 
                        $conn = $this->db();  | 
            
            
                                                        
            
                                    
            
            
                | 
                    36
                 | 
                                    
                             1                          | 
                
                 | 
                        $sql = sprintf(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    37
                 | 
                                    
                             1                          | 
                
                 | 
                            "SELECT %s FROM %s WHERE %s = :set_id AND %s = :group_id",  | 
            
            
                                                        
            
                                    
            
            
                | 
                    38
                 | 
                                    
                             1                          | 
                
                 | 
                            $this->getPrimaryKey(),  | 
            
            
                                                        
            
                                    
            
            
                | 
                    39
                 | 
                                    
                             1                          | 
                
                 | 
                            $this->getTable(),  | 
            
            
                                                        
            
                                    
            
            
                | 
                    40
                 | 
                                    
                             1                          | 
                
                 | 
                            _GROUP::SET_ID,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    41
                 | 
                                    
                             1                          | 
                
                 | 
                            _GROUP::ID  | 
            
            
                                                        
            
                                    
            
            
                | 
                    42
                 | 
                                    
                             1                          | 
                
                 | 
                        );  | 
            
            
                                                        
            
                                    
            
            
                | 
                    43
                 | 
                                    
                             1                          | 
                
                 | 
                        $stmt = $conn->prepare($sql);  | 
            
            
                                                        
            
                                    
            
            
                | 
                    44
                 | 
                                    
                             1                          | 
                
                 | 
                        $stmt->bindParam(':set_id', $setKey, PDO::PARAM_INT); | 
            
            
                                                        
            
                                    
            
            
                | 
                    45
                 | 
                                    
                             1                          | 
                
                 | 
                        $stmt->bindParam(':group_id', $groupKey, PDO::PARAM_INT); | 
            
            
                                                        
            
                                    
            
            
                | 
                    46
                 | 
                                    
                             1                          | 
                
                 | 
                        $stmt->execute();  | 
            
            
                                                        
            
                                    
            
            
                | 
                    47
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    48
                 | 
                                    
                             1                          | 
                
                 | 
                        $result = $stmt->fetch(PDO::FETCH_ASSOC);  | 
            
            
                                                        
            
                                    
            
            
                | 
                    49
                 | 
                                    
                             1                          | 
                
                 | 
                        return $result !== false;  | 
            
            
                                                        
            
                                    
            
            
                | 
                    50
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    51
                 | 
                                    
                                                     | 
                
                 | 
                }  |