@@ -9,11 +9,11 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Utility |
| 11 | 11 | { |
| 12 | - use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
|
| 12 | + use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
|
| 13 | 13 | |
| 14 | - use Common\ServerStats; // getServerStats Trait |
|
| 14 | + use Common\ServerStats; // getServerStats Trait |
|
| 15 | 15 | |
| 16 | - use Common\FilesManagement; // Files Management Trait |
|
| 16 | + use Common\FilesManagement; // Files Management Trait |
|
| 17 | 17 | |
| 18 | - //--------------- Custom module methods ----------------------------- |
|
| 18 | + //--------------- Custom module methods ----------------------------- |
|
| 19 | 19 | } |
@@ -29,20 +29,20 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectUrlLink extends Smartobject\BaseSmartObjectBasedUrl |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectUrlLink constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - parent::__construct(); |
|
| 38 | - $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
| 39 | - $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
| 32 | + /** |
|
| 33 | + * SmartobjectUrlLink constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + parent::__construct(); |
|
| 38 | + $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
| 39 | + $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
| 40 | 40 | |
| 41 | - $this->setControl('target', [ |
|
| 42 | - 'options' => [ |
|
| 43 | - '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
| 44 | - '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
| 45 | - ] |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 41 | + $this->setControl('target', [ |
|
| 42 | + 'options' => [ |
|
| 43 | + '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
| 44 | + '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
| 45 | + ] |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -30,113 +30,113 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartobjectCurrency extends Smartobject\BaseSmartObject |
| 32 | 32 | { |
| 33 | - public $_modulePlugin = false; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * SmartobjectCurrency constructor. |
|
| 37 | - */ |
|
| 38 | - public function __construct() |
|
| 39 | - { |
|
| 40 | - $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
| 41 | - $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
|
| 42 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
|
| 43 | - $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
|
| 44 | - $this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
|
| 45 | - $this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
|
| 46 | - |
|
| 47 | - $this->setControl('symbol', [ |
|
| 48 | - 'name' => 'text', |
|
| 49 | - 'size' => '15', |
|
| 50 | - 'maxlength' => '15' |
|
| 51 | - ]); |
|
| 52 | - |
|
| 53 | - $this->setControl('iso4217', [ |
|
| 54 | - 'name' => 'text', |
|
| 55 | - 'size' => '5', |
|
| 56 | - 'maxlength' => '5' |
|
| 57 | - ]); |
|
| 58 | - |
|
| 59 | - $this->setControl('rate', [ |
|
| 60 | - 'name' => 'text', |
|
| 61 | - 'size' => '5', |
|
| 62 | - 'maxlength' => '5' |
|
| 63 | - ]); |
|
| 64 | - |
|
| 65 | - $this->setControl('rate', [ |
|
| 66 | - 'name' => 'text', |
|
| 67 | - 'size' => '5', |
|
| 68 | - 'maxlength' => '5' |
|
| 69 | - ]); |
|
| 70 | - |
|
| 71 | - $this->hideFieldFromForm('default_currency'); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $key |
|
| 76 | - * @param string $format |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - public function getVar($key, $format = 's') |
|
| 80 | - { |
|
| 81 | - if ('s' === $format && in_array($key, ['rate', 'default_currency'])) { |
|
| 82 | - // return call_user_func(array($this, $key)); |
|
| 83 | - return $this->{$key}(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return parent::getVar($key, $format); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @return mixed |
|
| 91 | - */ |
|
| 92 | - public function getCurrencyLink() |
|
| 93 | - { |
|
| 94 | - $ret = $this->getVar('name', 'e'); |
|
| 95 | - |
|
| 96 | - return $ret; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return mixed |
|
| 101 | - */ |
|
| 102 | - public function getCode() |
|
| 103 | - { |
|
| 104 | - $ret = $this->getVar('iso4217', 'e'); |
|
| 105 | - |
|
| 106 | - return $ret; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return float|int|mixed|string |
|
| 111 | - */ |
|
| 112 | - public function rate() |
|
| 113 | - { |
|
| 114 | - return smart_currency($this->getVar('rate', 'e')); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function defaultCurrency() |
|
| 121 | - { |
|
| 122 | - if (true === $this->getVar('default_currency', 'e')) { |
|
| 123 | - return _YES; |
|
| 124 | - } else { |
|
| 125 | - return _NO; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function getDefaultCurrencyControl() |
|
| 133 | - { |
|
| 134 | - $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
|
| 135 | - if ($this->getVar('default_currency', 'e')) { |
|
| 136 | - $radio_box .= 'checked'; |
|
| 137 | - } |
|
| 138 | - $radio_box .= '>'; |
|
| 139 | - |
|
| 140 | - return $radio_box; |
|
| 141 | - } |
|
| 33 | + public $_modulePlugin = false; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * SmartobjectCurrency constructor. |
|
| 37 | + */ |
|
| 38 | + public function __construct() |
|
| 39 | + { |
|
| 40 | + $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
| 41 | + $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
|
| 42 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
|
| 43 | + $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
|
| 44 | + $this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
|
| 45 | + $this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
|
| 46 | + |
|
| 47 | + $this->setControl('symbol', [ |
|
| 48 | + 'name' => 'text', |
|
| 49 | + 'size' => '15', |
|
| 50 | + 'maxlength' => '15' |
|
| 51 | + ]); |
|
| 52 | + |
|
| 53 | + $this->setControl('iso4217', [ |
|
| 54 | + 'name' => 'text', |
|
| 55 | + 'size' => '5', |
|
| 56 | + 'maxlength' => '5' |
|
| 57 | + ]); |
|
| 58 | + |
|
| 59 | + $this->setControl('rate', [ |
|
| 60 | + 'name' => 'text', |
|
| 61 | + 'size' => '5', |
|
| 62 | + 'maxlength' => '5' |
|
| 63 | + ]); |
|
| 64 | + |
|
| 65 | + $this->setControl('rate', [ |
|
| 66 | + 'name' => 'text', |
|
| 67 | + 'size' => '5', |
|
| 68 | + 'maxlength' => '5' |
|
| 69 | + ]); |
|
| 70 | + |
|
| 71 | + $this->hideFieldFromForm('default_currency'); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $key |
|
| 76 | + * @param string $format |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + public function getVar($key, $format = 's') |
|
| 80 | + { |
|
| 81 | + if ('s' === $format && in_array($key, ['rate', 'default_currency'])) { |
|
| 82 | + // return call_user_func(array($this, $key)); |
|
| 83 | + return $this->{$key}(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return parent::getVar($key, $format); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return mixed |
|
| 91 | + */ |
|
| 92 | + public function getCurrencyLink() |
|
| 93 | + { |
|
| 94 | + $ret = $this->getVar('name', 'e'); |
|
| 95 | + |
|
| 96 | + return $ret; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return mixed |
|
| 101 | + */ |
|
| 102 | + public function getCode() |
|
| 103 | + { |
|
| 104 | + $ret = $this->getVar('iso4217', 'e'); |
|
| 105 | + |
|
| 106 | + return $ret; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return float|int|mixed|string |
|
| 111 | + */ |
|
| 112 | + public function rate() |
|
| 113 | + { |
|
| 114 | + return smart_currency($this->getVar('rate', 'e')); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function defaultCurrency() |
|
| 121 | + { |
|
| 122 | + if (true === $this->getVar('default_currency', 'e')) { |
|
| 123 | + return _YES; |
|
| 124 | + } else { |
|
| 125 | + return _NO; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function getDefaultCurrencyControl() |
|
| 133 | + { |
|
| 134 | + $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
|
| 135 | + if ($this->getVar('default_currency', 'e')) { |
|
| 136 | + $radio_box .= 'checked'; |
|
| 137 | + } |
|
| 138 | + $radio_box .= '>'; |
|
| 139 | + |
|
| 140 | + return $radio_box; |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -31,66 +31,66 @@ |
||
| 31 | 31 | |
| 32 | 32 | class SmartAddTo |
| 33 | 33 | { |
| 34 | - public $_layout; |
|
| 35 | - public $_method; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Constructor of SmartAddTo |
|
| 39 | - * |
|
| 40 | - * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
| 41 | - * @param int $method 0=directpage, 1=popup |
|
| 42 | - */ |
|
| 43 | - public function __construct($layout = 0, $method = 1) |
|
| 44 | - { |
|
| 45 | - $layout = (int)$layout; |
|
| 46 | - if ($layout < 0 || $layout > 3) { |
|
| 47 | - $layout = 0; |
|
| 48 | - } |
|
| 49 | - $this->_layout = $layout; |
|
| 50 | - |
|
| 51 | - $method = (int)$method; |
|
| 52 | - if ($method < 0 || $method > 1) { |
|
| 53 | - $method = 1; |
|
| 54 | - } |
|
| 55 | - $this->_method = $method; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param bool $fetchOnly |
|
| 60 | - * @return mixed|string|void |
|
| 61 | - */ |
|
| 62 | - public function render($fetchOnly = false) |
|
| 63 | - { |
|
| 64 | - global $xoTheme, $xoopsTpl; |
|
| 65 | - |
|
| 66 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 67 | - |
|
| 68 | - $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
| 69 | - $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
| 70 | - |
|
| 71 | - $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
| 72 | - |
|
| 73 | - if ($fetchOnly) { |
|
| 74 | - return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
| 75 | - } else { |
|
| 76 | - $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function renderForBlock() |
|
| 84 | - { |
|
| 85 | - global $xoTheme; |
|
| 86 | - |
|
| 87 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 88 | - |
|
| 89 | - $block = []; |
|
| 90 | - $block['smartobject_addto_method'] = $this->_method; |
|
| 91 | - $block['smartobject_addto_layout'] = $this->_layout; |
|
| 92 | - $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
| 93 | - |
|
| 94 | - return $block; |
|
| 95 | - } |
|
| 34 | + public $_layout; |
|
| 35 | + public $_method; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Constructor of SmartAddTo |
|
| 39 | + * |
|
| 40 | + * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
| 41 | + * @param int $method 0=directpage, 1=popup |
|
| 42 | + */ |
|
| 43 | + public function __construct($layout = 0, $method = 1) |
|
| 44 | + { |
|
| 45 | + $layout = (int)$layout; |
|
| 46 | + if ($layout < 0 || $layout > 3) { |
|
| 47 | + $layout = 0; |
|
| 48 | + } |
|
| 49 | + $this->_layout = $layout; |
|
| 50 | + |
|
| 51 | + $method = (int)$method; |
|
| 52 | + if ($method < 0 || $method > 1) { |
|
| 53 | + $method = 1; |
|
| 54 | + } |
|
| 55 | + $this->_method = $method; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param bool $fetchOnly |
|
| 60 | + * @return mixed|string|void |
|
| 61 | + */ |
|
| 62 | + public function render($fetchOnly = false) |
|
| 63 | + { |
|
| 64 | + global $xoTheme, $xoopsTpl; |
|
| 65 | + |
|
| 66 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 67 | + |
|
| 68 | + $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
| 69 | + $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
| 70 | + |
|
| 71 | + $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
| 72 | + |
|
| 73 | + if ($fetchOnly) { |
|
| 74 | + return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
| 75 | + } else { |
|
| 76 | + $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function renderForBlock() |
|
| 84 | + { |
|
| 85 | + global $xoTheme; |
|
| 86 | + |
|
| 87 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
| 88 | + |
|
| 89 | + $block = []; |
|
| 90 | + $block['smartobject_addto_method'] = $this->_method; |
|
| 91 | + $block['smartobject_addto_layout'] = $this->_layout; |
|
| 92 | + $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
| 93 | + |
|
| 94 | + return $block; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -30,22 +30,22 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartObjectCurrencyHandler extends Smartobject\SmartPersistableObjectHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * SmartObjectCurrencyHandler constructor. |
|
| 35 | - * @param \XoopsDatabase $db |
|
| 36 | - */ |
|
| 37 | - public function __construct(\XoopsDatabase $db) |
|
| 38 | - { |
|
| 39 | - parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function getCurrencies() |
|
| 46 | - { |
|
| 47 | - $currenciesObj =& $this->getObjects(null, true); |
|
| 48 | - |
|
| 49 | - return $currenciesObj; |
|
| 50 | - } |
|
| 33 | + /** |
|
| 34 | + * SmartObjectCurrencyHandler constructor. |
|
| 35 | + * @param \XoopsDatabase $db |
|
| 36 | + */ |
|
| 37 | + public function __construct(\XoopsDatabase $db) |
|
| 38 | + { |
|
| 39 | + parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function getCurrencies() |
|
| 46 | + { |
|
| 47 | + $currenciesObj =& $this->getObjects(null, true); |
|
| 48 | + |
|
| 49 | + return $currenciesObj; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -30,10 +30,10 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartJax extends \Projax |
| 32 | 32 | { |
| 33 | - public function initiateFromUserside() |
|
| 34 | - { |
|
| 35 | - global $xoTheme; |
|
| 36 | - $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/prototype.js'); |
|
| 37 | - $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/scriptaculous.js'); |
|
| 38 | - } |
|
| 33 | + public function initiateFromUserside() |
|
| 34 | + { |
|
| 35 | + global $xoTheme; |
|
| 36 | + $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/prototype.js'); |
|
| 37 | + $xoTheme->addScript(SMARTOBJECT_URL . 'include/projax/js/scriptaculous.js'); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -23,82 +23,82 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class SmartObjectColumn |
| 25 | 25 | { |
| 26 | - public $_keyname; |
|
| 27 | - public $_align; |
|
| 28 | - public $_width; |
|
| 29 | - public $_customMethodForValue; |
|
| 30 | - public $_extraParams; |
|
| 31 | - public $_sortable; |
|
| 32 | - public $_customCaption; |
|
| 26 | + public $_keyname; |
|
| 27 | + public $_align; |
|
| 28 | + public $_width; |
|
| 29 | + public $_customMethodForValue; |
|
| 30 | + public $_extraParams; |
|
| 31 | + public $_sortable; |
|
| 32 | + public $_customCaption; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * SmartObjectColumn constructor. |
|
| 36 | - * @param $keyname |
|
| 37 | - * @param string $align |
|
| 38 | - * @param bool $width |
|
| 39 | - * @param bool $customMethodForValue |
|
| 40 | - * @param bool $param |
|
| 41 | - * @param bool $customCaption |
|
| 42 | - * @param bool $sortable |
|
| 43 | - */ |
|
| 44 | - public function __construct( |
|
| 45 | - $keyname, |
|
| 46 | - $align = 'left', |
|
| 47 | - $width = false, |
|
| 48 | - $customMethodForValue = false, |
|
| 49 | - $param = false, |
|
| 50 | - $customCaption = false, |
|
| 51 | - $sortable = true |
|
| 52 | - ) { |
|
| 53 | - $this->_keyname = $keyname; |
|
| 54 | - $this->_align = $align; |
|
| 55 | - $this->_width = $width; |
|
| 56 | - $this->_customMethodForValue = $customMethodForValue; |
|
| 57 | - $this->_sortable = $sortable; |
|
| 58 | - $this->_param = $param; |
|
| 59 | - $this->_customCaption = $customCaption; |
|
| 60 | - } |
|
| 34 | + /** |
|
| 35 | + * SmartObjectColumn constructor. |
|
| 36 | + * @param $keyname |
|
| 37 | + * @param string $align |
|
| 38 | + * @param bool $width |
|
| 39 | + * @param bool $customMethodForValue |
|
| 40 | + * @param bool $param |
|
| 41 | + * @param bool $customCaption |
|
| 42 | + * @param bool $sortable |
|
| 43 | + */ |
|
| 44 | + public function __construct( |
|
| 45 | + $keyname, |
|
| 46 | + $align = 'left', |
|
| 47 | + $width = false, |
|
| 48 | + $customMethodForValue = false, |
|
| 49 | + $param = false, |
|
| 50 | + $customCaption = false, |
|
| 51 | + $sortable = true |
|
| 52 | + ) { |
|
| 53 | + $this->_keyname = $keyname; |
|
| 54 | + $this->_align = $align; |
|
| 55 | + $this->_width = $width; |
|
| 56 | + $this->_customMethodForValue = $customMethodForValue; |
|
| 57 | + $this->_sortable = $sortable; |
|
| 58 | + $this->_param = $param; |
|
| 59 | + $this->_customCaption = $customCaption; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getKeyName() |
|
| 63 | - { |
|
| 64 | - return $this->_keyname; |
|
| 65 | - } |
|
| 62 | + public function getKeyName() |
|
| 63 | + { |
|
| 64 | + return $this->_keyname; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function getAlign() |
|
| 71 | - { |
|
| 72 | - return $this->_align; |
|
| 73 | - } |
|
| 67 | + /** |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function getAlign() |
|
| 71 | + { |
|
| 72 | + return $this->_align; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function isSortable() |
|
| 79 | - { |
|
| 80 | - return $this->_sortable; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function isSortable() |
|
| 79 | + { |
|
| 80 | + return $this->_sortable; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return bool|string |
|
| 85 | - */ |
|
| 86 | - public function getWidth() |
|
| 87 | - { |
|
| 88 | - if ($this->_width) { |
|
| 89 | - $ret = $this->_width; |
|
| 90 | - } else { |
|
| 91 | - $ret = ''; |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * @return bool|string |
|
| 85 | + */ |
|
| 86 | + public function getWidth() |
|
| 87 | + { |
|
| 88 | + if ($this->_width) { |
|
| 89 | + $ret = $this->_width; |
|
| 90 | + } else { |
|
| 91 | + $ret = ''; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $ret; |
|
| 95 | - } |
|
| 94 | + return $ret; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - public function getCustomCaption() |
|
| 101 | - { |
|
| 102 | - return $this->_customCaption; |
|
| 103 | - } |
|
| 97 | + /** |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + public function getCustomCaption() |
|
| 101 | + { |
|
| 102 | + return $this->_customCaption; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -28,17 +28,17 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class SmartobjectTag extends SmartMlObject |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * SmartobjectTag constructor. |
|
| 33 | - */ |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - $this->initVar('tagid', XOBJ_DTYPE_INT, '', true); |
|
| 37 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true); |
|
| 38 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC); |
|
| 39 | - $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC); |
|
| 31 | + /** |
|
| 32 | + * SmartobjectTag constructor. |
|
| 33 | + */ |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + $this->initVar('tagid', XOBJ_DTYPE_INT, '', true); |
|
| 37 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true); |
|
| 38 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC); |
|
| 39 | + $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC); |
|
| 40 | 40 | |
| 41 | - // call parent constructor to get Multilanguage field initiated |
|
| 42 | - $this->SmartMlObject(); |
|
| 43 | - } |
|
| 41 | + // call parent constructor to get Multilanguage field initiated |
|
| 42 | + $this->SmartMlObject(); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -25,805 +25,805 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SmartObjectTable |
| 27 | 27 | { |
| 28 | - public $_id; |
|
| 29 | - public $_objectHandler; |
|
| 30 | - public $_columns; |
|
| 31 | - public $_criteria; |
|
| 32 | - public $_actions; |
|
| 33 | - public $_objects = false; |
|
| 34 | - public $_aObjects; |
|
| 35 | - public $_custom_actions; |
|
| 36 | - public $_sortsel; |
|
| 37 | - public $_ordersel; |
|
| 38 | - public $_limitsel; |
|
| 39 | - public $_filtersel; |
|
| 40 | - public $_filterseloptions; |
|
| 41 | - public $_filtersel2; |
|
| 42 | - public $_filtersel2options; |
|
| 43 | - public $_filtersel2optionsDefault; |
|
| 44 | - |
|
| 45 | - public $_tempObject; |
|
| 46 | - public $_tpl; |
|
| 47 | - public $_introButtons; |
|
| 48 | - public $_quickSearch = false; |
|
| 49 | - public $_actionButtons = false; |
|
| 50 | - public $_head_css_class = 'bg3'; |
|
| 51 | - public $_hasActions = false; |
|
| 52 | - public $_userSide = false; |
|
| 53 | - public $_printerFriendlyPage = false; |
|
| 54 | - public $_tableHeader = false; |
|
| 55 | - public $_tableFooter = false; |
|
| 56 | - public $_showActionsColumnTitle = true; |
|
| 57 | - public $_isTree = false; |
|
| 58 | - public $_showFilterAndLimit = true; |
|
| 59 | - public $_enableColumnsSorting = true; |
|
| 60 | - public $_customTemplate = false; |
|
| 61 | - public $_withSelectedActions = []; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Constructor |
|
| 65 | - * |
|
| 66 | - * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
| 67 | - * @param CriteriaElement $criteria |
|
| 68 | - * @param array $actions array representing the actions to offer |
|
| 69 | - * |
|
| 70 | - * @param bool $userSide |
|
| 71 | - */ |
|
| 72 | - public function __construct( |
|
| 73 | - SmartPersistableObjectHandler $objectHandler, |
|
| 74 | - CriteriaElement $criteria = null, |
|
| 75 | - $actions = ['edit', 'delete'], |
|
| 76 | - $userSide = false |
|
| 77 | - ) { |
|
| 78 | - $this->_id = $objectHandler->className; |
|
| 79 | - $this->_objectHandler = $objectHandler; |
|
| 80 | - |
|
| 81 | - if (!$criteria) { |
|
| 82 | - $criteria = new \CriteriaCompo(); |
|
| 83 | - } |
|
| 84 | - $this->_criteria = $criteria; |
|
| 85 | - $this->_actions = $actions; |
|
| 86 | - $this->_custom_actions = []; |
|
| 87 | - $this->_userSide = $userSide; |
|
| 88 | - if ($userSide) { |
|
| 89 | - $this->_head_css_class = 'head'; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param $op |
|
| 95 | - * @param bool $caption |
|
| 96 | - * @param bool $text |
|
| 97 | - */ |
|
| 98 | - public function addActionButton($op, $caption = false, $text = false) |
|
| 99 | - { |
|
| 100 | - $action = [ |
|
| 101 | - 'op' => $op, |
|
| 102 | - 'caption' => $caption, |
|
| 103 | - 'text' => $text |
|
| 104 | - ]; |
|
| 105 | - $this->_actionButtons[] = $action; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param $columnObj |
|
| 110 | - */ |
|
| 111 | - public function addColumn($columnObj) |
|
| 112 | - { |
|
| 113 | - $this->_columns[] = $columnObj; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param $name |
|
| 118 | - * @param $location |
|
| 119 | - * @param $value |
|
| 120 | - */ |
|
| 121 | - public function addIntroButton($name, $location, $value) |
|
| 122 | - { |
|
| 123 | - $introButton = []; |
|
| 124 | - $introButton['name'] = $name; |
|
| 125 | - $introButton['location'] = $location; |
|
| 126 | - $introButton['value'] = $value; |
|
| 127 | - $this->_introButtons[] = $introButton; |
|
| 128 | - unset($introButton); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function addPrinterFriendlyLink() |
|
| 132 | - { |
|
| 133 | - $current_urls = smart_getCurrentUrls(); |
|
| 134 | - $current_url = $current_urls['full']; |
|
| 135 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param $fields |
|
| 140 | - * @param string $caption |
|
| 141 | - */ |
|
| 142 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 143 | - { |
|
| 144 | - $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $content |
|
| 149 | - */ |
|
| 150 | - public function addHeader($content) |
|
| 151 | - { |
|
| 152 | - $this->_tableHeader = $content; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param $content |
|
| 157 | - */ |
|
| 158 | - public function addFooter($content) |
|
| 159 | - { |
|
| 160 | - $this->_tableFooter = $content; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param $caption |
|
| 165 | - */ |
|
| 166 | - public function addDefaultIntroButton($caption) |
|
| 167 | - { |
|
| 168 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param $method |
|
| 173 | - */ |
|
| 174 | - public function addCustomAction($method) |
|
| 175 | - { |
|
| 176 | - $this->_custom_actions[] = $method; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @param $default_sort |
|
| 181 | - */ |
|
| 182 | - public function setDefaultSort($default_sort) |
|
| 183 | - { |
|
| 184 | - $this->_sortsel = $default_sort; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - public function getDefaultSort() |
|
| 191 | - { |
|
| 192 | - if ($this->_sortsel) { |
|
| 193 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 194 | - } else { |
|
| 195 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param $default_order |
|
| 201 | - */ |
|
| 202 | - public function setDefaultOrder($default_order) |
|
| 203 | - { |
|
| 204 | - $this->_ordersel = $default_order; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - public function getDefaultOrder() |
|
| 211 | - { |
|
| 212 | - if ($this->_ordersel) { |
|
| 213 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 214 | - } else { |
|
| 215 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param array $actions |
|
| 221 | - */ |
|
| 222 | - public function addWithSelectedActions($actions = []) |
|
| 223 | - { |
|
| 224 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 225 | - $this->_withSelectedActions = $actions; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Adding a filter in the table |
|
| 230 | - * |
|
| 231 | - * @param string $key key to the field that will be used for sorting |
|
| 232 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 233 | - * @param bool $default |
|
| 234 | - */ |
|
| 235 | - public function addFilter($key, $method, $default = false) |
|
| 236 | - { |
|
| 237 | - $this->_filterseloptions[$key] = $method; |
|
| 238 | - $this->_filtersel2optionsDefault = $default; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param $default_filter |
|
| 243 | - */ |
|
| 244 | - public function setDefaultFilter($default_filter) |
|
| 245 | - { |
|
| 246 | - $this->_filtersel = $default_filter; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function isForUserSide() |
|
| 250 | - { |
|
| 251 | - $this->_userSide = true; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param $template |
|
| 256 | - */ |
|
| 257 | - public function setCustomTemplate($template) |
|
| 258 | - { |
|
| 259 | - $this->_customTemplate = $template; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function setSortOrder() |
|
| 263 | - { |
|
| 264 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 265 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 266 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 267 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 268 | - |
|
| 269 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 270 | - && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 271 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 272 | - } else { |
|
| 273 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 277 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 278 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 279 | - $ordersArray = $this->getOrdersArray(); |
|
| 280 | - $this->_criteria->setOrder($this->_ordersel); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param $id |
|
| 285 | - */ |
|
| 286 | - public function setTableId($id) |
|
| 287 | - { |
|
| 288 | - $this->_id = $id; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * @param $objects |
|
| 293 | - */ |
|
| 294 | - public function setObjects($objects) |
|
| 295 | - { |
|
| 296 | - $this->_objects = $objects; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - public function createTableRows() |
|
| 300 | - { |
|
| 301 | - $this->_aObjects = []; |
|
| 302 | - |
|
| 303 | - $doWeHaveActions = false; |
|
| 304 | - |
|
| 305 | - $objectclass = 'odd'; |
|
| 306 | - if (count($this->_objects) > 0) { |
|
| 307 | - foreach ($this->_objects as $object) { |
|
| 308 | - $aObject = []; |
|
| 309 | - |
|
| 310 | - $i = 0; |
|
| 311 | - |
|
| 312 | - $aColumns = []; |
|
| 313 | - |
|
| 314 | - foreach ($this->_columns as $column) { |
|
| 315 | - $aColumn = []; |
|
| 316 | - |
|
| 317 | - if (0 == $i) { |
|
| 318 | - $class = 'head'; |
|
| 319 | - } elseif (0 == $i % 2) { |
|
| 320 | - $class = 'even'; |
|
| 321 | - } else { |
|
| 322 | - $class = 'odd'; |
|
| 323 | - } |
|
| 324 | - if (method_exists($object, 'initiateCustomFields')) { |
|
| 325 | - //$object->initiateCustomFields(); |
|
| 326 | - } |
|
| 327 | - if ('checked' === $column->_keyname) { |
|
| 328 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 329 | - } elseif ($column->_customMethodForValue |
|
| 330 | - && method_exists($object, $column->_customMethodForValue)) { |
|
| 331 | - $method = $column->_customMethodForValue; |
|
| 332 | - if ($column->_param) { |
|
| 333 | - $value = $object->$method($column->_param); |
|
| 334 | - } else { |
|
| 335 | - $value = $object->$method(); |
|
| 336 | - } |
|
| 337 | - } else { |
|
| 338 | - /** |
|
| 339 | - * If the column is the identifier, then put a link on it |
|
| 340 | - */ |
|
| 341 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 342 | - $value = $object->getItemLink(); |
|
| 343 | - } else { |
|
| 344 | - $value = $object->getVar($column->getKeyName()); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $aColumn['value'] = $value; |
|
| 349 | - $aColumn['class'] = $class; |
|
| 350 | - $aColumn['width'] = $column->getWidth(); |
|
| 351 | - $aColumn['align'] = $column->getAlign(); |
|
| 352 | - |
|
| 353 | - $aColumns[] = $aColumn; |
|
| 354 | - ++$i; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $aObject['columns'] = $aColumns; |
|
| 358 | - $aObject['id'] = $object->id(); |
|
| 359 | - |
|
| 360 | - $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
| 361 | - |
|
| 362 | - $aObject['class'] = $objectclass; |
|
| 363 | - |
|
| 364 | - $actions = []; |
|
| 365 | - |
|
| 366 | - // Adding the custom actions if any |
|
| 367 | - foreach ($this->_custom_actions as $action) { |
|
| 368 | - if (method_exists($object, $action)) { |
|
| 369 | - $actions[] = $object->$action(); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 374 | - $controller = new SmartObjectController($this->_objectHandler); |
|
| 375 | - |
|
| 376 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 377 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 378 | - } |
|
| 379 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 380 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 381 | - } |
|
| 382 | - $aObject['actions'] = $actions; |
|
| 383 | - |
|
| 384 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 385 | - |
|
| 386 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 387 | - |
|
| 388 | - $this->_aObjects[] = $aObject; |
|
| 389 | - } |
|
| 390 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 391 | - } else { |
|
| 392 | - $colspan = count($this->_columns) + 1; |
|
| 393 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 394 | - } |
|
| 395 | - $this->_hasActions = $doWeHaveActions; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * @param bool $debug |
|
| 400 | - * @return mixed |
|
| 401 | - */ |
|
| 402 | - public function fetchObjects($debug = false) |
|
| 403 | - { |
|
| 404 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public function getDefaultFilter() |
|
| 411 | - { |
|
| 412 | - if ($this->_filtersel) { |
|
| 413 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 414 | - } else { |
|
| 415 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * @return array|bool |
|
| 421 | - */ |
|
| 422 | - public function getFiltersArray() |
|
| 423 | - { |
|
| 424 | - $ret = []; |
|
| 425 | - $field = []; |
|
| 426 | - $field['caption'] = _CO_OBJ_NONE; |
|
| 427 | - $field['selected'] = ''; |
|
| 428 | - $ret['default'] = $field; |
|
| 429 | - unset($field); |
|
| 430 | - |
|
| 431 | - if ($this->_filterseloptions) { |
|
| 432 | - foreach ($this->_filterseloptions as $key => $value) { |
|
| 433 | - $field = []; |
|
| 434 | - if (is_array($value)) { |
|
| 435 | - $field['caption'] = $key; |
|
| 436 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 437 | - } else { |
|
| 438 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 439 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 440 | - } |
|
| 441 | - $ret[$key] = $field; |
|
| 442 | - unset($field); |
|
| 443 | - } |
|
| 444 | - } else { |
|
| 445 | - $ret = false; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return $ret; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @param $default_filter2 |
|
| 453 | - */ |
|
| 454 | - public function setDefaultFilter2($default_filter2) |
|
| 455 | - { |
|
| 456 | - $this->_filtersel2 = $default_filter2; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @return string |
|
| 461 | - */ |
|
| 462 | - public function getDefaultFilter2() |
|
| 463 | - { |
|
| 464 | - if ($this->_filtersel2) { |
|
| 465 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 466 | - } else { |
|
| 467 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return array |
|
| 473 | - */ |
|
| 474 | - public function getFilters2Array() |
|
| 475 | - { |
|
| 476 | - $ret = []; |
|
| 477 | - |
|
| 478 | - foreach ($this->_filtersel2options as $key => $value) { |
|
| 479 | - $field = []; |
|
| 480 | - $field['caption'] = $value; |
|
| 481 | - $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 482 | - $ret[$key] = $field; |
|
| 483 | - unset($field); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $ret; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @param $limitsArray |
|
| 491 | - * @param $params_of_the_options_sel |
|
| 492 | - */ |
|
| 493 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 494 | - { |
|
| 495 | - // Rendering the form to select options on the table |
|
| 496 | - $current_urls = smart_getCurrentUrls(); |
|
| 497 | - $current_url = $current_urls['full']; |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * What was $params_of_the_options_sel doing again ? |
|
| 501 | - */ |
|
| 502 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 503 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 504 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @return array |
|
| 509 | - */ |
|
| 510 | - public function getLimitsArray() |
|
| 511 | - { |
|
| 512 | - $ret = []; |
|
| 513 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 514 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 515 | - |
|
| 516 | - $ret['5']['caption'] = '5'; |
|
| 517 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 518 | - |
|
| 519 | - $ret['10']['caption'] = '10'; |
|
| 520 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 521 | - |
|
| 522 | - $ret['15']['caption'] = '15'; |
|
| 523 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 524 | - |
|
| 525 | - $ret['20']['caption'] = '20'; |
|
| 526 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 527 | - |
|
| 528 | - $ret['25']['caption'] = '25'; |
|
| 529 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 530 | - |
|
| 531 | - $ret['30']['caption'] = '30'; |
|
| 532 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 533 | - |
|
| 534 | - $ret['35']['caption'] = '35'; |
|
| 535 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 536 | - |
|
| 537 | - $ret['40']['caption'] = '40'; |
|
| 538 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 539 | - |
|
| 540 | - return $ret; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @return bool |
|
| 545 | - */ |
|
| 546 | - public function getObjects() |
|
| 547 | - { |
|
| 548 | - return $this->_objects; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - public function hideActionColumnTitle() |
|
| 552 | - { |
|
| 553 | - $this->_showActionsColumnTitle = false; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - public function hideFilterAndLimit() |
|
| 557 | - { |
|
| 558 | - $this->_showFilterAndLimit = false; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @return array |
|
| 563 | - */ |
|
| 564 | - public function getOrdersArray() |
|
| 565 | - { |
|
| 566 | - $ret = []; |
|
| 567 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 568 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 569 | - |
|
| 570 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 571 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 572 | - |
|
| 573 | - return $ret; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @return mixed|string|void |
|
| 578 | - */ |
|
| 579 | - public function renderD() |
|
| 580 | - { |
|
| 581 | - return $this->render(false, true); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - public function renderForPrint() |
|
| 585 | - { |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @param bool $fetchOnly |
|
| 590 | - * @param bool $debug |
|
| 591 | - * @return mixed|string|void |
|
| 592 | - */ |
|
| 593 | - public function render($fetchOnly = false, $debug = false) |
|
| 594 | - { |
|
| 595 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 596 | - |
|
| 597 | - $this->_tpl = new \XoopsTpl(); |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 601 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 602 | - * and we will free it after |
|
| 603 | - */ |
|
| 604 | - $this->_tempObject = $this->_objectHandler->create(); |
|
| 605 | - |
|
| 606 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 607 | - |
|
| 608 | - $this->setSortOrder(); |
|
| 609 | - |
|
| 610 | - if (!$this->_isTree) { |
|
| 611 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 612 | - } else { |
|
| 613 | - $this->_limitsel = 'all'; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 617 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 618 | - $limitsArray = $this->getLimitsArray(); |
|
| 619 | - $this->_criteria->setLimit($this->_limitsel); |
|
| 620 | - |
|
| 621 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 622 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 623 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 624 | - $filtersArray = $this->getFiltersArray(); |
|
| 625 | - |
|
| 626 | - if ($filtersArray) { |
|
| 627 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 631 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 632 | - // check if method associate with this filter exists in the handler |
|
| 633 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 634 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 635 | - $this->_criteria->add($filter['criteria']); |
|
| 636 | - } else { |
|
| 637 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 638 | - |
|
| 639 | - // then we will create the selfilter2 options by calling this method |
|
| 640 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 641 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 642 | - |
|
| 643 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 644 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 645 | - |
|
| 646 | - $filters2Array = $this->getFilters2Array(); |
|
| 647 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 648 | - |
|
| 649 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 650 | - if ('default' !== $this->_filtersel2) { |
|
| 651 | - $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - // Check if we have a quicksearch |
|
| 657 | - |
|
| 658 | - if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 659 | - $quicksearch_criteria = new \CriteriaCompo(); |
|
| 660 | - if (is_array($this->_quickSearch['fields'])) { |
|
| 661 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
| 662 | - $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 666 | - } |
|
| 667 | - $this->_criteria->add($quicksearch_criteria); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - $this->_objects = $this->fetchObjects($debug); |
|
| 671 | - |
|
| 672 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 673 | - if ($this->_criteria->getLimit() > 0) { |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Geeting rid of the old params |
|
| 677 | - * $new_get_array is an array containing the new GET parameters |
|
| 678 | - */ |
|
| 679 | - $new_get_array = []; |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 683 | - * but without the pagenave parameters. This array will be used in the |
|
| 684 | - * OptionsSelection |
|
| 685 | - */ |
|
| 686 | - $params_of_the_options_sel = []; |
|
| 687 | - |
|
| 688 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 689 | - foreach ($_GET as $k => $v) { |
|
| 690 | - if (!in_array($k, $not_needed_params)) { |
|
| 691 | - $new_get_array[] = "$k=$v"; |
|
| 692 | - $params_of_the_options_sel[] = "$k=$v"; |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Adding the new params of the pagenav |
|
| 698 | - */ |
|
| 699 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 700 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 701 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 702 | - $otherParams = implode('&', $new_get_array); |
|
| 703 | - |
|
| 704 | - $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 705 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 706 | - } |
|
| 707 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 708 | - |
|
| 709 | - // retreive the current url and the query string |
|
| 710 | - $current_urls = smart_getCurrentUrls(); |
|
| 711 | - $current_url = $current_urls['full_phpself']; |
|
| 712 | - $query_string = $current_urls['querystring']; |
|
| 713 | - if ($query_string) { |
|
| 714 | - $query_string = str_replace('?', '', $query_string); |
|
| 715 | - } |
|
| 716 | - $query_stringArray = explode('&', $query_string); |
|
| 717 | - $new_query_stringArray = []; |
|
| 718 | - foreach ($query_stringArray as $query_string) { |
|
| 719 | - if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
| 720 | - $new_query_stringArray[] = $query_string; |
|
| 721 | - } |
|
| 722 | - } |
|
| 723 | - $new_query_string = implode('&', $new_query_stringArray); |
|
| 724 | - |
|
| 725 | - $orderArray = []; |
|
| 726 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
| 727 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 728 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
| 729 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 730 | - |
|
| 731 | - $aColumns = []; |
|
| 732 | - |
|
| 733 | - foreach ($this->_columns as $column) { |
|
| 734 | - $qs_param = ''; |
|
| 735 | - $aColumn = []; |
|
| 736 | - $aColumn['width'] = $column->getWidth(); |
|
| 737 | - $aColumn['align'] = $column->getAlign(); |
|
| 738 | - $aColumn['key'] = $column->getKeyName(); |
|
| 739 | - if ('checked' === $column->_keyname) { |
|
| 740 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 741 | - } elseif ($column->getCustomCaption()) { |
|
| 742 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
| 743 | - } else { |
|
| 744 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 745 | - } |
|
| 746 | - // Are we doing a GET sort on this column ? |
|
| 747 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 748 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 749 | - || ($this->_sortsel == $column->getKeyName()); |
|
| 750 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 751 | - |
|
| 752 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 753 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 754 | - } |
|
| 755 | - if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
| 756 | - $aColumn['caption'] = $aColumn['caption']; |
|
| 757 | - } elseif ($getSort) { |
|
| 758 | - $aColumn['caption'] = '<a href="' |
|
| 759 | - . $current_url |
|
| 760 | - . '?' |
|
| 761 | - . $this->_objectHandler->_itemname |
|
| 762 | - . '_' |
|
| 763 | - . 'sortsel=' |
|
| 764 | - . $column->getKeyName() |
|
| 765 | - . '&' |
|
| 766 | - . $this->_objectHandler->_itemname |
|
| 767 | - . '_' |
|
| 768 | - . 'ordersel=' |
|
| 769 | - . $orderArray[$order]['neworder'] |
|
| 770 | - . $qs_param |
|
| 771 | - . '&' |
|
| 772 | - . $new_query_string |
|
| 773 | - . '">' |
|
| 774 | - . $aColumn['caption'] |
|
| 775 | - . ' <img src="' |
|
| 776 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 777 | - . $orderArray[$order]['image'] |
|
| 778 | - . '" alt="ASC"></a>'; |
|
| 779 | - } else { |
|
| 780 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 781 | - } |
|
| 782 | - $aColumns[] = $aColumn; |
|
| 783 | - } |
|
| 784 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 785 | - |
|
| 786 | - if ($this->_quickSearch) { |
|
| 787 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - $this->createTableRows(); |
|
| 791 | - |
|
| 792 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 793 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 794 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 795 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 796 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 797 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 798 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 799 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 800 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 801 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 802 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 803 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 804 | - if (!empty($this->_withSelectedActions)) { |
|
| 805 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 809 | - if ($fetchOnly) { |
|
| 810 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 811 | - } else { |
|
| 812 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - public function disableColumnsSorting() |
|
| 817 | - { |
|
| 818 | - $this->_enableColumnsSorting = false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * @param bool $debug |
|
| 823 | - * @return mixed|string|void |
|
| 824 | - */ |
|
| 825 | - public function fetch($debug = false) |
|
| 826 | - { |
|
| 827 | - return $this->render(true, $debug); |
|
| 828 | - } |
|
| 28 | + public $_id; |
|
| 29 | + public $_objectHandler; |
|
| 30 | + public $_columns; |
|
| 31 | + public $_criteria; |
|
| 32 | + public $_actions; |
|
| 33 | + public $_objects = false; |
|
| 34 | + public $_aObjects; |
|
| 35 | + public $_custom_actions; |
|
| 36 | + public $_sortsel; |
|
| 37 | + public $_ordersel; |
|
| 38 | + public $_limitsel; |
|
| 39 | + public $_filtersel; |
|
| 40 | + public $_filterseloptions; |
|
| 41 | + public $_filtersel2; |
|
| 42 | + public $_filtersel2options; |
|
| 43 | + public $_filtersel2optionsDefault; |
|
| 44 | + |
|
| 45 | + public $_tempObject; |
|
| 46 | + public $_tpl; |
|
| 47 | + public $_introButtons; |
|
| 48 | + public $_quickSearch = false; |
|
| 49 | + public $_actionButtons = false; |
|
| 50 | + public $_head_css_class = 'bg3'; |
|
| 51 | + public $_hasActions = false; |
|
| 52 | + public $_userSide = false; |
|
| 53 | + public $_printerFriendlyPage = false; |
|
| 54 | + public $_tableHeader = false; |
|
| 55 | + public $_tableFooter = false; |
|
| 56 | + public $_showActionsColumnTitle = true; |
|
| 57 | + public $_isTree = false; |
|
| 58 | + public $_showFilterAndLimit = true; |
|
| 59 | + public $_enableColumnsSorting = true; |
|
| 60 | + public $_customTemplate = false; |
|
| 61 | + public $_withSelectedActions = []; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Constructor |
|
| 65 | + * |
|
| 66 | + * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
| 67 | + * @param CriteriaElement $criteria |
|
| 68 | + * @param array $actions array representing the actions to offer |
|
| 69 | + * |
|
| 70 | + * @param bool $userSide |
|
| 71 | + */ |
|
| 72 | + public function __construct( |
|
| 73 | + SmartPersistableObjectHandler $objectHandler, |
|
| 74 | + CriteriaElement $criteria = null, |
|
| 75 | + $actions = ['edit', 'delete'], |
|
| 76 | + $userSide = false |
|
| 77 | + ) { |
|
| 78 | + $this->_id = $objectHandler->className; |
|
| 79 | + $this->_objectHandler = $objectHandler; |
|
| 80 | + |
|
| 81 | + if (!$criteria) { |
|
| 82 | + $criteria = new \CriteriaCompo(); |
|
| 83 | + } |
|
| 84 | + $this->_criteria = $criteria; |
|
| 85 | + $this->_actions = $actions; |
|
| 86 | + $this->_custom_actions = []; |
|
| 87 | + $this->_userSide = $userSide; |
|
| 88 | + if ($userSide) { |
|
| 89 | + $this->_head_css_class = 'head'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param $op |
|
| 95 | + * @param bool $caption |
|
| 96 | + * @param bool $text |
|
| 97 | + */ |
|
| 98 | + public function addActionButton($op, $caption = false, $text = false) |
|
| 99 | + { |
|
| 100 | + $action = [ |
|
| 101 | + 'op' => $op, |
|
| 102 | + 'caption' => $caption, |
|
| 103 | + 'text' => $text |
|
| 104 | + ]; |
|
| 105 | + $this->_actionButtons[] = $action; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param $columnObj |
|
| 110 | + */ |
|
| 111 | + public function addColumn($columnObj) |
|
| 112 | + { |
|
| 113 | + $this->_columns[] = $columnObj; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param $name |
|
| 118 | + * @param $location |
|
| 119 | + * @param $value |
|
| 120 | + */ |
|
| 121 | + public function addIntroButton($name, $location, $value) |
|
| 122 | + { |
|
| 123 | + $introButton = []; |
|
| 124 | + $introButton['name'] = $name; |
|
| 125 | + $introButton['location'] = $location; |
|
| 126 | + $introButton['value'] = $value; |
|
| 127 | + $this->_introButtons[] = $introButton; |
|
| 128 | + unset($introButton); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function addPrinterFriendlyLink() |
|
| 132 | + { |
|
| 133 | + $current_urls = smart_getCurrentUrls(); |
|
| 134 | + $current_url = $current_urls['full']; |
|
| 135 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param $fields |
|
| 140 | + * @param string $caption |
|
| 141 | + */ |
|
| 142 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 143 | + { |
|
| 144 | + $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $content |
|
| 149 | + */ |
|
| 150 | + public function addHeader($content) |
|
| 151 | + { |
|
| 152 | + $this->_tableHeader = $content; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param $content |
|
| 157 | + */ |
|
| 158 | + public function addFooter($content) |
|
| 159 | + { |
|
| 160 | + $this->_tableFooter = $content; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param $caption |
|
| 165 | + */ |
|
| 166 | + public function addDefaultIntroButton($caption) |
|
| 167 | + { |
|
| 168 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param $method |
|
| 173 | + */ |
|
| 174 | + public function addCustomAction($method) |
|
| 175 | + { |
|
| 176 | + $this->_custom_actions[] = $method; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @param $default_sort |
|
| 181 | + */ |
|
| 182 | + public function setDefaultSort($default_sort) |
|
| 183 | + { |
|
| 184 | + $this->_sortsel = $default_sort; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + public function getDefaultSort() |
|
| 191 | + { |
|
| 192 | + if ($this->_sortsel) { |
|
| 193 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 194 | + } else { |
|
| 195 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param $default_order |
|
| 201 | + */ |
|
| 202 | + public function setDefaultOrder($default_order) |
|
| 203 | + { |
|
| 204 | + $this->_ordersel = $default_order; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + public function getDefaultOrder() |
|
| 211 | + { |
|
| 212 | + if ($this->_ordersel) { |
|
| 213 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 214 | + } else { |
|
| 215 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param array $actions |
|
| 221 | + */ |
|
| 222 | + public function addWithSelectedActions($actions = []) |
|
| 223 | + { |
|
| 224 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 225 | + $this->_withSelectedActions = $actions; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Adding a filter in the table |
|
| 230 | + * |
|
| 231 | + * @param string $key key to the field that will be used for sorting |
|
| 232 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 233 | + * @param bool $default |
|
| 234 | + */ |
|
| 235 | + public function addFilter($key, $method, $default = false) |
|
| 236 | + { |
|
| 237 | + $this->_filterseloptions[$key] = $method; |
|
| 238 | + $this->_filtersel2optionsDefault = $default; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param $default_filter |
|
| 243 | + */ |
|
| 244 | + public function setDefaultFilter($default_filter) |
|
| 245 | + { |
|
| 246 | + $this->_filtersel = $default_filter; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function isForUserSide() |
|
| 250 | + { |
|
| 251 | + $this->_userSide = true; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param $template |
|
| 256 | + */ |
|
| 257 | + public function setCustomTemplate($template) |
|
| 258 | + { |
|
| 259 | + $this->_customTemplate = $template; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function setSortOrder() |
|
| 263 | + { |
|
| 264 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 265 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 266 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 267 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 268 | + |
|
| 269 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 270 | + && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 271 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 272 | + } else { |
|
| 273 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 277 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 278 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 279 | + $ordersArray = $this->getOrdersArray(); |
|
| 280 | + $this->_criteria->setOrder($this->_ordersel); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param $id |
|
| 285 | + */ |
|
| 286 | + public function setTableId($id) |
|
| 287 | + { |
|
| 288 | + $this->_id = $id; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * @param $objects |
|
| 293 | + */ |
|
| 294 | + public function setObjects($objects) |
|
| 295 | + { |
|
| 296 | + $this->_objects = $objects; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + public function createTableRows() |
|
| 300 | + { |
|
| 301 | + $this->_aObjects = []; |
|
| 302 | + |
|
| 303 | + $doWeHaveActions = false; |
|
| 304 | + |
|
| 305 | + $objectclass = 'odd'; |
|
| 306 | + if (count($this->_objects) > 0) { |
|
| 307 | + foreach ($this->_objects as $object) { |
|
| 308 | + $aObject = []; |
|
| 309 | + |
|
| 310 | + $i = 0; |
|
| 311 | + |
|
| 312 | + $aColumns = []; |
|
| 313 | + |
|
| 314 | + foreach ($this->_columns as $column) { |
|
| 315 | + $aColumn = []; |
|
| 316 | + |
|
| 317 | + if (0 == $i) { |
|
| 318 | + $class = 'head'; |
|
| 319 | + } elseif (0 == $i % 2) { |
|
| 320 | + $class = 'even'; |
|
| 321 | + } else { |
|
| 322 | + $class = 'odd'; |
|
| 323 | + } |
|
| 324 | + if (method_exists($object, 'initiateCustomFields')) { |
|
| 325 | + //$object->initiateCustomFields(); |
|
| 326 | + } |
|
| 327 | + if ('checked' === $column->_keyname) { |
|
| 328 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 329 | + } elseif ($column->_customMethodForValue |
|
| 330 | + && method_exists($object, $column->_customMethodForValue)) { |
|
| 331 | + $method = $column->_customMethodForValue; |
|
| 332 | + if ($column->_param) { |
|
| 333 | + $value = $object->$method($column->_param); |
|
| 334 | + } else { |
|
| 335 | + $value = $object->$method(); |
|
| 336 | + } |
|
| 337 | + } else { |
|
| 338 | + /** |
|
| 339 | + * If the column is the identifier, then put a link on it |
|
| 340 | + */ |
|
| 341 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 342 | + $value = $object->getItemLink(); |
|
| 343 | + } else { |
|
| 344 | + $value = $object->getVar($column->getKeyName()); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $aColumn['value'] = $value; |
|
| 349 | + $aColumn['class'] = $class; |
|
| 350 | + $aColumn['width'] = $column->getWidth(); |
|
| 351 | + $aColumn['align'] = $column->getAlign(); |
|
| 352 | + |
|
| 353 | + $aColumns[] = $aColumn; |
|
| 354 | + ++$i; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $aObject['columns'] = $aColumns; |
|
| 358 | + $aObject['id'] = $object->id(); |
|
| 359 | + |
|
| 360 | + $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
| 361 | + |
|
| 362 | + $aObject['class'] = $objectclass; |
|
| 363 | + |
|
| 364 | + $actions = []; |
|
| 365 | + |
|
| 366 | + // Adding the custom actions if any |
|
| 367 | + foreach ($this->_custom_actions as $action) { |
|
| 368 | + if (method_exists($object, $action)) { |
|
| 369 | + $actions[] = $object->$action(); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 374 | + $controller = new SmartObjectController($this->_objectHandler); |
|
| 375 | + |
|
| 376 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 377 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 378 | + } |
|
| 379 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 380 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 381 | + } |
|
| 382 | + $aObject['actions'] = $actions; |
|
| 383 | + |
|
| 384 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 385 | + |
|
| 386 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 387 | + |
|
| 388 | + $this->_aObjects[] = $aObject; |
|
| 389 | + } |
|
| 390 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 391 | + } else { |
|
| 392 | + $colspan = count($this->_columns) + 1; |
|
| 393 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 394 | + } |
|
| 395 | + $this->_hasActions = $doWeHaveActions; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * @param bool $debug |
|
| 400 | + * @return mixed |
|
| 401 | + */ |
|
| 402 | + public function fetchObjects($debug = false) |
|
| 403 | + { |
|
| 404 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public function getDefaultFilter() |
|
| 411 | + { |
|
| 412 | + if ($this->_filtersel) { |
|
| 413 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 414 | + } else { |
|
| 415 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * @return array|bool |
|
| 421 | + */ |
|
| 422 | + public function getFiltersArray() |
|
| 423 | + { |
|
| 424 | + $ret = []; |
|
| 425 | + $field = []; |
|
| 426 | + $field['caption'] = _CO_OBJ_NONE; |
|
| 427 | + $field['selected'] = ''; |
|
| 428 | + $ret['default'] = $field; |
|
| 429 | + unset($field); |
|
| 430 | + |
|
| 431 | + if ($this->_filterseloptions) { |
|
| 432 | + foreach ($this->_filterseloptions as $key => $value) { |
|
| 433 | + $field = []; |
|
| 434 | + if (is_array($value)) { |
|
| 435 | + $field['caption'] = $key; |
|
| 436 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 437 | + } else { |
|
| 438 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 439 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 440 | + } |
|
| 441 | + $ret[$key] = $field; |
|
| 442 | + unset($field); |
|
| 443 | + } |
|
| 444 | + } else { |
|
| 445 | + $ret = false; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return $ret; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @param $default_filter2 |
|
| 453 | + */ |
|
| 454 | + public function setDefaultFilter2($default_filter2) |
|
| 455 | + { |
|
| 456 | + $this->_filtersel2 = $default_filter2; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @return string |
|
| 461 | + */ |
|
| 462 | + public function getDefaultFilter2() |
|
| 463 | + { |
|
| 464 | + if ($this->_filtersel2) { |
|
| 465 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 466 | + } else { |
|
| 467 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return array |
|
| 473 | + */ |
|
| 474 | + public function getFilters2Array() |
|
| 475 | + { |
|
| 476 | + $ret = []; |
|
| 477 | + |
|
| 478 | + foreach ($this->_filtersel2options as $key => $value) { |
|
| 479 | + $field = []; |
|
| 480 | + $field['caption'] = $value; |
|
| 481 | + $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 482 | + $ret[$key] = $field; |
|
| 483 | + unset($field); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $ret; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @param $limitsArray |
|
| 491 | + * @param $params_of_the_options_sel |
|
| 492 | + */ |
|
| 493 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 494 | + { |
|
| 495 | + // Rendering the form to select options on the table |
|
| 496 | + $current_urls = smart_getCurrentUrls(); |
|
| 497 | + $current_url = $current_urls['full']; |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * What was $params_of_the_options_sel doing again ? |
|
| 501 | + */ |
|
| 502 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 503 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 504 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @return array |
|
| 509 | + */ |
|
| 510 | + public function getLimitsArray() |
|
| 511 | + { |
|
| 512 | + $ret = []; |
|
| 513 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 514 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 515 | + |
|
| 516 | + $ret['5']['caption'] = '5'; |
|
| 517 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 518 | + |
|
| 519 | + $ret['10']['caption'] = '10'; |
|
| 520 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 521 | + |
|
| 522 | + $ret['15']['caption'] = '15'; |
|
| 523 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 524 | + |
|
| 525 | + $ret['20']['caption'] = '20'; |
|
| 526 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 527 | + |
|
| 528 | + $ret['25']['caption'] = '25'; |
|
| 529 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 530 | + |
|
| 531 | + $ret['30']['caption'] = '30'; |
|
| 532 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 533 | + |
|
| 534 | + $ret['35']['caption'] = '35'; |
|
| 535 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 536 | + |
|
| 537 | + $ret['40']['caption'] = '40'; |
|
| 538 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 539 | + |
|
| 540 | + return $ret; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @return bool |
|
| 545 | + */ |
|
| 546 | + public function getObjects() |
|
| 547 | + { |
|
| 548 | + return $this->_objects; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + public function hideActionColumnTitle() |
|
| 552 | + { |
|
| 553 | + $this->_showActionsColumnTitle = false; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + public function hideFilterAndLimit() |
|
| 557 | + { |
|
| 558 | + $this->_showFilterAndLimit = false; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @return array |
|
| 563 | + */ |
|
| 564 | + public function getOrdersArray() |
|
| 565 | + { |
|
| 566 | + $ret = []; |
|
| 567 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 568 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 569 | + |
|
| 570 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 571 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 572 | + |
|
| 573 | + return $ret; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @return mixed|string|void |
|
| 578 | + */ |
|
| 579 | + public function renderD() |
|
| 580 | + { |
|
| 581 | + return $this->render(false, true); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + public function renderForPrint() |
|
| 585 | + { |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @param bool $fetchOnly |
|
| 590 | + * @param bool $debug |
|
| 591 | + * @return mixed|string|void |
|
| 592 | + */ |
|
| 593 | + public function render($fetchOnly = false, $debug = false) |
|
| 594 | + { |
|
| 595 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 596 | + |
|
| 597 | + $this->_tpl = new \XoopsTpl(); |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 601 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 602 | + * and we will free it after |
|
| 603 | + */ |
|
| 604 | + $this->_tempObject = $this->_objectHandler->create(); |
|
| 605 | + |
|
| 606 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 607 | + |
|
| 608 | + $this->setSortOrder(); |
|
| 609 | + |
|
| 610 | + if (!$this->_isTree) { |
|
| 611 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 612 | + } else { |
|
| 613 | + $this->_limitsel = 'all'; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 617 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 618 | + $limitsArray = $this->getLimitsArray(); |
|
| 619 | + $this->_criteria->setLimit($this->_limitsel); |
|
| 620 | + |
|
| 621 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 622 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 623 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 624 | + $filtersArray = $this->getFiltersArray(); |
|
| 625 | + |
|
| 626 | + if ($filtersArray) { |
|
| 627 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 631 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 632 | + // check if method associate with this filter exists in the handler |
|
| 633 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 634 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 635 | + $this->_criteria->add($filter['criteria']); |
|
| 636 | + } else { |
|
| 637 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 638 | + |
|
| 639 | + // then we will create the selfilter2 options by calling this method |
|
| 640 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 641 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 642 | + |
|
| 643 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 644 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 645 | + |
|
| 646 | + $filters2Array = $this->getFilters2Array(); |
|
| 647 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 648 | + |
|
| 649 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 650 | + if ('default' !== $this->_filtersel2) { |
|
| 651 | + $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + // Check if we have a quicksearch |
|
| 657 | + |
|
| 658 | + if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 659 | + $quicksearch_criteria = new \CriteriaCompo(); |
|
| 660 | + if (is_array($this->_quickSearch['fields'])) { |
|
| 661 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
| 662 | + $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 666 | + } |
|
| 667 | + $this->_criteria->add($quicksearch_criteria); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + $this->_objects = $this->fetchObjects($debug); |
|
| 671 | + |
|
| 672 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 673 | + if ($this->_criteria->getLimit() > 0) { |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Geeting rid of the old params |
|
| 677 | + * $new_get_array is an array containing the new GET parameters |
|
| 678 | + */ |
|
| 679 | + $new_get_array = []; |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 683 | + * but without the pagenave parameters. This array will be used in the |
|
| 684 | + * OptionsSelection |
|
| 685 | + */ |
|
| 686 | + $params_of_the_options_sel = []; |
|
| 687 | + |
|
| 688 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 689 | + foreach ($_GET as $k => $v) { |
|
| 690 | + if (!in_array($k, $not_needed_params)) { |
|
| 691 | + $new_get_array[] = "$k=$v"; |
|
| 692 | + $params_of_the_options_sel[] = "$k=$v"; |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Adding the new params of the pagenav |
|
| 698 | + */ |
|
| 699 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 700 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 701 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 702 | + $otherParams = implode('&', $new_get_array); |
|
| 703 | + |
|
| 704 | + $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 705 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 706 | + } |
|
| 707 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 708 | + |
|
| 709 | + // retreive the current url and the query string |
|
| 710 | + $current_urls = smart_getCurrentUrls(); |
|
| 711 | + $current_url = $current_urls['full_phpself']; |
|
| 712 | + $query_string = $current_urls['querystring']; |
|
| 713 | + if ($query_string) { |
|
| 714 | + $query_string = str_replace('?', '', $query_string); |
|
| 715 | + } |
|
| 716 | + $query_stringArray = explode('&', $query_string); |
|
| 717 | + $new_query_stringArray = []; |
|
| 718 | + foreach ($query_stringArray as $query_string) { |
|
| 719 | + if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
| 720 | + $new_query_stringArray[] = $query_string; |
|
| 721 | + } |
|
| 722 | + } |
|
| 723 | + $new_query_string = implode('&', $new_query_stringArray); |
|
| 724 | + |
|
| 725 | + $orderArray = []; |
|
| 726 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
| 727 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 728 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
| 729 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 730 | + |
|
| 731 | + $aColumns = []; |
|
| 732 | + |
|
| 733 | + foreach ($this->_columns as $column) { |
|
| 734 | + $qs_param = ''; |
|
| 735 | + $aColumn = []; |
|
| 736 | + $aColumn['width'] = $column->getWidth(); |
|
| 737 | + $aColumn['align'] = $column->getAlign(); |
|
| 738 | + $aColumn['key'] = $column->getKeyName(); |
|
| 739 | + if ('checked' === $column->_keyname) { |
|
| 740 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 741 | + } elseif ($column->getCustomCaption()) { |
|
| 742 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
| 743 | + } else { |
|
| 744 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 745 | + } |
|
| 746 | + // Are we doing a GET sort on this column ? |
|
| 747 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 748 | + && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 749 | + || ($this->_sortsel == $column->getKeyName()); |
|
| 750 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 751 | + |
|
| 752 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 753 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 754 | + } |
|
| 755 | + if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
| 756 | + $aColumn['caption'] = $aColumn['caption']; |
|
| 757 | + } elseif ($getSort) { |
|
| 758 | + $aColumn['caption'] = '<a href="' |
|
| 759 | + . $current_url |
|
| 760 | + . '?' |
|
| 761 | + . $this->_objectHandler->_itemname |
|
| 762 | + . '_' |
|
| 763 | + . 'sortsel=' |
|
| 764 | + . $column->getKeyName() |
|
| 765 | + . '&' |
|
| 766 | + . $this->_objectHandler->_itemname |
|
| 767 | + . '_' |
|
| 768 | + . 'ordersel=' |
|
| 769 | + . $orderArray[$order]['neworder'] |
|
| 770 | + . $qs_param |
|
| 771 | + . '&' |
|
| 772 | + . $new_query_string |
|
| 773 | + . '">' |
|
| 774 | + . $aColumn['caption'] |
|
| 775 | + . ' <img src="' |
|
| 776 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 777 | + . $orderArray[$order]['image'] |
|
| 778 | + . '" alt="ASC"></a>'; |
|
| 779 | + } else { |
|
| 780 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 781 | + } |
|
| 782 | + $aColumns[] = $aColumn; |
|
| 783 | + } |
|
| 784 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 785 | + |
|
| 786 | + if ($this->_quickSearch) { |
|
| 787 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + $this->createTableRows(); |
|
| 791 | + |
|
| 792 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 793 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 794 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 795 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 796 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 797 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 798 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 799 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 800 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 801 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 802 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 803 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 804 | + if (!empty($this->_withSelectedActions)) { |
|
| 805 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 809 | + if ($fetchOnly) { |
|
| 810 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 811 | + } else { |
|
| 812 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + public function disableColumnsSorting() |
|
| 817 | + { |
|
| 818 | + $this->_enableColumnsSorting = false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * @param bool $debug |
|
| 823 | + * @return mixed|string|void |
|
| 824 | + */ |
|
| 825 | + public function fetch($debug = false) |
|
| 826 | + { |
|
| 827 | + return $this->render(true, $debug); |
|
| 828 | + } |
|
| 829 | 829 | } |