<?php

/**
 * @name EOLINKER ams open source，EOLINKER open source version
 * @link https://global.eolinker.com/
 * @package EOLINKER
 * @author www.eolinker.com eoLinker Ltd.co 2015-2018
 * 
 * eoLinker is the world's leading and domestic largest online API interface management platform, providing functions such as automatic generation of API documents, API automated testing, Mock testing, team collaboration, etc., aiming to solve the problem of low development efficiency caused by separation of front and rear ends.
 * If you have any problems during the process of use, please join the user discussion group for feedback, we will solve the problem for you with the fastest speed and best service attitude.
 *
 * 
 *
 * Website：https://global.eolinker.com/
 * Slack：eolinker.slack.com
 * facebook：@EoLinker
 * twitter：@eoLinker
 */
class AutoGenerateModule
{
    /**
     * Import API
     * @param $data
     * @param $project_id
     * @param $user_id
     * @return bool
     */
    public function importApi(&$data, &$project_id, &$user_id)
    {
        $dao = new AutoGenerateDao();
        $result = $dao->importApi($data, $project_id);
        if ($result) {
            $log_dao = new ProjectLogDao();
            $log_dao->addOperationLog($project_id, $user_id, ProjectLogDao::$OP_TARGET_PROJECT, $project_id, ProjectLogDao::$OP_TYPE_UPDATE, '通过自动生成文档功能更新接口文档', date('Y-m-d H:i:s', time()));
            return $result;
        } else {
            return FALSE;
        }
    }

    /**
     * Check Project Permission
     * @param $user_name
     * @param $user_password
     * @param $project_id
     * @return bool|array
     */
    public function checkProjectPermission(&$user_name, &$user_password, &$project_id)
    {
        $dao = new GuestDao;
        $user_info = $dao->getLoginInfo($user_name);
        if (md5($user_password) == $user_info['userPassword']) {
            $project_dao = new ProjectDao();
            if ($project_dao->checkProjectPermission($project_id, $user_info['userID'])) {
                $auth_dao = new AuthorizationDao();
                $result = $auth_dao->getProjectUserType($user_info['userID'], $project_id);
                if ($result === FALSE) {
                    return FALSE;
                } elseif ($result > 2) {
                    return FALSE;
                } else {
                    return $user_info;
                }
            } else {
                return FALSE;
            }
        } else {
            return FALSE;
        }
    }
}