Example #1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return PRIVACY_BOL_CronDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
 /**
  * @param array $actionList <$key, value>
  * @param array $userId
  * @return boolean
  */
 public function saveActionValues(array $actionList, $userId)
 {
     if ($actionList === null || !is_array($actionList) || count($actionList) === 0) {
         return false;
     }
     $userDto = BOL_UserService::getInstance()->findUserById($userId);
     if (empty($userDto)) {
         return false;
     }
     $actionKeyList = array_keys($actionList);
     $actionDtoList = $this->findActionList($actionKeyList);
     $result = $this->actionDataDao->findByActionListForUserList($actionKeyList, array($userId));
     $actionDataDtoList = !empty($result[$userId]) ? $result[$userId] : array();
     $actionKeyList = array_keys($actionDtoList);
     $savedActionList = array();
     $affectedRows = 0;
     foreach ($actionList as $key => $value) {
         if (in_array($key, $actionKeyList)) {
             $actionDataDto = new PRIVACY_BOL_ActionData();
             if (!empty($actionDataDtoList[$key])) {
                 $actionDataDto = $actionDataDtoList[$key];
             }
             /* @var $action PRIVACY_CLASS_Action */
             $action = $actionDtoList[$key];
             $actionDataDto->key = $key;
             $actionDataDto->userId = $userId;
             $actionDataDto->pluginKey = $action->pluginKey;
             $actionDataDto->value = $value;
             $this->actionDataDao->save($actionDataDto);
             if (OW::getDbo()->getAffectedRows()) {
                 $affectedRows++;
                 $cronDto = new PRIVACY_BOL_Cron();
                 $cronDto->userId = $userId;
                 $cronDto->action = $key;
                 $cronDto->value = $value;
                 $cronDto->timeStamp = time();
                 $savedActionList[] = $cronDto;
             }
             if (isset($this->actionData[$userId][$key])) {
                 unset($this->actionData[$userId][$key]);
             }
         }
     }
     if ($affectedRows) {
         PRIVACY_BOL_CronDao::getInstance()->batchSaveOrUpdate($savedActionList);
     }
     return $affectedRows;
 }