public function find($id, Application_Model_User $user) { $result = $this->getDbTable()->find($id); if (0 === count($result)) { return; } $user->setOptions($result->current()->toArray()); }
public function importEmployee($options, $targetPath) { include_once LIBRARY_PATH . "/Base/Excel/PHPExcel.php"; $objPHPExcel = new PHPExcel(); $objPHPExcel = PHPExcel_IOFactory::load($targetPath); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { if ($worksheet->getTitle() == "user") { $rowctr = 0; $insertctr = 0; $updatectr = 0; foreach ($worksheet->getRowIterator() as $row) { if ($row->getRowIndex() != 1) { $options['employeeCode'] = $worksheet->getCell("A" . $row->getRowIndex())->getCalculatedValue(); $options['email'] = $worksheet->getCell("B" . $row->getRowIndex())->getCalculatedValue(); $options['username'] = $worksheet->getCell("C" . $row->getRowIndex())->getCalculatedValue(); //$options['password']=$worksheet->getCell("D".$row->getRowIndex())->getCalculatedValue(); $options['firstName'] = $worksheet->getCell("E" . $row->getRowIndex())->getCalculatedValue(); $options['middleName'] = $worksheet->getCell("F" . $row->getRowIndex())->getCalculatedValue(); $options['lastName'] = $worksheet->getCell("G" . $row->getRowIndex())->getCalculatedValue(); $options['dob'] = $worksheet->getCell("H" . $row->getRowIndex())->getCalculatedValue(); $options['sex'] = $worksheet->getCell("I" . $row->getRowIndex())->getCalculatedValue(); $options['mobile'] = $worksheet->getCell("J" . $row->getRowIndex())->getCalculatedValue(); $options['contactNo'] = $worksheet->getCell("K" . $row->getRowIndex())->getCalculatedValue(); $options['extensionNo'] = $worksheet->getCell("L" . $row->getRowIndex())->getCalculatedValue(); $options['skype'] = $worksheet->getCell("M" . $row->getRowIndex())->getCalculatedValue(); $options['doj'] = $worksheet->getCell("N" . $row->getRowIndex())->getCalculatedValue(); $options['marriageAnniversary'] = $worksheet->getCell("O" . $row->getRowIndex())->getCalculatedValue(); $options['fatherName'] = $worksheet->getCell("P" . $row->getRowIndex())->getCalculatedValue(); $options['correspondenceAddress'] = $worksheet->getCell("Q" . $row->getRowIndex())->getCalculatedValue(); $options['pan'] = $worksheet->getCell("R" . $row->getRowIndex())->getCalculatedValue(); $options['designationId'] = $worksheet->getCell("S" . $row->getRowIndex())->getCalculatedValue(); $options['departmentId'] = $worksheet->getCell("T" . $row->getRowIndex())->getCalculatedValue(); $options['status'] = 'active'; if ($options['designationId'] == "") { $options['designationId'] = '15'; } //other if ($options['departmentId'] == "") { $options['departmentId'] = '10'; } //other if ($options['employeeCode'] == "53") { $options['userLevelId'] = '2'; //super admin $options['password'] = "******"; } elseif ($options['employeeCode'] == "2") { $options['userLevelId'] = '3'; //hr $options['username'] = $options['email']; } elseif ($options['employeeCode'] == "5") { $options['userLevelId'] = '4'; //pm $options['username'] = $options['email']; } else { $options['userLevelId'] = '1'; //employee $options['username'] = $options['email']; } $user = new Application_Model_User(); $user = $user->fetchRow("employee_code='{$options['employeeCode']}'"); if (false === $user) { //insert $user = new Application_Model_User($options); if ($user->save() > 0) { $insertctr++; } } else { //update $user->setOptions($options); if ($user->save()) { $updatectr++; } } $rowctr++; } } //end of row iterator foreach } // If worksheet = Sheet1 } // end of worksheet iterator foreach return $rowctr; }
public function addAction() { $request = $this->getRequest(); $form = new Admin_Form_User(); $options = $request->getPost(); if ($request->isPost()) { /*---- email validation ----*/ $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.')))); /*-------------------------*/ if ($form->isValid($options)) { $model = new Application_Model_User(); $options['dob'] = $options['year'] . "-" . $options['month'] . "-" . $options['day']; $options['status'] = 'active'; $options['password'] = md5($options['password']); $options['preferredLanguage'] = 'English'; //$options['userLevelId'] =$options['userLevelId']; //$model->setOptions($options); // $id=$model->save(); /*--------- Upload image START -------------------------*/ $upload = new Zend_File_Transfer_Adapter_Http(); if ($upload->isValid('image')) { $upload->setDestination("media/picture/profile/"); try { $upload->receive('image'); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $file_name = $upload->getFileName('image'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "profile_" . $id . ".{$ext}"; $targetPath = 'media/picture/profile/' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $options['image'] = $target_file_name; /*--- Generate Thumbnail ---*/ $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(100, 100); $thumb->save($targetPath = 'media/picture/profile/thumb_' . $target_file_name); $model->setOptions($options); $model->setId($id); $id = $model->save(); } /*--------- Upload image END -------------------------*/ //$options['dob'] = $options['year']."-".$options['month']."-".$options['day']; //$model->setOptions($options); //$model->save(); $user = new Application_Model_User($options); $user_id = $user->save(); if ($user_id > 0) { /*---- default permission settings ----*/ $user->setDefaultPermissions($user_id); $user->setDefaultJournal($user_id); } $this->view->msg = "'User has been inserted successfully!"; $form->reset(); } else { $form->reset(); $form->populate($options); } } $this->view->form = $form; }