Exemple #1
0
 /**
  * @param User $user Optional. Default is NULL.
  * @param array $parameters Optional. An associative array of parameters.
  *     See also {@link PluginPeer::buildParameters()}. Default is NULL.
  * @param PropelPDO $con Optional. The database connection to use.
  *     Default is NULL.
  * @return PluginSandbox
  */
 public function execute(User $user = null, array $parameters = null, PropelPDO $con = null)
 {
     if ($user === null) {
         $account = $this->getAccount($con);
         $domain = null;
     } else {
         $account = $user->getAccount($con);
         $domain = $user->getDomain($con);
     }
     return new PluginSandbox($this, $account, $domain, $user, $parameters);
 }
Exemple #2
0
 /**
  * Updates a user
  *
  * @param int $intId The user ID
  * @param array $arrData The data array
  * @throws Exception
  * @return int The user ID
  */
 public function do_update($intId = null, $arrData)
 {
     $user = null;
     $con = Propel::getConnection();
     if (!$con->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     try {
         $authUser = $this->requireUser();
         $accountId = $authUser->getAccountId();
         $validator = new KickstartValidator();
         $locale = Localizer::getInstance();
         if ($intId and (!isset($arrData['Password']) or $arrData['Password'] == '')) {
             unset($this->filter_basic['Password']);
             unset($arrData['Password']);
             unset($arrData['Password2']);
         }
         $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale));
         if ($warnings) {
             return array('result' => false, 'warnings' => $warnings);
         }
         if ($intId) {
             $user = $authUser->getSubordinate($intId);
         } else {
             $user = new User();
             $user->setAccountId($accountId)->setDomainId($authUser->getDomainId());
         }
         if (isset($arrData['Password'])) {
             $user->setPassword($arrData['Password']);
         }
         $allowedFields = array('Name' => true, 'Firstname' => true, 'Lastname' => true, 'Phone' => true, 'Email' => true, 'Number' => true);
         if ($authUser->getIsAdmin()) {
             $allowedFields += array('DomainId' => true, 'ManagerOf' => true, 'IsAdmin' => true);
         }
         $user->fromArray(array_intersect_key($arrData, $allowedFields));
         // Fail if domain does not belong to authenticated account
         $domain = $user->getDomain($con);
         if ($domain === null or $domain->getAccountId() !== $accountId) {
             throw new Exception('Invalid domain ID #' . $user->getDomainId());
         }
         $user->save($con);
         if (!empty($arrData['Properties'])) {
             $user->setProperties($arrData['Properties'], $con);
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     if (!$con->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     return $user->getId();
 }
Exemple #3
0
 /**
  * Checks whether the clocking's start and end dates are within the time limit.
  * Throws an exception if the time limit is exceeded.
  *
  * @return void
  * @see pastGraceTimeExceeded()
  */
 private function validateTimeLimits(Account $account, User $authUser, Clocking $clocking, PropelPDO $con = null)
 {
     $type = $clocking->getClockingType($con);
     if ($type === null) {
         throw new Exception('Could not get clocking type with ID #' . $clocking->getTypeId() . ' for clocking #' . $clocking->getId() . '.');
     }
     // Check time limit in seconds
     $propertyName = KeyReplace::replace(self::PROPERTY_CLOCKING_TIME_LIMIT, array('type' => $type->getIdentifier()));
     $domain = $authUser->getDomain($con);
     $lastChanged = $clocking->getLastChanged('U');
     $end = $clocking->getEnd('U');
     // Check clocking-type-specific limit first, fall back to default
     $editTimeLimit = PropertyPeer::get($propertyName, $account, $domain, $authUser, $con);
     if ($editTimeLimit === null) {
         $editTimeLimit = PropertyPeer::get(self::PROPERTY_CLOCKING_TIME_LIMIT_DEFAULT, $account, $domain, $authUser, $con);
     }
     $errorData = array('changed' => $lastChanged, 'end' => $end, 'limit' => $editTimeLimit);
     if ($editTimeLimit !== null and !is_numeric($editTimeLimit)) {
         throw new APIException(self::ERROR_TIME_LIMIT, 'Invalid non-numeric value ' . json_encode($editTimeLimit) . ' encountered for property "' . $propertyName . '".', $errorData);
     }
     $minTimeAllowed = time() - $editTimeLimit;
     $result = ((double) $end > $minTimeAllowed and ($clocking->isNew() or (double) $lastChanged > $minTimeAllowed));
     if ($result) {
         return;
     }
     throw new APIException(self::ERROR_TIME_LIMIT, 'Clocking cannot be edited any more after ' . round($editTimeLimit / 3600.0, 2) . ' hours.', $errorData);
 }
Exemple #4
0
 /**
  * Creates and returns an associative array of plugin parameters.
  *
  * @param string $entityName The name of the entity causing the plugin to
  *     be invoked.
  * @param string $eventName The name of the event causing the plugin to
  *     be invoked.
  * @param User $user Optional. The user to execute the plugin on behalf of.
  *     Default is NULL.
  * @param mixed $data Optional. Additional data for the plugin.
  *     Default is NULL.
  * @param PropelPDO $con Optional. The database connection to use.
  *     Default is NULL.
  * @return array An array with the following keys:
  *     - _ENTITY       The value of {@link $entityName}.
  *     - _EVENT        The value of {@link $eventName}.
  *     - _DOMAIN       The domain {@link $user} belongs to.
  *     - _AUTH_USER    An associative array with properties of the authenticated user.
  *     - _USER         An associative array with properties of {@link $user}.
  *     - _DATA         Data specified in {@link $data}.
  * @see fireEvent()
  * @uses $authUser
  */
 public static function buildParameters($entityName, $eventName, User $user = null, $data = null, PropelPDO $con = null)
 {
     if ($user === null) {
         $domainData = null;
         $userData = null;
     } else {
         $domain = $user->getDomain($con);
         $domainData = $domain === null ? null : $domain->toArray();
         $userData = $user->toArray();
         unset($userData['Password']);
     }
     if (self::$authUser === null) {
         $authUserData = null;
     } else {
         $authUserData = self::$authUser->toArray();
         unset($authUserData['Password']);
     }
     return array('_ENTITY' => $entityName, '_EVENT' => $eventName, '_DOMAIN' => $domainData, '_AUTH_USER' => $authUserData, '_USER' => $userData, '_DATA' => $data);
 }