/** * A protected method to initialize this class * @param mixed[] $record Record to be loaded to the class (Optional, Default = array()) * @throws E_USER_ERROR Invalid class name * @access protected * * @uses module_TrackerFactory_API * @uses module_TrackerFactory::manufacture() */ function _init($record = array()) { // Get tracker implementation name if (is_null($this->_trackerName)) { @preg_match('/module_(.*)_Tracker_DataObject/i', get_class($this), $matches); if (is_array($matches) && count($matches) == 2) { $this->_trackerName = ucwords($matches[1]); } else { trigger_error('module_Tracker_DataObject::_init -- Invalid class name', E_USER_ERROR); } } // Cache the DAO $factory =& module_TrackerFactory_API::getInstance(); $this->_cachedDAO =& $factory->manufacture($this->_trackerName); // Populate record if record is parsed to the parameter if (is_array($record) && count($record) > 0) { foreach($this->_records as $key => $value) { if (array_key_exists($key, $record)) { $this->_records[$key] = $record[$key]; } } } // Make sure that "trackername" is always be overwritten $this->_records['trackername'] = $this->_trackerName; // Update the "update" flag $this->_update = !(is_null($this->_records['statid']) || is_null($this->_records['stattype'])); }
/** * DeleteRecordForAllTrackerByNewsletterID * Delete all records for all trackers that matches specific newsletter ID * If an invalid id is passed in (<= 0), this returns false. * If the tracker modules don't have any data for this newsletterid, this also returns false. * * @param Int $newsletterID Newsletter ID * * @throws E_USER_NOTICE Invalid newsletter ID * * @static * * @uses Db::Query() * @uses Db::Fetch() * @uses Db::FreeResult() * @uses module_TrackerFactory_API * @uses module_TrackerFactory_API::getInstance() * @uses module_TrackerFactory_API::manufacture() * @uses module_Tracker::getDatabaseObject() * @uses module_Tracker_DataObject::delete() * * @todo use transaction so u know whether or not to start transaction or not * * @return Boolean Returns TRUE if successful, FALSE otherwise */ function DeleteRecordForAllTrackerByNewsletterID($newsletterID) { /** * Sanitize/Declare variables used by function */ $db = null; $factory = null; $trackers = array(); $mNewsletterID = intval($newsletterID); /** * ----- */ /** * Pre-checking */ if ($mNewsletterID == 0) { trigger_error('module_Tracker::DeleteRecordForAllTrackerByNewsletterID -- Invalid newsletter ID', E_USER_NOTICE); return false; } /** * ----- */ /** * Passes pre-check, do pre-processing */ $db = IEM::getDatabase(); $factory =& module_TrackerFactory_API::getInstance(); /** * ----- */ $rs = $db->Query('SELECT * FROM ' . SENDSTUDIO_TABLEPREFIX . "module_tracker WHERE newsletterid = {$mNewsletterID}"); if ($rs === false) { return true; } $status = true; while (($record = $db->Fetch($rs)) != false) { if (!array_key_exists($record['trackername'], $trackers)) { $trackers[$record['trackername']] =& $factory->manufacture($record['trackername']); } $do = $trackers[$record['trackername']]->getDataObject($record); $status = $do->delete(); if ($status == false) { break; } } $db->FreeResult($rs); return $status; }