PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/module/Indicator/src/Indicator/Model/Indicator.php

https://gitlab.com/mnomansheikh/ampuz
PHP | 205 lines | 176 code | 16 blank | 13 comment | 9 complexity | 047998d3dfb5d0c464df745931f2a750 MD5 | raw file
  1. <?php
  2. namespace Indicator\Model;
  3. use Zend\InputFilter\Factory as InputFactory;
  4. use Zend\InputFilter\InputFilter;
  5. use Zend\InputFilter\InputFilterAwareInterface;
  6. use Zend\InputFilter\InputFilterInterface;
  7. class Indicator implements InputFilterAwareInterface
  8. {
  9. public $user_id;
  10. public $id;
  11. public $name;
  12. public $measuring_unit_id;
  13. public $measuring_unit_value;
  14. public $menu_id;
  15. public $sub_menu_id;
  16. public $frequency_id;
  17. public $company_id;
  18. public $indicator_description;
  19. public $data_type;
  20. public $role;
  21. public $gender_required;
  22. public $is_attachment;
  23. public $is_uploading;
  24. public $bulk_type;
  25. public $last_updateon;
  26. public $last_updateby;
  27. public $create_date;
  28. public $create_by;
  29. public $is_active;
  30. public $inputFilter;
  31. public function exchangeArray($data)
  32. {
  33. $this->id = (!empty($data['id'])) ? $data['id'] : null;
  34. $this->menu_id = (!empty($data['menu_id'])) ? $data['menu_id'] : null;
  35. $this->sub_menu_id = (!empty($data['sub_menu_id'])) ? $data['sub_menu_id'] : null;
  36. $this->company_id = (!empty($data['company_id'])) ? $data['company_id'] : null;
  37. $this->name = (!empty($data['name'])) ? $data['name'] : null;
  38. $this->measuring_unit_id = (!empty($data['measuring_unit_id'])) ? $data['measuring_unit_id'] : null;
  39. $this->measuring_unit_value = (!empty($data['measuring_unit_value'])) ? $data['measuring_unit_value'] : null;
  40. $this->before_remainder = (!empty($data['before_remainder'])) ? $data['before_remainder'] : null;
  41. $this->max_remainder = (!empty($data['max_remainder'])) ? $data['max_remainder'] : null;
  42. $this->user_id = (!empty($data['user_id'])) ? $data['user_id'] : null;
  43. $this->frequency_id = (!empty($data['frequency_id'])) ? $data['frequency_id'] : null;
  44. if($data['is_attachment'] == 1){
  45. $this->role = '1';
  46. }else if($data['is_uploading'] == 1){
  47. $this->role = '2';
  48. }else{
  49. $this->role = '3';
  50. //$this->is_attachment = (isset($data['is_attachment'])) ? $data['is_attachment'] : null;
  51. //$this->is_uploading = (isset($data['is_uploading'])) ? $data['is_uploading'] : null;
  52. }
  53. if($data['role'] == '1'){
  54. $this->is_attachment = (isset($data['is_attachment'])) ? $data['is_attachment'] : null;
  55. }else{
  56. $this->is_attachment = null;
  57. }
  58. if($data['role'] == '2'){
  59. $this->is_uploading = (isset($data['is_uploading'])) ? $data['is_uploading'] : null;
  60. }else{
  61. $this->is_uploading = null;
  62. }
  63. $this->bulk_type = (isset($data['bulk_type'])) ? $data['bulk_type'] : null;
  64. $this->create_date = (isset($data['create_date'])) ? $data['create_date'] : null;
  65. $this->create_by = (isset($data['create_by'])) ? $data['create_by'] : null;
  66. $this->last_updateon = (isset($data['last_updateon'])) ? $data['last_updateon'] : null;
  67. $this->last_updateby = (isset($data['last_updateby'])) ? $data['last_updateby'] : null;
  68. $this->is_active = (isset($data['is_active'])) ? $data['is_active'] : null;
  69. }
  70. // Add the following method:
  71. public function getArrayCopy()
  72. {
  73. return get_object_vars($this);
  74. }
  75. public function setInputFilter(InputFilterInterface $inputFilter)
  76. {
  77. throw new \Exception("Not used");
  78. }
  79. public function getInputFilter()
  80. {
  81. if (!$this->inputFilter) {
  82. $inputFilter = new InputFilter();
  83. $factory = new InputFactory();
  84. $inputFilter->add(array(
  85. 'name' => 'id',
  86. 'required' => false,
  87. 'filters' => array(
  88. array('name' => 'Int'),
  89. ),
  90. ));
  91. $inputFilter->add(array(
  92. 'name' => 'menu_id',
  93. 'required' => false,
  94. 'filters' => array(
  95. array('name' => 'StripTags'),
  96. array('name' => 'StringTrim'),
  97. ),
  98. /* 'validators' => array(
  99. array(
  100. 'name' => 'StringLength',
  101. 'options' => array(
  102. 'encoding' => 'UTF-8',
  103. 'min' => 1,
  104. 'max' => 100,
  105. ),
  106. ),
  107. ),*/
  108. ));
  109. $inputFilter->add(array(
  110. 'name' => 'sub_menu_id',
  111. 'required' => false,
  112. 'filters' => array(
  113. array('name' => 'StripTags'),
  114. array('name' => 'StringTrim'),
  115. ),
  116. ));
  117. $inputFilter->add(array(
  118. 'name' => 'company_id',
  119. 'required' => false,
  120. 'filters' => array(
  121. array('name' => 'StripTags'),
  122. array('name' => 'StringTrim'),
  123. ),
  124. ));
  125. $inputFilter->add(
  126. $factory->createInput(array(
  127. 'name' => 'fileupload',
  128. 'required' => false,
  129. ))
  130. );
  131. $inputFilter->add(array(
  132. 'name' => 'measuring_unit_value',
  133. 'required' => true,
  134. 'filters' => array(
  135. array('name' => 'StripTags'),
  136. array('name' => 'StringTrim'),
  137. ),
  138. 'validators' => array(
  139. array(
  140. 'name' => 'StringLength',
  141. 'options' => array(
  142. 'encoding' => 'UTF-8',
  143. 'min' => 1,
  144. 'max' => 100,
  145. ),
  146. ),
  147. ),
  148. ));
  149. $inputFilter->add(array(
  150. 'name' => 'before_remainder',
  151. 'required' => true,
  152. 'filters' => array(
  153. array('name' => 'StripTags'),
  154. array('name' => 'StringTrim'),
  155. ),
  156. 'validators' => array(
  157. array(
  158. 'name' => 'StringLength',
  159. 'options' => array(
  160. 'encoding' => 'UTF-8',
  161. 'min' => 1,
  162. 'max' => 100,
  163. ),
  164. ),
  165. ),
  166. ));
  167. $inputFilter->add(array(
  168. 'name' => 'max_remainder',
  169. 'required' => true,
  170. 'filters' => array(
  171. array('name' => 'StripTags'),
  172. array('name' => 'StringTrim'),
  173. ),
  174. 'validators' => array(
  175. array(
  176. 'name' => 'StringLength',
  177. 'options' => array(
  178. 'encoding' => 'UTF-8',
  179. 'min' => 1,
  180. 'max' => 100,
  181. ),
  182. ),
  183. ),
  184. ));
  185. $this->inputFilter = $inputFilter;
  186. }
  187. return $this->inputFilter;
  188. }
  189. }