protected function _getSession() { if (!$this->_session) { $this->_session = App_Main::getSession(); } return $this->_session; }
/** * Processing data before saving user info * * @return Admin_Model_User */ protected function _beforeSave() { if ($this->userExists()) { $this->_dataSaveAllowed = false; App_Main::getSession()->addError('Username or email already exists'); return false; } return parent::_beforeSave(); }
/** * Get messages array by message type */ public function getMessages($type = null) { if (empty($this->_messages)) { $this->_messages = App_Main::getSession()->getMessages(true); } if ($this->_messages->getItems($type)) { return $this->_messages->getItems($type); } return false; }
/** * Load a project informaiton with JSON formated * * @return type */ public function loadAction() { if (!$this->isUserLoggedIn()) { echo Zend_Json::encode(array('success' => 0, 'redirect' => App_Main::getUrl(''))); return; } $projectId = $this->getRequestParam('project_bc_id'); if (!($project = App_Main::getSession()->getUser()->getProjectById($projectId, 'bc_id'))) { $project = App_Main::getModel('project/project')->load($projectId, 'bc_id'); } //$project->setEndDate('2011-05-10'); echo Zend_Json::encode(array('success' => 1, 'project' => $project->prepareDataForJson(true, true))); }
/** * Add a new website * @return type */ public function website_addAction() { $websiteCode = $this->getRequest()->getParam('website_code'); $website = App_Main::getModel('core/website'); if (!$website->validateWebsiteCode($websiteCode)) { App_Main::getSession()->addError('The website code you have specified is invalid or is already existing. Please try a new one code'); $this->_redirect('backend/config/websites'); return; } $website->setData('code', $websiteCode); $website->setData('name', $this->getRequest()->getParam('website_name')); $website->save(); $this->_redirect('backend/config/index', array('website' => $website->getId())); }
/** * Save the EAV entity data XML * * @param int $entityTypeId * @param bool $returnObj * @return mixed */ public function submit_eav_xmlAction($entityTypeId = null, $returnObj = false) { $data = $this->getRequest()->getParam('eav_data'); if (!empty($data)) { $eavLoader = App_Main::getModel('backend/eav_edit'); $entity = $eavLoader->submitXmlEavData($data, $entityTypeId); } if ($returnObj) { return $entity; } if ($this->getRequest()->isXmlHttpRequest() && empty($entity)) { App_Main::getSession()->addError('Error saving data and entity. Entity not defined'); } else { $this->getResponse()->setHeader('Content-Type', 'text/xml'); return $this->load_eav_xmlAction($entity->getEntityTypeId(), $entity->getId()); } }
/** * Get the Basecamp API connector object * * @return Connect_Basecamp */ public function getBcConnect() { //check for user session if (!($user = App_Main::getSession()->getUser())) { App_Main::throwException('User session not found. Please login to connect'); return; } //check for bc host and bc token in the user object if (!$user->getBcHost() || !$user->getBcAuthToken()) { App_Main::throwException('Unable to connect to BC::unable to find sufficient credentials'); return; } //load the bc connect api object if not loaded already if (!$this->_bcConnect) { $this->_bcConnect = new Connect_Basecamp($user->getBcHost(), $user->getBcAuthToken(), 'X', self::BC_CONNECT_FORMAT); } return $this->_bcConnect; }
/** * Retrieve session object * * @return Core_Model_Session */ public function getSession() { if (!$this->_session) { $this->_session = App_Main::getSession(); } return $this->_session; }
/** * Save the project data submitted from the project edit form * called from Project_Controller_CreateController::saveAction * Marketing lead and the dev lead are submitted along with the data * * @param type $data */ public function saveProject($data) { //if the project doesnot exists create a new project in Basecamp if (!$this->getId()) { $this->setTitle($data['title']); $project = $this->createNewBcProject($data['title']); if (!$project) { return false; } $this->load($project->getId()); } $this->setMLead($data['m_lead']); $this->setDLead($data['d_lead']); $this->save(); //add the project to the users loaded projects list App_Main::getSession()->getUser()->addProjectToStack($this); /*//process the milestone data passed from the form if(!empty($data['milestones']) && is_array($data['milestones'])) { $milestones = array(); foreach($data['milestones'] as $msInfo) { $msSaved = $this->saveMilestone($msInfo['title'], $msInfo['date'], $msInfo['user'], $msInfo['type'], @$msInfo['bc_id']); if(!$msSaved) { continue; } $milestones[] = $msSaved; } //$this->_milestones = $milestones; }*/ return $this; }
/** * Saves the eav data speecific to the entity or entity type id specified * * @param string $xmlData * @param int $entityTypeId * @return Core_Model_Abstract */ public function submitXmlEavData($xmlData, $entityTypeId = null) { $xml = new SimpleXMLElement($xmlData); $entityNode = $xml->entity; if ($entityNode['entityTypeId']) { $entityTypeId = (string) $entity['entityTypeId']; } //initiate the model for the entity and update the submitted entity if (!empty($entityNode['entity_id'])) { $entityId = intval((string) $entityNode['entity_id']); $entityId = is_int($entityId) ? $entityId : null; if (!empty($entityId)) { $entity = $this->loadEntity($entityId); } } //initiate the model for the entity type and save it as a new entity if ((empty($entity) || !$entity instanceof Core_Model_Abstract) && !empty($entityTypeId)) { $entityModel = $this->getResource()->getEntityModel($entityTypeId); if (!empty($entityModel)) { $entity = App_Main::getModel($entityModel); $entity->setEntityTypeId($entityTypeId); } } if (empty($entity)) { App_Main::getSession()->addError('Unable to load the entity model for the submitted data.'); return false; } //Assign the attribute values into the entity object prior to saving foreach ($entityNode->children() as $childNode) { $backend = (string) $childNode['backendType']; $attributeCode = (string) $childNode->getName(); $attributeId = (string) $childNode['attributeId']; $entity->setData($attributeCode, (string) $childNode); } $entity->setUpdatedAt(now()); $entity->save(); return $entity; }
/** * Submit the user profile */ public function submit_user_profileAction() { $request = $this->getRequest(); $userId = $request->getParam('user_id'); if (empty($userId)) { $this->_redirect(''); } $user = App_Main::getModel('admin/user'); $user->setUserId($userId); $user->setFirstname($request->getParam('firstname')); $user->setLastname($request->getParam('lastname')); $user->setEmail($request->getParam('email')); if ($request->getParam('change_password') && $request->getParam('new_password') && $request->getParam('new_password') != 'new_password') { $user->setNewPassword($request->getParam('new_password')); App_Main::getSession()->addSuccess('User account password changed to ' . $user->getNewPassword()); } $user->save(); $this->_redirect('admin/index/edit_profile'); App_Main::getSession()->addSuccess('User account profile updated'); }
/** * Retrieve Session Form Key * * @return string */ public function getFormKey() { return App_Main::getSession()->getFormKey(); }
/** * Add session id to URL if configured * * @param string $url * @return Core_Model_Url */ protected function _prepareSessionUrl($url) { if (!$this->getUseSession()) { return $this; } $session = App_Main::getSession(); if ($sessionId = $session->getSessionId()) { $this->setQueryParam($session->getSessionIdQueryParam(), $sessionId); } return $this; }
/** * Send the new password to the user * @param string $password * @return bool */ private function sendNewPasswordEmail($password) { $mail = $this->_getMail(); $mail->setTemplate('widfy/change_password.phtml'); $mail->setToEmail($this->getEmail()); $mail->setToName($this->getName()); $mail->setSubject('WIDFY password reset'); $mail->setTemplateVar(array('user_name' => $this->getName(), 'new_password' => $password)); try { $mail->send(); } catch (Exception $e) { App_Main::getSession()->addError('Erorr sending password reset email ' . $e->getMessage()); } return true; }
/** * Check whether the current user loaded is the sesion user * * @return type */ public function isUserIsSessionUser() { return App_Main::getSession()->getUser() && $this->getUser() ? App_Main::getSession()->getUser()->getId() == $this->getUser()->getId() : false; }
/** * Load the milestone corresponding to the todolist * If the milestone is not found in the local database it will be loaded from * Basecamp and saved to the database * * @return type */ public function loadMilestone() { if (!$this->getMilestoneId()) { return false; } $milestone = App_Main::getModel('project/milestone')->load($this->getMilestoneId(), 'bc_id'); if (!$milestone->getId()) { //load the milestone from Basecamp $milestone->loadFromBc($this->getMilestoneId()); } $this->setMilestone(); if (!$milestone->getId()) { $milestone->setTitle($data['title']); $milestone->setMilestoneDate($data['user']); $milestone->setMilestoneDate($data['date']); $milestone->setProjectId($projectId); $milestone->setAddedDate(now()); $milestone->setUpdatedDate(now()); $milestone->save(); } else { if ($milestone->getTitle() != $data['title'] && $milestone->getBcId()) { //save the title is it is changed from BC App_Main::getSession()->addError('You can not change the title of an already registed milestone'); } } //write the logic to save the milestone informaiton to basecamp }