| Total Complexity | 43 |
| Total Lines | 275 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CdavLib often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CdavLib, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class CdavLib |
||
| 29 | { |
||
| 30 | |||
| 31 | private $db; |
||
| 32 | |||
| 33 | private $user; |
||
| 34 | |||
| 35 | private $langs; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Constructor |
||
| 39 | * |
||
| 40 | * @param User $user user |
||
| 41 | * @param DoliDB $db Database handler |
||
| 42 | * @param Translate $langs translation |
||
| 43 | */ |
||
| 44 | public function __construct($user, $db, $langs) |
||
| 45 | { |
||
| 46 | $this->user = $user; |
||
| 47 | $this->db = $db; |
||
| 48 | $this->langs = $langs; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Base sql request for calendar events |
||
| 53 | * |
||
| 54 | * @param int $calid Calendard id |
||
| 55 | * @param int|boolean $oid Oid |
||
| 56 | * @param int|boolean $ouri Ouri |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function getSqlCalEvents($calid, $oid = false, $ouri = false) |
||
| 60 | { |
||
| 61 | // TODO : replace GROUP_CONCAT by |
||
| 62 | $sql = 'SELECT |
||
| 63 | a.tms AS lastupd, |
||
| 64 | a.*, |
||
| 65 | sp.firstname, |
||
| 66 | sp.lastname, |
||
| 67 | sp.address, |
||
| 68 | sp.zip, |
||
| 69 | sp.town, |
||
| 70 | co.label country_label, |
||
| 71 | sp.phone, |
||
| 72 | sp.phone_perso, |
||
| 73 | sp.phone_mobile, |
||
| 74 | s.nom AS soc_nom, |
||
| 75 | s.address soc_address, |
||
| 76 | s.zip soc_zip, |
||
| 77 | s.town soc_town, |
||
| 78 | cos.label soc_country_label, |
||
| 79 | s.phone soc_phone, |
||
| 80 | ac.sourceuid, |
||
| 81 | (SELECT GROUP_CONCAT(u.login) FROM '.MAIN_DB_PREFIX.'actioncomm_resources ar |
||
| 82 | LEFT OUTER JOIN '.MAIN_DB_PREFIX.'user AS u ON (u.rowid=fk_element) |
||
| 83 | WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users |
||
| 84 | FROM '.MAIN_DB_PREFIX.'actioncomm AS a'; |
||
| 85 | if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ? |
||
| 86 | { |
||
| 87 | $sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.') |
||
| 88 | LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = sc.fk_soc) |
||
| 89 | LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact) |
||
| 90 | LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)'; |
||
| 91 | } |
||
| 92 | else |
||
| 93 | { |
||
| 94 | $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc) |
||
| 95 | LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.rowid = a.fk_contact) |
||
| 96 | LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)'; |
||
| 97 | } |
||
| 98 | |||
| 99 | $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays |
||
| 100 | LEFT JOIN '.MAIN_DB_PREFIX.'c_country as cos ON cos.rowid = s.fk_pays |
||
| 101 | WHERE a.id IN (SELECT ar.fk_actioncomm FROM '.MAIN_DB_PREFIX.'actioncomm_resources ar WHERE ar.element_type=\'user\' AND ar.fk_element='.intval($calid).') |
||
| 102 | AND a.code IN (SELECT cac.code FROM '.MAIN_DB_PREFIX.'c_actioncomm cac WHERE cac.type<>\'systemauto\') |
||
| 103 | AND a.entity IN ('.getEntity('societe', 1).')'; |
||
| 104 | if($oid!==false) { |
||
| 105 | if($ouri===false) |
||
| 106 | { |
||
| 107 | $sql.=' AND a.id = '.intval($oid); |
||
| 108 | } |
||
| 109 | else |
||
| 110 | { |
||
| 111 | $sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')'; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | return $sql; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Convert calendar row to VCalendar string |
||
| 120 | * |
||
| 121 | * @param int $calid Calendar id |
||
| 122 | * @param Object $obj Object id |
||
| 123 | * @return string |
||
| 124 | */ |
||
| 125 | public function toVCalendar($calid, $obj) |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * getFullCalendarObjects |
||
| 250 | * |
||
| 251 | * @param int $calendarId Calendar id |
||
| 252 | * @param int $bCalendarData Add calendar data |
||
| 253 | * @return array|string[][] |
||
| 254 | */ |
||
| 255 | public function getFullCalendarObjects($calendarId, $bCalendarData) |
||
| 305 |