Index: src/__phutil_library_map__.php =================================================================== --- src/__phutil_library_map__.php +++ src/__phutil_library_map__.php @@ -201,6 +201,9 @@ 'ConduitAPI_phpast_Method' => 'applications/phpast/conduit/ConduitAPI_phpast_Method.php', 'ConduitAPI_phpast_getast_Method' => 'applications/phpast/conduit/ConduitAPI_phpast_getast_Method.php', 'ConduitAPI_phpast_version_Method' => 'applications/phpast/conduit/ConduitAPI_phpast_version_Method.php', + 'ConduitAPI_phrequent_Method' => 'applications/phrequent/conduit/ConduitAPI_phrequent_Method.php', + 'ConduitAPI_phrequent_start_Method' => 'applications/phrequent/conduit/ConduitAPI_phrequent_start_Method.php', + 'ConduitAPI_phrequent_stop_Method' => 'applications/phrequent/conduit/ConduitAPI_phrequent_stop_Method.php', 'ConduitAPI_phriction_Method' => 'applications/phriction/conduit/ConduitAPI_phriction_Method.php', 'ConduitAPI_phriction_edit_Method' => 'applications/phriction/conduit/ConduitAPI_phriction_edit_Method.php', 'ConduitAPI_phriction_history_Method' => 'applications/phriction/conduit/ConduitAPI_phriction_history_Method.php', @@ -2319,6 +2322,9 @@ 'ConduitAPI_phpast_Method' => 'ConduitAPIMethod', 'ConduitAPI_phpast_getast_Method' => 'ConduitAPI_phpast_Method', 'ConduitAPI_phpast_version_Method' => 'ConduitAPI_phpast_Method', + 'ConduitAPI_phrequent_Method' => 'ConduitAPIMethod', + 'ConduitAPI_phrequent_start_Method' => 'ConduitAPI_phrequent_Method', + 'ConduitAPI_phrequent_stop_Method' => 'ConduitAPI_phrequent_Method', 'ConduitAPI_phriction_Method' => 'ConduitAPIMethod', 'ConduitAPI_phriction_edit_Method' => 'ConduitAPI_phriction_Method', 'ConduitAPI_phriction_history_Method' => 'ConduitAPI_phriction_Method', Index: src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php =================================================================== --- /dev/null +++ src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php @@ -0,0 +1,13 @@ + 'required phid' + ); + } + + public function defineReturnType() { + return 'bool'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $user_id = $request->getUser()->getPHID(); + $object_id = $request->getValue('object'); + + $usertime = new PhrequentUserTime(); + $usertime->setDateStarted(time()); + $usertime->setUserPHID($user_id); + $usertime->setObjectPHID($object_id); + $usertime->save(); + + return true; + } + +} Index: src/applications/phrequent/conduit/ConduitAPI_phrequent_stop_Method.php =================================================================== --- /dev/null +++ src/applications/phrequent/conduit/ConduitAPI_phrequent_stop_Method.php @@ -0,0 +1,60 @@ + 'required phid' + ); + } + + public function defineReturnType() { + return 'bool'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $user = $request->getUser(); + $phid = $request->getValue('object'); + + if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) { + // Don't do anything, it's not being tracked. + return false; + } + + $usertime_dao = new PhrequentUserTime(); + $conn = $usertime_dao->establishConnection('r'); + + queryfx( + $conn, + 'UPDATE %T usertime '. + 'SET usertime.dateEnded = UNIX_TIMESTAMP() '. + 'WHERE usertime.userPHID = %s '. + 'AND usertime.objectPHID = %s '. + 'AND usertime.dateEnded IS NULL '. + 'ORDER BY usertime.dateStarted, usertime.id DESC '. + 'LIMIT 1', + $usertime_dao->getTableName(), + $user->getPHID(), + $phid); + + return true; + } + +}