当前位置: 首页>>代码示例>>PHP>>正文


PHP UserService::getUserByField方法代码示例

本文整理汇总了PHP中UserService::getUserByField方法的典型用法代码示例。如果您正苦于以下问题:PHP UserService::getUserByField方法的具体用法?PHP UserService::getUserByField怎么用?PHP UserService::getUserByField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserService的用法示例。


在下文中一共展示了UserService::getUserByField方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calcAction

 /**
  * Calculates the leave left for a given user
  */
 public function calcAction()
 {
     $username = $this->_getParam('username');
     $user = $this->userService->getUserByField('username', $username);
     $type = $this->_getParam('type', 'Annual');
     $validTypes = array('Annual', 'Sick', 'Long Service');
     if (!in_array($type, $validTypes)) {
         return;
     }
     if ($user == null) {
         $this->log->warn("Invalid username");
         echo 0;
         return;
     }
     // Calculate how much is left
     $leave = $this->userService->getLeaveForUser($user);
     $accruedLeave = $this->userService->calculateLeave($user);
     $leaveApplications = $this->userService->getLeaveApplicationsForUser($user);
     $leaveTotal = 0;
     $leaveTotals = array();
     foreach ($leaveApplications as $app) {
         if ($app->status == LeaveApplication::LEAVE_APPROVED) {
             $current = ifset($leaveTotals, $app->leavetype, 0);
             $current += $app->days;
             $leaveTotals[$app->leavetype] = $current;
         }
     }
     if ($type == 'Annual') {
         echo "About " . sprintf("%d", floor($leave->days + $accruedLeave - ifset($leaveTotals, "Annual", 0))) . " days of annual leave available, " . ifset($leaveTotals, "Annual", 0) . " taken";
     } else {
         echo ifset($leaveTotals, $type, 0) . ' days of ' . $type . ' leave taken';
     }
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:36,代码来源:LeaveController.php

示例2: synchroniseUser

 /**
  * Create or update a user's account
  *
  * @param string $username
  * @param array $entry
  */
 private function synchroniseUser($entry)
 {
     $mapping = ifset($this->config, 'mapping', array());
     $username = ifset($entry, $mapping['username'], false);
     if (!$username) {
         throw new Exception("No username mapping found.");
     }
     // Cast back from the array representation
     $username = $username[0];
     // get all the user's details and map the relevant attributes... which we'll skip!
     $user = $this->userService->getUserByField('username', $username);
     if ($user == null) {
         $params = array();
         $params['username'] = $username;
         $params['password'] = md5(time() . rand(1, 10000));
         // Fill in mapped params
         $email = ifset($entry, $mapping['email'], null);
         if ($email) {
             $email = $email[0];
         } else {
             $email = $params['password'] . '@null.com';
         }
         $params['email'] = $email;
         try {
             $user = $this->userService->createUser($params, false);
         } catch (Exception $e) {
             $this->log->err("Failed creating user for {$username}: " . $e->getMessage() . ': ' . current_url() . "\r\n" . print_r($params, true));
             return null;
         }
     }
     za()->log(__CLASS__ . ':' . __LINE__ . " User is " . get_class($user));
     return $user;
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:39,代码来源:LdapAuthComponent.php

示例3: saveContact

 /**
  * Save a contact against a given client object
  * 
  *
  * @param array|Contact $params 
  * @return Contact
  */
 public function saveContact($params)
 {
     $contact = null;
     try {
         $this->dbService->beginTransaction();
         // Get an existing one
         $contact = $this->dbService->saveObject($params, 'Contact');
         // check for a user object to also update
         if ($contact->id) {
             $user = $this->userService->getUserByField('contactid', $contact->id);
             if ($user) {
                 $params = array('firstname' => $contact->firstname, 'lastname' => $contact->lastname, 'email' => $contact->email);
                 $this->userService->updateUser($user, $params);
             }
         }
         $this->trackerService->track('update-contact', $contact->id, null, null, print_r($params, true));
         $this->dbService->commit();
     } catch (Exception $e) {
         $this->dbService->rollback();
         $this->log->err("Failed creating contact for params " . print_r($params, true) . ": " . $e->getMessage());
         $contact = null;
         throw $e;
     }
     return $contact;
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:32,代码来源:ClientService.php

示例4: detailedtimesheetAction

 /**
  * Get the detailed timesheet for this project.
  *
  */
 public function detailedtimesheetAction()
 {
     $project = $this->projectService->getProject($this->_getParam('projectid'));
     $client = $this->clientService->getClient($this->_getParam('clientid'));
     $task = $this->projectService->getTask($this->_getParam('taskid'));
     $user = $this->userService->getUserByField('username', $this->_getParam('username'));
     if (!$project && !$client && !$task && !$user) {
         return;
     }
     if ($task) {
         $this->view->records = $this->projectService->getDetailedTimesheet(null, $task->id);
     } else {
         if ($project) {
             $start = null;
             $this->view->records = $this->projectService->getDetailedTimesheet(null, null, $project->id);
         } else {
             if ($client) {
                 $start = null;
                 $this->view->records = $this->projectService->getDetailedTimesheet(null, null, null, $client->id);
             } else {
                 if ($user) {
                     $this->view->records = $this->projectService->getDetailedTimesheet($user);
                 }
             }
         }
     }
     $this->view->task = $task;
     $this->renderRawView('timesheet/ajax-timesheet-details.php');
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:33,代码来源:TimesheetController.php

示例5: notifyUser

 /**
  * Notify the user (or users) about something
  *
  * @param string $subject
  * @param array|User $user
  * @param string $msg
  */
 public function notifyUser($subject, $users, $msg, $from = null, $fromname = null, $html = false)
 {
     include_once 'Zend/Mail.php';
     if (!is_array($users) && !$users instanceof ArrayAccess) {
         $users = array($users);
     }
     foreach ($users as $u) {
         if (!$u instanceof NovemberUser) {
             $this->log->debug("Getting user for " . var_export($u, true));
             $u = $this->userService->getUserByField('username', $u);
         }
         if ($u == null) {
             $this->log->debug("Tried sending to non-existent user");
             continue;
         }
         $mail = new Zend_Mail();
         if ($from == null) {
             $mail->setFrom(za()->getConfig('from_email'), za()->getConfig('name'));
         } else {
             if (!$fromname) {
                 $fromname = za()->getConfig('name');
             }
             $mail->setFrom($from, $fromname);
         }
         $message = null;
         if ($msg instanceof TemplatedMessage) {
             $msg->model['user'] = $u;
             $message = $this->generateEmail($msg->template, $msg->model);
         } else {
             $message = $msg;
         }
         if ($html) {
             $mail->setBodyHtml($message);
         } else {
             $mail->setBodyText($message);
         }
         $mail->addTo($u->email, $u->username);
         $mail->setSubject($subject);
         try {
             $this->log->debug("Sending message '{$subject}' to " . $u->email);
             $mail->send();
         } catch (Zend_Mail_Transport_Exception $e) {
             $this->log->debug(__CLASS__ . ':' . __LINE__ . " Failed sending mail: " . $e->getMessage());
             throw $e;
         }
     }
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:54,代码来源:NotificationService.php

示例6: setwatchersAction

 /**
  * Update all the watchers for a given item
  */
 public function setwatchersAction()
 {
     $itemType = ucfirst($this->_getParam('attachedtotype'));
     $itemId = $this->_getParam('attachedtoid');
     if ($itemType == null || $itemId == null) {
         $this->flash("Could not update subscribers, null request passed");
         $this->redirect('error');
         return;
     }
     // get all watchers and then remove
     $subscribers = $this->notificationService->deleteAllSubscribers($itemId, $itemType);
     foreach ($this->_getParam('watchusers') as $username) {
         $user = $this->userService->getUserByField('username', $username);
         $this->notificationService->createWatch($user, $itemId, $itemType);
     }
     $caller = $this->getCallingUrl();
     if ($this->_getParam('_ajax')) {
     } else {
         if (mb_strlen($caller)) {
             $this->_redirect($caller);
         }
     }
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:26,代码来源:NoteController.php

示例7: useraccessAction

 /**
  * Action to list the access a user has to certain elements
  *
  */
 public function useraccessAction()
 {
     $username = $this->_getParam('username');
     if ($username == null) {
         $this->flash("Must provide username!");
         $this->redirect('admin');
         return;
     }
     $this->view->access = $this->accessService->getAccessList($username);
     $this->view->user = $this->userService->getUserByField('username', $username);
     $this->view->modules = za()->getConfig('modules');
     $this->view->modules[] = 'default';
     $this->renderView('admin/user-access.php');
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:18,代码来源:AdminController.php

示例8: markPaidExpenses

 /**
  * Marks all expenses in an expense report as paid
  */
 public function markPaidExpenses(ExpenseReport $report)
 {
     try {
         $this->dbService->beginTransaction();
         $this->dbService->update('expense', array('paiddate' => $report->paiddate), 'expensereportid=' . (int) $report->id);
         $this->dbService->update('expense', array('paiddate' => $report->paiddate), 'userreportid=' . (int) $report->id);
         // Get all the expenses affected, and notify the user involved that it's been paid
         // If a username is set on the report, it's based around user expenses,
         // so just get those
         $expenses = array();
         if (mb_strlen($report->username)) {
             $expenses = $this->getExpenses(array('userreportid=' => $report->id));
         } else {
             $expenses = $this->getExpenses(array('expensereportid=' => $report->id));
         }
         // Keep a map of user -> expenses for that user to limit the number
         // of emails to send
         $userExpenseMap = new ArrayObject();
         foreach ($expenses as $expense) {
             /* @var $expense Expense */
             $user = $this->userService->getUserByField('username', $expense->username);
             $userExpenses = ifset($userExpenseMap, $user->username, array());
             $userExpenses[] = $expense;
             $userExpenseMap[$user->username] = $userExpenses;
         }
         foreach ($userExpenseMap as $username => $expenses) {
             // create the email for this user and send it away
             $msg = new TemplatedMessage('expense-paid.php', array('expenses' => $expenses));
             $this->notificationService->notifyUser('Expenses Paid', $username, $msg);
             $this->log->debug("Sent email to {$username}");
         }
         $this->dbService->commit();
     } catch (Exception $e) {
         $this->dbService->rollback();
         throw $e;
     }
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:40,代码来源:ExpenseService.php

示例9: processIncomingEmails

 /**
  * Processes incoming emails so that issues can be created/updated
  *
  * @param unknown_type $emails
  */
 public function processIncomingEmails($emails)
 {
     foreach ($emails as $mail) {
         // First we need to find which customer the email belongs to
         $from = ifset($mail->headers, 'from', false);
         if (!$from) {
             za()->log("Failed finding from email header in " . print_r($mail, true));
             continue;
         }
         // clean it up a bit
         if (!preg_match("/[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}/i", $from, $matches)) {
             za()->log("Error finding valid email address", Zend_Log::ERR);
             continue;
         }
         $email = $matches[0];
         // Get the contact now. If it doesn't exist that's okay, it
         // might be a system user instead.
         $contact = $this->clientService->getContactByField('email', $email);
         // If not found by primary, try secondary
         if (!$contact) {
             $contact = $this->clientService->getContactByField('altemail', $email);
         }
         // We'll also see whether this issue was sent in by a user
         // of the system.
         $user = $this->userService->getUserByField('email', $email);
         if (!$contact && !$user) {
             za()->log("No valid user found with 'from' address {$email}", Zend_Log::WARN);
             $this->trackerService->track('invalid-issue-email', $email, null, null, serialize($mail));
             continue;
         }
         // Next up, see if the contact has an associated user, because
         // we'll add them in as the 'creator' of the issue
         if ($contact != null) {
             $contactUser = $this->userService->getUserbyField('contactid', $contact->id);
             if ($contactUser != null) {
                 $user = $contactUser;
             }
         }
         if ($user != null) {
             za()->setUser($user);
         }
         $params = array();
         // Saving a new issue uses the title of the email
         $subject = ifset($mail->headers, 'subject', false);
         if (!$subject) {
             // we'll accept an empty subject, just create a default title
             $subject = "Support request from {$from}";
         }
         $textBody = $this->emailService->getTextBody($mail);
         $issue = null;
         // Try and get an existing ticket
         za()->log("Checking email subject {$subject}");
         if (preg_match("/#(\\d+)/", $subject, $matches)) {
             // existing
             $id = $matches[1];
             $issue = $this->getIssue($id);
             if ($issue) {
                 za()->log("Adding note to request {$id}");
                 // Make sure the issue found currently belongs to the contact
                 // client!
                 // if there's no contact, make sure there's a user instead
                 if ($contact) {
                     if ($issue->clientid != $contact->clientid) {
                         $issue = null;
                     }
                 } else {
                     if (!$user) {
                         $issue = null;
                     }
                 }
             } else {
                 $this->log->warn("Request not found for id {$id}");
             }
         }
         $infoText = "";
         if ($user) {
             $infoText = "Email coming from user #" . $user->id . " -  " . $user->username . " ";
         }
         if ($contact) {
             $infoText = "Email coming from contact #" . $contact->id . " - " . $contact->firstname . " ";
         }
         $this->trackerService->track('incoming-issue-email', $email, null, null, "Processing email from " . $email . ": " . $infoText);
         $notifyOfId = false;
         // If we've already got an issue, it means we're wanting to
         // just update its comments
         if ($issue) {
             // Just add an additional comment to the
             // current issue.
             $poster = $contact ? $contact->firstname : $user->getUsername();
             $note = $this->notificationService->addNoteTo($issue, $textBody, $subject, $poster);
             $this->notificationService->sendWatchNotifications($note, array('controller' => 'issue', 'action' => 'edit', 'params' => array('id' => $issue->id)));
             za()->log("Note added to request {$issue->id}", Zend_Log::INFO);
         } else {
             // new
             $issue = new Issue();
//.........这里部分代码省略.........
开发者ID:nyeholt,项目名称:relapse,代码行数:101,代码来源:IssueService.php

示例10: viewAction

 /**
  * View the expenses for a given user / client
  */
 public function viewAction()
 {
     $view = new CompositeView();
     $view->addScriptPath('extensions/expenses/views');
     $report = $this->byId(null, 'ExpenseReport');
     $client = null;
     $user = null;
     $expenses = array();
     // we either have a fixed report, or we have a dynamic one
     if ($report) {
         if (mb_strlen($report->username)) {
             $expenses = $this->expenseService->getExpenses(array('userreportid=' => $report->id));
             $user = $this->userService->getUserByField('username', $report->username);
         } else {
             $expenses = $this->expenseService->getExpenses(array('expensereportid=' => $report->id));
             $client = $this->clientService->getClient($report->clientid);
         }
         $view->start = $report->from;
         $view->end = $report->to;
     } else {
         $client = $this->clientService->getClient($this->_getParam('clientid'));
         $user = $this->userService->getUserByField('username', $this->_getParam('username'));
         $view->user = $user;
         $start = $this->_getParam('start', $this->_getParam('start', $this->calculateDefaultStartDate()));
         $end = $this->_getParam('end', $this->_getParam('end', $this->calculateDefaultEndDate()));
         $expenses = $this->expenseService->getDynamicExpenseReport($start, $end, $user, $client);
         $view->start = $start;
         $view->end = $end;
     }
     $view->expenses = $expenses;
     $view->client = $client;
     $view->user = $user;
     $view->report = $report;
     $view->mode = $this->_getParam('pdf') ? 'pdf' : 'html';
     $content = $view->render('expense/view.php');
     if ($this->_getParam('pdf')) {
         ini_set('memory_limit', '32M');
         include_once "dompdf/dompdf_config.inc.php";
         include_once "dompdf/include/dompdf.cls.php";
         include_once "dompdf/include/frame_tree.cls.php";
         include_once "dompdf/include/stylesheet.cls.php";
         include_once "dompdf/include/frame.cls.php";
         include_once "dompdf/include/style.cls.php";
         include_once "dompdf/include/attribute_translator.cls.php";
         include_once "dompdf/include/frame_factory.cls.php";
         include_once "dompdf/include/frame_decorator.cls.php";
         include_once "dompdf/include/positioner.cls.php";
         include_once "dompdf/include/block_positioner.cls.php";
         include_once "dompdf/include/block_frame_decorator.cls.php";
         include_once "dompdf/include/frame_reflower.cls.php";
         include_once "dompdf/include/block_frame_reflower.cls.php";
         include_once "dompdf/include/frame_reflower.cls.php";
         include_once "dompdf/include/text_frame_reflower.cls.php";
         include_once "dompdf/include/canvas_factory.cls.php";
         include_once "dompdf/include/canvas.cls.php";
         include_once "dompdf/include/abstract_renderer.cls.php";
         include_once "dompdf/include/renderer.cls.php";
         include_once "dompdf/include/cpdf_adapter.cls.php";
         include_once "dompdf/include/font_metrics.cls.php";
         include_once "dompdf/include/block_renderer.cls.php";
         include_once "dompdf/include/text_renderer.cls.php";
         include_once "dompdf/include/image_cache.cls.php";
         include_once "dompdf/include/text_frame_decorator.cls.php";
         include_once "dompdf/include/inline_positioner.cls.php";
         include_once "dompdf/include/page_frame_reflower.cls.php";
         include_once "dompdf/include/page_frame_decorator.cls.php";
         include_once "dompdf/include/table_frame_decorator.cls.php";
         include_once "dompdf/include/cellmap.cls.php";
         include_once "dompdf/include/table_frame_reflower.cls.php";
         include_once "dompdf/include/table_row_frame_decorator.cls.php";
         include_once "dompdf/include/null_positioner.cls.php";
         include_once "dompdf/include/table_row_frame_reflower.cls.php";
         include_once "dompdf/include/table_cell_frame_decorator.cls.php";
         include_once "dompdf/include/table_cell_positioner.cls.php";
         include_once "dompdf/include/table_cell_frame_reflower.cls.php";
         include_once "dompdf/include/table_row_group_frame_decorator.cls.php";
         include_once "dompdf/include/table_row_group_frame_reflower.cls.php";
         include_once "dompdf/include/table_cell_renderer.cls.php";
         include_once "dompdf/include/inline_frame_decorator.cls.php";
         include_once "dompdf/include/inline_frame_reflower.cls.php";
         include_once "dompdf/include/image_frame_decorator.cls.php";
         include_once "dompdf/include/image_frame_reflower.cls.php";
         include_once "dompdf/include/inline_renderer.cls.php";
         include_once "dompdf/include/image_renderer.cls.php";
         include_once "dompdf/include/dompdf_exception.cls.php";
         $dompdf = new DOMPDF();
         // $dompdf->set_paper('letter', 'landscape');
         $dompdf->load_html($content);
         $dompdf->render();
         $name = "expenses-" . date('Y-m-d', strtotime($view->start)) . '-to-' . date('Y-m-d', strtotime($view->end)) . '.pdf';
         $dompdf->stream($name);
     } else {
         echo $content;
     }
 }
开发者ID:nyeholt,项目名称:relapse,代码行数:98,代码来源:ExpenseController.php


注:本文中的UserService::getUserByField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。