| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace MGModule\DNSManager2\models\whmcs\customFields;
- use MGModule\DNSManager2 as main;
- /**
- * Product Custom Fields Colletion
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class repository{
- public $relationID;
- public $type;
- private $_fields = array();
- static private $configuration;
-
- static function setConfiguration(array $configuration){
- self::$configuration = $configuration;
- }
-
- /**
- * Load Product Custom Fields
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param int $productID
- */
- function __construct($type,$relationID) {
- $this->type = $type;
- $this->relationID = $relationID;
- $result = main\mgLibs\MySQL\query::select(
- customField::fieldDeclaration()
- ,customField::tableName()
- , array(
- 'relid' => $this->relationID
- ,'type' => $this->type
- )
- );
-
- while ($row = $result->fetch()){
- $this->_fields[] = new customField($row['id'],$this->type, $this->relationID,$row);
- }
- }
-
-
-
- /**
- * Compare current Fields with Declaration from Module Configuration
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param bool $onlyRequired
- * @return array
- */
- function checkFields(array $configuration = array()){
- if(empty($configuration))
- {
- $configuration = self::$configuration;
- }
-
- $missingFields = array();
-
- foreach($configuration as $fieldDeclaration)
- {
- $found = false;
- foreach($this->_fields as $field)
- {
- if($fieldDeclaration->name === $field->name)
- {
- $found = true;
- break;
- }
- }
- if(!$found)
- {
- $name = (empty($fieldDeclaration->friendlyName))?$fieldDeclaration->name:$fieldDeclaration->friendlyName;
- $missingFields[$fieldDeclaration->name] = $name;
- }
- }
- return $missingFields;
- }
-
- /**
- * Generate Custom Fields Depends on declaration in Module Configuration
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- function generateFromConfiguration(array $configuration = array()){
- if(empty($configuration))
- {
- $configuration = self::$configuration;
- }
-
- foreach($configuration as $fieldDeclaration)
- {
- $found = false;
- foreach($this->_fields as $field)
- {
- if($fieldDeclaration->name === $field->name)
- {
- $found = true;
- break;
- }
- }
-
- if(!$found)
- {
- $fieldDeclaration->save();
- $this->_fields[] = $fieldDeclaration;
- }
- }
- }
-
- /**
- *
- * @return customField[]
- */
- function get(){
- return $this->_fields;
- }
- }
|