| Total Complexity | 14 |
| Total Lines | 231 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class DatasetMapper |
||
| 19 | { |
||
| 20 | private $userId; |
||
| 21 | private $l10n; |
||
| 22 | private $db; |
||
| 23 | private $logger; |
||
| 24 | const TABLE_NAME = 'analytics_dataset'; |
||
| 25 | |||
| 26 | public function __construct( |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * get datasets |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public function index() |
||
| 45 | { |
||
| 46 | $sql = $this->db->getQueryBuilder(); |
||
| 47 | $sql->from(self::TABLE_NAME) |
||
| 48 | ->select('id') |
||
| 49 | ->addSelect('name') |
||
| 50 | ->addSelect('dimension1') |
||
| 51 | ->addSelect('dimension2') |
||
| 52 | ->addSelect('value') |
||
| 53 | ->where($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId))) |
||
| 54 | ->andWhere($sql->expr()->eq('type', $sql->createNamedParameter('2'))) |
||
| 55 | ->addOrderBy('name', 'ASC'); |
||
| 56 | $statement = $sql->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 57 | $result = $statement->fetchAll(); |
||
| 58 | $statement->closeCursor(); |
||
| 59 | return $result; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * create dataset |
||
| 64 | * @param $name |
||
| 65 | * @param $dimension1 |
||
| 66 | * @param $dimension2 |
||
| 67 | * @param $value |
||
| 68 | * @return int |
||
| 69 | * @throws \OCP\DB\Exception |
||
| 70 | */ |
||
| 71 | public function create($name, $dimension1, $dimension2, $value) |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * get single dataset |
||
| 89 | * @param int $id |
||
| 90 | * @param string|null $user_id |
||
| 91 | * @return array |
||
| 92 | */ |
||
| 93 | public function read(int $id, string $user_id = null) |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * update dataset |
||
| 112 | * @param $id |
||
| 113 | * @param $name |
||
| 114 | * @param $subheader |
||
| 115 | * @param $parent |
||
| 116 | * @param $type |
||
| 117 | * @param $link |
||
| 118 | * @param $visualization |
||
| 119 | * @param $chart |
||
| 120 | * @param $chartoptions |
||
| 121 | * @param $dataoptions |
||
| 122 | * @param $dimension1 |
||
| 123 | * @param $dimension2 |
||
| 124 | * @param $value |
||
| 125 | * @param $filteroptions |
||
| 126 | * @return bool |
||
| 127 | */ |
||
| 128 | public function update($id, $name, $subheader, $parent, $type, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value, $filteroptions = null) |
||
| 129 | { |
||
| 130 | $name = $this->truncate($name, 64); |
||
| 131 | $sql = $this->db->getQueryBuilder(); |
||
| 132 | $sql->update(self::TABLE_NAME) |
||
| 133 | ->set('name', $sql->createNamedParameter($name)) |
||
| 134 | ->set('subheader', $sql->createNamedParameter($subheader)) |
||
| 135 | ->set('type', $sql->createNamedParameter($type)) |
||
| 136 | ->set('link', $sql->createNamedParameter($link)) |
||
| 137 | ->set('visualization', $sql->createNamedParameter($visualization)) |
||
| 138 | ->set('chart', $sql->createNamedParameter($chart)) |
||
| 139 | ->set('chartoptions', $sql->createNamedParameter($chartoptions)) |
||
| 140 | ->set('dataoptions', $sql->createNamedParameter($dataoptions)) |
||
| 141 | ->set('parent', $sql->createNamedParameter($parent)) |
||
| 142 | ->set('dimension1', $sql->createNamedParameter($dimension1)) |
||
| 143 | ->set('dimension2', $sql->createNamedParameter($dimension2)) |
||
| 144 | ->set('value', $sql->createNamedParameter($value)) |
||
| 145 | ->where($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId))) |
||
| 146 | ->andWhere($sql->expr()->eq('id', $sql->createNamedParameter($id))); |
||
| 147 | if ($filteroptions !== null) $sql->set('filteroptions', $sql->createNamedParameter($filteroptions)); |
||
| 148 | $sql->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 149 | return true; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * update dataset options |
||
| 154 | * @param $id |
||
| 155 | * @param $chartoptions |
||
| 156 | * @param $dataoptions |
||
| 157 | * @param $filteroptions |
||
| 158 | * @return bool |
||
| 159 | */ |
||
| 160 | public function updateOptions($id, $chartoptions, $dataoptions, $filteroptions) |
||
| 161 | { |
||
| 162 | $sql = $this->db->getQueryBuilder(); |
||
| 163 | $sql->update(self::TABLE_NAME) |
||
| 164 | ->set('chartoptions', $sql->createNamedParameter($chartoptions)) |
||
| 165 | ->set('dataoptions', $sql->createNamedParameter($dataoptions)) |
||
| 166 | ->set('filteroptions', $sql->createNamedParameter($filteroptions)) |
||
| 167 | ->where($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId))) |
||
| 168 | ->andWhere($sql->expr()->eq('id', $sql->createNamedParameter($id))); |
||
| 169 | $sql->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 170 | return true; |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * read dataset options |
||
| 175 | * @param $id |
||
| 176 | * @return array |
||
| 177 | */ |
||
| 178 | public function readOptions($id) |
||
| 179 | { |
||
| 180 | $sql = $this->db->getQueryBuilder(); |
||
| 181 | $sql->from(self::TABLE_NAME) |
||
| 182 | ->select('name') |
||
| 183 | ->addSelect('visualization') |
||
| 184 | ->addSelect('chart') |
||
| 185 | ->addSelect('user_id') |
||
| 186 | ->where($sql->expr()->eq('id', $sql->createNamedParameter($id))); |
||
| 187 | $statement = $sql->execute(); |
||
|
1 ignored issue
–
show
|
|||
| 188 | $result = $statement->fetch(); |
||
| 189 | $statement->closeCursor(); |
||
| 190 | return $result; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * delete dataset |
||
| 195 | * @param $id |
||
| 196 | * @return bool |
||
| 197 | */ |
||
| 198 | public function delete($id) |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * get the newest timestamp of the data of a dataset |
||
| 210 | * @param $datasetId |
||
| 211 | * @return int |
||
| 212 | */ |
||
| 213 | public function getLastUpdate($datasetId) |
||
| 214 | { |
||
| 215 | $sql = $this->db->getQueryBuilder(); |
||
| 216 | $sql->from('analytics_facts') |
||
| 217 | ->select($sql->func()->max('timestamp')) |
||
| 218 | ->where($sql->expr()->eq('dataset', $sql->createNamedParameter($datasetId))); |
||
| 219 | $result = (int)$sql->execute()->fetchOne(); |
||
|
1 ignored issue
–
show
|
|||
| 220 | return $result; |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * get the report owner |
||
| 225 | * @param $datasetId |
||
| 226 | * @return int |
||
| 227 | */ |
||
| 228 | public function getOwner($datasetId) |
||
| 229 | { |
||
| 230 | $sql = $this->db->getQueryBuilder(); |
||
| 231 | $sql->from(self::TABLE_NAME) |
||
| 232 | ->select('user_id') |
||
| 233 | ->where($sql->expr()->eq('id', $sql->createNamedParameter($datasetId))); |
||
| 234 | $result = (string)$sql->execute()->fetchOne(); |
||
|
1 ignored issue
–
show
|
|||
| 235 | return $result; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * truncates fiels do DB-field size |
||
| 240 | * |
||
| 241 | * @param $string |
||
| 242 | * @param $length |
||
| 243 | * @param $dots |
||
| 244 | * @return string |
||
| 245 | */ |
||
| 246 | private function truncate($string, $length, $dots = "...") |
||
| 249 | } |
||
| 250 | } |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.