| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace MGModule\DNSManager2\models\whmcs\customFields;
- use MGModule\DNSManager2 as main;
- /**
- * Product Custom Fields depends on WHMCS
- *
- * @Table(name=tblcustomfields,preventUpdate,prefixed=false)
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class customField extends \MGModule\DNSManager2\mgLibs\models\orm{
- /**
- * @Column()
- * @var int
- */
- public $id;
- /**
- *
- * @var string
- */
- public $parentType;
-
- /**
- *
- * @var int
- */
- public $parentId;
-
- /**
- *
- * @var int
- */
- public $definition;
-
-
- /**
- * @Column(name=fieldname,as=fieldnameFull)
- * @var string
- */
- public $name;
-
- /**
- *
- * @var string
- */
- public $friendlyName;
-
- /**
- * @Column()
- * @var string
- */
- public $fieldtype = 'text';
-
- /**
- *
- * @Column()
- * @var string
- */
- public $description = '';
-
- /**
- * @Column(as=fieldoptionsEncoded)
- * @var array
- */
- public $fieldoptions = array();
- /**
- * @Column()
- * @var string
- */
- public $regexpr = '';
-
- /**
- * @Column()
- * @var boolean
- */
- public $adminonly = 'on';
-
- /**
- * @Column()
- * @var boolean
- */
- public $required = '';
-
- /**
- * @Column()
- * @var boolean
- */
- public $showorder = '';
-
- /**
- * @Column()
- * @var boolean
- */
- public $showinvoice = '';
-
- /**
- * @Column()
- * @var boolean
- */
- public $sortorder = 0;
-
- /**
- * Load Custom Field
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param int $productID
- * @param int $id
- * @param array $data
- */
- function __construct($id = null, $parentType = null, $parentID = null, $data = array()) {
- $this->id = $id;
- $this->parentType = $parentType;
- $this->parentId = $parentID;
-
- if($this->id && empty($data))
- {
- $conditions = array(
- 'id' => $this->id
- ,'reldid' => $this->parentId
- ,'type' => $this->parentType
- );
-
- $data = main\mgLibs\MySQL\query::select(
- self::$fieldDeclaration
- , self::tableName()
- , $conditions
- )->fetch();
-
- if(empty($data))
- {
- throw new main\mgLibs\exceptions\system('Unable to find custom field:'.http_build_query($conditions));
- }
- }
-
- if(!empty($data))
- {
- if(!empty($data['fieldnameFull']))
- {
- $tmp = explode('|',$data['fieldnameFull']);
- $data['name'] = $data['fieldnameFull'] = $tmp[0];
-
- if(!empty($tmp[1]))
- {
- $data['friendlyName'] = $tmp[1];
- }
- }
-
- if(isset($data['fieldoptionsEncoded']))
- {
- $data['fieldoptions'] = array_filter(explode(',', $data['fieldoptionsEncoded']));
- }
- $this->fillProperties($data);
- }
- }
-
- /**
- * Save Field
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- function save(){
-
- $data = array(
- 'type' => $this->parentType
- ,'relid' => $this->productID
- ,'fieldtype' => $this->fieldtype
- ,'description' => $this->description
- ,'fieldoptions' => implode(',',$this->fieldoptions)
- ,'regexpr' => $this->regexpr
- ,'adminonly' => $this->adminonly
- ,'required' => $this->required
- ,'showorder' => $this->showorder
- ,'showinvoice' => $this->showinvoice
- ,'sortorder' => $this->sortorder
- );
-
- if(empty($this->friendlyName))
- {
- $data['fieldname'] = $this->name;
- }
- else
- {
- $data['fieldname'] = $this->name.'|'.$this->friendlyName;
- }
-
- if($this->id)
- {
- main\mgLibs\MySQL\query::update(
- self::tableName()
- , $data
- , array(
- 'id' => $this->id
- )
- );
- }
- else
- {
- $this->id = main\mgLibs\MySQL\query::insert(
- self::tableName()
- ,$data
- );
- }
- }
-
- }
|