public function getPhotoFilePath() { $stu = $this; $filename = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('sf_app') . '/images/tmp/stu_photo_' . $stu->getCode() . '.png'; $url_filename = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . '/images/tmp/'; $photo_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; $student_id = $this->getId(); $c = new Criteria(); $c->add(StudentPhotoPeer::STUDENT_ID, $student_id); $photo = StudentPhotoPeer::doSelectOne($c); $contents = ""; if ($photo != null) { $contents = base64_decode($photo->getThumbnail()->getContents()); } else { $fh = fopen($photo_dir . 'no_photo.png'); $contents = fread($fh, filesize($photo_dir . 'no_photo.png')); fclose($fh); } $fh = fopen($filename, "w+"); fwrite($fh, $contents); fclose($fh); return $url_filename . 'stu_photo_' . $this->getCode() . '.png'; }
public function executeUpdateStudent() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_type = $this->getRequestParameter('action_type'); $counseling_id = $this->getRequestParameter('counseling_id'); $counseling = CounselingPeer::retrieveByPK($counseling_id); $this->forward404Unless($counseling); $accal_id = $this->getRequestParameter('accal_id'); $accal = AcademicCalendarPeer::retrieveByPK($accal_id); $this->forward404Unless($accal); // add/update student_detail if ($action_type == $action_i18n || !$this->getRequestParameter('student_detail_id')) { $student_detail = new StudentDetail(); } else { $student_detail = StudentDetailPeer::retrieveByPk($this->getRequestParameter('student_detail_id')); $this->forward404Unless($student_detail); } $student_detail->setId($this->getRequestParameter('student_detail_id')); $student_detail->setShortName($this->getRequestParameter('short_name')); $student_detail->setPob($this->getRequestParameter('pob')); if ($this->getRequestParameter('dob')) { $student_detail->setDob($this->getRequestParameter('dob')); } $student_detail->setSex($this->getRequestParameter('sex')); $student_detail->setReligionId($this->getRequestParameter('religion_id')); $student_detail->setCountryId($this->getRequestParameter('country_id')); $student_detail->setNativeLanguage($this->getRequestParameter('native_language')); $student_detail->setAddress($this->getRequestParameter('address')); $student_detail->setPostCode($this->getRequestParameter('post_code')); $student_detail->setRegionId($this->getRequestParameter('region_id')); $student_detail->setPhone($this->getRequestParameter('phone')); $student_detail->setCellphone($this->getRequestParameter('cellphone')); $student_detail->setCompany($this->getRequestParameter('company')); $student_detail->setParentName($this->getRequestParameter('father')); $student_detail->setJobTitle($this->getRequestParameter('job_title')); $student_detail->setSchoolOfOrigin($this->getRequestParameter('school_of_origin')); $student_detail->setSchoolOfOriginAddress($this->getRequestParameter('school_of_origin_address')); $student_detail->setRegNote($this->getRequestParameter('reg_note')); $student_detail->setChildNumber($this->getRequestParameter('child_number')); $student_detail->setBloodSiblings($this->getRequestParameter('blood_siblings')); $student_detail->setStepSiblings($this->getRequestParameter('step_siblings')); $student_detail->setOrphanageStatus($this->getRequestParameter('orphanage_status')); $student_detail->setResidenceStatus($this->getRequestParameter('residence_status')); $student_detail->setHomeDistance($this->getRequestParameter('home_distance')); $student_detail->setTransport($this->getRequestParameter('transport')); $student_detail->setAcademicCalendarId($this->getRequestParameter('department2')); $student_detail->setIllness($this->getRequestParameter('illness')); $student_detail->setIllnessNote($this->getRequestParameter('illness_note')); $student_detail->setGraduationGrade($this->getRequestParameter('graduation_grade')); $student_detail->setGraduationYear($this->getRequestParameter('graduation_year')); $student_detail->setBloodType($this->getRequestParameter('blood_type')); $student_detail->setTall($this->getRequestParameter('tall')); $student_detail->setDepartmentOfOrigin($this->getRequestParameter('department_of_origin')); $student_detail->setWeight($this->getRequestParameter('weight')); $student_detail->save(); if ($action_type == $action_i18n || !$this->getRequestParameter('id')) { $student = new Student(); } else { $student = StudentPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($student); } $student->setId($this->getRequestParameter('id')); $student->setCode($this->getRequestParameter('code')); $student->setCode2($this->getRequestParameter('code2')); $student->setCode3($this->getRequestParameter('code3')); $student->setName($this->getRequestParameter('name')); $student->setClassName($this->getRequestParameter('class_name')); $student->setAcademicCalendarId($this->getRequestParameter('academic_calendar_id')); $student->setCurriculumId($this->getRequestParameter('curriculum_id')); $student->setClassGroupId($this->getRequestParameter('class_group_id')); $student->setStatus($this->getRequestParameter('status')); $student->setStudentDetail($student_detail); if ($this->getRequestParameter('password') != null && strlen($this->getRequestParameter('password')) > 0) { // password set $crypted = sha1(sfConfig::get('app_salt') . $this->getRequestParameter('password')); if ($student->getPassword() != $crypted && strlen($this->getRequestParameter('password')) > 0) { // password changed $student->setPassword($crypted); } } elseif ($student->getPassword() == null || $student->getPassword() == '') { // create $crypted = sha1(sfConfig::get('app_salt') . $student_detail->getDob('dmY')); $student->setPassword($crypted); } $student->save(); if ($student->getStatus() == Student::STATUS_GRADUATE) { $student->setGraduationDate(date('Y/m/d')); $student->save(); } // save photo $photo_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('photoFile') && $this->getRequestParameter('photoFile') != '' && $this->getRequestParameter('photoFile') != null) { // get photo content $photo_file = $photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile'); $content = file_get_contents($photo_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($photo_file); // generate photo $photo = imagecreatetruecolor(150, 195); imagecopyresized($photo, $im, 0, 0, 0, 0, 150, 195, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 130); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 130, $w, $h); // get photo record $c = new Criteria(); $c->add(StudentPhotoPeer::STUDENT_ID, $student->getId()); $student_photo = StudentPhotoPeer::doSelectOne($c); if ($student_photo == null) { $student_photo = new StudentPhoto(); $student_photo->setStudent($student); } // save photo imagepng($photo, $photo_file); $student_photo->setPhoto(base64_encode(file_get_contents($photo_file))); imagepng($thumb, $photo_file); $student_photo->setThumbnail(base64_encode(file_get_contents($photo_file))); $student_photo->save(); unlink($photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile')); } return $this->redirect('counseling_sd/listStudent?accal_id=' . $accal->getId() . '&counseling_id=' . $counseling->getId()); }
public function executeGetPhoto() { $this->setTemplate('blank'); $photo_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; $student_id = $this->getRequestParameter('id'); $c = new Criteria(); $c->add(StudentPhotoPeer::STUDENT_ID, $student_id); $photo = StudentPhotoPeer::doSelectOne($c); $this->getResponse()->setHttpHeader('Content-Type', 'image/png'); $contents = ""; if ($photo != null && $photo->getThumbnail()->getContents()) { $contents = imagecreatefromstring(base64_decode($photo->getThumbnail()->getContents())); } else { $contents = imagecreatefrompng($photo_dir . 'no_photo.png'); } return imagepng($contents); }
public function executeUpdateStudent() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_type = $this->getRequestParameter('action_type'); // add/update member_detail if ($action_type == $action_i18n || !$this->getRequestParameter('member_detail_id')) { $member_detail = new MemberDetail(); } else { $member_detail = MemberDetailPeer::retrieveByPk($this->getRequestParameter('member_detail_id')); $this->forward404Unless($member_detail); } $member_detail->setId($this->getRequestParameter('member_detail_id')); $member_detail->setPob($this->getRequestParameter('pob')); if ($this->getRequestParameter('dob')) { $member_detail->setDob($this->getRequestParameter('dob')); } $member_detail->setSex($this->getRequestParameter('sex')); $member_detail->setAddress($this->getRequestParameter('address')); $member_detail->setRegionId($this->getRequestParameter('region_id')); $member_detail->setPostCode($this->getRequestParameter('post_code')); $member_detail->setPhone($this->getRequestParameter('phone')); $member_detail->setCellphone($this->getRequestParameter('cellphone')); $member_detail->setReligionId($this->getRequestParameter('religion_id')); $member_detail->setSchoolOfOrigin($this->getRequestParameter('school_of_origin')); $member_detail->setGraduationYear($this->getRequestParameter('graduation_year')); $member_detail->setGraduationGrade($this->getRequestParameter('graduation_grade')); $member_detail->setCompany($this->getRequestParameter('company')); $member_detail->setJobTitle($this->getRequestParameter('job_title')); $member_detail->setCollegeOfOrigin($this->getRequestParameter('college_of_origin')); $member_detail->setDepartmentOfOrigin($this->getRequestParameter('department_of_origin')); $member_detail->setRegYear($this->getRequestParameter('reg_year')); $member_detail->setParentName($this->getRequestParameter('parent_name')); $member_detail->save(); // add student detail if ($action_type == $action_i18n || !$this->getRequestParameter('student_detail_id')) { $student_detail = new StudentDetail(); } else { $student_detail = StudentDetailPeer::retrieveByPk($this->getRequestParameter('student_detail_id')); $this->forward404Unless($student_detail); } $student_detail->setId($this->getRequestParameter('student_detail_id')); $student_detail->setPob($this->getRequestParameter('pob')); if ($this->getRequestParameter('dob')) { $student_detail->setDob($this->getRequestParameter('dob')); } $student_detail->setSex($this->getRequestParameter('sex')); $student_detail->setAddress($this->getRequestParameter('address')); $student_detail->setRegionId($this->getRequestParameter('region_id')); $student_detail->setPostCode($this->getRequestParameter('post_code')); $student_detail->setPhone($this->getRequestParameter('phone')); $student_detail->setCellphone($this->getRequestParameter('cellphone')); $student_detail->setReligionId($this->getRequestParameter('religion_id')); $student_detail->setSchoolOfOrigin($this->getRequestParameter('school_of_origin')); $student_detail->setGraduationYear($this->getRequestParameter('graduation_year')); $student_detail->setGraduationGrade($this->getRequestParameter('graduation_grade')); $student_detail->setCompany($this->getRequestParameter('company')); $student_detail->setJobTitle($this->getRequestParameter('job_title')); $student_detail->setCollegeOfOrigin($this->getRequestParameter('college_of_origin')); $student_detail->setDepartmentOfOrigin($this->getRequestParameter('department_of_origin')); $student_detail->setRegYear($this->getRequestParameter('reg_year')); $student_detail->setParentName($this->getRequestParameter('parent_name')); $student_detail->save(); if ($action_type == $action_i18n || !$this->getRequestParameter('id')) { $member = new Member(); } else { $member = MemberPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($member); } $member->setId($this->getRequestParameter('id')); $member->setCode($this->getRequestParameter('code')); $member->setNoReg($this->getRequestParameter('no_reg')); $member->setName($this->getRequestParameter('name')); $member->setClassName($this->getRequestParameter('class_name')); $member->setDepartmentId($this->getRequestParameter('department_id')); $old_status = $member->getStatus(); $member->setStatus($this->getRequestParameter('status')); $member->setType('1'); $member->setMemberDetail($member_detail); if ($this->getRequestParameter('password') != null && strlen($this->getRequestParameter('password')) > 0) { // password set $crypted = sha1(sfConfig::get('app_salt') . $this->getRequestParameter('password')); if ($member->getPassword() != $crypted && strlen($this->getRequestParameter('password')) > 0) { // password changed $member->setPassword($crypted); } } elseif ($member->getPassword() == null || $member->getPassword() == '') { // create $crypted = sha1(sfConfig::get('app_salt') . $this->getRequestParameter('code') . $member_detail->getDob('dm')); $member->setPassword($crypted); } $member->save(); if ($action_type == $action_i18n || !$this->getRequestParameter('student_id')) { $student = new Student(); } else { $student = StudentPeer::retrieveByPk($this->getRequestParameter('student_id')); $this->forward404Unless($student); } $student->setId($this->getRequestParameter('student_id')); $student->setCode($this->getRequestParameter('code')); $student->setName($this->getRequestParameter('name')); $old_status = $student->getStatus(); $student->setMemberId($member); $student->setStatus($this->getRequestParameter('status')); $student->setStudentDetail($student_detail); if ($this->getRequestParameter('password') != null && strlen($this->getRequestParameter('password')) > 0) { // password set $crypted = sha1(sfConfig::get('app_salt') . $this->getRequestParameter('password')); if ($student->getPassword() != $crypted && strlen($this->getRequestParameter('password')) > 0) { // password changed $student->setPassword($crypted); } } elseif ($student->getPassword() == null || $student->getPassword() == '') { // create $crypted = sha1(sfConfig::get('app_salt') . $this->getRequestParameter('code') . $student_detail->getDob('dm')); $student->setPassword($crypted); } $student->save(); // save member photo $photo_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('photoFile') && $this->getRequestParameter('photoFile') != '' && $this->getRequestParameter('photoFile') != null) { // get photo content $photo_file = $photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile'); $content = file_get_contents($photo_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($photo_file); // generate photo $photo = imagecreatetruecolor(150, 200); imagecopyresized($photo, $im, 0, 0, 0, 0, 150, 200, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 150); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 150, $w, $h); // get photo record $c = new Criteria(); $c->add(MemberPhotoPeer::MEMBER_ID, $member->getId()); $member_photo = MemberPhotoPeer::doSelectOne($c); if ($member_photo == null) { $member_photo = new MemberPhoto(); $member_photo->setMember($member); } // save photo imagepng($photo, $photo_file); $member_photo->setPhoto(base64_encode(file_get_contents($photo_file))); imagepng($thumb, $photo_file); $member_photo->setThumbnail(base64_encode(file_get_contents($photo_file))); $member_photo->save(); unlink($photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile')); } // save student photo $photo_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('photoFile') && $this->getRequestParameter('photoFile') != '' && $this->getRequestParameter('photoFile') != null) { // get photo content $photo_file = $photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile'); $content = file_get_contents($photo_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($photo_file); // generate photo $photo = imagecreatetruecolor(150, 195); imagecopyresized($photo, $im, 0, 0, 0, 0, 150, 195, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 130); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 130, $w, $h); // get photo record $c = new Criteria(); $c->add(StudentPhotoPeer::STUDENT_ID, $student->getId()); $student_photo = StudentPhotoPeer::doSelectOne($c); if ($student_photo == null) { $student_photo = new StudentPhoto(); $student_photo->setStudent($student); } // save photo imagepng($photo, $photo_file); $student_photo->setPhoto(base64_encode(file_get_contents($photo_file))); imagepng($thumb, $photo_file); $student_photo->setThumbnail(base64_encode(file_get_contents($photo_file))); $student_photo->save(); unlink($photo_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('photoFile')); } if ($this->hasRequestParameter('filter_noreg') && $this->getRequestParameter('filter_noreg') != '' && $this->getRequestParameter('filter_noreg') != null) { return $this->redirect('member/listStudent?filters[NO_REG]=' . $this->getRequestParameter('no_reg')); } elseif ($this->hasRequestParameter('filter_code') && $this->getRequestParameter('filter_code') != '' && $this->getRequestParameter('filter_code') != null) { return $this->redirect('member/listStudent?filters[CODE]=' . $this->getRequestParameter('filter_code')); } elseif ($this->hasRequestParameter('filter_deptid') && $this->getRequestParameter('filter_deptid') != '' && $this->getRequestParameter('filter_deptid') != null) { return $this->redirect('member/listStudent?filters[DEPARTMENT_ID]=' . $this->getRequestParameter('filter_deptid')); } elseif ($this->hasRequestParameter('filter_status') && $this->getRequestParameter('filter_status') != '' && $this->getRequestParameter('filter_status') != null) { return $this->redirect('member/listStudent?filters[STATUS]=' . $this->getRequestParameter('filter_status')); } elseif ($this->hasRequestParameter('filter_name') && $this->getRequestParameter('filter_name') != '' && $this->getRequestParameter('filter_name') != null) { return $this->redirect('member/listStudent?filters[NAME]=' . $this->getRequestParameter('name')); } else { return $this->redirect('member/listStudent'); } }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = StudentPhotoPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setStudentId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setPhoto($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setThumbnail($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setFilename($arr[$keys[4]]); } }
public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(StudentPhotoPeer::ID, $pks, Criteria::IN); $objs = StudentPhotoPeer::doSelect($criteria, $con); } return $objs; }