/** * * @param WOOOF $wo * @param VO_TblPersonProfile $obj * @return false | id */ public static function savePersonProfile(WOOOF $wo, VO_TblPersonProfile &$obj) { $place = __CLASS__ . '::' . __FUNCTION__; $wo->debug("{$place}: "); $t1 = new WOOOF_dataBaseTable($wo->db, 'person_profiles'); if (!$t1->constructedOk) { return false; } if ($wo->hasContent($obj->id)) { // update $obj->updatedDateTime = WOOOF::currentGMTDateTime(); $res = $t1->updateRowFromArraySimple($obj->toArray()); if ($res === FALSE) { return false; } } else { // insert $obj->isDeleted = '0'; $obj->createdDateTime = WOOOF::currentGMTDateTime(); $obj->updatedDateTime = $obj->createdDateTime; $newId = $t1->insertRowFromArraySimple($obj->toArray()); if ($newId === FALSE) { return false; } $obj->id = $newId; } return $obj->id; }
/** * * @param WOOOF $wo * @param VO_TblFlagItems $obj * @param char $action * @param bool $fetchBack * @return false | type of reported object * Returns actually saved $obj if $fetchBack is set to true */ public static function save(WOOOF $wo, VO_TblFlagItems &$obj, $action = 'I', $fetchBack = true) { $place = __CLASS__ . '::' . __FUNCTION__; $wo->debug("{$place}: "); if (!$wo->hasContent($obj->flaggedByUserId)) { $wo->logError(self::_ECP . "3011 No value provided for [flaggedByUserId]"); return false; } if (!$wo->hasContent($obj->whatId)) { $wo->logError(self::_ECP . "3012 No value provided for [whatId]"); return false; } if (!$wo->hasContent($obj->whatType)) { $wo->logError(self::_ECP . "3013 No value provided for [whatType]"); return false; } if ($obj->flaggedByUserId === $obj->whatId) { $wo->logError(self::_ECP . "3014 Id's cannot be the same"); return false; } $tblFlagItems = new WOOOF_dataBaseTable($wo->db, 'flag_items'); if ($tblFlagItems === FALSE) { return false; } //insert if ($action === 'I') { $obj->flaggedDateTime = WOOOF::currentGMTDateTime(); $newId = $tblFlagItems->insertRowFromArraySimple($obj->toArray()); if ($newId === FALSE) { return false; } } else { $obj->flaggedDateTime = $wo->currentGMTDateTime(); $res = $tblFlagItems->updateRowFromArraySimple($obj->toArray()); if ($res === FALSE) { return false; } } return $obj->whatType; }
/** * * @param WOOOF $wo * @param VO_TblMovieRamaUserMoviesOpinions $obj * @return false | liked movie id */ public static function saveUserOpinion(WOOOF $wo, VO_TblMovieRamaUserMoviesOpinions &$obj) { $place = __CLASS__ . '::' . __FUNCTION__; $wo->debug("{$place}: "); if (!$wo->hasContent($obj->movieramaUserId)) { $wo->logError(self::_ECP . "3001 No value provided for [movieramaUserId]"); return false; } if (!$wo->hasContent($obj->movieId)) { $wo->logError(self::_ECP . "3002 No value provided for [movieId]"); return false; } if ($obj->movieramaUserId === $obj->movieId) { $wo->logError(self::_ECP . "3003 Id's cannot be the same"); return false; } if (!$wo->hasContent($obj->isPositive)) { $wo->logError(self::_ECP . "3004 No value provided for [isPositive]"); return false; } $tblUserMovieOpinions = new WOOOF_dataBaseTable($wo->db, 'movierama_user_movies_opinions'); if (!$tblUserMovieOpinions->constructedOk) { return false; } // insert $newId = $tblUserMovieOpinions->insertRowFromArraySimple($obj->toArray()); if ($newId === FALSE) { return false; } return $obj->movieId; }
/** * * @param WOOOF $wo * @param id $movieramaUserId * @param array $evaluationData * @return false | id */ public static function create(WOOOF $wo, $evaluationData, $movieramaUserId) { $place = __CLASS__ . '::' . __FUNCTION__; $wo->debug("{$place}: 'Create Evaluation'"); if (!$wo->hasContent($movieramaUserId)) { $wo->logError(self::_ECP . "2389 You must provide a [movieramaUserId]"); return false; } //CHECK FOR PREVIOUS EVALUATIONS OF THE SAME OBJECT $whatId = $evaluationData['whatId']; $whatType = $evaluationData['whatType']; $evalTemplateId = $evaluationData['evalTemplateId']; $sql = "\n\t\t\tSELECT *\n\t\t\tFROM evaluations e\n\t\t\tJOIN ( \n\t\t\t SELECT MAX(ev.roundNumber) AS max_roundNumber\n\t\t\t FROM evaluations ev\n\t\t\t WHERE whatId='{$whatId}' AND whatType='{$whatType}' AND userId='{$movieramaUserId}'\n\t\t\t\t\tAND evalTemplateId='{$evalTemplateId}' AND isDeleted='0'\n\t\t\t ) eval\n\t\t\t ON eval.max_roundNumber = e.roundNumber\n\t\t\tWHERE whatId='{$whatId}' AND whatType='{$whatType}' AND userId='{$movieramaUserId}'\n\t\t\t\t AND evalTemplateId='{$evalTemplateId}' AND isDeleted='0'\n\t\t"; $res = $wo->db->getResultByQuery($sql, true, false); if ($res === FALSE) { return FALSE; } $res = $wo->db->resultRows; $nextRoundNumber = 0; foreach ($res as $maxRoundNumberRec) { $nextRoundNumber = $maxRoundNumberRec['roundNumber']; } $tblEvaluationInsert = new VO_TblEvaluations(); $tblEvaluationInsert->whatId = $evaluationData['whatId']; $tblEvaluationInsert->whatType = $evaluationData['whatType']; $tblEvaluationInsert->evalTemplateId = $evaluationData['evalTemplateId']; //$tblEvaluationInsert->isViewable = $evaluationData['isViewable']; $tblEvaluationInsert->isViewable = '0'; $tblEvaluationInsert->roundNumber = $nextRoundNumber + 1; $tblEvaluationInsert->isRunning = '0'; $tblEvaluationInsert->userId = $movieramaUserId; $insertedEvalId = self::save($wo, $tblEvaluationInsert); if ($insertedEvalId === FALSE) { return false; } //copy the template evaluation criteria in evaluation_criteria table $tblTplEvalCriteria = new WOOOF_dataBaseTable($wo->db, 'eval_template_criteria'); if (!$tblTplEvalCriteria->constructedOk) { return false; } $res = $tblTplEvalCriteria->getResult(['evalTemplateId' => $evaluationData['evalTemplateId'], 'isDeleted' => '0'], 'weight', '', '', '', true, false); if ($res === FALSE) { return false; } $tblEvaluationCriteria = new WOOOF_dataBaseTable($wo->db, 'evaluation_criteria'); if (!$tblEvaluationCriteria->constructedOk) { return false; } foreach ($tblTplEvalCriteria->resultRows as $aTplCriteria) { $tblEvalCriteria = new VO_TblEvaluationCriteria(); $tblEvalCriteria->evaluationId = $insertedEvalId; $tblEvalCriteria->evalTemplateId = $aTplCriteria['evalTemplateId']; $tblEvalCriteria->label = $aTplCriteria['label']; $tblEvalCriteria->description = $aTplCriteria['description']; $tblEvalCriteria->evaluationTypeDVCode = $aTplCriteria['evaluationTypeDVCode']; $tblEvalCriteria->isOptional = $aTplCriteria['isOptional']; $tblEvalCriteria->weight = $aTplCriteria['weight']; //save criteria $newCriteriaId = $tblEvaluationCriteria->insertRowFromArraySimple($tblEvalCriteria->toArray()); if ($newCriteriaId === FALSE) { return false; } } return $insertedEvalId; }