Ejemplo n.º 1
0
 public function check()
 {
     $result = true;
     // Require a title
     if (empty($this->title)) {
         $this->setError(JText::_('COM_AKEEBASUBS_LEVEL_ERR_TITLE'));
         $result = false;
     }
     // Make sure the title is unique
     $existingItems = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->title($this->title)->getList(true);
     if (!empty($existingItems)) {
         $count = 0;
         $k = $this->getKeyName();
         foreach ($existingItems as $item) {
             if ($item->{$k} != $this->{$k}) {
                 $count++;
             }
         }
         if ($count) {
             $this->setError(JText::_('COM_AKEEBASUBS_LEVEL_ERR_TITLEUNIQUE'));
             $result = false;
         }
     }
     // Create a new or sanitise an existing slug
     require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/filter.php';
     if (empty($this->slug)) {
         // Auto-fetch a slug
         $this->slug = AkeebasubsHelperFilter::toSlug($this->title);
     } else {
         // Make sure nobody adds crap characters to the slug
         $this->slug = AkeebasubsHelperFilter::toSlug($this->slug);
     }
     // Look for a similar slug
     $existingItems = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->slug($this->slug)->getList(true);
     if (!empty($existingItems)) {
         $count = 0;
         $k = $this->getKeyName();
         foreach ($existingItems as $item) {
             if ($item->{$k} != $this->{$k}) {
                 $count++;
             }
         }
         if ($count) {
             $this->setError(JText::_('COM_AKEEBASUBS_LEVEL_ERR_SLUGUNIQUE'));
             $result = false;
         }
     }
     // Do we have an image?
     if (empty($this->image)) {
         $this->setError(JText::_('COM_AKEEBASUBS_LEVEL_ERR_IMAGE'));
         $result = false;
     }
     // Check the fixed expiration date and make sure it's in the future
     $nullDate = JFactory::getDbo()->getNullDate();
     if (!empty($this->fixed_date) && !($this->fixed_date == $nullDate)) {
         $jNow = JFactory::getDate();
         $jFixed = JFactory::getDate($this->fixed_date);
         if ($jNow->toUnix() > $jFixed->toUnix()) {
             $this->fixed_date = $nullDate;
         }
     }
     // Is the duration less than a day and this is not a forever or a fixed date subscription?
     if ($this->forever) {
         $this->duration = 0;
     } elseif (!empty($this->fixed_date) && !($this->fixed_date == $nullDate)) {
         // We only want the duration to be a positive number or zero
         if ($this->duration < 0) {
             $this->duration = 0;
         }
     } elseif ($this->duration < 1) {
         $this->setError(JText::_('COM_AKEEBASUBS_LEVEL_ERR_LENGTH'));
         $result = false;
     }
     // Serialise params
     if (is_array($this->params)) {
         if (!empty($this->params)) {
             $this->params = json_encode($this->params);
         }
     }
     if (is_null($this->params) || empty($this->params)) {
         $this->params = '';
     }
     // Normalise plugins
     if (!empty($this->payment_plugins)) {
         if (is_array($this->payment_plugins)) {
             $payment_plugins = $this->payment_plugins;
         } else {
             $payment_plugins = explode(',', $this->payment_plugins);
         }
         if (in_array('', $payment_plugins)) {
             $this->payment_plugins = '';
         } else {
             $this->payment_plugins = implode(',', $payment_plugins);
         }
     } else {
         $this->payment_plugins = '';
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Publish an IP Agent linked with Joomla! user ID $user_id and limit
  * parameters $params
  *
  * @param   integer  $user_id  The Joomla! user ID
  * @param   array    $params   IP parameters for the agent
  *
  * @return  void
  */
 private function publishAgent($user_id, $params)
 {
     // First, check if we already have agents for that user ID
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__iproperty_agents'))->where($db->qn('user_id') . ' = ' . $db->q($user_id));
     $db->setQuery($query);
     $agents = $db->loadObjectList();
     if (empty($agents)) {
         // If we do not have any existing agents, create a new company and a new agent record
         // Load the user data
         $user = F0FModel::getTmpInstance('Users', 'AkeebasubsModel')->user_id($user_id)->getMergedData($user_id);
         // Create a company
         $name = empty($user->businessname) ? $user->name : $user->businessname;
         require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/filter.php';
         $alias = AkeebasubsHelperFilter::toSlug($name);
         $company = (object) array('name' => $name, 'alias' => $alias, 'description' => '&nbsp;', 'street' => $user->address1, 'city' => $user->city, 'locstate' => $user->state, 'province' => '', 'postcode' => $user->zip, 'country' => $user->country, 'fax' => '', 'phone' => '', 'email' => $user->email, 'website' => '', 'featured' => 0, 'icon' => 'nopic.png', 'clicense' => '', 'language' => '', 'state' => 1, 'params' => json_encode($params));
         $db->insertObject('#__iproperty_companies', $company);
         $companyid = $db->insertid();
         // Create an agent
         $nameParts = explode(' ', $user->name, 2);
         $firstName = $nameParts[0];
         if (count($nameParts) > 1) {
             $lastName = $nameParts[1];
         } else {
             $lastName = '';
         }
         $alias = AkeebasubsHelperFilter::toSlug($user->name);
         $agent = (object) array('agent_type' => 1, 'hometeam' => 0, 'fname' => $firstName, 'lname' => $lastName, 'alias' => $alias, 'company' => $companyid, 'email' => $user->email, 'phone' => '', 'mobile' => '', 'fax' => '', 'street' => $user->address1, 'street2' => $user->address2, 'city' => $user->city, 'locstate' => $user->state, 'province' => '', 'postcode' => $user->zip, 'country' => $user->country, 'website' => '', 'bio' => '&nbsp;', 'user_id' => $user_id, 'featured' => 0, 'icon' => 'nopic.png', 'msn' => '', 'skype' => '', 'gtalk' => '', 'linkedin' => '', 'facebook' => '', 'twitter' => '', 'social1' => '', 'alicense' => '', 'state' => 1, 'params' => '');
         $db->insertObject('#__iproperty_agents', $agent);
     } else {
         // If we have existing agents, we need to do two things:
         // a. Make sure all agent records are enabled
         $query = $db->getQuery(true)->update($db->qn('#__iproperty_agents'))->set($db->qn('state') . ' = ' . $db->q(1))->where($db->qn('user_id') . ' = ' . $db->q($user_id));
         $db->setQuery($query);
         $db->execute();
         // b. Update the company parameters
         $company_ids_raw = array();
         foreach ($agents as $agent) {
             $company_ids_raw[] = $agent->company;
         }
         $company_ids_raw = array_unique($company_ids_raw);
         $company_ids = array();
         foreach ($company_ids_raw as $cid) {
             $company_ids[] = $db->q($cid);
         }
         $query = $db->getQuery(true)->select('*')->from($db->qn('#__iproperty_companies'))->where($db->qn('id') . ' IN (' . implode(',', $company_ids) . ')');
         $db->setQuery($query);
         $companies = $db->loadObjectList();
         foreach ($companies as $company) {
             $cparams = json_decode($company->params, true);
             $cparams = $this->mixParams($cparams, $params);
             $company->params = json_encode($cparams);
             $company->state = 1;
             $result = $db->updateObject('#__iproperty_companies', $company, 'id');
         }
     }
 }