/**
  * add logout entry to the access log
  *
  * @param string $_sessionId the session id
  * @param string $_ipAddress the ip address the user connects from
  * @return void|Tinebase_Model_AccessLog
  */
 public function setLogout($_sessionId)
 {
     try {
         $loginRecord = $this->_backend->getByProperty($_sessionId, 'sessionid');
     } catch (Tinebase_Exception_NotFound $tenf) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not find access log login record for session id ' . $_sessionId);
         return;
     }
     $loginRecord->lo = Tinebase_DateTime::now();
     // call update of backend direct to save overhead of $this->update()
     return $this->_backend->update($loginRecord);
 }
예제 #2
0
 /**
  * add logout entry to the access log
  *
  * @param string $_sessionId the session id
  * @param string $_ipAddress the ip address the user connects from
  * @return void|Tinebase_Model_AccessLog
  */
 public function setLogout($_sessionId, $_ipAddress = NULL)
 {
     try {
         $loginRecord = $this->_backend->getByProperty($_sessionId, 'sessionid');
     } catch (Tinebase_Exception_NotFound $tenf) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not find access log login record for session id ' . $_sessionId);
         return;
     }
     $loginRecord->lo = Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG);
     if ($_ipAddress !== NULL) {
         $loginRecord->ip = $_ipAddress;
     }
     return $this->update($loginRecord);
 }
 /**
  * get vacation
  */
 protected function _getVacation()
 {
     try {
         $vacationRecord = $this->_vacationBackend->getByProperty($this->_accountId, 'account_id');
         $vacationRecord->addresses = Zend_Json::decode($vacationRecord->addresses);
         $this->_vacation = $vacationRecord->getFSV();
     } catch (Tinebase_Exception_NotFound $tenf) {
         // do nothing
     }
 }
 /**
  * get vacation
  */
 protected function _getVacation()
 {
     try {
         $vacationRecord = $this->_vacationBackend->getByProperty($this->_accountId, 'account_id');
         $vacationRecord->addresses = Zend_Json::decode($vacationRecord->addresses);
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Got vacation from DB: ' . print_r($vacationRecord->toArray(), TRUE));
         }
         $this->_vacation = $vacationRecord->getFSV();
     } catch (Tinebase_Exception_NotFound $tenf) {
         // do nothing
     }
 }
예제 #5
0
 /**
  * load state data
  *
  * @return array
  */
 public function loadStateInfo()
 {
     $result = array();
     if (Tinebase_Core::getUser()) {
         $userId = Tinebase_Core::getUser()->getId();
         try {
             $state = $this->_backend->getByProperty($userId, 'user_id');
             $result = Zend_Json::decode($state->data);
         } catch (Tinebase_Exception_NotFound $tenf) {
             // no state found
         }
     }
     return $result;
 }
 /**
  * update to 6.7
  * 
  * - remove costcenter from contract, create costcenter-employee-mm table
  */
 public function update_6()
 {
     $table = new Setup_Backend_Schema_Table_Xml('<table>
         <name>humanresources_costcenter</name>
         <version>1</version>
         <declaration>
             <field>
                 <name>id</name>
                 <type>text</type>
                 <length>40</length>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>start_date</name>
                 <type>datetime</type>
                 <notnull>false</notnull>
             </field>
             <field>
                 <name>employee_id</name>
                 <type>text</type>
                 <length>40</length>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>cost_center_id</name>
                 <type>text</type>
                 <length>40</length>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>created_by</name>
                 <type>text</type>
                 <length>40</length>
             </field>
             <field>
                 <name>creation_time</name>
                 <type>datetime</type>
             </field> 
             <field>
                 <name>last_modified_by</name>
                 <type>text</type>
                 <length>40</length>
             </field>
             <field>
                 <name>last_modified_time</name>
                 <type>datetime</type>
             </field>
             <field>
                 <name>is_deleted</name>
                 <type>boolean</type>
                 <default>false</default>
             </field>
             <field>
                 <name>deleted_by</name>
                 <type>text</type>
                 <length>40</length>
             </field>
             <field>
                 <name>deleted_time</name>
                 <type>datetime</type>
             </field>
             <index>
                 <name>id</name>
                 <primary>true</primary>
                 <field>
                     <name>id</name>
                 </field>
             </index>
         </declaration>
     </table>');
     $this->_backend->createTable($table, 'HumanResources');
     // find all contracts
     $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'humanresources_contract')->where('is_deleted=0');
     $stmt = $select->query();
     $contracts = $stmt->fetchAll();
     $now = new Tinebase_DateTime();
     $be = HumanResources_Controller_CostCenter::getInstance();
     foreach ($contracts as $contract) {
         if ($contract['cost_center_id']) {
             $costcenter = new HumanResources_Model_CostCenter(array('employee_id' => $contract['employee_id'], 'cost_center_id' => $contract['cost_center_id'], 'start_date' => $contract['start_date'] ? $contract['start_date'] : (string) $now));
             $be->create($costcenter);
         }
     }
     // remove costcenter property from contract
     try {
         $this->_backend->dropCol('humanresources_contract', 'cost_center_id');
     } catch (Exception $e) {
     }
     // create type config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId();
     // update vacation status config
     $kfc = $cb->getByProperty('freetimeStatus');
     $kfc->name = HumanResources_Config::VACATION_STATUS;
     $cb->update($kfc);
     // create sickness status config
     $sicknessStatusConfig = array('name' => HumanResources_Config::SICKNESS_STATUS, 'records' => array(array('id' => 'EXCUSED', 'value' => 'Excused', 'icon' => 'images/oxygen/16x16/actions/smiley.png', 'system' => TRUE), array('id' => 'UNEXCUSED', 'value' => 'Unexcused', 'icon' => 'images/oxygen/16x16/actions/tools-report-bug.png', 'system' => TRUE)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => HumanResources_Config::SICKNESS_STATUS, 'value' => json_encode($sicknessStatusConfig))));
     // update sickness records, set status = excused
     $filter = new HumanResources_Model_FreeTimeFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'SICKNESS')));
     $ftb = new HumanResources_Backend_FreeTime();
     $records = $ftb->search($filter);
     $ftb->updateMultiple($records->id, array('status' => 'EXCUSED'));
     // create persistenfilters
     $pfe = Tinebase_PersistentFilter::getInstance();
     $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(), 'model' => 'HumanResources_Model_EmployeeFilter');
     $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Currently employed", 'description' => "Employees which are currently employed", 'filters' => array(array('field' => 'is_employed', 'operator' => 'equals', 'value' => 1))))));
     // add workingtime json
     $field = '<field>
         <name>workingtime_json</name>
         <type>text</type>
         <length>1024</length>
         <notnull>true</notnull>
     </field>';
     $declaration = new Setup_Backend_Schema_Field_Xml($field);
     $this->_backend->addCol('humanresources_contract', $declaration);
     $this->setTableVersion('humanresources_contract', '4');
     // change freetime type field length
     $field = '<field>
                 <name>type</name>
                 <type>text</type>
                 <length>64</length>
                 <default>vacation</default>
             </field>';
     $declaration = new Setup_Backend_Schema_Field_Xml($field);
     $this->_backend->alterCol('humanresources_freetime', $declaration);
     $this->setTableVersion('humanresources_freetime', '3');
     // add vacation types
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config', 'modlogActive' => FALSE));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId();
     $filter = new Tinebase_Model_ConfigFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => HumanResources_Config::FREETIME_TYPE)));
     $ftt = $cb->search($filter)->getFirstRecord();
     $val = json_decode($ftt->value);
     $existing = $val->records;
     $existing[] = array('id' => 'VACATION_REMAINING', 'value' => 'Remaining Vacation', 'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => TRUE);
     $existing[] = array('id' => 'VACATION_EXTRA', 'value' => 'Extra Vacation', 'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => TRUE);
     $freeTimeTypeConfig = array('name' => HumanResources_Config::FREETIME_TYPE, 'records' => $existing);
     $ftt->value = json_encode($freeTimeTypeConfig);
     $cb->update($ftt);
     // update json of workingtime models if they still exist
     $controller = HumanResources_Controller_WorkingTime::getInstance();
     $controller->modlogActive(FALSE);
     $filter = new HumanResources_Model_WorkingTimeFilter(array());
     //array('field' => 'working_hours', 'operator' => 'equals', 'value' => '40')));
     $allWT = $controller->search($filter);
     $wt40 = $allWT->filter('working_hours', "40");
     foreach ($wt40 as $wt) {
         $wt->json = '{"days":[8,8,8,8,8,0,0]}';
         $controller->update($wt);
     }
     $wt37 = $allWT->filter('working_hours', "37.5");
     foreach ($wt37 as $wt) {
         $wt->json = '{"days":[8,8,8,8,5.5,0,0]}';
         $controller->update($wt);
     }
     $wt20 = $allWT->filter('working_hours', "20");
     foreach ($wt20 as $wt) {
         $wt->json = '{"days":[4,4,4,4,4,0,0]}';
         $controller->update($wt);
     }
     $this->setApplicationVersion('HumanResources', '6.7');
 }