/** * Returns not the IDs of the item, module, user, etc. but real values. * * @param integer $userId The ID of the user who calls this method. * * @return array Array with 'user', 'module', 'process', 'description', 'itemId', * 'item', 'projectId', 'details', 'time' and 'project'. */ public function getMessage($userId) { $messageData = $this->getMessageData($userId); $data = array(); $this->_deleteOutdatedMessages(); if (true === empty($messageData)) { return false; } $userObject = new Phprojekt_User_User(); $user = $userObject->find($messageData[0]->actorId); $data['user'] = $userObject->displayName; $data['module'] = ucfirst(Phprojekt_Module::getModuleName($messageData[0]->moduleId)); $data['process'] = $messageData[0]->process; $data['description'] = Phprojekt::getInstance()->translate($messageData[0]->description); $data['itemId'] = $messageData[0]->itemId; $data['item'] = $messageData[0]->itemName; $data['projectId'] = $messageData[0]->projectId; $data['details'] = $messageData[0]->details; // Convert time to user timezone if ($messageData[0]->process == Phprojekt_Notification::LAST_ACTION_REMIND) { $addTime = Phprojekt::getInstance()->getConfig()->remindBefore * 60; } else { $addTime = 0; } $data['time'] = date("H:i", Phprojekt_Converter_Time::utcToUser($messageData[0]->validFrom) + $addTime); // Convert project name $project = new Project_Models_Project(); $data['project'] = $project->find($data['projectId'])->title; return $data; }
/** * Test saveToBackingStore function */ public function testSaveToFilter() { $user = new Phprojekt_User_User(array('db' => $this->sharedFixture)); $user->find(1); $record = new Phprojekt_Project(array('db' => $this->sharedFixture)); $filter = new Phprojekt_Filter_UserFilter($record, 'title', 'PHProjekt'); $tree = new Phprojekt_Tree_Node_Database($record, 1); $tree = $tree->setup($filter); $filter->saveToBackingStore($user); }
/** * Sets the recipients according to the received IDs. * * @param array $recipients Array with user IDs. * * @return void */ public function setTo($recipients) { $phpUser = new Phprojekt_User_User(); $setting = new Phprojekt_Setting(); foreach ($recipients as $recipient) { $email = $setting->getSetting('email', (int) $recipient); if (!empty($email)) { if ((int) $recipient) { $phpUser->find($recipient); } else { $phpUser->find(Phprojekt_Auth::getUserId()); } $name = trim($phpUser->firstname . ' ' . $phpUser->lastname); if (!empty($name)) { $name = $name . ' (' . $phpUser->username . ')'; } else { $name = $phpUser->username; } $this->addTo($email, $name); } } }
/** * Returns the detail (fields and data) of one user. * * The return have: * - The metadata of each field. * - The data of the user. * - The number of rows. * * If the request parameter "id" is null or 0, the data will be all values of a "new user", * if the "id" is an existing user, the data will be all the values of the user. * * OPTIONAL request parameters: * <pre> * - integer <b>id</b> id of the user to consult. * </pre> * * The return is in JSON format. * * @return void */ public function jsonDetailAction() { $user = new Phprojekt_User_User(); $id = (int) $this->getRequest()->getParam("id"); $user->find($id); $data = array(); $data['id'] = $user->id; $data['username'] = empty($user->username) ? "" : $user->username; $data['firstname'] = empty($user->firstname) ? "" : $user->firstname; $data['lastname'] = empty($user->lastname) ? "" : $user->lastname; $data['status'] = empty($user->status) ? "" : $user->status; $data['admin'] = empty($user->admin) ? "" : $user->admin; $setting = new Phprojekt_Setting(); $setting->setModule('User'); $fields = $setting->getModel()->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); $values = $setting->getList(0, $fields, $user->id); $values = $values[0]; unset($values['id']); if (!empty($data['id'])) { $data = array_merge($data, $values); } else { foreach ($fields as $field) { if (!array_key_exists($field['key'], $values)) { continue; } if (!is_null($field['default'])) { $data[$field['key']] = $field['default']; } else { $data[$field['key']] = ""; } } } $records = array($data); $metadata = $user->getInformation(Phprojekt_ModelInformation_Default::ORDERING_FORM); $metadata = $metadata->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); $data = array("metadata" => $metadata, "data" => $records, "numRows" => count($records)); Phprojekt_Converter_Json::echoConvert($data); }
/** * Test the display */ public function testdisplay() { $user = new Phprojekt_User_User(); $this->assertEquals(array('lastname', 'firstname'), $user->getDisplay()); $user->find(2); $this->assertEquals('Solt, Gustavo', $user->applyDisplay(array('lastname', 'firstname'), $user)); $this->assertEquals('gus, Solt, Gustavo', $user->applyDisplay(array('username', 'lastname', 'firstname'), $user)); $this->assertEquals('gus', $user->applyDisplay(array('username'), $user)); }
protected function _isValidUserId($userId) { if (!is_numeric($userId) || $userId < 1) { return false; } $validUser = false; $user = new Phprojekt_User_User(); if ($user->find((int) $userId)) { $validUser = true; } return $validUser; }
/** * Test the display */ public function testdisplay() { $user = new Phprojekt_User_User(); $this->assertEquals(array('lastname', 'firstname'), $user->getDisplay()); $user->find(1); $this->assertEquals('Mustermann, Max', $user->applyDisplay(array('lastname', 'firstname'), $user)); $this->assertEquals('Test, Mustermann, Max', $user->applyDisplay(array('username', 'lastname', 'firstname'), $user)); $this->assertEquals('Test', $user->applyDisplay(array('username'), $user)); }
/** * Sends a mail containing the Minutes protocol. * * A pdf can be also attached to the mail. * * REQUIRES request parameters: * <pre> * - integer <b>id</b> id of the minute to send. * </pre> * * OPTIONAL request parameters: * <pre> * - array <b>options</b> If contain 'pdf', a pdf is attached to the mail. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success' or 'error'. * - message => Success or error message. * - id => id of the minute. * </pre> * * @throws Zend_Controller_Action_Exception On error in the send action or wrong id. * * @return void */ public function jsonSendMailAction() { $errors = array(); $params = $this->getRequest()->getParams(); $this->setCurrentProjectId(); // Sanity check if (empty($params['id']) || !is_numeric($params['id'])) { throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400); } $minutesId = (int) $params['id']; $minutes = $this->getModelObject()->find($minutesId); // Was the id provided a valid one? if (!$minutes instanceof Phprojekt_Model_Interface || !$minutes->id) { // Invalid ID throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400); } // Security check: is the current user owner of this minutes entry? if ($minutes->ownerId != PHprojekt_Auth::getUserId()) { throw new Zend_Controller_Action_Exception(self::USER_IS_NOT_OWNER, 403); } $mail = new Phprojekt_Mail(); /* @var $mail Zend_Mail */ $smtpTransport = $mail->setTransport(); $validator = new Zend_Validate_EmailAddress(); $emailsListed = $this->getRequest()->getParam('recipients', array()); $emailsListed = $this->_getMailFromUserIds($emailsListed, $validator); $emailsWritten = $this->getRequest()->getParam('additional', ''); $emailsWritten = $this->_getMailFromCsvString($emailsWritten, $validator); $userMails = array_merge($emailsListed, $emailsWritten); $errors = $this->_addRecipients($mail, $userMails, $errors); // Sanity check if (array() === $mail->getRecipients()) { $errors[] = array('message' => self::MISSING_MAIL_RECIPIENTS, 'value' => null); } if (!count($errors)) { // Handle PDF attachment if needed if (!empty($params['options']) && is_array($params['options'])) { if (in_array('pdf', $params['options'])) { $pdf = (string) Minutes_Helpers_Pdf::getPdf($minutes); $mail->createAttachment($pdf, 'application/x-pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_8BIT, 'minutes_' . $minutesId . '.pdf'); } } // Set sender address $ownerModel = new Phprojekt_User_User(); $ownerModel->find($minutes->ownerId); $ownerEmail = $ownerModel->getSetting('email'); $mail->setFrom($ownerEmail, $ownerModel->displayName); // Set subject $subject = sprintf('%s "%s", %s', Phprojekt::getInstance()->translate('Meeting minutes for'), $minutes->title, $minutes->meetingDatetime); $mail->setSubject($subject); // Set mail content $mail->setBodyText($subject, 'utf-8'); $mail->setBodyHtml($this->_getHtmlList($minutes), 'utf-8'); // Keep send() commented out until test phase is over $mail->send($smtpTransport); $return = array('type' => 'success', 'message' => Phprojekt::getInstance()->translate(self::MAIL_SUCCESS_TEXT), 'id' => $minutesId); } else { $message = Phprojekt::getInstance()->translate(self::MAIL_FAIL_TEXT); foreach ($errors as $error) { $message .= "\n"; $message .= sprintf("%s %s", Phprojekt::getInstance()->translate($error['message']), $error['value']); } $return = array('type' => 'error', 'message' => nl2br($message), 'id' => $minutesId); } Phprojekt_Converter_Json::echoConvert($return); }
/** * Test create an user */ public function testCreateUser() { try { $user = new Phprojekt_User_User(array('db' => $this->sharedFixture)); $user->username = '******'; $user->firstname = 'Gustavo'; $user->lastname = 'Solt'; $this->assertTrue($user->save()); $gustavo = new Phprojekt_User_User(array('db' => $this->sharedFixture)); $gustavo->find($user->id); $this->assertEquals('gustavo', $gustavo->username); } catch (Exception $e) { $this->fail($e->getMessage()); } }
/** * Has Many and belongs to many test * * @return void */ public function testHasManyAndBelongsToMany() { $user = new Phprojekt_User_User(array('db' => $this->sharedFixture)); $user->find(1); $group = $user->groups->fetchAll(); $this->assertEquals('default', $user->groups->find(1)->name); $this->assertEquals('ninasgruppe', $group[1]->name); $this->assertEquals('TEST GROUP', $group[2]->name); $this->assertEquals(5, $user->groups->count()); $group = new Phprojekt_Groups_Groups(array('db' => $this->sharedFixture)); $group->find(1); $users = $group->users->fetchAll(); $this->assertEquals('david', $users[0]->username); $this->assertEquals(5, $group->users->count()); }
/** * Save the login data into Settings and Cookies. * * @param integer $userId Current user ID. * * @return void */ private static function _saveLoginData($userId) { // The hash string is changed everytime it is used, and the expiration time updated. // DB Settings table: create new md5 hash and update expiration time for it // Set the settings pair to save $pair = array(self::LOGGED_TOKEN . '_hash' => md5(time() . mt_rand()), self::LOGGED_TOKEN . '_expires' => strtotime('+1 week')); // Store matching keepLogged data in DB and browser $user = new Phprojekt_User_User(); $user->find($userId); $settings = $user->settings->fetchAll(); foreach ($pair as $key => $value) { $found = false; foreach ($settings as $setting) { // Update if ($setting->keyValue == $key) { $setting->value = $value; $setting->save(); $found = true; break; } } if (!$found) { // Create $record = $user->settings->create(); $record->moduleId = 0; $record->keyValue = $key; $record->value = $value; $record->identifier = 'Login'; $record->save(); } } // Cookies: update md5 hash and expiration time // If we are under Unittest execution, don't work with cookies: if (!headers_sent()) { self::_setCookies($pair[self::LOGGED_TOKEN . '_hash'], $userId, $pair[self::LOGGED_TOKEN . '_expires']); } }