public function testError() { Logger::err('foo'); $this->assertEquals(1, preg_match('/ERR \\(' . Zend_Log::ERR . '\\): foo/', file_get_contents(Logger::$logStream))); }
/** * User profile action * * @return void */ public function profileAction() { $request = $this->getRequest(); $user = $this->_user; $form = new \Application_Form_UserUpdate($user); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $data = $form->getValues(); try { $changed = $this->_updateUser($user, $data); $this->view->success = 1; if ($changed) { $message = 'Profile updated successfully.'; $msgPriority = 'success'; $form = new \Application_Form_UserUpdate($user); } else { $message = 'No changes were made.'; $msgPriority = 'notice'; } $this->view->messages()->addMessage($message, $msgPriority); } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500); $this->view->success = 0; #$message = ('development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: UCPA001'); $message = 'Application error: UCPA001 - ' . $e->getMessage(); $this->view->messages()->addMessage($message, 'error'); Logger::err($e->getMessage()); } } else { // Submitted form data is invalid $this->getResponse()->setHttpResponseCode(500); $this->view->success = 0; } } else { // Not a POST request } $this->view->form = $form; JqueryViewHelper::assignData(array('userId' => $user->getId())); }
/** * Theme action * * @return void */ public function themeAction() { $request = $this->getRequest(); $form = new \Admin_Form_SiteTheme(); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $data = $form->getValues(); try { // Uploaded image or remote image? if (isset($data['remoteImage']) && !empty($data['remoteImage'])) { // Remote image } else { // Uploaded image if (!$form->logo->isUploaded() || !$form->logo->receive()) { throw new Admin_SiteControllerException('Image upload failed'); } Logger::debug(__METHOD__ . ':: logo = ' . $form->logo->getFileName()); $imgPath = $form->logo->getFileName(); } $imageInfo = getimagesize($imgPath); $filename = basename($imgPath); $image = array('width' => $imageInfo[0], 'height' => $imageInfo[1], 'mime' => $imageInfo['mime'], 'filename' => $filename, 'path' => $imgPath); Logger::debug(__METHOD__ . ':: imageInfo = ' . var_export($imageInfo, true)); Logger::debug(__METHOD__ . ':: filename = ' . $filename); // Move uploaded logo image to public accessible folder #rename($imgPath, APPLICATION_PATH . '/public/images/tmp/' . $filename); # or use something like /preview?type=image&name=xx script to return image from upload folder? # /preview?t=theme&n=filename.png $templateLogoMaxWidth = 286; $templateLogoMaxHeight = 77; Logger::debug(__METHOD__ . ":: maxWidth x maxHeight = {$templateLogoMaxWidth} x {$templateLogoMaxHeight}"); if ($imageInfo[0] > $templateLogoMaxWidth || $imageInfo[1] > $templateLogoMaxHeight) { /* // Use GD/ImageMagick to resize image to fit template $newWidth = $templateLogoMaxWidth; $newHeight = $templateLogoMaxHeight; if($imageInfo[0] > $imageInfo[1]) { // width > height $newHeight = $imageInfo[1] * ($templateLogoMaxHeight / $imageInfo[0]); } elseif($imageInfo[0] < $imageInfo[1]) { // width < height $newWidth = $imageInfo[0] * ($templateLogoMaxWidth / $imageInfo[1]); } Logger::debug(__METHOD__.":: newWidth x newHeight = $newWidth x $newHeight"); $this->_resizeImage($image, $newWidth, $newHeight); */ $this->_resizeImage($image, $templateLogoMaxWidth, $templateLogoMaxHeight); $imageInfo = getimagesize($image['path']); if ($imageInfo[0] > $templateLogoMaxWidth || $imageInfo[1] > $templateLogoMaxHeight) { throw new Admin_SiteControllerException('Failed to resize image'); } } $this->view->assign(array('filename' => $filename, 'width' => $imageInfo[0], 'height' => $imageInfo[1], 'success' => 1)); #$message = 'Logo uploaded successfully.'; #$this->_helper->sessionMessenger($message, 'success'); } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500); $this->view->success = 0; $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: ASiT001'; $this->view->messages()->addMessage($message, 'error'); Logger::err($e->getMessage()); } } else { // Subnmitted form data is invalid $this->getResponse()->setHttpResponseCode(500); $this->view->success = 0; } } else { // Not a POST request } $this->view->form = $form; // Special handling for AJAX form submissions if ($request->isPost() && $request->isXmlHttpRequest()) { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $vars = $this->view->getVars(); unset($vars['form']); #$this->getResponse()->setBody('<textarea>' . Zend_Json::encode($vars) . '</textarea>'); $this->getResponse()->setHeader('Content-Type', 'application/json')->setBody(Zend_Json::encode($vars)); } }
/** * Edit action * * @return void */ public function editAction() { $request = $this->getRequest(); $timeZone = new DateTimeZone($this->_user->getProfile()->getTimeZone()->getName()); $params = $request->getParams(); // Get the user that is being updated $userId = $request->getParam('userId', null); if (null === ($user = UserService::findOneById($userId))) { throw new \Admin_UsersControllerException('No user found.'); } $form = new \Admin_Form_UserEdit(); $form->setDefaultsFromUser($user); // Pre-validate form; set conditional requirements $form->preValidate($request->getParams()); if ($request->isPost()) { // AJAX request with partial form submission? (probably an AJAX request to update a single property) if ($request->isXmlHttpRequest() && $form->isValidPartial($params)) { #Logger::debug(__METHOD__.':: params-pre = '.var_export($params, true)); $params = array_merge($params, $this->_prepFormData($form->getValues(), $user)); #Logger::debug(__METHOD__.':: params-post = '.var_export($params, true)); } if ($form->isValid($params)) { $data = $form->getValues(); #Logger::debug(__METHOD__.':: data = '.var_export($data, true)); try { $changed = $this->_updateUser($user, $data); $this->view->success = 1; $this->view->userId = $userId; if ($changed) { $message = 'User modified successfully.'; $msgPriority = 'success'; } else { $message = 'No changes were made.'; $msgPriority = 'notice'; } if (!$request->isXmlHttpRequest()) { $this->_helper->sessionMessenger($message, $msgPriority); return $this->_helper->getHelper('Redirector')->gotoRoute(array(), 'adminUsers'); } $this->view->messages()->addMessage($message, $msgPriority); } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500); $this->view->success = 0; $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: AUCEA001'; $this->view->messages()->addMessage($message, 'error'); Logger::err(__METHOD__ . '::' . $e->getMessage()); } } else { // Submitted form data is invalid $this->getResponse()->setHttpResponseCode(500); $this->view->success = 0; Logger::debug(__METHOD__ . ':: formErrors = ' . var_export($form->getMessages(), true)); if ($request->isXmlHttpRequest()) { $this->view->messages()->addMessage('Application error: AUCEA000', 'error'); #$this->view->messages()->addMessage($form->getMessages(), 'error'); } } } else { // Not a POST request $form->setDefaultsFromUser($user); } $this->view->assign(array('editHistory' => UserEditEventService::findByUser($user->getId()), 'timeZone' => $timeZone, 'form' => $form, 'userId' => $userId)); JqueryViewHelper::assignData(array('userId' => $userId)); }