Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * UserController
- *
- * @uses Controller responsible for most if not all of the front
- * facing use
- */
- class UserController extends Esolist_Controller_Action
- {
- protected $_redirectOnAclFail = 'user/dashboard';
- protected $_ignoreActions = array(
- 'dashboard',
- 'video-tutorials',
- 'my-account',
- 'login',
- 'logout',
- 'forgot-password',
- 'shout',
- 'noie6',
- 'canceled-account',
- 'cancel-account'
- );
- /**
- * UserController::init()
- *
- * @return void
- */
- public function init()
- {
- parent::init(true);
- $this->_helper->layout->setLayout('layout');
- if( !isset($this->_user->user_has_setup) ){
- //Rad_Misc_Redirect::InternalGo('wizard', 2, 'user-setup');
- }
- $actionName = $this->getRequest()->getActionName();
- // CHeck if the action exists
- $actionFunc = $this->getFrontController()
- ->getDispatcher()
- ->formatActionName($actionName);
- // ACL checks
- $this->view->pageType = $actionName;
- if (!in_array($actionName, $this->_ignoreActions)
- && method_exists($this, $actionFunc))
- {
- if (!$this->_user->can('viewAppPage_' . $actionName))
- {
- $this->getRequest()->setActionName('upsell');
- }
- }
- // Possible fix for signup error?
- if($this->_user instanceof Esolist_User)
- {
- $this->view->current_user = $this->_user;
- // Check if they haven't paid their bills
- if($this->_user->isInNonPayment()
- && ($actionName !== 'logout' && $actionName !== 'login'))
- {
- $this->_redirect('billing/canceled-account/?nonPayment=true'); die;
- $this->getRequest()->setActionName('my-account');
- }
- }
- }
- public function upsellAction()
- {
- // Do nothing
- }
- /**
- * AgentBrokerController::dashboardAction()
- * @uses Responsible for generation of the user "Dashboard"
- * which contains all important quick reference data
- */
- public function dashboardAction()
- {
- $this->_helper->layout->setLayout('user/shout/layout');
- //die('THIS IS A TEST');
- //echo $this->_user->user_level; die;
- $this->view->isDashboard = true;
- $this->view->title = 'Dashboard';
- $social = new Application_Model_Social;
- $reports = new Application_Model_Reports;
- // Grab our latest report and recent listings
- $this->view->latest_report = $reports->getLatestReport($this->_user->getGUID());
- if($this->view->latest_report instanceof Esolist_Report)
- {
- $this->view->next_report = $this->view->latest_report->time_created + Rad_Misc_Date::MONTH;
- }
- $this->view->recent_listings = $this->models->listings
- ->fetchListings($this->_user->getGUID(), 0, 0, 0, 0, 5);
- // Our latest top networks
- $this->view->syndication_networks = $this->models->syndication->getTopNetworks($this->_user->getGUID());
- $this->view->latest_status = $social->getLatest($this->_user->getGUID());
- $this->view->all_listings = $this->_user->getListings(null, null);
- $this->view->all_listings_count = is_array($this->view->all_listings) ? count($this->view->all_listings) : 0;
- if( is_object($this->view->latest_status) )
- {
- $this->view->latest_status = $this->view->latest_status->message;
- }
- // Now pick out the latest status updated
- // from the first social network
- if( is_array($this->social_networks) && count($this->social_networks) > 0 )
- {
- //$this->view->shout_statuses = $this->_getEntities('social_status', null, $this->_user->getGUID(), null, 0, 5, false, 'asc');
- $this->view->shout_statuses = Rad_Entities_Functions_Entity::getEntities('social_status', null,
- $this->_user->getGUID(), null, 0, 5, false);
- //Zend_Debug::dump($this->view->shout_statuses); die;
- }
- // Pass social network data
- if(isset($this->_user->social_statistics))
- {
- $this->view->social_statistics = $this->_user->social_statistics->convert();
- }
- // Change the view script if they're a basic-type account
- if($this->_user->is('basic_agent'))
- {
- $this->renderScript('user/dashboard/basic.phtml');
- }
- }
- /**
- * AgentBrokerController::listingsAction()
- * @uses Retrieve all listings belonging to the user and display
- * through the view
- */
- public function listingsAction()
- {
- // Array of "types" that we allow the user to sort by
- $types = array(
- 'active' => 0,
- 'enabled' => 'yes',
- 'archived' => 0,
- 'queued' => 0,
- 'draft' => 0
- );
- // Set up proper pagination
- $page = 1;
- $row = null;
- if( count(($pagination = explode('/', ltrim($this->_getParam('page'), '/')))) > 0 )
- {
- $page = $pagination[0];
- if( isset($pagination[1]) )
- {
- $row = $pagination[1];
- }
- }
- $this->view->title = 'Listings';
- // Check whether we're handling archived listings or not
- $type = $this->_getParam('type');
- // Build conditionals by which we're going to
- // fetch our listings
- $conditions = array(
- 'e.owner_guid' => $this->_user->getGUID()
- );
- // Now set the proper type to true
- if (isset($types[$type])) {
- $types[$type] = 1;
- }
- array_shift($types);
- foreach ($types as $type => $value) {
- $conditions[$type] = $value;
- }
- // Retrieve pertinent listing data
- $paginator = $this->models->listings->getPaginator($conditions, 'e.time_updated desc');
- $propertyCount = $paginator->getTotalItemCount();
- $properties = $paginator->getAdapter()->getAllItems();
- // What sort of listing selections can we allow?
- $allowedTypes = array(
- 'active' => $this->_translate('active'),
- 'archived' => $this->_translate('archived'),
- /*'queued' => $this->_translate('queued'),*/
- 'draft' => $this->_translate('draft'),
- );
- if($this->_user->is('basic_agent'))
- {
- unset($allowedTypes['archived']);
- }
- $this->view->allowed_types = $allowedTypes;
- $this->view->listings_select = $properties;
- $this->view->listing_select_count = $propertyCount;
- $this->view->type = $this->_getParam('type', 'active');
- $this->view->page = $page;
- $this->view->row = $row;
- $this->view->listings = $paginator;
- }
- /**
- * AgentBrokerController::shoutAction()
- * @uses The shout page where a specific listing is gotten
- * or the very latest listing and displaed
- */
- public function shoutAction()
- {
- // Are we handling a specific listing
- // or letting the system handle the data?
- if( $this->_hasParam('listing') )
- {
- // Retrieve our listing and set the ddata
- $guid = $this->_getParam('listing');
- $listing = $this->_getEntity($guid);
- if( $this->_user->can('read_listing', 0, $listing) )
- {
- $this->view->listing = $listing;
- }
- }else{
- // Grab our very latest listing
- $listing = $this->_user->getListings(0,1);
- if( is_array($listing) )
- {
- $this->view->listing = current($listing);
- }
- }
- $this->view->all_listings = $this->_user->getListings(null, null);
- $this->view->all_listings_count = is_array($this->view->all_listings) ? count($this->view->all_listings) : 0;
- $this->view->social_networks_list = Esolist_Social::getSocialNetworks();
- $this->_helper->layout->setLayout('user/shout/layout');
- if(isset($this->_user->social_network_to_load))
- {
- $this->view->network_to_load = $this->_user->social_network_to_load;
- }elseif(isset($this->view->social_networks) && count($this->view->social_networks)){
- $this->view->network_to_load = $this->view->social_networks[0]->getGUID();
- }
- }
- /**
- * AgentBrokerController::spreadAction()
- * @uses Fetch data such as leads and visits
- * according to lisiting
- */
- public function spreadAction()
- {
- $this->view->title = 'Spread';
- $this->view->listings = $this->_user->getListings(null, null);
- $this->view->syndications = Zend_Registry::get('syndication');
- }
- /**
- * AgentBrokerController::meterAction()
- * @uses Display "meter" data
- */
- public function meterAction()
- {
- $this->view->title = 'Meter';
- /**
- * The below is the data neccesary to break down all the visits
- */
- $meterModel = new Application_Model_Meter;
- $seriesData = $meterModel->getVisitBreakdown($this->_user->getGUID());
- $listings = $this->_user->getListings(null, null);
- // Calculate the total amount of visits and leads for the entire group
- $totalVisits = 0;
- $totalLeads = 0;
- foreach($seriesData as $domain => $item)
- {
- foreach($item as $k => $datum)
- {
- $totalVisits += $data['visits'];
- $totalLeads += $data['leads'];
- }
- }
- /**
- * We will now attempt to collect twitter data for visualization
- */
- try{
- // Make sure this fucker has a twitter account
- if($this->_user->hasNetwork('twitter'))
- {
- // Collect the twitter objects
- $twitterAccounts = $this->_user->getChildObjects('social_network', 'twitter', null, null);
- if($twitterAccounts)
- {
- // Grab the first one and collect data
- $twitterAccounts[0]->activateApi();
- $api = $twitterAccounts[0]->getApi();
- $data = $api->account->verifyCredentials();
- $data = Rad_Misc_Array::fromXml($data->getIterator()->asXml());
- $this->view->twitter_data = array(
- 'followers_count' => $data['followers_count'],
- 'following_count' => $data['friends_count'],
- 'status_count' => $data['statuses_count'],
- 'favourites_count' => $data['favourites_count']
- );
- }
- }else{
- // Data fillll :D
- $twitterAccounts = array_map(array($this, '_getEntity'), array(1942, 3819));
- $twitter = $this->_getEntity(1942);
- $twitter->activateApi();
- $api = $twitter->getApi();
- $data = $api->account->verifyCredentials();
- $data = Rad_Misc_Array::fromXml($data->getIterator()->asXml());
- $this->view->twitter_data = array(
- 'followers_count' => $data['followers_count'],
- 'following_count' => $data['friends_count'],
- 'status_count' => $data['statuses_count'],
- 'favourites_count' => $data['favourites_count']
- );
- $twitterAccountsNorm = array();
- foreach($twitterAccounts as $account)
- {
- $twitterAccountsNorm[$account->getGUID()] = $account->getUsername();
- }
- $this->view->twitterAccounts = $twitterAccountsNorm;
- }
- }catch(Zend_Http_Client_Adapter_Exception $e){
- }
- $this->view->to_date = Rad_Misc_Format::Date(time());
- $this->view->from_date = Rad_Misc_Format::Date(strtotime(date('m/1/Y')));
- $this->view->total_visits = $totalVisits;
- $this->view->total_leads = $totalLeads;
- $this->view->listings = $listings;
- $this->view->chart = $seriesData;
- }
- /**
- * AgentBrokerController::reportsAction()
- * @uses Generate reports overviewing all listings
- */
- public function reportsAction()
- {
- $guid = $this->_getParam('guid');
- /**
- * Magical voodoo
- */
- if($guid)
- {
- $report = $this->_getEntity($guid);
- $reportXML = simplexml_load_file($report->getFilenameOnDisk());
- $MAX_INT = 9999999999999;
- $dates = array();
- $edgeDates = array('from' => $MAX_INT, 'to' => 0);
- $networkData = array();
- $totalNetworkData = array();
- $unStackedNetworkData = array();
- $wantedNetworks = Zend_Registry::get('wanted_networks');
- foreach($reportXML->networks->network as $network)
- {
- $network = (array)$network;
- $networkDate = strtotime($network['month'] . '/' . $network['day'] . '/' . $network['year']);
- $edgeDates['from'] = $edgeDates['from'] > $networkDate ? $networkDate : $edgeDates['from'];
- $edgeDates['to'] = $edgeDates['to'] < $networkDate ? $networkDate : $edgeDates['to'];
- $leadsTotal += $network['leads'];
- $visitsTotal += $network['visits'];
- if(in_array($network['domain'], $wantedNetworks))
- {
- $networkData[$network['domain']]['domain'] = $network['domain'];
- $networkData[$network['domain']]['leads'] += $network['leads'];
- $networkData[$network['domain']]['visits'] += $network['visits'];
- $networkData[$network['domain']]['lead_percentage'] += (float)$network['lead_percentage'];
- $networkData[$network['domain']]['visit_percentage'] += (float)$network['visit_percentage'];
- }else{
- $networkData['other']['domain'] = 'other';
- $networkData['other']['leads'] += $network['leads'];
- $networkData['other']['visits'] += $network['visits'];
- $networkData['other']['lead_percentage'] += (float)$network['lead_percentage'];
- $networkData['other']['visit_percentage'] += (float)$network['visit_percentage'];
- }
- $totalNetworkData[$network['domain']]['domain'] = $network['domain'];
- $totalNetworkData[$network['domain']]['leads'] += $network['leads'];
- $totalNetworkData[$network['domain']]['visits'] += $network['visits'];
- $totalNetworkData[$network['domain']]['lead_percentage'] += (float)$network['lead_percentage'];
- $totalNetworkData[$network['domain']]['visit_percentage'] += (float)$network['visit_percentage'];
- $unStackedNetworkData[] = $network;
- }
- }
- if(isset($report->from_date) && isset($report->to_date))
- {
- $this->view->report_from_date = Rad_Misc_Format::Date($report->from_date->convert());
- $this->view->report_to_date = Rad_Misc_Format::Date($report->to_date->convert());
- }
- $request = $this->getRequest();
- $this->view->chart_dates = range($edgeDates['from'], $edgeDates['to'], Rad_Misc_Date::DAY);
- $this->view->report = isset($report) ? $report : null;
- $this->view->report_xml = isset($reportXML) && $reportXML instanceof SimpleXMLElement ? $reportXML : null;
- $this->view->total_leads = $leadsTotal;
- $this->view->total_visits = $visitsTotal;
- $this->view->unstacked_data = $unStackedNetworkData;
- $this->view->network_data = $networkData;
- $this->view->other_data = $othersData;
- $this->view->total_data = $totalNetworkData;
- $this->view->from_date = $request->getQuery('from');
- $this->view->to_date = $request->getQuery('to');
- $this->view->listing = $request->getQuery('listing');
- $this->view->listings = $this->_user->getListings(null, null);
- $this->view->reports = $this->_user->getChildObjects('file', 'report', null, null);
- }
- public function leadsAction()
- {
- $defaultSearchTerm = $this->_translate('enter-email-or-name');
- // Get all our parameters together for searching
- $fromDate = $this->_getParam('from_date', null);
- $toDate = $this->_getParam('to_date', null);
- $searchTerm = $this->_getParam('search_term', null);
- $guid = $this->_getParam('guid', null);
- $page = $this->_getParam('page', 1);
- $row = $this->_getParam('row', null);
- if($searchTerm == $defaultSearchTerm) {
- $searchTerm = null;
- }
- if(($fromDate == $toDate) && !is_null($fromDate)) {
- // Look ahead 23 hours and 49
- $toDate += Rad_Misc_Date::DAY - 1;
- }
- $leadModel = new Application_Model_Leads;
- // Set up our paginator
- $leads = $leadModel->getPaginator($this->_user->getGUID(), $searchTerm, $guid, $fromDate, $toDate);
- $leads->setItemCountPerPage(10);
- $leads->setCurrentPageNumber($page);
- // Get all our listings
- $listings = $this->_user->getListings(null, null);
- $this->view->listings = $listings;
- $this->view->leads = $leads;
- $this->view->from_date = $fromDate;
- $this->view->to_date = $toDate;
- $this->view->listing_guid = $guid;
- $this->view->date_range_used = false;
- if( !is_null($fromDate) && !is_null($toDate) )
- {
- $this->view->date_range_used = true;
- }
- // Construct pagination prefix
- // to mantain the integrity of our search if one
- // was made
- $paginationPrefix = '';
- $paginationPrefixArray = array(
- 'from_date' => $fromDate,
- 'to_date' => $toDate,
- 'search_term' => $searchTerm,
- 'guid' => $guid,
- 'row' => $row
- );
- foreach( $paginationPrefixArray as $key => $potentialPrefix )
- {
- if( !empty($potentialPrefix) )
- {
- $paginationPrefix .= $key . '/' . $potentialPrefix . '/';
- }
- }
- if( empty($searchTerm) )
- {
- $this->view->search_term = $this->_translate('enter-email-or-name');
- }else{
- $this->view->search_term = $searchTerm;
- }
- $this->view->pagination_prefix = 'leads/' . $paginationPrefix . 'page/';
- // Process CSV download request
- if( $this->_request->getQuery('csv') == true )
- {
- $this->_helper->layout->disableLayout();
- $this->_helper->viewRenderer->setNoRender(true);
- // Get all leads
- $allLeads = $leads->getAdapter()->getAllItems();
- $leadArray = array(
- array('Date', 'Name', 'Email', 'Phone', 'Listing name', 'Listing Address', 'Type', 'Date of Showing')
- );
- foreach( $allLeads as $lead )
- {
- $leadArray[] = array(Rad_Misc_Format::Date($lead->time_created), $lead->name,
- $lead->email, $lead->phone, $lead->getListing()->name,
- $lead->getListing()->street, $lead->ltype, $lead->scheduled_show);
- }
- $this->_helper->file->sendData(Rad_Misc_Array::toDsv($leadArray), Rad_Misc_File::getMimeType('csv'), $this->_user->getGUID() . '-' . time() . '.csv');
- }
- }
- public function videoTutorialsAction()
- {
- }
- /**
- * UserController::myAccountAction()
- *
- * @return void
- */
- public function myAccountAction()
- {
- //Zend_Debug::dump($this->_user->subscription_id); die;
- $userLevelsModel = new Application_Model_UserLevels;
- $userLevels = $userLevelsModel->fetchAll('visible = 1');
- $errors = array();
- // Adjust plans
- if($this->_request->isPost())
- {
- $post = $this->_getAllParams();
- // First check if we have a billing entity set
- if(! isset($this->_user->billing_information_guid))
- {
- $billingInfo = new Esolist_Billing_PaymentInformation;
- }else{
- $billingInfo = $this->_getEntity($this->_user->billing_information_guid->convert());
- }
- $billingInfo->address = $post['billing-address'];
- $billingInfo->city = $post['billing-city'];
- $billingInfo->state = $post['billing-state'];
- $billingInfo->name_on_card = $post['billing-name_on_card'];
- $billingInfo->zip = $post['billing-zip'];
- $billingInfo->expiration = $post['cc_month'] . $post['cc_year'];
- $billingInfo->save();
- }
- reset($userLevels);
- if(isset($this->_user->user_level))
- {
- $uLevel = $this->_user->user_level->convert();
- foreach($userLevels as $userLevel)
- {
- if($uLevel == $userLevel->id) {
- $this->view->user_level = $userLevel;
- break;
- }
- }
- }
- // Empty object
- $billingInformation = new StdClass;
- if(isset($this->_user->billing_information_guid))
- {
- $billingInformation = $this->_getEntity($this->_user->billing_information_guid);
- }
- $lastPayment = null;
- $nextPayment = null;
- if(isset($this->_user->last_payment))
- {
- $lastPayment = $this->_user->last_payment->convert();
- }
- if(isset($this->_user->next_payment))
- {
- $nextPayment = $this->_user->next_payment->convert();
- }
- $this->view->pageType = 'myAccount';
- $this->view->user_levels = $userLevels;
- $this->view->last_payment = $lastPayment;
- $this->view->next_payment = $nextPayment;
- $this->view->billingInformation = $billingInformation;
- }
- /**
- * UserController::loginAction()
- *
- * @return void
- */
- public function loginAction()
- {
- $this->_helper->layout->setLayout('user/lifp_layout');
- if( $this->_request->isPost() )
- {
- $post = $this->_request->getPost();
- $user = $this->models->users->emailExists($post['email']);
- if( $user instanceof Esolist_User )
- {
- $auth = Rad_Auth::getInstance();
- $post['remember_me'] = isset($post['remember_me']) ? $post['remember_me'] : false;
- $validationContainer = new Rad_Auth_Adapter_UserEntity($user, $post['password'], $post['remember_me']);
- $result = $auth->authenticate($validationContainer);
- if($result->isValid())
- {
- $this->_redirect($user->getPrimaryAppInstance()->getUrl());
- }else{
- $this->view->error = 'bad-password';
- }
- }else{
- $this->view->error = 'bad-username';
- }
- }
- }
- /**
- * UserController::logoutAction()
- *
- * @return void
- */
- public function logoutAction()
- {
- if(Rad_Auth::getInstance()->hasIdentity())
- {
- Rad_Auth::getInstance()->clearIdentity();
- }
- Rad_Misc_Redirect::InternalGo('user/login', 2, 'login'); die;
- }
- /**
- * UserController::forgotPasswordAction()
- *
- * @return void
- */
- public function forgotPasswordAction()
- {
- $this->_helper->layout->setLayout('user/lifp_layout');
- $this->view->emailed = false;
- if($this->_request->isPost())
- {
- $user = $this->models->users->emailExists($this->_getParam('email'));
- if($user instanceof Esolist_User)
- {
- $newPassword = Rad_Misc_Character::random(6);
- $user->password = $newPassword;
- $user->save();
- $this->view->emailed = true;
- Esolist_Mail_Notification::forgotPassword(array(
- 'to' => array(
- 'name' => $user->name,
- 'email' => $user->email
- ),
- 'data' => array(
- 'new_password' => $newPassword,
- 'user' => $user
- )
- ));
- }else{
- $this->view->error = 'no-user-found';
- }
- }
- }
- /**
- * UserController::noie6Action()
- *
- * @return void
- */
- public function noie6Action()
- {
- $this->view->title = 'IE is a false prophet.';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement