| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace MGModule\DNSManager2\models\whmcs\clients\customFields;
- use MGModule\DNSManager2 as main;
- /**
- * Description of repository
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class repository {
- public $serviceID;
- private $_customFields;
- /**
- * Mozna by bylo dodac wersje z wczytywanie po samym productid
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param type $accountID
- */
- function __construct($serviceID, array $data = array()) {
- $this->serviceID = $serviceID;
-
- if($data)
- {
- foreach ($data as $name => $value)
- {
- $field = new customField();
- $field->name = $name;
- $field->value = $value;
- $this->_customFields[$field->name] = $field;
- }
- }
- else
- {
- $this->load();
- }
- }
-
- function __isset($name) {
- return $this->_customFields[$name];
- }
-
- function __get($name) {
- if(isset($this->_customFields[$name]))
- {
- return $this->_customFields[$name]->value;
- }
- }
-
- function __set($name, $value) {
- if(isset($this->_customFields[$name]))
- {
- $this->_customFields[$name]->value = $value;
- }
- }
-
- function load(){
- $query = "
- SELECT
- C.fieldname as name
- ,V.fieldid as fieldid
- ,V.value as value
- FROM
- tblcustomfieldsvalues V
- JOIN
- tblcustomfields C
- ON
- V.fieldid = C.id
- AND C.type = 'client'
- WHERE
- V.relid = :account_id
- ";
- $result = \MGModule\DNSManager2\mgLibs\MySQL\query::query($query,array(
- 'account_id' => $this->serviceID
- ));
-
- while($row = $result->fetch())
- {
- $name = explode('|', $row['name']);
-
- if(isset($this->_customFields[$name[0]]))
- {
- $this->_customFields[$name[0]]->id = $row['fieldid'];
- }
- else
- {
- $field = new customField();
- $field->id = $row['fieldid'];
- $field->name = $name[0];
- $field->value = $row['value'];
-
- $this->_customFields[$field->name] = $field;
- }
- }
- }
-
- /**
- * Update Custom Fields
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- function update(){
- $this->load();
-
- foreach($this->_customFields as $field){
- main\mgLibs\MySQL\query::update(
- 'tblcustomfieldsvalues'
- , array(
- 'value' => $field->value
- )
- , array(
- 'fieldid' => $field->id
- ,'relid' => $this->serviceID
- )
- );
- }
- }
- }
|