@@ -30,123 +30,123 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartobjectRating extends Smartobject\BaseSmartObject |
| 32 | 32 | { |
| 33 | - public $_modulePlugin = false; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * SmartobjectRating constructor. |
|
| 37 | - */ |
|
| 38 | - public function __construct() |
|
| 39 | - { |
|
| 40 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
| 41 | - $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
| 42 | - $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
| 43 | - $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
| 44 | - $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
| 45 | - $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
| 46 | - $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
| 47 | - |
|
| 48 | - $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
| 49 | - |
|
| 50 | - $this->setControl('dirname', [ |
|
| 51 | - 'handler' => 'rating', |
|
| 52 | - 'method' => 'getModuleList', |
|
| 53 | - 'onSelect' => 'submit' |
|
| 54 | - ]); |
|
| 55 | - |
|
| 56 | - $this->setControl('item', [ |
|
| 57 | - 'object' => &$this, |
|
| 58 | - 'method' => 'getItemList' |
|
| 59 | - ]); |
|
| 60 | - |
|
| 61 | - $this->setControl('uid', 'user'); |
|
| 62 | - |
|
| 63 | - $this->setControl('rate', [ |
|
| 64 | - 'handler' => 'rating', |
|
| 65 | - 'method' => 'getRateList' |
|
| 66 | - ]); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param string $key |
|
| 71 | - * @param string $format |
|
| 72 | - * @return mixed |
|
| 73 | - */ |
|
| 74 | - public function getVar($key, $format = 's') |
|
| 75 | - { |
|
| 76 | - if ('s' === $format && in_array($key, ['name', 'dirname'])) { |
|
| 77 | - // return call_user_func(array($this, $key)); |
|
| 78 | - return $this->{$key}(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return parent::getVar($key, $format); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function name() |
|
| 88 | - { |
|
| 89 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
| 90 | - |
|
| 91 | - return $ret; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return mixed |
|
| 96 | - */ |
|
| 97 | - public function dirname() |
|
| 98 | - { |
|
| 99 | - global $smartobjectRatingHandler; |
|
| 100 | - $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
| 101 | - |
|
| 102 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return mixed |
|
| 107 | - */ |
|
| 108 | - public function getItemList() |
|
| 109 | - { |
|
| 110 | - $plugin = $this->getModulePlugin(); |
|
| 111 | - |
|
| 112 | - return $plugin->getItemList(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - public function getItemValue() |
|
| 119 | - { |
|
| 120 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
| 121 | - $plugin = $this->getModulePlugin(); |
|
| 122 | - $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
| 123 | - if (!$pluginItemInfo) { |
|
| 124 | - return ''; |
|
| 125 | - } |
|
| 126 | - $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
| 127 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
| 128 | - |
|
| 129 | - return $ret; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return mixed |
|
| 134 | - */ |
|
| 135 | - public function getRateValue() |
|
| 136 | - { |
|
| 137 | - return $this->getVar('rate'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return bool |
|
| 142 | - */ |
|
| 143 | - public function getModulePlugin() |
|
| 144 | - { |
|
| 145 | - if (!$this->_modulePlugin) { |
|
| 146 | - global $smartobjectRatingHandler; |
|
| 147 | - $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $this->_modulePlugin; |
|
| 151 | - } |
|
| 33 | + public $_modulePlugin = false; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * SmartobjectRating constructor. |
|
| 37 | + */ |
|
| 38 | + public function __construct() |
|
| 39 | + { |
|
| 40 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
| 41 | + $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
| 42 | + $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
| 43 | + $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
| 44 | + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
| 45 | + $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
| 46 | + $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
| 47 | + |
|
| 48 | + $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
| 49 | + |
|
| 50 | + $this->setControl('dirname', [ |
|
| 51 | + 'handler' => 'rating', |
|
| 52 | + 'method' => 'getModuleList', |
|
| 53 | + 'onSelect' => 'submit' |
|
| 54 | + ]); |
|
| 55 | + |
|
| 56 | + $this->setControl('item', [ |
|
| 57 | + 'object' => &$this, |
|
| 58 | + 'method' => 'getItemList' |
|
| 59 | + ]); |
|
| 60 | + |
|
| 61 | + $this->setControl('uid', 'user'); |
|
| 62 | + |
|
| 63 | + $this->setControl('rate', [ |
|
| 64 | + 'handler' => 'rating', |
|
| 65 | + 'method' => 'getRateList' |
|
| 66 | + ]); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param string $key |
|
| 71 | + * @param string $format |
|
| 72 | + * @return mixed |
|
| 73 | + */ |
|
| 74 | + public function getVar($key, $format = 's') |
|
| 75 | + { |
|
| 76 | + if ('s' === $format && in_array($key, ['name', 'dirname'])) { |
|
| 77 | + // return call_user_func(array($this, $key)); |
|
| 78 | + return $this->{$key}(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return parent::getVar($key, $format); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function name() |
|
| 88 | + { |
|
| 89 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
| 90 | + |
|
| 91 | + return $ret; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return mixed |
|
| 96 | + */ |
|
| 97 | + public function dirname() |
|
| 98 | + { |
|
| 99 | + global $smartobjectRatingHandler; |
|
| 100 | + $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
| 101 | + |
|
| 102 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return mixed |
|
| 107 | + */ |
|
| 108 | + public function getItemList() |
|
| 109 | + { |
|
| 110 | + $plugin = $this->getModulePlugin(); |
|
| 111 | + |
|
| 112 | + return $plugin->getItemList(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + public function getItemValue() |
|
| 119 | + { |
|
| 120 | + $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
| 121 | + $plugin = $this->getModulePlugin(); |
|
| 122 | + $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
| 123 | + if (!$pluginItemInfo) { |
|
| 124 | + return ''; |
|
| 125 | + } |
|
| 126 | + $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
| 127 | + $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
| 128 | + |
|
| 129 | + return $ret; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return mixed |
|
| 134 | + */ |
|
| 135 | + public function getRateValue() |
|
| 136 | + { |
|
| 137 | + return $this->getVar('rate'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return bool |
|
| 142 | + */ |
|
| 143 | + public function getModulePlugin() |
|
| 144 | + { |
|
| 145 | + if (!$this->_modulePlugin) { |
|
| 146 | + global $smartobjectRatingHandler; |
|
| 147 | + $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $this->_modulePlugin; |
|
| 151 | + } |
|
| 152 | 152 | } |
@@ -117,14 +117,14 @@ |
||
| 117 | 117 | */ |
| 118 | 118 | public function getItemValue() |
| 119 | 119 | { |
| 120 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
| 120 | + $moduleUrl = XOOPS_URL.'/modules/'.$this->getVar('dirname', 'n').'/'; |
|
| 121 | 121 | $plugin = $this->getModulePlugin(); |
| 122 | 122 | $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
| 123 | 123 | if (!$pluginItemInfo) { |
| 124 | 124 | return ''; |
| 125 | 125 | } |
| 126 | 126 | $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
| 127 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
| 127 | + $ret = '<a href="'.$moduleUrl.$itemPath.'">'.$pluginItemInfo['caption'].'</a>'; |
|
| 128 | 128 | |
| 129 | 129 | return $ret; |
| 130 | 130 | } |
@@ -30,17 +30,17 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartObjectTree extends \XoopsObjectTree |
| 32 | 32 | { |
| 33 | - public function _initialize() |
|
| 34 | - { |
|
| 35 | - foreach (array_keys($this->_objects) as $i) { |
|
| 36 | - $key1 = $this->_objects[$i]->getVar($this->_myId); |
|
| 37 | - $this->tree[$key1]['obj'] = $this->_objects[$i]; |
|
| 38 | - $key2 = $this->_objects[$i]->getVar($this->_parentId, 'e'); |
|
| 39 | - $this->tree[$key1]['parent'] = $key2; |
|
| 40 | - $this->tree[$key2]['child'][] = $key1; |
|
| 41 | - if (isset($this->_rootId)) { |
|
| 42 | - $this->tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - } |
|
| 33 | + public function _initialize() |
|
| 34 | + { |
|
| 35 | + foreach (array_keys($this->_objects) as $i) { |
|
| 36 | + $key1 = $this->_objects[$i]->getVar($this->_myId); |
|
| 37 | + $this->tree[$key1]['obj'] = $this->_objects[$i]; |
|
| 38 | + $key2 = $this->_objects[$i]->getVar($this->_parentId, 'e'); |
|
| 39 | + $this->tree[$key1]['parent'] = $key2; |
|
| 40 | + $this->tree[$key2]['child'][] = $key1; |
|
| 41 | + if (isset($this->_rootId)) { |
|
| 42 | + $this->tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | |
| 24 | 24 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 25 | 25 | |
| 26 | -require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
|
| 26 | +require_once XOOPS_ROOT_PATH.'/class/tree.php'; |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Class smartobjecttree |
@@ -21,60 +21,60 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SmartPersistableMlObjectHandler extends Smartobject\SmartPersistableObjectHandler |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @param null|\CriteriaElement $criteria |
|
| 26 | - * @param bool $id_as_key |
|
| 27 | - * @param bool $as_object |
|
| 28 | - * @param bool $debug |
|
| 29 | - * @param bool $language |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function getObjects( |
|
| 33 | - \CriteriaElement $criteria = null, |
|
| 34 | - $id_as_key = false, |
|
| 35 | - $as_object = true, |
|
| 36 | - $debug = false, |
|
| 37 | - $language = false |
|
| 38 | - ) { |
|
| 39 | - // Create the first part of the SQL query to join the "_text" table |
|
| 40 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
| 24 | + /** |
|
| 25 | + * @param null|\CriteriaElement $criteria |
|
| 26 | + * @param bool $id_as_key |
|
| 27 | + * @param bool $as_object |
|
| 28 | + * @param bool $debug |
|
| 29 | + * @param bool $language |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function getObjects( |
|
| 33 | + \CriteriaElement $criteria = null, |
|
| 34 | + $id_as_key = false, |
|
| 35 | + $as_object = true, |
|
| 36 | + $debug = false, |
|
| 37 | + $language = false |
|
| 38 | + ) { |
|
| 39 | + // Create the first part of the SQL query to join the "_text" table |
|
| 40 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
| 41 | 41 | |
| 42 | - if ($language) { |
|
| 43 | - // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
| 42 | + if ($language) { |
|
| 43 | + // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
| 44 | 44 | |
| 45 | - // if no criteria was previously created, let's create it |
|
| 46 | - if (!$criteria) { |
|
| 47 | - $criteria = new \CriteriaCompo(); |
|
| 48 | - } |
|
| 49 | - $criteria->add(new \Criteria('language', $language)); |
|
| 45 | + // if no criteria was previously created, let's create it |
|
| 46 | + if (!$criteria) { |
|
| 47 | + $criteria = new \CriteriaCompo(); |
|
| 48 | + } |
|
| 49 | + $criteria->add(new \Criteria('language', $language)); |
|
| 50 | 50 | |
| 51 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
| 52 | - } |
|
| 51 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
| 55 | - } |
|
| 54 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param mixed $id |
|
| 59 | - * @param bool $language |
|
| 60 | - * @param bool $as_object |
|
| 61 | - * @param bool $debug |
|
| 62 | - * @return mixed |
|
| 63 | - */ |
|
| 64 | - public function &get($id, $language = false, $as_object = true, $debug = false) |
|
| 65 | - { |
|
| 66 | - if (!$language) { |
|
| 67 | - return parent::get($id, $as_object, $debug); |
|
| 68 | - } else { |
|
| 69 | - $criteria = new \CriteriaCompo(); |
|
| 70 | - $criteria->add(new \Criteria('language', $language)); |
|
| 57 | + /** |
|
| 58 | + * @param mixed $id |
|
| 59 | + * @param bool $language |
|
| 60 | + * @param bool $as_object |
|
| 61 | + * @param bool $debug |
|
| 62 | + * @return mixed |
|
| 63 | + */ |
|
| 64 | + public function &get($id, $language = false, $as_object = true, $debug = false) |
|
| 65 | + { |
|
| 66 | + if (!$language) { |
|
| 67 | + return parent::get($id, $as_object, $debug); |
|
| 68 | + } else { |
|
| 69 | + $criteria = new \CriteriaCompo(); |
|
| 70 | + $criteria->add(new \Criteria('language', $language)); |
|
| 71 | 71 | |
| 72 | - return parent::get($id, $as_object, $debug, $criteria); |
|
| 73 | - } |
|
| 74 | - } |
|
| 72 | + return parent::get($id, $as_object, $debug, $criteria); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - public function changeTableNameForML() |
|
| 77 | - { |
|
| 78 | - $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
| 79 | - } |
|
| 76 | + public function changeTableNameForML() |
|
| 77 | + { |
|
| 78 | + $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $language = false |
| 38 | 38 | ) { |
| 39 | 39 | // Create the first part of the SQL query to join the "_text" table |
| 40 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
| 40 | + $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname.' INNER JOIN '.$this->table.'_text AS '.$this->_itemname.'_text ON '.$this->_itemname.'.'.$this->keyName.'='.$this->_itemname.'_text.'.$this->keyName; |
|
| 41 | 41 | |
| 42 | 42 | if ($language) { |
| 43 | 43 | // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
@@ -75,6 +75,6 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function changeTableNameForML() |
| 77 | 77 | { |
| 78 | - $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
| 78 | + $this->table = $this->db->prefix($this->_moduleName.'_'.$this->_itemname.'_text'); |
|
| 79 | 79 | } |
| 80 | 80 | } |
@@ -25,157 +25,157 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SmartObjectTreeTable extends Smartobject\BaseSmartObjectTable |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * SmartObjectTreeTable constructor. |
|
| 30 | - * @param SmartPersistableObjectHandler $objectHandler |
|
| 31 | - * @param bool $criteria |
|
| 32 | - * @param array $actions |
|
| 33 | - * @param bool $userSide |
|
| 34 | - */ |
|
| 35 | - public function __construct( |
|
| 36 | - SmartPersistableObjectHandler $objectHandler, |
|
| 37 | - $criteria = false, |
|
| 38 | - $actions = ['edit', 'delete'], |
|
| 39 | - $userSide = false |
|
| 40 | - ) { |
|
| 41 | - $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
| 42 | - $this->_isTree = true; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Get children objects given a specific parentid |
|
| 47 | - * |
|
| 48 | - * @var int $parentid id of the parent which children we want to retreive |
|
| 49 | - * @return array of SmartObject |
|
| 50 | - */ |
|
| 51 | - public function getChildrenOf($parentid = 0) |
|
| 52 | - { |
|
| 53 | - return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param $object |
|
| 58 | - * @param int $level |
|
| 59 | - */ |
|
| 60 | - public function createTableRow($object, $level = 0) |
|
| 61 | - { |
|
| 62 | - $aObject = []; |
|
| 63 | - |
|
| 64 | - $i = 0; |
|
| 65 | - |
|
| 66 | - $aColumns = []; |
|
| 67 | - $doWeHaveActions = false; |
|
| 68 | - |
|
| 69 | - foreach ($this->_columns as $column) { |
|
| 70 | - $aColumn = []; |
|
| 71 | - |
|
| 72 | - if (0 == $i) { |
|
| 73 | - $class = 'head'; |
|
| 74 | - } elseif (0 == $i % 2) { |
|
| 75 | - $class = 'even'; |
|
| 76 | - } else { |
|
| 77 | - $class = 'odd'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
| 81 | - $method = $column->_customMethodForValue; |
|
| 82 | - $value = $object->$method(); |
|
| 83 | - } else { |
|
| 84 | - /** |
|
| 85 | - * If the column is the identifier, then put a link on it |
|
| 86 | - */ |
|
| 87 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 88 | - $value = $object->getItemLink(); |
|
| 89 | - } else { |
|
| 90 | - $value = $object->getVar($column->getKeyName()); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $space = ''; |
|
| 95 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 96 | - for ($i = 0; $i < $level; ++$i) { |
|
| 97 | - $space .= '--'; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ('' !== $space) { |
|
| 102 | - $space .= ' '; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $aColumn['value'] = $space . $value; |
|
| 106 | - $aColumn['class'] = $class; |
|
| 107 | - $aColumn['width'] = $column->getWidth(); |
|
| 108 | - $aColumn['align'] = $column->getAlign(); |
|
| 109 | - $aColumn['key'] = $column->getKeyName(); |
|
| 110 | - |
|
| 111 | - $aColumns[] = $aColumn; |
|
| 112 | - ++$i; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $aObject['columns'] = $aColumns; |
|
| 116 | - |
|
| 117 | - $class = 'even' === $class ? 'odd' : 'even'; |
|
| 118 | - $aObject['class'] = $class; |
|
| 119 | - |
|
| 120 | - $actions = []; |
|
| 121 | - |
|
| 122 | - // Adding the custom actions if any |
|
| 123 | - foreach ($this->_custom_actions as $action) { |
|
| 124 | - if (method_exists($object, $action)) { |
|
| 125 | - $actions[] = $object->$action(); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 130 | - $controller = new SmartObjectController($this->_objectHandler); |
|
| 131 | - |
|
| 132 | - if (in_array('edit', $this->_actions)) { |
|
| 133 | - $actions[] = $controller->getEditItemLink($object, false, true); |
|
| 134 | - } |
|
| 135 | - if (in_array('delete', $this->_actions)) { |
|
| 136 | - $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
| 137 | - } |
|
| 138 | - $aObject['actions'] = $actions; |
|
| 139 | - |
|
| 140 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 141 | - $aObject['id'] = $object->id(); |
|
| 142 | - $this->_aObjects[] = $aObject; |
|
| 143 | - |
|
| 144 | - $childrenObjects = $this->getChildrenOf($object->id()); |
|
| 145 | - |
|
| 146 | - $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
| 147 | - |
|
| 148 | - if ($childrenObjects) { |
|
| 149 | - ++$level; |
|
| 150 | - foreach ($childrenObjects as $subObject) { |
|
| 151 | - $this->createTableRow($subObject, $level); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function createTableRows() |
|
| 157 | - { |
|
| 158 | - $this->_aObjects = []; |
|
| 159 | - |
|
| 160 | - if (count($this->_objects) > 0) { |
|
| 161 | - foreach ($this->getChildrenOf() as $object) { |
|
| 162 | - $this->createTableRow($object); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 166 | - } else { |
|
| 167 | - $colspan = count($this->_columns) + 1; |
|
| 168 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @return mixed |
|
| 174 | - */ |
|
| 175 | - public function fetchObjects() |
|
| 176 | - { |
|
| 177 | - $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
| 178 | - |
|
| 179 | - return $ret; |
|
| 180 | - } |
|
| 28 | + /** |
|
| 29 | + * SmartObjectTreeTable constructor. |
|
| 30 | + * @param SmartPersistableObjectHandler $objectHandler |
|
| 31 | + * @param bool $criteria |
|
| 32 | + * @param array $actions |
|
| 33 | + * @param bool $userSide |
|
| 34 | + */ |
|
| 35 | + public function __construct( |
|
| 36 | + SmartPersistableObjectHandler $objectHandler, |
|
| 37 | + $criteria = false, |
|
| 38 | + $actions = ['edit', 'delete'], |
|
| 39 | + $userSide = false |
|
| 40 | + ) { |
|
| 41 | + $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
| 42 | + $this->_isTree = true; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Get children objects given a specific parentid |
|
| 47 | + * |
|
| 48 | + * @var int $parentid id of the parent which children we want to retreive |
|
| 49 | + * @return array of SmartObject |
|
| 50 | + */ |
|
| 51 | + public function getChildrenOf($parentid = 0) |
|
| 52 | + { |
|
| 53 | + return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param $object |
|
| 58 | + * @param int $level |
|
| 59 | + */ |
|
| 60 | + public function createTableRow($object, $level = 0) |
|
| 61 | + { |
|
| 62 | + $aObject = []; |
|
| 63 | + |
|
| 64 | + $i = 0; |
|
| 65 | + |
|
| 66 | + $aColumns = []; |
|
| 67 | + $doWeHaveActions = false; |
|
| 68 | + |
|
| 69 | + foreach ($this->_columns as $column) { |
|
| 70 | + $aColumn = []; |
|
| 71 | + |
|
| 72 | + if (0 == $i) { |
|
| 73 | + $class = 'head'; |
|
| 74 | + } elseif (0 == $i % 2) { |
|
| 75 | + $class = 'even'; |
|
| 76 | + } else { |
|
| 77 | + $class = 'odd'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
| 81 | + $method = $column->_customMethodForValue; |
|
| 82 | + $value = $object->$method(); |
|
| 83 | + } else { |
|
| 84 | + /** |
|
| 85 | + * If the column is the identifier, then put a link on it |
|
| 86 | + */ |
|
| 87 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 88 | + $value = $object->getItemLink(); |
|
| 89 | + } else { |
|
| 90 | + $value = $object->getVar($column->getKeyName()); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $space = ''; |
|
| 95 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 96 | + for ($i = 0; $i < $level; ++$i) { |
|
| 97 | + $space .= '--'; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ('' !== $space) { |
|
| 102 | + $space .= ' '; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $aColumn['value'] = $space . $value; |
|
| 106 | + $aColumn['class'] = $class; |
|
| 107 | + $aColumn['width'] = $column->getWidth(); |
|
| 108 | + $aColumn['align'] = $column->getAlign(); |
|
| 109 | + $aColumn['key'] = $column->getKeyName(); |
|
| 110 | + |
|
| 111 | + $aColumns[] = $aColumn; |
|
| 112 | + ++$i; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $aObject['columns'] = $aColumns; |
|
| 116 | + |
|
| 117 | + $class = 'even' === $class ? 'odd' : 'even'; |
|
| 118 | + $aObject['class'] = $class; |
|
| 119 | + |
|
| 120 | + $actions = []; |
|
| 121 | + |
|
| 122 | + // Adding the custom actions if any |
|
| 123 | + foreach ($this->_custom_actions as $action) { |
|
| 124 | + if (method_exists($object, $action)) { |
|
| 125 | + $actions[] = $object->$action(); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 130 | + $controller = new SmartObjectController($this->_objectHandler); |
|
| 131 | + |
|
| 132 | + if (in_array('edit', $this->_actions)) { |
|
| 133 | + $actions[] = $controller->getEditItemLink($object, false, true); |
|
| 134 | + } |
|
| 135 | + if (in_array('delete', $this->_actions)) { |
|
| 136 | + $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
| 137 | + } |
|
| 138 | + $aObject['actions'] = $actions; |
|
| 139 | + |
|
| 140 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 141 | + $aObject['id'] = $object->id(); |
|
| 142 | + $this->_aObjects[] = $aObject; |
|
| 143 | + |
|
| 144 | + $childrenObjects = $this->getChildrenOf($object->id()); |
|
| 145 | + |
|
| 146 | + $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
| 147 | + |
|
| 148 | + if ($childrenObjects) { |
|
| 149 | + ++$level; |
|
| 150 | + foreach ($childrenObjects as $subObject) { |
|
| 151 | + $this->createTableRow($subObject, $level); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function createTableRows() |
|
| 157 | + { |
|
| 158 | + $this->_aObjects = []; |
|
| 159 | + |
|
| 160 | + if (count($this->_objects) > 0) { |
|
| 161 | + foreach ($this->getChildrenOf() as $object) { |
|
| 162 | + $this->createTableRow($object); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 166 | + } else { |
|
| 167 | + $colspan = count($this->_columns) + 1; |
|
| 168 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @return mixed |
|
| 174 | + */ |
|
| 175 | + public function fetchObjects() |
|
| 176 | + { |
|
| 177 | + $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
| 178 | + |
|
| 179 | + return $ret; |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | use XoopsModules\Smartobject; |
| 14 | 14 | |
| 15 | -require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php'; |
|
| 15 | +require_once SMARTOBJECT_ROOT_PATH.'class/smartobjecttable.php'; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * SmartObjectTreeTable class |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $space .= ' '; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $aColumn['value'] = $space . $value; |
|
| 105 | + $aColumn['value'] = $space.$value; |
|
| 106 | 106 | $aColumn['class'] = $class; |
| 107 | 107 | $aColumn['width'] = $column->getWidth(); |
| 108 | 108 | $aColumn['align'] = $column->getAlign(); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 129 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
| 130 | 130 | $controller = new SmartObjectController($this->_objectHandler); |
| 131 | 131 | |
| 132 | 132 | if (in_array('edit', $this->_actions)) { |
@@ -25,66 +25,66 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SmartPlugin |
| 27 | 27 | { |
| 28 | - public $_infoArray; |
|
| 28 | + public $_infoArray; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * SmartPlugin constructor. |
|
| 32 | - * @param $array |
|
| 33 | - */ |
|
| 34 | - public function __construct($array) |
|
| 35 | - { |
|
| 36 | - $this->_infoArray = $array; |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * SmartPlugin constructor. |
|
| 32 | + * @param $array |
|
| 33 | + */ |
|
| 34 | + public function __construct($array) |
|
| 35 | + { |
|
| 36 | + $this->_infoArray = $array; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param $item |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function getItemInfo($item) |
|
| 44 | - { |
|
| 45 | - if (isset($this->_infoArray['items'][$item])) { |
|
| 46 | - return $this->_infoArray['items'][$item]; |
|
| 47 | - } else { |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * @param $item |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function getItemInfo($item) |
|
| 44 | + { |
|
| 45 | + if (isset($this->_infoArray['items'][$item])) { |
|
| 46 | + return $this->_infoArray['items'][$item]; |
|
| 47 | + } else { |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return mixed |
|
| 54 | - */ |
|
| 55 | - public function getItemList() |
|
| 56 | - { |
|
| 57 | - $itemsArray = $this->_infoArray['items']; |
|
| 58 | - foreach ($itemsArray as $k => $v) { |
|
| 59 | - $ret[$k] = $v['caption']; |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * @return mixed |
|
| 54 | + */ |
|
| 55 | + public function getItemList() |
|
| 56 | + { |
|
| 57 | + $itemsArray = $this->_infoArray['items']; |
|
| 58 | + foreach ($itemsArray as $k => $v) { |
|
| 59 | + $ret[$k] = $v['caption']; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return $ret; |
|
| 63 | - } |
|
| 62 | + return $ret; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return bool|int|string |
|
| 67 | - */ |
|
| 68 | - public function getItem() |
|
| 69 | - { |
|
| 70 | - $ret = false; |
|
| 71 | - foreach ($this->_infoArray['items'] as $k => $v) { |
|
| 72 | - $search_str = str_replace('%u', '', $v['url']); |
|
| 73 | - if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) { |
|
| 74 | - $ret = $k; |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - } |
|
| 65 | + /** |
|
| 66 | + * @return bool|int|string |
|
| 67 | + */ |
|
| 68 | + public function getItem() |
|
| 69 | + { |
|
| 70 | + $ret = false; |
|
| 71 | + foreach ($this->_infoArray['items'] as $k => $v) { |
|
| 72 | + $search_str = str_replace('%u', '', $v['url']); |
|
| 73 | + if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) { |
|
| 74 | + $ret = $k; |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return $ret; |
|
| 80 | - } |
|
| 79 | + return $ret; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @param $item |
|
| 84 | - * @return mixed |
|
| 85 | - */ |
|
| 86 | - public function getItemIdForItem($item) |
|
| 87 | - { |
|
| 88 | - return $_REQUEST[$this->_infoArray['items'][$item]['request']]; |
|
| 89 | - } |
|
| 82 | + /** |
|
| 83 | + * @param $item |
|
| 84 | + * @return mixed |
|
| 85 | + */ |
|
| 86 | + public function getItemIdForItem($item) |
|
| 87 | + { |
|
| 88 | + return $_REQUEST[$this->_infoArray['items'][$item]['request']]; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | $ret = false; |
| 71 | 71 | foreach ($this->_infoArray['items'] as $k => $v) { |
| 72 | 72 | $search_str = str_replace('%u', '', $v['url']); |
| 73 | - if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) { |
|
| 73 | + if (strpos($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], $search_str) > 0) { |
|
| 74 | 74 | $ret = $k; |
| 75 | 75 | break; |
| 76 | 76 | } |
@@ -20,121 +20,121 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class SmartobjectCategory extends Smartobject\SmartSeoObject |
| 22 | 22 | { |
| 23 | - public $_categoryPath; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * SmartobjectCategory constructor. |
|
| 27 | - */ |
|
| 28 | - public function __construct() |
|
| 29 | - { |
|
| 30 | - $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
| 31 | - $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
| 32 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
| 33 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
| 34 | - $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
| 35 | - |
|
| 36 | - $this->initCommonVar('doxcode'); |
|
| 37 | - |
|
| 38 | - $this->setControl('image', ['name' => 'image']); |
|
| 39 | - $this->setControl('parentid', ['name' => 'parentcategory']); |
|
| 40 | - $this->setControl('description', [ |
|
| 41 | - 'name' => 'textarea', |
|
| 42 | - 'itemHandler' => false, |
|
| 43 | - 'method' => false, |
|
| 44 | - 'module' => false, |
|
| 45 | - 'form_editor' => 'default' |
|
| 46 | - ]); |
|
| 47 | - |
|
| 48 | - // call parent constructor to get SEO fields initiated |
|
| 49 | - parent::__construct(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * returns a specific variable for the object in a proper format |
|
| 54 | - * |
|
| 55 | - * @access public |
|
| 56 | - * @param string $key key of the object's variable to be returned |
|
| 57 | - * @param string $format format to use for the output |
|
| 58 | - * @return mixed formatted value of the variable |
|
| 59 | - */ |
|
| 60 | - public function getVar($key, $format = 's') |
|
| 61 | - { |
|
| 62 | - if ('s' === $format && in_array($key, ['description', 'image'])) { |
|
| 63 | - // return call_user_func(array($this, $key)); |
|
| 64 | - return $this->{$key}(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return parent::getVar($key, $format); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function description() |
|
| 74 | - { |
|
| 75 | - return $this->getValueFor('description', false); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return bool|mixed |
|
| 80 | - */ |
|
| 81 | - public function image() |
|
| 82 | - { |
|
| 83 | - $ret = $this->getVar('image', 'e'); |
|
| 84 | - if ('-1' == $ret) { |
|
| 85 | - return false; |
|
| 86 | - } else { |
|
| 87 | - return $ret; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - public function toArray() |
|
| 95 | - { |
|
| 96 | - $this->setVar('doxcode', true); |
|
| 97 | - global $myts; |
|
| 98 | - $objectArray = parent::toArray(); |
|
| 99 | - if ($objectArray['image']) { |
|
| 100 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return $objectArray; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Create the complete path of a category |
|
| 108 | - * |
|
| 109 | - * @todo this could be improved as it uses multiple queries |
|
| 110 | - * @param bool $withAllLink make all name clickable |
|
| 111 | - * @param bool $currentCategory |
|
| 112 | - * @return string complete path (breadcrumb) |
|
| 113 | - */ |
|
| 114 | - public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
| 115 | - { |
|
| 116 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 117 | - $controller = new SmartObjectController($this->handler); |
|
| 118 | - |
|
| 119 | - if (!$this->_categoryPath) { |
|
| 120 | - if ($withAllLink && !$currentCategory) { |
|
| 121 | - $ret = $controller->getItemLink($this); |
|
| 122 | - } else { |
|
| 123 | - $currentCategory = false; |
|
| 124 | - $ret = $this->getVar('name'); |
|
| 125 | - } |
|
| 126 | - $parentid = $this->getVar('parentid'); |
|
| 127 | - if (0 != $parentid) { |
|
| 128 | - $parentObj = $this->handler->get($parentid); |
|
| 129 | - if ($parentObj->isNew()) { |
|
| 130 | - exit; |
|
| 131 | - } |
|
| 132 | - $parentid = $parentObj->getVar('parentid'); |
|
| 133 | - $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
| 134 | - } |
|
| 135 | - $this->_categoryPath = $ret; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $this->_categoryPath; |
|
| 139 | - } |
|
| 23 | + public $_categoryPath; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * SmartobjectCategory constructor. |
|
| 27 | + */ |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
| 31 | + $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
| 32 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
| 33 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
| 34 | + $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
| 35 | + |
|
| 36 | + $this->initCommonVar('doxcode'); |
|
| 37 | + |
|
| 38 | + $this->setControl('image', ['name' => 'image']); |
|
| 39 | + $this->setControl('parentid', ['name' => 'parentcategory']); |
|
| 40 | + $this->setControl('description', [ |
|
| 41 | + 'name' => 'textarea', |
|
| 42 | + 'itemHandler' => false, |
|
| 43 | + 'method' => false, |
|
| 44 | + 'module' => false, |
|
| 45 | + 'form_editor' => 'default' |
|
| 46 | + ]); |
|
| 47 | + |
|
| 48 | + // call parent constructor to get SEO fields initiated |
|
| 49 | + parent::__construct(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * returns a specific variable for the object in a proper format |
|
| 54 | + * |
|
| 55 | + * @access public |
|
| 56 | + * @param string $key key of the object's variable to be returned |
|
| 57 | + * @param string $format format to use for the output |
|
| 58 | + * @return mixed formatted value of the variable |
|
| 59 | + */ |
|
| 60 | + public function getVar($key, $format = 's') |
|
| 61 | + { |
|
| 62 | + if ('s' === $format && in_array($key, ['description', 'image'])) { |
|
| 63 | + // return call_user_func(array($this, $key)); |
|
| 64 | + return $this->{$key}(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return parent::getVar($key, $format); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function description() |
|
| 74 | + { |
|
| 75 | + return $this->getValueFor('description', false); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return bool|mixed |
|
| 80 | + */ |
|
| 81 | + public function image() |
|
| 82 | + { |
|
| 83 | + $ret = $this->getVar('image', 'e'); |
|
| 84 | + if ('-1' == $ret) { |
|
| 85 | + return false; |
|
| 86 | + } else { |
|
| 87 | + return $ret; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + public function toArray() |
|
| 95 | + { |
|
| 96 | + $this->setVar('doxcode', true); |
|
| 97 | + global $myts; |
|
| 98 | + $objectArray = parent::toArray(); |
|
| 99 | + if ($objectArray['image']) { |
|
| 100 | + $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return $objectArray; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Create the complete path of a category |
|
| 108 | + * |
|
| 109 | + * @todo this could be improved as it uses multiple queries |
|
| 110 | + * @param bool $withAllLink make all name clickable |
|
| 111 | + * @param bool $currentCategory |
|
| 112 | + * @return string complete path (breadcrumb) |
|
| 113 | + */ |
|
| 114 | + public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
| 115 | + { |
|
| 116 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 117 | + $controller = new SmartObjectController($this->handler); |
|
| 118 | + |
|
| 119 | + if (!$this->_categoryPath) { |
|
| 120 | + if ($withAllLink && !$currentCategory) { |
|
| 121 | + $ret = $controller->getItemLink($this); |
|
| 122 | + } else { |
|
| 123 | + $currentCategory = false; |
|
| 124 | + $ret = $this->getVar('name'); |
|
| 125 | + } |
|
| 126 | + $parentid = $this->getVar('parentid'); |
|
| 127 | + if (0 != $parentid) { |
|
| 128 | + $parentObj = $this->handler->get($parentid); |
|
| 129 | + if ($parentObj->isNew()) { |
|
| 130 | + exit; |
|
| 131 | + } |
|
| 132 | + $parentid = $parentObj->getVar('parentid'); |
|
| 133 | + $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
| 134 | + } |
|
| 135 | + $this->_categoryPath = $ret; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $this->_categoryPath; |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | global $myts; |
| 98 | 98 | $objectArray = parent::toArray(); |
| 99 | 99 | if ($objectArray['image']) { |
| 100 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
| 100 | + $objectArray['image'] = $this->getImageDir().$objectArray['image']; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | return $objectArray; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getCategoryPath($withAllLink = true, $currentCategory = false) |
| 115 | 115 | { |
| 116 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
| 116 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
| 117 | 117 | $controller = new SmartObjectController($this->handler); |
| 118 | 118 | |
| 119 | 119 | if (!$this->_categoryPath) { |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | exit; |
| 131 | 131 | } |
| 132 | 132 | $parentid = $parentObj->getVar('parentid'); |
| 133 | - $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
| 133 | + $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory).' > '.$ret; |
|
| 134 | 134 | } |
| 135 | 135 | $this->_categoryPath = $ret; |
| 136 | 136 | } |
@@ -30,116 +30,116 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartobjectAdsenseHandler extends Smartobject\SmartPersistableObjectHandler |
| 32 | 32 | { |
| 33 | - public $adFormats; |
|
| 34 | - public $adFormatsList; |
|
| 35 | - public $objects = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * SmartobjectAdsenseHandler constructor. |
|
| 39 | - * @param \XoopsDatabase $db |
|
| 40 | - */ |
|
| 41 | - public function __construct(\XoopsDatabase $db) |
|
| 42 | - { |
|
| 43 | - parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 44 | - $this->adFormats = []; |
|
| 45 | - $this->adFormatsList = []; |
|
| 46 | - |
|
| 47 | - $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 48 | - $this->adFormats['728x90_as']['width'] = 728; |
|
| 49 | - $this->adFormats['728x90_as']['height'] = 90; |
|
| 50 | - $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 51 | - |
|
| 52 | - $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 53 | - $this->adFormats['468x60_as']['width'] = 468; |
|
| 54 | - $this->adFormats['468x60_as']['height'] = 60; |
|
| 55 | - $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 56 | - |
|
| 57 | - $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 58 | - $this->adFormats['234x60_as']['width'] = 234; |
|
| 59 | - $this->adFormats['234x60_as']['height'] = 60; |
|
| 60 | - $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 61 | - |
|
| 62 | - $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 63 | - $this->adFormats['120x600_as']['width'] = 120; |
|
| 64 | - $this->adFormats['120x600_as']['height'] = 600; |
|
| 65 | - $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 66 | - |
|
| 67 | - $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 68 | - $this->adFormats['160x600_as']['width'] = 160; |
|
| 69 | - $this->adFormats['160x600_as']['height'] = 600; |
|
| 70 | - $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 71 | - |
|
| 72 | - $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 73 | - $this->adFormats['120x240_as']['width'] = 120; |
|
| 74 | - $this->adFormats['120x240_as']['height'] = 240; |
|
| 75 | - $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 76 | - |
|
| 77 | - $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 78 | - $this->adFormats['336x280_as']['width'] = 136; |
|
| 79 | - $this->adFormats['336x280_as']['height'] = 280; |
|
| 80 | - $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 81 | - |
|
| 82 | - $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 83 | - $this->adFormats['300x250_as']['width'] = 300; |
|
| 84 | - $this->adFormats['300x250_as']['height'] = 250; |
|
| 85 | - $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 86 | - |
|
| 87 | - $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 88 | - $this->adFormats['250x250_as']['width'] = 250; |
|
| 89 | - $this->adFormats['250x250_as']['height'] = 250; |
|
| 90 | - $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 91 | - |
|
| 92 | - $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 93 | - $this->adFormats['200x200_as']['width'] = 200; |
|
| 94 | - $this->adFormats['200x200_as']['height'] = 200; |
|
| 95 | - $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 96 | - |
|
| 97 | - $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 98 | - $this->adFormats['180x150_as']['width'] = 180; |
|
| 99 | - $this->adFormats['180x150_as']['height'] = 150; |
|
| 100 | - $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 101 | - |
|
| 102 | - $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 103 | - $this->adFormats['125x125_as']['width'] = 125; |
|
| 104 | - $this->adFormats['125x125_as']['height'] = 125; |
|
| 105 | - $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - public function getFormats() |
|
| 112 | - { |
|
| 113 | - return $this->adFormatsList; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param $obj |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function beforeSave($obj) |
|
| 121 | - { |
|
| 122 | - if ('' === $obj->getVar('tag')) { |
|
| 123 | - $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return true; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return array|bool |
|
| 131 | - */ |
|
| 132 | - public function getAdsensesByTag() |
|
| 133 | - { |
|
| 134 | - if (!$this->objects) { |
|
| 135 | - $adsensesObj =& $this->getObjects(null, true); |
|
| 136 | - $ret = []; |
|
| 137 | - foreach ($adsensesObj as $adsenseObj) { |
|
| 138 | - $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 139 | - } |
|
| 140 | - $this->objects = $ret; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $this->objects; |
|
| 144 | - } |
|
| 33 | + public $adFormats; |
|
| 34 | + public $adFormatsList; |
|
| 35 | + public $objects = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * SmartobjectAdsenseHandler constructor. |
|
| 39 | + * @param \XoopsDatabase $db |
|
| 40 | + */ |
|
| 41 | + public function __construct(\XoopsDatabase $db) |
|
| 42 | + { |
|
| 43 | + parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
| 44 | + $this->adFormats = []; |
|
| 45 | + $this->adFormatsList = []; |
|
| 46 | + |
|
| 47 | + $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 48 | + $this->adFormats['728x90_as']['width'] = 728; |
|
| 49 | + $this->adFormats['728x90_as']['height'] = 90; |
|
| 50 | + $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 51 | + |
|
| 52 | + $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 53 | + $this->adFormats['468x60_as']['width'] = 468; |
|
| 54 | + $this->adFormats['468x60_as']['height'] = 60; |
|
| 55 | + $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 56 | + |
|
| 57 | + $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 58 | + $this->adFormats['234x60_as']['width'] = 234; |
|
| 59 | + $this->adFormats['234x60_as']['height'] = 60; |
|
| 60 | + $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 61 | + |
|
| 62 | + $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 63 | + $this->adFormats['120x600_as']['width'] = 120; |
|
| 64 | + $this->adFormats['120x600_as']['height'] = 600; |
|
| 65 | + $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 66 | + |
|
| 67 | + $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 68 | + $this->adFormats['160x600_as']['width'] = 160; |
|
| 69 | + $this->adFormats['160x600_as']['height'] = 600; |
|
| 70 | + $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 71 | + |
|
| 72 | + $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 73 | + $this->adFormats['120x240_as']['width'] = 120; |
|
| 74 | + $this->adFormats['120x240_as']['height'] = 240; |
|
| 75 | + $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 76 | + |
|
| 77 | + $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 78 | + $this->adFormats['336x280_as']['width'] = 136; |
|
| 79 | + $this->adFormats['336x280_as']['height'] = 280; |
|
| 80 | + $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 81 | + |
|
| 82 | + $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 83 | + $this->adFormats['300x250_as']['width'] = 300; |
|
| 84 | + $this->adFormats['300x250_as']['height'] = 250; |
|
| 85 | + $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 86 | + |
|
| 87 | + $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 88 | + $this->adFormats['250x250_as']['width'] = 250; |
|
| 89 | + $this->adFormats['250x250_as']['height'] = 250; |
|
| 90 | + $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 91 | + |
|
| 92 | + $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 93 | + $this->adFormats['200x200_as']['width'] = 200; |
|
| 94 | + $this->adFormats['200x200_as']['height'] = 200; |
|
| 95 | + $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 96 | + |
|
| 97 | + $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 98 | + $this->adFormats['180x150_as']['width'] = 180; |
|
| 99 | + $this->adFormats['180x150_as']['height'] = 150; |
|
| 100 | + $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 101 | + |
|
| 102 | + $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 103 | + $this->adFormats['125x125_as']['width'] = 125; |
|
| 104 | + $this->adFormats['125x125_as']['height'] = 125; |
|
| 105 | + $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + public function getFormats() |
|
| 112 | + { |
|
| 113 | + return $this->adFormatsList; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param $obj |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function beforeSave($obj) |
|
| 121 | + { |
|
| 122 | + if ('' === $obj->getVar('tag')) { |
|
| 123 | + $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return true; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return array|bool |
|
| 131 | + */ |
|
| 132 | + public function getAdsensesByTag() |
|
| 133 | + { |
|
| 134 | + if (!$this->objects) { |
|
| 135 | + $adsensesObj =& $this->getObjects(null, true); |
|
| 136 | + $ret = []; |
|
| 137 | + foreach ($adsensesObj as $adsenseObj) { |
|
| 138 | + $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 139 | + } |
|
| 140 | + $this->objects = $ret; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $this->objects; |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | public function getAdsensesByTag() |
| 133 | 133 | { |
| 134 | 134 | if (!$this->objects) { |
| 135 | - $adsensesObj =& $this->getObjects(null, true); |
|
| 135 | + $adsensesObj = & $this->getObjects(null, true); |
|
| 136 | 136 | $ret = []; |
| 137 | 137 | foreach ($adsensesObj as $adsenseObj) { |
| 138 | 138 | $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
@@ -29,29 +29,29 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectBasedUrl extends Smartobject\BaseSmartObject |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectBasedUrl constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false); |
|
| 38 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false); |
|
| 39 | - $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false); |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * SmartobjectBasedUrl constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false); |
|
| 38 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false); |
|
| 39 | + $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $key |
|
| 44 | - * @param string $format |
|
| 45 | - * @return mixed |
|
| 46 | - */ |
|
| 47 | - public function getVar($key, $format = 'e') |
|
| 48 | - { |
|
| 49 | - if (0 === strpos($key, 'url_')) { |
|
| 50 | - return parent::getVar('url', $format); |
|
| 51 | - } elseif (0 === strpos($key, 'caption_')) { |
|
| 52 | - return parent::getVar('caption', $format); |
|
| 53 | - } else { |
|
| 54 | - return parent::getVar($key, $format); |
|
| 55 | - } |
|
| 56 | - } |
|
| 42 | + /** |
|
| 43 | + * @param string $key |
|
| 44 | + * @param string $format |
|
| 45 | + * @return mixed |
|
| 46 | + */ |
|
| 47 | + public function getVar($key, $format = 'e') |
|
| 48 | + { |
|
| 49 | + if (0 === strpos($key, 'url_')) { |
|
| 50 | + return parent::getVar('url', $format); |
|
| 51 | + } elseif (0 === strpos($key, 'caption_')) { |
|
| 52 | + return parent::getVar('caption', $format); |
|
| 53 | + } else { |
|
| 54 | + return parent::getVar($key, $format); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -41,116 +41,116 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class SmartObjectExport |
| 43 | 43 | { |
| 44 | - public $handler; |
|
| 45 | - public $criteria; |
|
| 46 | - public $fields; |
|
| 47 | - public $format; |
|
| 48 | - public $filename; |
|
| 49 | - public $filepath; |
|
| 50 | - public $options; |
|
| 51 | - public $outputMethods = false; |
|
| 52 | - public $notDisplayFields; |
|
| 44 | + public $handler; |
|
| 45 | + public $criteria; |
|
| 46 | + public $fields; |
|
| 47 | + public $format; |
|
| 48 | + public $filename; |
|
| 49 | + public $filepath; |
|
| 50 | + public $options; |
|
| 51 | + public $outputMethods = false; |
|
| 52 | + public $notDisplayFields; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Constructor |
|
| 56 | - * |
|
| 57 | - * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
| 58 | - * @param \CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
| 59 | - * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
| 60 | - * @param bool|string $filename name of the file to be created |
|
| 61 | - * @param bool|string $filepath path where the file will be saved |
|
| 62 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 63 | - * @param array|bool $options options of the format to be exported in |
|
| 64 | - */ |
|
| 65 | - public function __construct( |
|
| 66 | - SmartPersistableObjectHandler $objectHandler, |
|
| 67 | - \CriteriaElement $criteria = null, |
|
| 68 | - $fields = false, |
|
| 69 | - $filename = false, |
|
| 70 | - $filepath = false, |
|
| 71 | - $format = 'csv', |
|
| 72 | - $options = false |
|
| 73 | - ) { |
|
| 74 | - $this->handler = $objectHandler; |
|
| 75 | - $this->criteria = $criteria; |
|
| 76 | - $this->fields = $fields; |
|
| 77 | - $this->filename = $filename; |
|
| 78 | - $this->format = $format; |
|
| 79 | - $this->options = $options; |
|
| 80 | - $this->notDisplayFields = false; |
|
| 81 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor |
|
| 56 | + * |
|
| 57 | + * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
| 58 | + * @param \CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
| 59 | + * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
| 60 | + * @param bool|string $filename name of the file to be created |
|
| 61 | + * @param bool|string $filepath path where the file will be saved |
|
| 62 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 63 | + * @param array|bool $options options of the format to be exported in |
|
| 64 | + */ |
|
| 65 | + public function __construct( |
|
| 66 | + SmartPersistableObjectHandler $objectHandler, |
|
| 67 | + \CriteriaElement $criteria = null, |
|
| 68 | + $fields = false, |
|
| 69 | + $filename = false, |
|
| 70 | + $filepath = false, |
|
| 71 | + $format = 'csv', |
|
| 72 | + $options = false |
|
| 73 | + ) { |
|
| 74 | + $this->handler = $objectHandler; |
|
| 75 | + $this->criteria = $criteria; |
|
| 76 | + $this->fields = $fields; |
|
| 77 | + $this->filename = $filename; |
|
| 78 | + $this->format = $format; |
|
| 79 | + $this->options = $options; |
|
| 80 | + $this->notDisplayFields = false; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Renders the export |
|
| 85 | - * @param $filename |
|
| 86 | - */ |
|
| 87 | - public function render($filename) |
|
| 88 | - { |
|
| 89 | - $this->filename = $filename; |
|
| 83 | + /** |
|
| 84 | + * Renders the export |
|
| 85 | + * @param $filename |
|
| 86 | + */ |
|
| 87 | + public function render($filename) |
|
| 88 | + { |
|
| 89 | + $this->filename = $filename; |
|
| 90 | 90 | |
| 91 | - $objects = $this->handler->getObjects($this->criteria); |
|
| 92 | - $rows = []; |
|
| 93 | - $columnsHeaders = []; |
|
| 94 | - $firstObject = true; |
|
| 95 | - foreach ($objects as $object) { |
|
| 96 | - $row = []; |
|
| 97 | - foreach ($object->vars as $key => $var) { |
|
| 98 | - if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
| 99 | - if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
| 100 | - && method_exists($object, $this->outputMethods[$key])) { |
|
| 101 | - $method = $this->outputMethods[$key]; |
|
| 102 | - $row[$key] = $object->$method(); |
|
| 103 | - } else { |
|
| 104 | - $row[$key] = $object->getVar($key); |
|
| 105 | - } |
|
| 106 | - if ($firstObject) { |
|
| 107 | - // then set the columnsHeaders array as well |
|
| 108 | - $columnsHeaders[$key] = $var['form_caption']; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - $firstObject = false; |
|
| 113 | - $rows[] = $row; |
|
| 114 | - unset($row); |
|
| 115 | - } |
|
| 116 | - $data = []; |
|
| 117 | - $data['rows'] = $rows; |
|
| 118 | - $data['columnsHeaders'] = $columnsHeaders; |
|
| 119 | - $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
| 120 | - $smartExportRenderer->execute(); |
|
| 121 | - } |
|
| 91 | + $objects = $this->handler->getObjects($this->criteria); |
|
| 92 | + $rows = []; |
|
| 93 | + $columnsHeaders = []; |
|
| 94 | + $firstObject = true; |
|
| 95 | + foreach ($objects as $object) { |
|
| 96 | + $row = []; |
|
| 97 | + foreach ($object->vars as $key => $var) { |
|
| 98 | + if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
| 99 | + if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
| 100 | + && method_exists($object, $this->outputMethods[$key])) { |
|
| 101 | + $method = $this->outputMethods[$key]; |
|
| 102 | + $row[$key] = $object->$method(); |
|
| 103 | + } else { |
|
| 104 | + $row[$key] = $object->getVar($key); |
|
| 105 | + } |
|
| 106 | + if ($firstObject) { |
|
| 107 | + // then set the columnsHeaders array as well |
|
| 108 | + $columnsHeaders[$key] = $var['form_caption']; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + $firstObject = false; |
|
| 113 | + $rows[] = $row; |
|
| 114 | + unset($row); |
|
| 115 | + } |
|
| 116 | + $data = []; |
|
| 117 | + $data['rows'] = $rows; |
|
| 118 | + $data['columnsHeaders'] = $columnsHeaders; |
|
| 119 | + $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
| 120 | + $smartExportRenderer->execute(); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Set an array contaning the alternate methods to use instead of the default getVar() |
|
| 125 | - * |
|
| 126 | - * $outputMethods array example: 'uid' => 'getUserName'... |
|
| 127 | - * @param $outputMethods |
|
| 128 | - */ |
|
| 129 | - public function setOuptutMethods($outputMethods) |
|
| 130 | - { |
|
| 131 | - $this->outputMethods = $outputMethods; |
|
| 132 | - } |
|
| 123 | + /** |
|
| 124 | + * Set an array contaning the alternate methods to use instead of the default getVar() |
|
| 125 | + * |
|
| 126 | + * $outputMethods array example: 'uid' => 'getUserName'... |
|
| 127 | + * @param $outputMethods |
|
| 128 | + */ |
|
| 129 | + public function setOuptutMethods($outputMethods) |
|
| 130 | + { |
|
| 131 | + $this->outputMethods = $outputMethods; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /* |
|
| 134 | + /* |
|
| 135 | 135 | * Set an array of fields that we don't want in export |
| 136 | 136 | */ |
| 137 | - /** |
|
| 138 | - * @param $fields |
|
| 139 | - */ |
|
| 140 | - public function setNotDisplayFields($fields) |
|
| 141 | - { |
|
| 142 | - if (!$this->notDisplayFields) { |
|
| 143 | - if (is_array($fields)) { |
|
| 144 | - $this->notDisplayFields = $fields; |
|
| 145 | - } else { |
|
| 146 | - $this->notDisplayFields = [$fields]; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - if (is_array($fields)) { |
|
| 150 | - $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
| 151 | - } else { |
|
| 152 | - $this->notDisplayFields[] = $fields; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 137 | + /** |
|
| 138 | + * @param $fields |
|
| 139 | + */ |
|
| 140 | + public function setNotDisplayFields($fields) |
|
| 141 | + { |
|
| 142 | + if (!$this->notDisplayFields) { |
|
| 143 | + if (is_array($fields)) { |
|
| 144 | + $this->notDisplayFields = $fields; |
|
| 145 | + } else { |
|
| 146 | + $this->notDisplayFields = [$fields]; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + if (is_array($fields)) { |
|
| 150 | + $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
| 151 | + } else { |
|
| 152 | + $this->notDisplayFields[] = $fields; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |