Alternc  latest
Alternc logiel libre pour l'hébergement
Legacyobject.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Any Legacy AlternC Api should use this class as a parent
5  * to be able to handle properly the access rights & error messages
6  *
7  * @author benjamin
8  */
10 
11  protected $admin; // m_admin instance
12  protected $cuid; // current user id
13  protected $isAdmin; // is it an Admin account?
14  protected $db; // PDO DB access to AlternC's database.
15 
16  const ERR_INVALID_ARGUMENT = 111201;
17  const ERR_ALTERNC_FUNCTION = 111202;
18  const ERR_NOT_FOUND = 111203;
19 
20  function __construct($service) {
21  global $admin, $cuid;
22  if (!($service instanceof Alternc_Api_Service)) {
23  throw new \Exception("Bad argument: service is not an Alternc_Api_Service", self::ERR_INVALID_ARGUMENT);
24  }
25  // We store the global $cuid to AlternC legacy classes
26  $this->db = $service->db;
27  $this->cuid = $cuid = $service->token->uid;
28  $this->isAdmin = $service->token->isAdmin;
29  // We use the global $admin from AlternC legacy classes
30  $this->admin = $admin;
31  // Set the legacy rights:
32  $this->admin->enabled = $this->isAdmin;
33  }
34 
35  /** return a proper Alternc_Api_Response from an error class and error string
36  * from AlternC legacy class
37  */
38  protected function alterncLegacyErrorManager() {
39  global $err;
40  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[" . $err->clsid . "] " . $err->error));
41  }
42 
43  /** ensure that offset & count are set properly from $options.
44  */
45  protected function offsetAndCount($options, $max) {
46  $offset = -1;
47  $count = -1;
48  if (isset($options["count"]))
49  $count = intval($options["count"]);
50  if (isset($options["offset"]))
51  $offset = intval($options["offset"]);
52  if ($offset != -1 || $count != -1) {
53  if ($offset < 0 || $offset > $max)
54  $offset = 0;
55  if ($count < 0 || $count > 1000)
56  $count = 1000;
57  }
58  return array($offset, $count);
59  }
60 
61 }
62 
63 // Aternc_Api_Legacyobject
64 
$err
Definition: bootstrap.php:72
Any Legacy AlternC Api should use this class as a parent to be able to handle properly the access rig...
Definition: Legacyobject.php:9
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class
offsetAndCount($options, $max)
ensure that offset & count are set properly from $options.
Standard Response object for the AlternC API.
Definition: Response.php:7
Service API used by server to export API methods this class can be used to implement an API service /...
Definition: Service.php:11
if($dryrun) print cuid
Definition: mail_add.php:94