public static function checkStatusAd() { $activePaids = ApartmentPaid::model()->findAll('date_end <= NOW() AND status=' . ApartmentPaid::STATUS_ACTIVE); foreach ($activePaids as $paid) { $paid->status = ApartmentPaid::STATUS_NO_ACTIVE; if ($paid->paid_id == PaidServices::ID_SPECIAL_OFFER || $paid->paid_id == PaidServices::ID_UP_IN_SEARCH) { $apartment = Apartment::model()->findByPk($paid->apartment_id); if ($apartment) { $apartment->scenario = 'update_status'; if ($paid->paid_id == PaidServices::ID_SPECIAL_OFFER) { $apartment->is_special_offer = 0; $apartment->update(array('is_special_offer')); } if ($paid->paid_id == PaidServices::ID_UP_IN_SEARCH) { $apartment->date_up_search = new CDbExpression('NULL'); $apartment->update(array('date_up_search')); } } } if (!$paid->update(array('status'))) { //deb($paid->getErrors()); } } $adEndActivity = Apartment::model()->with('user')->findAll('t.date_end_activity <= NOW() AND t.activity_always != 1 AND (t.active=:status OR t.owner_active=:status)', array(':status' => Apartment::STATUS_ACTIVE)); foreach ($adEndActivity as $ad) { $ad->scenario = 'update_status'; if (isset($ad->user) && $ad->user->isAdmin == 1) { $ad->active = Apartment::STATUS_INACTIVE; } else { $ad->active = Apartment::STATUS_INACTIVE; $ad->owner_active = Apartment::STATUS_INACTIVE; } $ad->save(false); } }
public static function checkStatusAd() { $activePaids = ApartmentPaid::model()->findAll('date_end <= NOW() AND status=' . ApartmentPaid::STATUS_ACTIVE); foreach ($activePaids as $paid) { $paid->status = ApartmentPaid::STATUS_NO_ACTIVE; if ($paid->paid_id == PaidServices::ID_SPECIAL_OFFER || $paid->paid_id == PaidServices::ID_UP_IN_SEARCH) { $apartment = Apartment::model()->findByPk($paid->apartment_id); if ($apartment) { $apartment->scenario = 'update_status'; if ($paid->paid_id == PaidServices::ID_SPECIAL_OFFER) { $apartment->is_special_offer = 0; $apartment->update(array('is_special_offer')); } if ($paid->paid_id == PaidServices::ID_UP_IN_SEARCH) { $apartment->date_up_search = new CDbExpression('NULL'); $apartment->update(array('date_up_search')); } } } if (!$paid->update(array('status'))) { //deb($paid->getErrors()); } } }
public static function applyToApartment($apartmentId, $paidId, $dateEnd, $interval = null) { $apartment = Apartment::model()->findByPk($apartmentId); if (!$apartment) { throw new CHttpException('PaidService no valid data'); } $data = Yii::app()->statePersister->load(); if (isset($data['next_check_status'])) { $data['next_check_status'] = time() - BeginRequest::TIME_UPDATE; Yii::app()->statePersister->save($data); } unset($data); $apartment->scenario = 'update_status'; $apartmentPaid = ApartmentPaid::model()->findByAttributes(array('paid_id' => $paidId, 'apartment_id' => $apartmentId, 'user_id' => $apartment->owner_id)); if (!$apartmentPaid) { $apartmentPaid = new ApartmentPaid(); $apartmentPaid->date_end = $dateEnd; } else { if (time() < strtotime($apartmentPaid->date_end) && $interval) { $apartmentPaid->date_end = new CDbExpression('date_end + ' . $interval); } else { $apartmentPaid->date_end = $dateEnd; } } $apartmentPaid->paid_id = $paidId; $apartmentPaid->apartment_id = $apartment->id; $apartmentPaid->user_id = $apartment->owner_id; $apartmentPaid->date_start = new CDbExpression('NOW()'); $apartmentPaid->status = ApartmentPaid::STATUS_ACTIVE; $apartmentPaid->save(); // reloading date_end field $apartmentPaid = ApartmentPaid::model()->findByPk($apartmentPaid->id); switch ($paidId) { case PaidServices::ID_SPECIAL_OFFER: $apartment->is_special_offer = 1; $apartment->is_free_to = $apartmentPaid->date_end; return $apartment->update(array('is_special_offer', 'is_free_to')); break; case PaidServices::ID_UP_IN_SEARCH: $apartment->date_up_search = new CDbExpression('NOW()'); return $apartment->update('date_up_search'); break; case PaidServices::ID_ADD_IN_SLIDER: return self::genImgForSlider($apartment->id); break; } return false; }