/** * Magic method that allows us to use the field data as properties. * Converts foreign keys to objects. * @param string $fieldName * @return mixed * @throws \Exception */ public function __get($fieldName) { $modelTable = $this->getModelTable(); $helper = $modelTable->getFieldDefinitionHelper(); if ($helper->fieldExists($fieldName)) { switch ($helper->getFieldType($fieldName)) { case FieldDefinition\Type::PRIMARY_KEY: case FieldDefinition\Type::NORMAL: case FieldDefinition\Type::FOREIGN_KEY: return $this->getFieldData($fieldName); break; case FieldDefinition\Type::FOREIGN_OBJECT: // search for the foreign key reference $foreignKeyFieldName = $helper->getForeignKeyFieldName($fieldName); $foreignKey = $this->getFieldData($foreignKeyFieldName); if ($foreignKey == null) { return null; } $foreignModelTable = $helper->getModelTable($foreignKeyFieldName); return $foreignModelTable->loadByPrimaryKey($foreignKey); break; case FieldDefinition\Type::MANY_FOREIGN_OBJECTS: $foreignKeys = $this->getFieldData($fieldName); $modelTable = $helper->getModelTable($fieldName); if ($foreignKeys == null) { $entityArray = new EntityArray(); $entityArray->setModelTable($modelTable); return $entityArray; } if (isset($foreignKeys)) { return $modelTable->loadByPrimaryKeys(explode(',', $foreignKeys)); } else { throw new \Exception('Foreign keys for ' . $fieldName . ' not found.'); } break; } } else { if ($this->fieldDataExists($fieldName)) { return $this->getFieldData($fieldName); } else { throw new \Exception('Value ' . $fieldName . ' not found.'); } } }
/** * Removes duplicate values from the array * @access public * @param Bool $set If True, the array will be changed. If False, the method will simply return a new EntityArray without duplicate values. (default: True) * @return EntityArray The calling filtered EntityArray if $set is True. A filtered copy of this EntityArray otherwise. */ public function unique($set = true) { $tempEntity = new EntityArray($this->entity); foreach ($this->array as $obj) { if (!$tempEntity->hasEntity($obj)) { $tempEntity->array[] = $obj; } } if ($set) { $this->array = $tempEntity->getArray(); return $this; } return $tempEntity; }
/** * Returns the user details * * @param string|int $id The user ID or full login name * @param bool $allowPeerUsers Optional. If TRUE and the method was called * by a plugin, users from the same company account but not managed by * the authenticated user can be returned as well. If FALSE, only * subordinate users will be returned. Default is FALSE. * @return array An associative array of user properties. */ public function do_details($id = null, $allowPeerUsers = false) { $user = $this->requireUser(); /* @var $user User */ if ((string) $id !== '') { // Check if it is a plugin execution $user = (PluginIXml::inPlugin() and $allowPeerUsers) ? $this->getPeerUser($user->getAccountId(), $id) : $user->getSubordinate($id); } return EntityArray::from($user) + array('Properties' => $user->getProperties()); }
/** * Lists bookings. * * @param int userid * @param int $start * @param int $end * @param array typeIds Optional. An array with IDs of the booking types to * limit the results to. Default is NULL. * @param bool $showDeleted Optional. Default is FALSE. * @param string orderby Order by key (start*, end, username, flexitime, overtime, denied) * @param string ordermode Order mode ("asc" or "desc"; default: desc) * @return array An array of booking items */ public function do_list_bookings($userId, $start, $end, array $typeIds = null, $showDeleted = false, $ordermode = null, $orderBy = null) { $user = $this->requireUser(); $query = $this->createBookingQuery($user)->join('Transaction.UserRelatedByUserId')->join('UserRelatedByUserId.Domain')->join('Domain.Account'); if ((string) $userId !== '') { $employee = $this->findUserById($userId); if ($employee === null) { throw new Exception('Employee with ID ' . $userId . ' could not be found.'); } $query->add(TransactionPeer::USER_ID, $employee->getId()); } if ((string) $start !== '') { $query->add(TransactionPeer::END, $start, Criteria::GREATER_EQUAL); } if ((string) $end !== '') { $query->add(TransactionPeer::START, $end, Criteria::LESS_EQUAL); } if (!empty($typeIds)) { $query->filterByBookingTypeId($typeIds, Criteria::IN); } if (!$showDeleted) { $query->add(TransactionPeer::DELETED, 0, Criteria::EQUAL); } if ($ordermode == 'asc') { $sortMethod = 'addAscendingOrderByColumn'; } else { $ordermode = 'desc'; $sortMethod = 'addDescendingOrderByColumn'; } switch ($orderBy) { case 'User': $query->orderBy('Account.Name', $ordermode); $query->orderBy('Account.Identifier', $ordermode); $query->orderBy('UserRelatedByUserId.Name', $ordermode); $query->orderBy('Transaction.Start', $ordermode); $query->orderBy('Transaction.End', $ordermode); break; case 'End': $query->orderBy('Transaction.End', $ordermode); $query->orderBy('Transaction.Start', $ordermode); $query->orderBy('Account.Name', $ordermode); $query->orderBy('Account.Identifier', $ordermode); $query->orderBy('UserRelatedByUserId.Name', $ordermode); break; case 'Start': default: $query->orderBy('Transaction.Start', $ordermode); $query->orderBy('Transaction.End', $ordermode); $query->orderBy('Account.Name', $ordermode); $query->orderBy('Account.Identifier', $ordermode); $query->orderBy('UserRelatedByUserId.Name', $ordermode); break; } $query->orderById($ordermode); $result = array(); foreach ($query->find() as $booking) { $result[] = EntityArray::from($booking); } return $result; }
/** * Merge a EntityArray to current EntityArray * @param EntityArray $entityArray * @return EntityArray */ public function merge(EntityArray $entityArray) { $list = new EntityArray(); // set model table if both arrays have the same model table if ($this->getModelTable() == $entityArray->getModelTable()) { $list->setModelTable($this->getModelTable()); } foreach ($this as $object) { $list->append($object); } foreach ($entityArray as $object) { $list->append($object); } return $list; }
public function showModif($db) { echo "<div id=\"body_content\">\n\t\t\t<div class=\"body\">\n\t\t\t<p> Modification de l'utilisateur : " . $this->_lastName . " " . $this->_firstName . " </p>"; try { echo "<form action=\"user.php?modif_id=" . $this->_id . "\" method=\"POST\">"; if ($db != null) { $query = "SELECT * FROM entity"; $sth = $db->prepare($query); $sth->execute(); $datas = $sth->fetchAll(); if (count($datas) > 0) { echo "Entité de rattachement de l'utilisateur : <select name=\"entity\" class=\"entity\">"; foreach ($datas as $data) { $entity_array = new EntityArray(); $entity_array->setEntityData($data['id'], null, $data['short_name']); } $entity_array->showModif($db, $this->_entityShortName); // Affichage du bandeau déroulant pour selectionner l'entité de rattachement echo "</select><br />"; echo "<label>Prénom : </label><input name=\"firstname\" type=\"text\" class=\"firstname\" placeholder=\"Prénom\" value=\"" . $this->_firstName . "\" required=\"required\" title=\"Prénom de l'utilisateur\"><br />\n\t\t\t\t\t\t<label>Nom : </label><input name=\"lastname\" type=\"text\" class=\"lastname\" placeholder=\"Nom de Famille\" value=\"" . $this->_lastName . "\" required=\"required\" title=\"Nom de famille de l'utilisateur\"><br />\n\t\t\t\t\t\t<label>e-mail : </label><input name=\"email\" type=\"text\" class=\"email\" placeholder=\"e-mail\" value=\"" . $this->_login . "\" required=\"required\" title=\"e-mail de service de l'utilisateur\"><br />\n\t\t\t\t\t\t<label>Mot de passe : </label><input name=\"password\" type=\"text\" placeholder=\"Password\" value=\"" . $this->_password . "\" required=\"required\" autocomplete=\"off\"><span class=\"marge\"></span><a href=\"mdp.php\" target=\"_blank\">Hashez le nouveau mot de passe </a><br />\n\t\t\t\t\t\t<input type=\"submit\" value=\"Créer\">\n\t\t\t\t\t</form>\n\n\t\t\t\t\t-><a href=\"user.php\"> retour</a>\n\t\t\t\t\t</div>\n\t\t\t\t</div>"; } } } catch (Exception $e) { // Catch des erreurs et écriture dans le fichier de log require 'error_log.php'; } }
public function showModif($db) { echo "<div id=\"body_content\">\n\t\t\t<div class=\"body\">\n\t\t\t<p> Modification du site : " . $this->_shortName . " (" . $this->_entityShortName . ") </p>"; try { echo "<form action=\"sites.php?modif_id=" . $this->_id . "\" method=\"POST\">\n\t\t\tEntité de rattachement du site : <select name=\"entity\" class=\"entity\">"; if ($db != null) { $query = "SELECT * FROM entity"; $sth = $db->prepare($query); $sth->execute(); $datas = $sth->fetchAll(); if (count($datas) > 0) { foreach ($datas as $data) { $entity_array = new EntityArray(); $entity_array->setEntityData($data['id'], null, $data['short_name']); } $entity_array->showModif($db, $this->_entityShortName); // Affichage du bandeau déroulant des entités auxquelles rattacher le site echo "</select><br />"; echo "<label>Nom du site : </label><input name=\"complete_name\" type=\"text\" class=\"complete_name\" placeholder=\"Nom Complete\" value=\"" . $this->_name . "\" required=\"required\" title=\"Nom complet de l'entité\"><br />\n\t\t\t\t\t\t<label>Nom court du site : </label><input name=\"short_name\" type=\"text\" class=\"short_name\" placeholder=\"Nom Court\" value=\"" . $this->_shortName . "\" required=\"required\" title=\"Nom court de l'entité\"><br />\n\t\t\t\t\t\t<input type=\"submit\" value=\"Créer\">\n\t\t\t\t\t</form>\n\n\t\t\t\t\t-><a href=\"sites.php\"> retour</a>\n\t\t\t\t\t</div>\n\t\t\t\t</div>"; } } } catch (Exception $e) { // Catch des erreurs et écriture dans le fichier de log require 'error_log.php'; } }
echo "<font color=\"FE2E2E\">Commande inconnue</font>"; } } } else { // On affiche le tableau d'entité existante try { // Récupération des entités existante en BDD $query = "SELECT * FROM entity ORDER BY short_name ASC"; $sth = $db->prepare($query); $sth->execute(); $datas = $sth->fetchAll(); if (count($datas) > 0) { // Début de l'affichage du tableau des entité echo "<div class=\"table\"><table border=\"1\"><tr><th> Nom Complet </th><th> Nom Court </th></tr>"; foreach ($datas as $data) { $entity_array = new EntityArray(); // création du tableau d'objet entité $entity_array->setEntityData($data['id'], $data['name'], $data['short_name']); // affectation des attributs de l'objet avec les valeurs existantes en BDD } $entity_array->showData(); // On affiche chaque objet du tableau, chaque objet correspondant à une ligne du tableau echo "</table></div><a href=\"new_entity.php\">créer une nouvelle entité</a>"; } else { echo "<font color=\"FE2E2E\">Requête échoué</font>"; } } catch (Exception $e) { // Catch des erreurs et écriture dans le fichier de log require 'error_log.php'; } }
/** * Removes a clocking entry * * @param int $id The clocking ID */ public function do_remove($id) { $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $authUser = $this->requireUser($con); $clocking = $this->getClockingById($id, $con); if ($clocking->getBooked()) { throw new Exception('Cannot remove clocking entry #' . $id . ' because it already has bookings. Please remove the transactions instead.'); } if (!$clocking->isOpen() and !$authUser->isAdmin()) { $account = $authUser->getAccount($con); if ($account === null) { throw new Exception('Could not get account of user #' . $authUser->getId() . ' "' . $authUser->getFQN($con) . '".'); } $type = $clocking->getClockingType($con); if ($type === null) { throw new Exception('Could not get clocking type with ID #' . $clocking->getTypeId() . '.'); } $this->validateTimeLimits($account, $authUser, $clocking, $con); } $clockingUser = $clocking->getUserRelatedByUserId($con); if ($clockingUser === null) { throw new Exception('Could not determine clocking\'s assigned user #' . $clocking->getUserId() . '.'); } PluginPeer::fireEvent($clockingUser, 'clocking', 'remove', EntityArray::from($clocking, $con), $con); $clocking->setDeleted(1)->save($con); } catch (Exception $e) { $con->rollBack(); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return true; }