| Total Complexity | 106 |
| Total Lines | 853 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Func_App 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 Func_App, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class Func_App extends bab_Functionality |
||
| 31 | { |
||
| 32 | public $addonPrefix; |
||
| 33 | public $classPrefix; |
||
| 34 | public $addonName; |
||
| 35 | public $controllerTg; |
||
| 36 | public $phpPath; |
||
| 37 | public $recordSetPath; |
||
| 38 | public $ctrlPath; |
||
| 39 | public $uiPath; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $language = null; |
||
| 45 | |||
| 46 | |||
| 47 | public function __construct() |
||
| 48 | { |
||
| 49 | $this->addonPrefix = 'libapp'; |
||
| 50 | $this->addonName = 'libapp'; |
||
| 51 | |||
| 52 | $this->classPrefix = $this->addonPrefix . '_'; |
||
| 53 | $this->controllerTg = 'addon/' . $this->addonName . '/main'; |
||
| 54 | |||
| 55 | $addon = bab_getAddonInfosInstance($this->addonName); |
||
| 56 | $this->phpPath = $addon->getPhpPath(); |
||
| 57 | $this->recordSetPath = $this->phpPath; |
||
| 58 | $this->ctrlPath = $this->phpPath; |
||
| 59 | $this->uiPath = $this->phpPath . 'ui/'; |
||
| 60 | |||
| 61 | $babDB = bab_getDB(); |
||
| 62 | |||
| 63 | $LibOrm = bab_Functionality::get('LibOrm'); |
||
| 64 | /*@var $LibOrm Func_LibOrm */ |
||
| 65 | |||
| 66 | $LibOrm->initMysql(); |
||
| 67 | ORM_RecordSet::setBackend(new ORM_MySqlBackend($babDB)); |
||
| 68 | } |
||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * @param string $class |
||
| 73 | * @return boolean |
||
| 74 | */ |
||
| 75 | public function loadObject($class) |
||
| 93 | } |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * @return string |
||
| 98 | */ |
||
| 99 | public function getUiPath() |
||
| 100 | { |
||
| 101 | return APP_UI_PATH; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public function getSetPath() |
||
| 108 | { |
||
| 109 | return APP_SET_PATH; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | public function getCtrlPath() |
||
| 116 | { |
||
| 117 | return APP_CTRL_PATH; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | public function getPhpPath() |
||
| 124 | { |
||
| 125 | return APP_PHP_PATH; |
||
| 126 | } |
||
| 127 | |||
| 128 | |||
| 129 | /** |
||
| 130 | * @return string |
||
| 131 | * |
||
| 132 | */ |
||
| 133 | public function getDescription() |
||
| 134 | { |
||
| 135 | return 'Application framework.'; |
||
| 136 | } |
||
| 137 | |||
| 138 | |||
| 139 | /** |
||
| 140 | * Get the addon name |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function getAddonName() |
||
| 144 | { |
||
| 145 | return $this->addonName; |
||
| 146 | } |
||
| 147 | |||
| 148 | |||
| 149 | /** |
||
| 150 | * @return bab_addonInfos |
||
| 151 | */ |
||
| 152 | public function getAddon() |
||
| 153 | { |
||
| 154 | return bab_getAddonInfosInstance($this->getAddonName()); |
||
| 155 | } |
||
| 156 | |||
| 157 | |||
| 158 | /** |
||
| 159 | * Register myself as a functionality. |
||
| 160 | * |
||
| 161 | */ |
||
| 162 | public static function register() |
||
| 163 | { |
||
| 164 | require_once $GLOBALS['babInstallPath'].'utilit/functionalityincl.php'; |
||
| 165 | $functionalities = new bab_functionalities(); |
||
|
|
|||
| 166 | |||
| 167 | $addon = bab_getAddonInfosInstance('libapp'); |
||
| 168 | |||
| 169 | $addon->registerFunctionality('App', 'app.php'); |
||
| 170 | } |
||
| 171 | |||
| 172 | |||
| 173 | /** |
||
| 174 | * Synchronize sql tables for all classes found in Application object |
||
| 175 | * using methods 'includeXxxxxClassName' |
||
| 176 | * sychronize if the two correspond methods are met and the set classname match the prefix from parameter |
||
| 177 | * do not synchronize if the set method has a VueSet suffix, in this case the table si juste a readonly vue |
||
| 178 | * |
||
| 179 | * @param string $prefix tables and classes prefix |
||
| 180 | * @return bab_synchronizeSql |
||
| 181 | */ |
||
| 182 | public function synchronizeSql($prefix) |
||
| 183 | { |
||
| 184 | if (!$prefix) { |
||
| 185 | return null; |
||
| 186 | } |
||
| 187 | |||
| 188 | require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; |
||
| 189 | $mysqlbackend = new ORM_MySqlBackend($GLOBALS['babDB']); |
||
| 190 | $sql = 'SET FOREIGN_KEY_CHECKS=0; |
||
| 191 | '; |
||
| 192 | |||
| 193 | foreach (get_class_methods($this) as $method) { |
||
| 194 | |||
| 195 | if (substr($method, 0, 7) === 'include' && substr($method, -3) === 'Set') { |
||
| 196 | $incl = $method; |
||
| 197 | $classNameMethod = substr($method, strlen('include')) . 'ClassName'; |
||
| 198 | |||
| 199 | |||
| 200 | $classname = $this->$classNameMethod(); |
||
| 201 | |||
| 202 | if ($prefix === substr($classname, 0, strlen($prefix)) |
||
| 203 | && 'Set' === substr($classname, -3) |
||
| 204 | && 'ViewSet' !== substr($classname, -7)) { |
||
| 205 | if (method_exists($this, $incl)) { |
||
| 206 | $this->$incl(); |
||
| 207 | |||
| 208 | $call = substr($classname, strlen($prefix)); |
||
| 209 | |||
| 210 | if (class_exists($classname)) { |
||
| 211 | |||
| 212 | /* @var $set ORM_RecordSet */ |
||
| 213 | $set = $this->$call(); |
||
| 214 | if (method_exists($set, 'useLang')) { |
||
| 215 | // This is necessary if the recordSet constructor uses a setLang(). |
||
| 216 | // We need to revert to multilang fields before synchronizing. |
||
| 217 | $set->useLang(false); |
||
| 218 | } |
||
| 219 | $sql .= $mysqlbackend->setToSql($set) . "\n"; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; |
||
| 227 | $synchronize = new bab_synchronizeSql(); |
||
| 228 | |||
| 229 | $synchronize->fromSqlString($sql); |
||
| 230 | |||
| 231 | return $synchronize; |
||
| 232 | } |
||
| 233 | |||
| 234 | |||
| 235 | |||
| 236 | public function getSynchronizeSql($prefix) |
||
| 237 | { |
||
| 238 | if (!$prefix) { |
||
| 239 | return null; |
||
| 240 | } |
||
| 241 | |||
| 242 | require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; |
||
| 243 | $mysqlbackend = new ORM_MySqlBackend($GLOBALS['babDB']); |
||
| 244 | $sql = ''; |
||
| 245 | |||
| 246 | foreach (get_class_methods($this) as $method) { |
||
| 247 | |||
| 248 | if (substr($method, 0, strlen('include')) === 'include' && substr($method, -strlen('Set')) === 'Set') { |
||
| 249 | $incl = $method; |
||
| 250 | $classNameMethod = substr($method, strlen('include')) . 'ClassName'; |
||
| 251 | |||
| 252 | $classname = $this->$classNameMethod(); |
||
| 253 | |||
| 254 | if ($prefix === substr($classname, 0, strlen($prefix)) |
||
| 255 | && 'Set' === substr($classname, -3) |
||
| 256 | && 'ViewSet' !== substr($classname, -6) |
||
| 257 | ) { |
||
| 258 | if (method_exists($this, $incl)) { |
||
| 259 | $this->$incl(); |
||
| 260 | $call = substr($classname, strlen($prefix)); |
||
| 261 | |||
| 262 | if (class_exists($classname) && method_exists($this, $call)) { |
||
| 263 | $set = $this->$call(); |
||
| 264 | $sql .= $mysqlbackend->setToSql($set) . "\n"; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 | } |
||
| 269 | } |
||
| 270 | |||
| 271 | return $sql; |
||
| 272 | } |
||
| 273 | |||
| 274 | |||
| 275 | |||
| 276 | public function includeBase() |
||
| 277 | { |
||
| 278 | require_once APP_PHP_PATH . 'base.class.php'; |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Includes app_RecordSet class definition. |
||
| 283 | */ |
||
| 284 | public function includeRecordSet() |
||
| 285 | { |
||
| 286 | require_once APP_SET_PATH . 'record.class.php'; |
||
| 287 | } |
||
| 288 | |||
| 289 | |||
| 290 | /** |
||
| 291 | * Includes app_TraceableRecordSet class definition. |
||
| 292 | */ |
||
| 293 | public function includeTraceableRecordSet() |
||
| 294 | { |
||
| 295 | require_once APP_SET_PATH . 'traceablerecord.class.php'; |
||
| 296 | } |
||
| 297 | |||
| 298 | |||
| 299 | |||
| 300 | /** |
||
| 301 | * SET DEFINITION |
||
| 302 | */ |
||
| 303 | |||
| 304 | //Log |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Includes LogSet class definition. |
||
| 308 | */ |
||
| 309 | public function includeLogSet() |
||
| 310 | { |
||
| 311 | require_once APP_SET_PATH . 'log.class.php'; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function LogClassName() |
||
| 318 | { |
||
| 319 | return 'app_Log'; |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return string |
||
| 324 | */ |
||
| 325 | public function LogSetClassName() |
||
| 326 | { |
||
| 327 | return $this->LogClassName() . 'Set'; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return app_LogSet |
||
| 332 | */ |
||
| 333 | public function LogSet() |
||
| 334 | { |
||
| 335 | $this->includeLogSet(); |
||
| 336 | $className = $this->LogSetClassName(); |
||
| 337 | $set = new $className($this); |
||
| 338 | return $set; |
||
| 339 | } |
||
| 340 | |||
| 341 | |||
| 342 | //Link |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Includes LinkSet class definition. |
||
| 346 | */ |
||
| 347 | public function includeLinkSet() |
||
| 348 | { |
||
| 349 | require_once APP_SET_PATH . 'link.class.php'; |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return string |
||
| 354 | */ |
||
| 355 | public function LinkClassName() |
||
| 356 | { |
||
| 357 | return 'app_Link'; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @return string |
||
| 362 | */ |
||
| 363 | public function LinkSetClassName() |
||
| 364 | { |
||
| 365 | return $this->LinkClassName() . 'Set'; |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @return app_LinkSet |
||
| 370 | */ |
||
| 371 | public function LinkSet() |
||
| 372 | { |
||
| 373 | $this->includeLinkSet(); |
||
| 374 | $className = $this->LinkSetClassName(); |
||
| 375 | $set = new $className($this); |
||
| 376 | return $set; |
||
| 377 | } |
||
| 378 | |||
| 379 | //CustomField |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Includes CustomFieldSet class definition. |
||
| 383 | */ |
||
| 384 | public function includeCustomFieldSet() |
||
| 385 | { |
||
| 386 | require_once APP_SET_PATH . 'customfield.class.php'; |
||
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | public function CustomFieldClassName() |
||
| 393 | { |
||
| 394 | return 'app_CustomField'; |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @return string |
||
| 399 | */ |
||
| 400 | public function CustomFieldSetClassName() |
||
| 401 | { |
||
| 402 | return $this->CustomFieldClassName() . 'Set'; |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return app_CustomFieldSet |
||
| 407 | */ |
||
| 408 | public function CustomFieldSet() |
||
| 409 | { |
||
| 410 | $this->includeCustomFieldSet(); |
||
| 411 | $className = $this->CustomFieldSetClassName(); |
||
| 412 | $set = new $className($this); |
||
| 413 | return $set; |
||
| 414 | } |
||
| 415 | |||
| 416 | |||
| 417 | //CustomSection |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Includes CustomSectionSet class definition. |
||
| 421 | */ |
||
| 422 | public function includeCustomSectionSet() |
||
| 423 | { |
||
| 424 | require_once APP_SET_PATH . 'traceablerecord.class.php'; |
||
| 425 | require_once APP_SET_PATH . 'customsection.class.php'; |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return string |
||
| 430 | */ |
||
| 431 | public function CustomSectionClassName() |
||
| 432 | { |
||
| 433 | return 'app_CustomSection'; |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @return string |
||
| 438 | */ |
||
| 439 | public function CustomSectionSetClassName() |
||
| 440 | { |
||
| 441 | return $this->CustomSectionClassName() . 'Set'; |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @return app_CustomSectionSet |
||
| 446 | */ |
||
| 447 | public function CustomSectionSet() |
||
| 448 | { |
||
| 449 | $this->includeCustomSectionSet(); |
||
| 450 | $className = $this->CustomSectionSetClassName(); |
||
| 451 | $set = new $className($this); |
||
| 452 | return $set; |
||
| 453 | } |
||
| 454 | |||
| 455 | |||
| 456 | //Tag |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Includes TagSet class definition. |
||
| 460 | */ |
||
| 461 | public function includeTagSet() |
||
| 462 | { |
||
| 463 | require_once APP_SET_PATH . 'tag.class.php'; |
||
| 464 | } |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @return string |
||
| 468 | */ |
||
| 469 | public function TagClassName() |
||
| 470 | { |
||
| 471 | return 'app_Tag'; |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @return string |
||
| 476 | */ |
||
| 477 | public function TagSetClassName() |
||
| 478 | { |
||
| 479 | return $this->TagClassName() . 'Set'; |
||
| 480 | } |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @return app_TagSet |
||
| 484 | */ |
||
| 485 | public function TagSet() |
||
| 486 | { |
||
| 487 | $this->includeTagSet(); |
||
| 488 | $className = $this->TagSetClassName(); |
||
| 489 | $set = new $className($this); |
||
| 490 | return $set; |
||
| 491 | } |
||
| 492 | |||
| 493 | |||
| 494 | |||
| 495 | |||
| 496 | |||
| 497 | |||
| 498 | |||
| 499 | |||
| 500 | /** |
||
| 501 | * Returns the app_Record corresponding to the specified |
||
| 502 | * reference $ref. |
||
| 503 | * |
||
| 504 | * @param string $ref A reference string (e.g. Contact:12) |
||
| 505 | * @return app_Record or null if no corresponding record is found. |
||
| 506 | */ |
||
| 507 | public function getRecordByRef($ref) |
||
| 508 | { |
||
| 509 | $refParts = explode(':', $ref); |
||
| 510 | if (count($refParts) !== 2) { |
||
| 511 | return null; |
||
| 512 | } |
||
| 513 | list($classname, $id) = $refParts; |
||
| 514 | $classSet = $classname . 'Set'; |
||
| 515 | $set = $this->$classSet(); |
||
| 516 | if (isset($set)) { |
||
| 517 | return $set->get($id); |
||
| 518 | } |
||
| 519 | return null; |
||
| 520 | } |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Returns the reference corresponding to the specified |
||
| 524 | * app_Record $record (e.g. Contact:12 or Deal:125) |
||
| 525 | * |
||
| 526 | * @param app_Record $record |
||
| 527 | * @return string |
||
| 528 | */ |
||
| 529 | public function getRecordRef(app_Record $record) |
||
| 530 | { |
||
| 531 | $fullClassName = get_class($record); |
||
| 532 | list(, $className) = explode('_', $fullClassName); |
||
| 533 | return $className . ':' . $record->id; |
||
| 534 | } |
||
| 535 | |||
| 536 | |||
| 537 | /** |
||
| 538 | * Specifies the language to use for translation. |
||
| 539 | * |
||
| 540 | * If $language is null, the language is reset to |
||
| 541 | * the current logged user language. |
||
| 542 | * |
||
| 543 | * @param string|null $language |
||
| 544 | */ |
||
| 545 | public function setTranslateLanguage($language) |
||
| 546 | { |
||
| 547 | $this->language = $language; |
||
| 548 | } |
||
| 549 | |||
| 550 | |||
| 551 | |||
| 552 | /** |
||
| 553 | * Translates the string. |
||
| 554 | * |
||
| 555 | * @param string $str |
||
| 556 | * @return string |
||
| 557 | */ |
||
| 558 | public function translate($str, $str_plurals = null, $number = null) |
||
| 559 | { |
||
| 560 | require_once APP_PHP_PATH . 'functions.php'; |
||
| 561 | $translation = $str; |
||
| 562 | if ($translate = bab_functionality::get('Translate/Gettext')) { |
||
| 563 | /* @var $translate Func_Translate_Gettext */ |
||
| 564 | $translate->setAddonName('libapp'); |
||
| 565 | $translation = $translate->translate($str, $str_plurals, $number); |
||
| 566 | } |
||
| 567 | |||
| 568 | return $translation; |
||
| 569 | } |
||
| 570 | |||
| 571 | /** |
||
| 572 | * @param string $str |
||
| 573 | * @param string $str_plurals |
||
| 574 | * @param int $number |
||
| 575 | * @return string |
||
| 576 | */ |
||
| 577 | public function translatable($str, $str_plurals = null, $number = null) |
||
| 578 | { |
||
| 579 | return $str; |
||
| 580 | } |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Translates all the string in an array and returns a new array. |
||
| 584 | * |
||
| 585 | * @param array $arr |
||
| 586 | * @return array |
||
| 587 | */ |
||
| 588 | public function translateArray($arr) |
||
| 596 | } |
||
| 597 | |||
| 598 | |||
| 599 | |||
| 600 | /** |
||
| 601 | * Returns a link for writting an email to the specified email address. |
||
| 602 | * |
||
| 603 | * @param string $addr |
||
| 604 | * @param string $subject |
||
| 605 | * @param string $body |
||
| 606 | * |
||
| 607 | * @return string |
||
| 608 | */ |
||
| 609 | public function mailTo($addr, $subject = null, $body = null) |
||
| 610 | { |
||
| 611 | $mailTo = 'mailto:' . $addr; |
||
| 612 | $parameters = array(); |
||
| 613 | if (isset($subject)) { |
||
| 614 | $parameters[] = 'subject=' . $subject; |
||
| 615 | } |
||
| 616 | if (isset($body)) { |
||
| 617 | $parameters[] = 'body=' . $body; |
||
| 618 | } |
||
| 619 | if (!empty($parameters)) { |
||
| 620 | $mailTo .= '?' . implode('&', $parameters); |
||
| 621 | } |
||
| 622 | |||
| 623 | return $mailTo; |
||
| 624 | } |
||
| 625 | |||
| 626 | |||
| 627 | |||
| 628 | /** |
||
| 629 | * Format a number for display |
||
| 630 | * |
||
| 631 | * @param float|string|null $number Numeric value with decimal |
||
| 632 | * @return string |
||
| 633 | */ |
||
| 634 | public function numberFormat($number, $decimals = 2) |
||
| 635 | { |
||
| 636 | if (is_null($number)) { |
||
| 637 | return '#,##'; |
||
| 638 | } |
||
| 639 | |||
| 640 | $number = number_format(floatval($number), $decimals, ',', ' '); |
||
| 641 | return str_replace(' ', bab_nbsp(), $number); |
||
| 642 | } |
||
| 643 | |||
| 644 | |||
| 645 | /** |
||
| 646 | * Format a number with an optional unit. |
||
| 647 | * |
||
| 648 | * If the value is >= 1000 the value is shortened and the corresponding prexif (k or M) is used. |
||
| 649 | * |
||
| 650 | * @param float|string|null $number |
||
| 651 | * @param string $unitSymbol (For example $, m2, Wh) |
||
| 652 | * @param int $decimals |
||
| 653 | * @return string|mixed |
||
| 654 | */ |
||
| 655 | public function shortFormatWithUnit($number, $unitSymbol = '', $decimals = 2) |
||
| 656 | { |
||
| 657 | if (is_null($number)) { |
||
| 658 | return '#,##'; |
||
| 659 | } |
||
| 660 | |||
| 661 | $prefix = ''; |
||
| 662 | if ($number >= 1000000) { |
||
| 663 | $number /= 1000000; |
||
| 664 | $prefix = 'M'; |
||
| 665 | } elseif ($number >= 1000) { |
||
| 666 | $number /= 1000; |
||
| 667 | $prefix = 'k'; |
||
| 668 | } |
||
| 669 | |||
| 670 | $number = number_format($number, $decimals, ',', ' '); |
||
| 671 | return str_replace(' ', bab_nbsp(), $number . ' ' . $prefix . $unitSymbol); |
||
| 672 | } |
||
| 673 | |||
| 674 | |||
| 675 | /** |
||
| 676 | * Reformat a phone number in the specified format. |
||
| 677 | * |
||
| 678 | * @param string $phone The phone number to be formatted |
||
| 679 | * @param int $format The format the phone number should be formatted into |
||
| 680 | * |
||
| 681 | * @return string The formatted phone number |
||
| 682 | */ |
||
| 683 | public function phoneNumberFormat($phone, $format = null) |
||
| 684 | { |
||
| 685 | $PhoneNumber = bab_Functionality::get('PhoneNumber'); |
||
| 686 | if ($PhoneNumber === false) { |
||
| 687 | return $phone; |
||
| 688 | } |
||
| 689 | |||
| 690 | if (!isset($format)) { |
||
| 691 | $format = bab_registry::get('/' . $this->addonName . '/numberFormat', $PhoneNumber->getDefaultFormat()); |
||
| 692 | } |
||
| 693 | $phoneNumberUtil = $PhoneNumber->PhoneNumberUtil(); |
||
| 694 | |||
| 695 | try { |
||
| 696 | $phoneNumber = $phoneNumberUtil->parse($phone, 'FR'); |
||
| 697 | $phone = $phoneNumberUtil->format($phoneNumber, $format); |
||
| 698 | } catch (\libphonenumber\NumberParseException $e) { |
||
| 699 | } |
||
| 700 | |||
| 701 | return $phone; |
||
| 702 | } |
||
| 703 | |||
| 704 | |||
| 705 | |||
| 706 | |||
| 707 | /** |
||
| 708 | * Includes Controller class definition. |
||
| 709 | */ |
||
| 710 | public function includeController() |
||
| 711 | { |
||
| 712 | require_once APP_PHP_PATH . '/controller.class.php'; |
||
| 713 | } |
||
| 714 | |||
| 715 | |||
| 716 | /** |
||
| 717 | * Includes RecordController class definition. |
||
| 718 | */ |
||
| 719 | public function includeRecordController() |
||
| 720 | { |
||
| 721 | require_once APP_CTRL_PATH . '/record.ctrl.php'; |
||
| 722 | } |
||
| 723 | |||
| 724 | |||
| 725 | /** |
||
| 726 | * Instanciates the controller. |
||
| 727 | * |
||
| 728 | * @return app_Controller |
||
| 729 | */ |
||
| 730 | public function Controller() |
||
| 731 | { |
||
| 732 | $this->includeController(); |
||
| 733 | return bab_getInstance($this->classPrefix.'Controller')->setApp($this); |
||
| 734 | } |
||
| 735 | |||
| 736 | |||
| 737 | /** |
||
| 738 | * Instanciates a controller class. |
||
| 739 | * |
||
| 740 | * @return bab_Controller |
||
| 741 | */ |
||
| 742 | public function ControllerProxy($className, $proxy = true) |
||
| 743 | { |
||
| 744 | $this->includeController(); |
||
| 745 | |||
| 746 | if ($proxy) { |
||
| 747 | return app_Controller::getProxyInstance($this, $className); |
||
| 748 | } |
||
| 749 | |||
| 750 | return new $className($this); |
||
| 751 | } |
||
| 752 | |||
| 753 | |||
| 754 | |||
| 755 | /** |
||
| 756 | * Include class app_Ui |
||
| 757 | * |
||
| 758 | */ |
||
| 759 | public function includeUi() |
||
| 762 | } |
||
| 763 | |||
| 764 | |||
| 765 | /** |
||
| 766 | * The app_Ui object propose an access to all ui files and ui objects (widgets) |
||
| 767 | * |
||
| 768 | * @return app_Ui |
||
| 769 | */ |
||
| 770 | public function Ui() |
||
| 771 | { |
||
| 772 | $this->includeUi(); |
||
| 773 | return bab_getInstance($this->classPrefix . 'Ui');//->setApp($this); |
||
| 774 | } |
||
| 775 | |||
| 776 | |||
| 777 | |||
| 778 | protected function includeAccess() |
||
| 779 | { |
||
| 780 | require_once WORKSPACE_PHP_PATH . '/access.class.php'; |
||
| 781 | } |
||
| 782 | |||
| 783 | |||
| 784 | |||
| 785 | |||
| 786 | |||
| 787 | /** |
||
| 788 | * Get upload path |
||
| 789 | * if the method return null, no upload functionality |
||
| 790 | * |
||
| 791 | * @return bab_Path |
||
| 792 | */ |
||
| 793 | public function getUploadPath() |
||
| 794 | { |
||
| 795 | require_once $GLOBALS['babInstallPath'].'utilit/path.class.php'; |
||
| 796 | return new bab_Path(bab_getAddonInfosInstance($this->getAddonName())->getUploadPath()); |
||
| 797 | } |
||
| 798 | |||
| 799 | |||
| 800 | /** |
||
| 801 | * |
||
| 802 | * @param string $name |
||
| 803 | * @param mixed $arguments |
||
| 804 | * @return mixed |
||
| 805 | */ |
||
| 806 | public function __call($name, $arguments) |
||
| 844 | } |
||
| 845 | } |
||
| 846 | |||
| 847 | |||
| 848 | /** |
||
| 849 | * Test if this App implementation handles the specified object class. |
||
| 850 | * |
||
| 851 | * The default is to consider that an object Xxxx implemented if the includeXxxxSet() method is |
||
| 852 | * declared public on this App. |
||
| 853 | * |
||
| 854 | * @param string $objectClassName App object name (eg. 'Contact' or 'CatalogItem') |
||
| 855 | * @return bool |
||
| 856 | */ |
||
| 857 | public function __isset($objectClassName) |
||
| 883 | } |
||
| 884 | } |
||
| 885 | |||
| 886 |