From 27e5c04e284a9e22df61be7f89d5dac11677da44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 19 Feb 2014 00:02:17 +0100 Subject: [PATCH] favoriten --- app/Config/routes.php | 7 ++ .../Component/MiconwareSessionComponent.php | 26 ++++- app/Controller/UserController.php | 40 ++++---- app/Model/DreamjobCompany.php | 20 +++- app/Model/DreamjobJobOpening.php | 21 ++++- app/Model/DreamjobWorker.php | 29 ++++-- app/View/Elements/barleft.ctp | 12 +-- app/View/Elements/job_opening_item.ctp | 94 ++++++++++--------- app/View/Elements/user_worker_header.ctp | 12 +-- app/View/Layouts/default.ctp | 1 - app/View/User/company.ctp | 12 +-- app/View/User/worker.ctp | 8 ++ 12 files changed, 185 insertions(+), 97 deletions(-) diff --git a/app/Config/routes.php b/app/Config/routes.php index 1998e49..b683bf3 100755 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -35,6 +35,13 @@ Router::connect('/user/:id', array('controller' => 'user', 'action' => 'profil'),array("id" => "[0-9]+")); Router::connect('/user/:id/page/:page', array('controller' => 'user', 'action' => 'profil'),array("id" => "[0-9]+","page" => "[0-9]+")); + Router::connect('/opening', array('controller' => 'job', 'action' => 'openingList')); + Router::connect('/opening/add', array('controller' => 'job', 'action' => 'openingAdd')); + Router::connect('/opening/:id', array('controller' => 'job', 'action' => 'openingGet'),array("id" => "[0-9]+")); + Router::connect('/opening/:id/:favorite', array('controller' => 'job', 'action' => 'openingGet'), array("id" => "[0-9]+",'favorite' => '(?i:favorite)')); + + Router::connect('/favorite', array('controller' => 'job', 'action' => 'favorite')); + Router::connect('/test/', array('controller' => 'user', 'action' => 'test')); /** * ...and connect the rest of 'Pages' controller's URLs. diff --git a/app/Controller/Component/MiconwareSessionComponent.php b/app/Controller/Component/MiconwareSessionComponent.php index a239e07..b905d21 100755 --- a/app/Controller/Component/MiconwareSessionComponent.php +++ b/app/Controller/Component/MiconwareSessionComponent.php @@ -3,14 +3,21 @@ App::uses('Component', 'Controller'); class MiconwareSessionComponent extends Component { public $components = array('Session'); + public $self_worker_obj; + public $self_company_obj; public function init($controller){ $controller->Security->requireSecure(); $this->User = ClassRegistry::init('User'); + $this->refreshCache(); } public function initWeb($controller){ $controller->set("isLoggedin",$this->isLoggedin()); + if($this->isLoggedin()){ + $controller->set("WORKER",($this->self_worker_obj)?$this->self_worker_obj:false); + $controller->set("COMPANY",($this->self_company_obj)?$this->self_company_obj:false); + } $controller->set("isStaff",$this->isStaff()); $controller->set("MEDIA_URL","http://dev.dreamjob.cc/media/"); $controller->set('default',array( @@ -22,13 +29,30 @@ class MiconwareSessionComponent extends Component { 'class' => '')) ); } + public function refreshCache(){ + if($this->isLoggedin()){ + $self_company = false; + $this->self_worker_obj = $this->getApplication('DreamjobWorker'); + if(!is_array($this->self_worker_obj) or count($this->self_worker_obj)<= 0){ + $this->self_company_obj = $this->getApplication('DreamjobCompany'); + $self_company = true; + } + } + } + public function getCompany(){ + return $this->self_company_obj; + } + + public function getWorker(){ + return $this->self_worker_obj; + } public function isLoggedin(){ return $this->Session->check('user'); } public function isStaff(){ - return true; + return false; } public function login($mail,$password){ diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index 1df10b2..210b366 100755 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -28,14 +28,19 @@ class UserController extends AppController { //self check $self_company = false; - $self = $this->MiconwareSession->getApplication('DreamjobWorker'); + $self = $this->MiconwareSession->getWorker(); if(!is_array($self) or count($self)<= 0){ - $self = $this->MiconwareSession->getApplication('DreamjobCompany'); + $self = $this->MiconwareSession->getCompany(); $self_company = true; } //get Profil + $hard_error = false; + $company = false; + $page = null; + $profil = null; + if(empty($this->request->params['id'])) { $profil = $self; $company = $self_company; @@ -48,24 +53,23 @@ class UserController extends AppController { $this->set('id', $this->request->params['id']); } //get Page - - $page = null; - if(is_array($profil) or count($profil) > 0){ - if(!empty($this->request->params['page'])){ - $page = $this->DreamjobPageText->find('first', - array('conditions' => array("DreamjobPageInh.id" => $this->request->params['page'],'DreamjobPageInh.user_id' => $profil['AppUser']['id'])) - ); - if(!is_array($page) or count($page)<= 0) - $page = $this->DreamjobPageImage->find('first', - array('conditions' => array("DreamjobPageInh.id" => $this->request->params['page'],'DreamjobPageInh.user_id' => $profil['AppUser']['id'])) - ); + if(($this->MiconwareSession->isLoggedin()) or ($company) ){ + if(is_array($profil) or count($profil) > 0){ + if(!empty($this->request->params['page'])){ + $page = $this->DreamjobPageText->find('first', + array('conditions' => array("DreamjobPageInh.id" => $this->request->params['page'],'DreamjobPageInh.user_id' => $profil['AppUser']['id'])) + ); + if(!is_array($page) or count($page)<= 0) + $page = $this->DreamjobPageImage->find('first', + array('conditions' => array("DreamjobPageInh.id" => $this->request->params['page'],'DreamjobPageInh.user_id' => $profil['AppUser']['id'])) + ); + } } - } - + }else + $hard_error = true; //error - $hard_error = false; - if($profil['AppUser']['id'] != $self['AppUser']['id']){ - if(($company == $self_company) and !($this->MiconwareSession->isStaff())){ + if(!$company and $profil['AppUser']['id'] != $self['AppUser']['id'] or $hard_error){ + if(($company == $self_company) and !($this->MiconwareSession->isStaff()) or $hard_error){ $hard_error = true; $this->MiconwareSession->setFlash(__('dreamjob.error.page.notFound'),'flash',array('alert'=>'danger')); $this->set('error', 'dreamjob.error.noPermision'); diff --git a/app/Model/DreamjobCompany.php b/app/Model/DreamjobCompany.php index bd2df43..59af77b 100755 --- a/app/Model/DreamjobCompany.php +++ b/app/Model/DreamjobCompany.php @@ -91,6 +91,16 @@ class DreamjobCompany extends AppModel { //'on' => 'create', // Limit validation to 'create' or 'update' operations ), ), + 'pro_user' => array( + 'numeric' => array( + 'rule' => array('numeric'), + //'message' => 'Your custom message here', + //'allowEmpty' => false, + //'required' => false, + //'last' => false, // Stop validation after this rule + //'on' => 'create', // Limit validation to 'create' or 'update' operations + ), + ), ); @@ -113,8 +123,14 @@ class DreamjobCompany extends AppModel { 'AppUser' => array( 'className' => 'AppUser', 'foreignKey' => 'id' - ) - ); + ), + 'User' => array( + 'className' => 'User', + 'foreignKey' => false, + 'conditions' => array('DreamjobCompany.djaccount_ptr_id=AppUser.id and User.id = AppUser.user_id'), + 'limit' => 1 + ) + ); public $hasMany = array( 'DreamjobPageInh' => array( 'className' => 'DreamjobPageInh', diff --git a/app/Model/DreamjobJobOpening.php b/app/Model/DreamjobJobOpening.php index 390b199..c874fb7 100644 --- a/app/Model/DreamjobJobOpening.php +++ b/app/Model/DreamjobJobOpening.php @@ -176,10 +176,15 @@ class DreamjobJobOpening extends AppModel { public $belongsTo = array( 'DreamjobCompany' => array( 'className' => 'DreamjobCompany', - 'foreignKey' => 'company_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' + 'foreignKey' => 'company_id' + ), + 'DreamjobUser' => array( + 'className' => 'DreamjobUser', + 'foreignKey' => 'company_id' + ), + 'AppUser' => array( + 'className' => 'AppUser', + 'foreignKey' => 'company_id' ), 'DreamjobListGraducation' => array( 'className' => 'DreamjobListGraducation', @@ -196,4 +201,12 @@ class DreamjobJobOpening extends AppModel { 'order' => '' ) ); + public $hasOne = array( + 'User' => array( + 'className' => 'User', + 'foreignKey' => false, + 'conditions' => array('DreamjobJobOpening.company_id = AppUser.id and User.id = AppUser.user_id'), + 'limit' => 1 + ) + ); } diff --git a/app/Model/DreamjobWorker.php b/app/Model/DreamjobWorker.php index c3b1dd4..0987af7 100755 --- a/app/Model/DreamjobWorker.php +++ b/app/Model/DreamjobWorker.php @@ -123,15 +123,20 @@ class DreamjobWorker extends AppModel { ); public $hasAndBelongsToMany = array( - 'User' => - array( - 'className' => 'User', - 'with' => 'AppUser', - //'joinTable' => 'mic_sys_micapp', - 'foreignKey' => 'id', - 'associationForeignKey' => 'user_id', - 'limit' => 1 - ) + 'User' =>array( + 'className' => 'User', + 'with' => 'AppUser', + 'foreignKey' => 'id', + 'associationForeignKey' => 'user_id', + 'limit' => 1 + ), + 'Favority' => array( + 'className' => 'DreamjobJobOpening', + 'with' => 'DreamjobJobFavority', + //'joinTable' => 'mic_dj_job_opening_worker', + 'foreignKey' => 'worker_id', + 'associationForeignKey' => 'opening_id' + ) ); public $belongsTo = array( 'DreamjobListGraducation' => array( @@ -147,6 +152,12 @@ class DreamjobWorker extends AppModel { 'AppUser' => array( 'className' => 'AppUser', 'foreignKey' => 'id' + ), + 'User' => array( + 'className' => 'User', + 'foreignKey' => false, + 'conditions' => array('DreamjobWorker.djaccount_ptr_id=AppUser.id and User.id = AppUser.user_id'), + 'limit' => 1 ) ); public $hasMany = array( diff --git a/app/View/Elements/barleft.ctp b/app/View/Elements/barleft.ctp index b4aa9bb..2de58bc 100755 --- a/app/View/Elements/barleft.ctp +++ b/app/View/Elements/barleft.ctp @@ -21,13 +21,13 @@ if($isLoggedin){ 0){ + foreach($WORKER['Favority'] as $val){ + if($val['id'] == $opening['DreamjobJobOpening']['id']) + $opening_in_fav=true; + } + } + +$avatar = false; +if($opening['AppUser']['take_systemwide']){ + if($opening['User']['avatar']) + $avatar = true; +}else{ + if($opening['AppUser']['avatar']) + $avatar = true; +} ?> - - - - - - - - - - - - - -

- "> - "/>"/> + Html->image($image,array('url' => array('controller'=>'job','action'=>'openingGet','id'=>$opening['DreamjobJobOpening']['id'],'favorite'=>'favorite'))); + ?>
- - -
- -
- "/> -
+ +
+ +
+
- - -
- -
-
- +
+ +
+ +
+
: : @@ -55,15 +66,12 @@
- "> - - - - + Html->link(__('dreamjob.opening.detail'),array('controller'=>'job', 'action'=>'openingGet', 'id'=> $opening['DreamjobJobOpening']['id']),array("class" => "btn btn-default"));?> + "> - + - + @@ -79,15 +87,13 @@ ${newcount}/ ${count} - - + disabled" + disabled" href="{% url de.miconware.dreamjob.jobs.views.application_send opening.pk %}"> - + - - +
diff --git a/app/View/Elements/user_worker_header.ctp b/app/View/Elements/user_worker_header.ctp index 89a17a5..76aead2 100644 --- a/app/View/Elements/user_worker_header.ctp +++ b/app/View/Elements/user_worker_header.ctp @@ -7,8 +7,8 @@
@@ -34,8 +34,8 @@

- - + +
@@ -43,7 +43,7 @@ :
Time->format('d.m.Y', $profil['User'][0]['bday']); + echo $this->Time->format('d.m.Y', $profil['User']['bday']); else echo $this->Time->format('d.m.Y', $profil['AppUser']['bday']); ?> diff --git a/app/View/Layouts/default.ctp b/app/View/Layouts/default.ctp index cbba29f..7bf8e44 100755 --- a/app/View/Layouts/default.ctp +++ b/app/View/Layouts/default.ctp @@ -112,7 +112,6 @@ Html->script(array('jquery.min','bootstrap.min','dreamjob')); - //echo $this->element('sql_dump'); ?> diff --git a/app/View/User/company.ctp b/app/View/User/company.ctp index 297b081..5a7ee54 100644 --- a/app/View/User/company.ctp +++ b/app/View/User/company.ctp @@ -4,7 +4,7 @@ */ $avatar = false; if($profil['AppUser']['take_systemwide']){ - if($profil['User'][0]['avatar']) + if($profil['User']['avatar']) $avatar = true; }else{ if($profil['AppUser']['avatar']) @@ -17,7 +17,7 @@ if($profil['AppUser']['take_systemwide']){

- - + +


@@ -56,8 +56,8 @@ if($profil['AppUser']['take_systemwide']){


- - + +

diff --git a/app/View/User/worker.ctp b/app/View/User/worker.ctp index 93bfbdc..a07602e 100644 --- a/app/View/User/worker.ctp +++ b/app/View/User/worker.ctp @@ -8,6 +8,11 @@ echo $this->element('user_worker_header'); ?>
+ 0 and ($COMPANY['DreamjobCompany']['pro_user']>0) ) + or ( !empty($WORKER) and is_array($WORKER) and count($WORKER) > 0 ) + ){ +?>
@@ -47,3 +52,6 @@ ?>
+