/**
  * Create new log entry and return it
  *
  * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationReadLog
  */
 static function createLog(ApplicationDataObject $object, $workspaces, $action = null, $save = true, $log_data = '')
 {
     if (is_null($action)) {
         $action = self::ACTION_READ;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     try {
         Notifier::notifyAction($object, $action, $log_data);
     } catch (Exception $ex) {
     }
     $manager = $object->manager();
     if (!$manager instanceof DataManager) {
         throw new Error('Invalid object manager');
     }
     // if
     $log = new ApplicationReadLog();
     if (logged_user() instanceof Contact) {
         $log->setTakenById(logged_user()->getId());
     } else {
         $log->setTakenById(0);
     }
     $log->setRelObjectId($object->getObjectId());
     $log->setAction($action);
     if ($save) {
         $log->save();
     }
     // if
     return $log;
 }
 /**
  * Create new log entry and return it
  *
  * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationLog
  */
 static function createLog($object, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '')
 {
     $args = array('action' => &$action, 'is_private' => &$is_private, 'is_silent' => &$is_silent, 'save' => &$save, 'log_data' => &$log_data);
     /**
      * Modify log and notification parameters before creating the application log registry
      */
     Hook::fire('application_logs_create', $object, $args);
     if (is_null($action)) {
         $action = self::ACTION_ADD;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     if ($object instanceof TemplateTask || $object instanceof TemplateMilestone) {
         $is_silent = true;
     }
     if (is_null($is_silent)) {
         $is_silent = $action == self::ACTION_DELETE;
     } else {
         $is_silent = (bool) $is_silent;
     }
     // if
     if (!$is_silent) {
         try {
             Notifier::notifyAction($object, $action, $log_data);
         } catch (Exception $ex) {
             Logger::log($ex->getMessage());
         }
     }
     $log = new ApplicationLog();
     if (logged_user() instanceof Contact) {
         $log->setTakenById(logged_user()->getId());
     } else {
         $log->setTakenById(0);
     }
     if ($object instanceof ContentDataObject) {
         $log->setRelObjectId($object->getObjectId());
         $log->setObjectName($object->getObjectName());
     }
     if ($object instanceof Member) {
         $log->setMemberId($object->getId());
         $log->setRelObjectId($object->getObjectId());
         $log->setObjectName($object->getName());
     }
     $log->setAction($action);
     $log->setIsPrivate($is_private);
     $log->setIsSilent($is_silent);
     $log->setLogData($log_data);
     if ($save) {
         $log->save();
     }
     // if
     return $log;
 }
 /**
  * Create new log entry and return it
  *
  * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationReadLog
  */
 static function createLog(ApplicationDataObject $object, $workspaces, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '')
 {
     if (is_null($action)) {
         $action = self::ACTION_READ;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     try {
         Notifier::notifyAction($object, $action, $log_data);
     } catch (Exception $ex) {
     }
     $manager = $object->manager();
     if (!$manager instanceof DataManager) {
         throw new Error('Invalid object manager');
     }
     // if
     $log = new ApplicationReadLog();
     if (logged_user() instanceof User) {
         $log->setTakenById(logged_user()->getId());
     } else {
         $log->setTakenById(0);
     }
     $log->setRelObjectId($object->getObjectId());
     $log->setRelObjectManager(get_class($manager));
     $log->setAction($action);
     if ($save) {
         $log->save();
     }
     // if
     if ($save) {
         if ($workspaces instanceof Project) {
             $wo = new WorkspaceObject();
             $wo->setObject($log);
             $wo->setWorkspace($workspaces);
             $wo->save();
         } else {
             if (is_array($workspaces)) {
                 foreach ($workspaces as $w) {
                     if ($w instanceof Project) {
                         $wo = new WorkspaceObject();
                         $wo->setObject($log);
                         $wo->setWorkspace($w);
                         $wo->save();
                     }
                 }
             }
         }
     }
     return $log;
 }
	/**
	 * Create new log entry and return it
	 *
	 * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
	 *
	 * @param ApplicationDataObject $object
	 * @param Project $project
	 * @param DataManager $manager
	 * @param boolean $save Save log object before you save it
	 * @return ApplicationLog
	 */
	static function createLog($object, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '') {
		if(is_null($action)) {
			$action = self::ACTION_ADD;
		} // if
		if(!self::isValidAction($action)) {
			throw new Error("'$action' is not valid log action");
		} // if

		if(is_null($is_silent)) {
			$is_silent = $action == self::ACTION_DELETE;
		} else {
			$is_silent = (boolean) $is_silent;
		} // if

		if (!$is_silent) {
			try {
				Notifier::notifyAction($object, $action, $log_data);
			} catch (Exception $ex) {
				Logger::log($ex->getMessage());
			}
		}
		
		$log = new ApplicationLog();
		if (logged_user() instanceof Contact) {
			$log->setTakenById(logged_user()->getId());
		} else {
			$log->setTakenById(0);
		}
		if ($object instanceof ContentDataObject) {
			$log->setRelObjectId($object->getObjectId());
			$log->setObjectName($object->getObjectName());
		}
		if ($object instanceof Member) {
			$log->setRelObjectId($object->getId());
			$log->setObjectName($object->getName());
		}
		
		$log->setAction($action);
		$log->setIsPrivate($is_private);
		$log->setIsSilent($is_silent);
		$log->setLogData($log_data);
		
		if($save) {
			$log->save();
		} // if
		
		return $log;
	} // createLog
 /**
  * Create new log entry and return it
  *
  * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationLog
  */
 static function createLog(ApplicationDataObject $object, $workspaces, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '')
 {
     if (is_null($action)) {
         $action = self::ACTION_ADD;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     if (is_null($is_silent)) {
         $is_silent = $action == self::ACTION_DELETE;
     } else {
         $is_silent = (bool) $is_silent;
     }
     // if
     if (!$is_silent) {
         try {
             Notifier::notifyAction($object, $action, $log_data);
         } catch (Exception $ex) {
         }
     }
     if ($object != null) {
         $manager = $object->manager();
     }
     if (!$manager instanceof DataManager) {
         throw new Error('Invalid object manager');
     }
     // if
     $log = new ApplicationLog();
     if (logged_user() instanceof User) {
         $log->setTakenById(logged_user()->getId());
     } else {
         $log->setTakenById(0);
     }
     $log->setRelObjectId($object->getObjectId());
     $log->setObjectName($object->getObjectName());
     $log->setRelObjectManager(get_class($manager));
     $log->setAction($action);
     $log->setIsPrivate($is_private);
     $log->setIsSilent($is_silent);
     $log->setLogData($log_data);
     if ($save) {
         $log->save();
     }
     // if
     // Update is private for this object
     /*if($object instanceof ProjectDataObject) {
     			ApplicationLogs::setIsPrivateForObject($object);
     		} // if*/
     if ($save) {
         if ($workspaces instanceof Project) {
             $wo = new WorkspaceObject();
             $wo->setObject($log);
             $wo->setWorkspace($workspaces);
             $wo->save();
         } else {
             if (is_array($workspaces)) {
                 foreach ($workspaces as $w) {
                     if ($w instanceof Project) {
                         $wo = new WorkspaceObject();
                         $wo->setObject($log);
                         $wo->setWorkspace($w);
                         $wo->save();
                     }
                 }
             }
         }
     }
     return $log;
 }