Ejemplo n.º 1
0
 /**
  * @method POST
  */
 public function postAction()
 {
     /** @var Entity $entity */
     $entity = new $this->entityName();
     $this->entityMapper->mapper($entity, $_POST);
     if ($this->entityMapper->hasErrors()) {
         return $this->jsonResponse($this->entityMapper->getErrors(), 400);
     }
     $persisted = $this->manager->save($entity);
     if (!$persisted) {
         return $this->jsonResponse(array('error' => self::PERSISTED_ERROR), 400);
     }
     return $this->jsonResponse(array('success' => 'Alles Gut!'));
 }
Ejemplo n.º 2
0
 public function submitNewManager()
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         $validator = Validator::make(array("last name" => Input::get("last_name")), array("last name" => "required"));
         if ($validator->fails()) {
             Input::flash();
             return Redirect::to('settings/employees/addmanager')->with('message', $validator->messages()->first());
         } else {
             if (!empty(Input::get("first_name") && !preg_match('/^[\\pL.-\\s]+$/u', Input::get("first_name"))) || !preg_match('/^[\\pL.-\\s]+$/u', Input::get("last_name"))) {
                 Input::flash();
                 return Redirect::to('settings/employees/addmanager')->with('message', "First name/last name fields must only contain alpabetic characters and whitespaces.");
             } else {
                 $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has added a new manager: <strong>" . Input::get("first_name") . " " . Input::get("last_name") . "<br/>";
                 $manager = new Manager();
                 $manager->first_name = !empty(Input::get("first_name")) ? trim(Input::get("first_name")) : null;
                 $manager->last_name = trim(Input::get("last_name"));
                 $manager->save();
                 //Log the changes made
                 $newLog = new UserLog();
                 $newLog->description = $desc;
                 $newLog->user_id = Session::get('user_id');
                 $newLog->type = "System";
                 $newLog->save();
                 return Redirect::to('settings/employees/addmanager')->with('success', "You have successfully added a new manager.");
             }
         }
     } else {
         return Redirect::to("/");
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Manager();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Manager'])) {
         $model->attributes = $_POST['Manager'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->username));
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ["txtName" => "required|unique:teams,name", 'staff' => 'required'], ["txtName.required" => "Please enter cate's name.", 'txt.unique' => 'This name has already been taken', 'staff.required' => 'Please select staff']);
     $team = new Manager();
     $team->name = $request->txtName;
     $team->created_user_id = Auth::user()->id;
     $team->save();
     foreach ($request->input('staff') as $key => $value) {
         $detail = new TeamDetail();
         $detail->team_id = $team->id;
         $detail->staff_id = $value;
         $detail->save();
     }
     return redirect()->route('admin.team.manager.index')->with('success', 'Posted completely!');
 }
Ejemplo n.º 5
0
 public function actionCreate()
 {
     if (Yii::app()->user->getIsSuperUser() == false && Yii::app()->user->checkAccess('createManager') == false) {
         throw new CHttpException(403);
     }
     $manager = new Manager();
     if (isset($_POST['Manager'])) {
         $manager->attributes = Yii::app()->request->getPost('Manager');
         if ($manager->validate() && $manager->save()) {
             $this->setFlashMessage('管理员添加成功');
             ManagerLog::logCurrentUserAction(1, '添加管理员', $manager->login_name);
             $this->redirect($this->getReturnUrl());
         }
     }
     $managerRoleOptions = ManagerRole::model()->getOptions();
     $this->breadcrumbs = array('管理员' => array('index'), '添加');
     $this->render('create', array('manager' => $manager, 'managerRoleOptions' => $managerRoleOptions, 'returnUrl' => $this->getReturnUrl()));
 }
Ejemplo n.º 6
0
    /**
     * Self Referencing
     */
    function self_referencing()
    {
        echo '<h1>Self Referencing Relationships</h1>';
        echo '<p>DataMapper allows you to have a model setup with a relationship to its self (hence, self referencing).</p>';
        echo '<p>Take a look at the Employee, Manager, Supervisor, and Underling models included in the DataMapper download.  You\'ll notice they all have references back to the employees table (with their inheritance of the Employee model). The relationships they\'re setup with are:</p>';
        echo '<ul><li>A Manager manages Many Supervisors.</li><li>A Supervisor has One Manager.</li><li>A Supervisor supervises Many Underlings.</li><li>An Underling has One Supervisor.</li></ul>';
        echo '<hr />';
        echo '<p>Here we create a number of different types of employees.</p>';
        echo '<code>
		// Create Manager<br />
		$m = new Manager();<br />
		$m->first_name = \'Jake\';<br />
		$m->last_name = \'Ronalds\';<br />
		$m->position = \'Manager\';<br />
		$m->save();<br />
		<br />
		<br />
		// Create Supervisors<br />
		$s = new Supervisor();<br />
		$s->first_name = \'Bob\';<br />
		$s->last_name = \'Thomas\';<br />
		$s->position = \'Supervisor\';<br />
		$s->save();<br />
		<br />
		$s = new Supervisor();<br />
		$s->first_name = \'Sarah\';<br />
		$s->last_name = \'Parker\';<br />
		$s->position = \'Supervisor\';<br />
		$s->save();<br />
		<br />
		<br />
		// Create Underlings<br />
		$u = new Underling();<br />
		$u->first_name = \'Fred\';<br />
		$u->last_name = \'Smith\';<br />
		$u->position = \'Underling\';<br />
		$u->save();<br />
		<br />
		$u = new Underling();<br />
		$u->first_name = \'Jayne\';<br />
		$u->last_name = \'Doe\';<br />
		$u->position = \'Underling\';<br />
		$u->save();<br />
		<br />
		$u = new Underling();<br />
		$u->first_name = \'Joe\';<br />
		$u->last_name = \'Public\';<br />
		$u->position = \'Underling\';<br />
		$u->save();<br />
		<br />
		$u = new Underling();<br />
		$u->first_name = \'Sam\';<br />
		$u->last_name = \'Rogers\';<br />
		$u->position = \'Underling\';<br />
		$u->save();</code>';
        // Create Manager
        $m = new Manager();
        $m->first_name = 'Jake';
        $m->last_name = 'Ronalds';
        $m->position = 'Manager';
        $m->save();
        // Create Supervisors
        $s = new Supervisor();
        $s->first_name = 'Bob';
        $s->last_name = 'Thomas';
        $s->position = 'Supervisor';
        $s->save();
        $s = new Supervisor();
        $s->first_name = 'Sarah';
        $s->last_name = 'Parker';
        $s->position = 'Supervisor';
        $s->save();
        // Create Underlings
        $u = new Underling();
        $u->first_name = 'Fred';
        $u->last_name = 'Smith';
        $u->position = 'Underling';
        $u->save();
        $u = new Underling();
        $u->first_name = 'Jayne';
        $u->last_name = 'Doe';
        $u->position = 'Underling';
        $u->save();
        $u = new Underling();
        $u->first_name = 'Joe';
        $u->last_name = 'Public';
        $u->position = 'Underling';
        $u->save();
        $u = new Underling();
        $u->first_name = 'Sam';
        $u->last_name = 'Rogers';
        $u->position = 'Underling';
        $u->save();
        echo '<hr />';
        echo '<p>Now we\'ll set up some relationships.</p>';
        echo '<code>// Get the first Supervisor<br />
		$s = new Supervisor();<br />
		$s->get(1);<br />
		<br />
		// Get first 2 Underlings<br />
		$u = new Underling();<br />
		$u->get(2);<br />
		<br />
		// Setup Supervisor to supervise those Underlings<br />
		$s->save($u->all);<br />
		<br />
		<br />
		// Get the second Supervisor<br />
		$s = new Supervisor();<br />
		$s->get(1, 1);<br />
		<br />
		// Get the other 2 Underlings<br />
		$u = new Underling();<br />
		$u->get(2, 2);<br />
		<br />
		// Setup Supervisor to supervise those Underlings<br />
		$s->save($u->all);<br />
		<br />
		<br />
		// Get the Manager<br />
		$m = new Manager();<br />
		$m->get();<br />
		<br />
		// Get the Supervisors<br />
		$s = new Supervisor();<br />
		$s->get();<br />
		<br />
		// Setup Manager to manage those Supervisors<br />
		$m->save($s->all);</code>';
        // Get the first Supervisor
        $s = new Supervisor();
        $s->get(1);
        // Get first 2 Underlings
        $u = new Underling();
        $u->get(2);
        // Setup Supervisor to supervise those Underlings
        $s->save($u->all);
        // Get the second Supervisor
        $s = new Supervisor();
        $s->get(1, 1);
        // Get the other 2 Underlings
        $u = new Underling();
        $u->get(2, 2);
        // Setup Supervisor to supervise those Underlings
        $s->save($u->all);
        // Get the Manager
        $m = new Manager();
        $m->get();
        // Get the Supervisors
        $s = new Supervisor();
        $s->get();
        // Setup Manager to manage those Supervisors
        $m->save($s->all);
        echo '<hr />';
        echo '<p>Now that we\'ve got our relationships setup, let\'s show how they\'re related to each other:</p>';
        echo '<code>$m = new Manager();<br />
		$m->get();<br />
		<br />
		echo $m->full_name() . \' is a \' . $m->position . \' who manages these Supervisors:&lt;br /&gt;\';<br />
		<br />
		$m->supervisor->get();<br />
		<br />
		foreach ($m->supervisor->all as $s)<br />
		{
		&nbsp;&nbsp;&nbsp;&nbsp;echo \'&nbsp;&nbsp;&nbsp;&nbsp;\' . $s->full_name() . \' is a \' . $s->position . \' who supervises these Underlings:&lt;br /&gt;\';<br />
			<br />
		&nbsp;&nbsp;&nbsp;&nbsp;$s->underling->get();<br />
			<br />
		&nbsp;&nbsp;&nbsp;&nbsp;foreach ($s->underling->all as $u)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;{<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo \'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\' . $u->full_name() . \' is an \' . $u->position . \'&lt;br /&gt;\';<br />
		&nbsp;&nbsp;&nbsp;&nbsp;}<br />
		}</code>';
        echo '<hr />';
        echo '<p>This produces:</p>';
        $m = new Manager();
        $m->get();
        echo $m->full_name() . ' is a ' . $m->position . ' who manages these Supervisors:<br />';
        $m->supervisor->get();
        foreach ($m->supervisor->all as $s) {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;' . $s->full_name() . ' is a ' . $s->position . ' who supervises these Underlings:<br />';
            $s->underling->get();
            foreach ($s->underling->all as $u) {
                echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $u->full_name() . ' is an ' . $u->position . '<br />';
            }
        }
        echo '<hr />';
        echo '<p>If we wanted to look at Sam Rogers\' supervisor and their supervisors manager, we could do:</p>';
        echo '<code>$u = new Underling();<br />
		$u->where(\'first_name\', \'Sam\')->where(\'last_name\', \'Rogers\')->get();<br />
		<br />
		$u->supervisor->get();<br />
		$u->supervisor->manager->get();<br />
		<br />
		echo $u->full_name . \' is supervised by \' . $u->supervisor->full_name() . \' who is in turn managed by \' . $u->supervisor->manager->full_name() . \'&lt;br /&gt;\';</code>';
        echo '<hr />';
        echo '<p>This produces:</p>';
        $u = new Underling();
        $u->where('first_name', 'Sam')->where('last_name', 'Rogers')->get();
        $u->supervisor->get();
        $u->supervisor->manager->get();
        echo $u->full_name() . ' is supervised by ' . $u->supervisor->full_name() . ' who is in turn managed by ' . $u->supervisor->manager->full_name() . '<br />';
        echo '<hr />';
        echo '<p>Ok, so let\'s do something different and show the total number of Managers:</p>';
        echo '<code>echo $m . \' count: \' . $m->count() . \'&nbsp;br /&nbsp;\';</code>';
        echo '<hr />';
        echo '<p>This produces:</p>';
        echo $m . ' count: ' . $m->count() . '<br />';
        echo '<hr />';
        echo '<p>Now let\'s show how many supervisors are related to ' . $m . ' ' . $m->full_name() . ':</p>';
        echo '<code>echo $m . \' \' . $m->full_name() . \' supervises \' .  $m->supervisor->count() . \' \' . plural($m->supervisor) . \'&lt;br /&gt;\' ;</code>';
        echo '<hr />';
        echo '<p>This produces:</p>';
        echo $m . ' ' . $m->full_name() . ' manages ' . $m->supervisor->count() . ' ' . plural($m->supervisor) . '.<br />';
        echo '<hr />';
        echo '<p>The total counts:</p>';
        echo ucfirst(plural($m)) . ': ' . $m->count() . '<br />';
        echo ucfirst(plural($s)) . ': ' . $s->count() . '<br />';
        echo ucfirst(plural($u)) . ': ' . $u->count() . '<br />';
        echo '<p><a href="' . site_url('examples') . '">Back to Examples</a></p>';
    }
Ejemplo n.º 7
0
 public function readline_leader($sheet, $project_id, $i)
 {
     $interviewer = new Manager();
     $interviewer->name = self::filter($sheet->getCell('C' . $i)->getValue());
     $interviewer->username = random_string();
     $interviewer->password = random_string();
     $interviewer->role = 'L';
     if (!$interviewer->save()) {
         foreach ($interviewer->getMessages() as $message) {
             throw new Exception($message);
         }
     }
 }
Ejemplo n.º 8
0
 public static function insertInterviewer($data, $project_id)
 {
     //对原有数据整理
     $interviewer = Manager::find(array('project_id =?0 and role=?1', "order" => "username desc", 'bind' => array(0 => $project_id, 1 => 'I')));
     $new_count = count($data);
     //1501 101
     $already_number = 0;
     if (count($interviewer) == 0) {
         $already_number = 0;
     } else {
         $already_number = $interviewer[0]->username - $project_id * 1000 - 100;
     }
     #异常
     if ($new_count + $already_number > 99) {
         throw new Exception('项目人数超限-99');
     }
     $start = $project_id * 1000 + 100 + $already_number + 1;
     try {
         $manager = new TxManager();
         $transaction = $manager->get();
         foreach ($data as $value) {
             $manager = new Manager();
             $manager->setTransaction($transaction);
             $manager->project_id = $project_id;
             $manager->role = "I";
             $manager->username = $start++;
             $manager->password = self::getRandString();
             $manager->name = $value;
             if ($manager->save() == false) {
                 $transaction->rollback("数据插入失败");
             }
         }
         $transaction->commit();
         return true;
     } catch (TxFailed $e) {
         throw new Exception($e->getMessage());
     }
 }