Example #1
0
	/**
	 * If table key (id) is NULL : inserts a new row
	 * otherwise updates existing row in the database table
	 *
	 * Can be overridden or overloaded by the child class
	 *
	 * @param  boolean  $updateNulls  TRUE: null object variables are also updated, FALSE: not.
	 * @return boolean                TRUE if successful otherwise FALSE
	 */
	public function store( $updateNulls=false ) {
		global $_CB_framework;
		if ( $this->time_paid && ( $this->time_paid != $this->_db->getNullDate() ) ) {
			$offset							=	(int) $_CB_framework->getCfg( 'offset' ) * 3600;

			list($y, $c, $d, $h, $m, $s)	=	sscanf( $this->time_paid, '%d-%d-%d %d:%d:%d');
			$time_paid						=	mktime($h, $m, $s, $c, $d, $y);			// we do NOT use PHP strtotime, which is broken
			$time_paid						+=	$offset;

			$dateDayHour					=	explode( ' ', date( 'Y-m-d w H o W', $time_paid ) );
			$dateDayHour[1]					+=	1;			// --> 1 = Sunday...7 = Saturday, ISO-8601 numeric representation of the day of the week, like MySQL

			$this->time_paid_date			=	$dateDayHour[0];
			$this->time_paid_day_of_week	=	$dateDayHour[1];
			$this->time_paid_yearweek		=	$dateDayHour[3] . '-W' . $dateDayHour[4];
			$this->time_paid_yearmonth		=	substr( $dateDayHour[0], 0, 7 );
			$this->time_paid_hour			=	$dateDayHour[2];
		}
		return parent::store( $updateNulls );
	}
	/**
	 * Deletes the payment_basket and all related payment_items in the database
	 * as well as corresponding newly created but inactive products
	 *
	 * @param  int      $oid   Key id of row to delete (otherwise it's the one of $this)
	 * @return boolean         TRUE if OK, FALSE if error
	 */
	public function delete( $oid = null ) {
		global $_CB_database;

		if ( $oid ) {
			$k				=	$this->_tbl_key;
			$this->$k		=	(int) $oid;
		}

		$subscriptions		=&	$this->getSubscriptions();
		foreach ( $subscriptions as $k => $v ) {
			if ( is_object( $v ) && in_array( $v->status, array( 'R', 'I' ) ) ) {
				if ( ! $subscriptions[$k]->hasPendingPayment( $this->id ) ) {
					$subscriptions[$k]->delete();
				}
			}
		}
		$query				=	"DELETE FROM #__cbsubs_payment_items"
			.	"\n WHERE payment_basket_id = ". (int) $this->id;
		$_CB_database->setQuery( $query );
		if ( !$_CB_database->query() ) {
			trigger_error( "delete paymentItems error:".htmlspecialchars($_CB_database->getErrorMsg()), E_USER_ERROR );
			return false;
		}
		if ( ! $this->deleteTotalizers() ) {
			return false;
		}
		if ( ! parent::delete( $oid ) ) {
			trigger_error( "delete paymentBasket error:".htmlspecialchars( $this->getError() ), E_USER_ERROR );
			return false;
		}
		return true;
	}
 /**
  * If table key (id) is NULL : inserts a new row
  * otherwise updates existing row in the database table
  *
  * Can be overridden or overloaded by the child class
  *
  * @param  boolean  $updateNulls  TRUE: null object variables are also updated, FALSE: not.
  * @return boolean                TRUE if successful otherwise FALSE
  */
 public function store($updateNulls = false)
 {
     if ($this->time_paid && $this->time_paid != $this->_db->getNullDate()) {
         $time_paid = cbpaidTimes::getInstance()->strToTime($this->time_paid);
         // we do NOT use PHP strtotime, which is broken
         $dateDayHour = explode(' ', cbpaidTimes::getInstance()->localDate('Y-m-d w H o W', $time_paid));
         $dateDayHour[1] += 1;
         // --> 1 = Sunday...7 = Saturday, ISO-8601 numeric representation of the day of the week, like MySQL
         $this->time_paid_date = $dateDayHour[0];
         $this->time_paid_day_of_week = $dateDayHour[1];
         $this->time_paid_yearweek = $dateDayHour[3] . '-W' . $dateDayHour[4];
         $this->time_paid_yearmonth = substr($dateDayHour[0], 0, 7);
         $this->time_paid_hour = $dateDayHour[2];
     }
     return parent::store($updateNulls);
 }
 /**
  * Constructor
  *
  * @param  CBdatabase  $db
  */
 public function __construct(&$db = null)
 {
     parent::__construct('#__cbsubs_notifications', 'id', $db);
 }