コード例 #1
0
 public function testFilterCurrency()
 {
     $this->assertEquals('123456789', filterCurrency('123456789'));
     $this->assertEquals('1234567.89', filterCurrency('1234567,89'));
     $this->assertEquals('1234567.89', filterCurrency('1.234.567,89'));
     $this->assertEquals('1234567.89', filterCurrency('1234567.89'));
     $this->assertEquals('1234567.89', filterCurrency('1,234,567.89'));
 }
コード例 #2
0
ファイル: tasks.class.php プロジェクト: eureka2/web2project
 /**
  * @todo Parent store could be partially used
  */
 public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $perms = $AppUI->acl();
     $stored = false;
     $this->w2PTrimAll();
     if (!$this->task_owner) {
         $this->task_owner = $AppUI->user_id;
     }
     $importing_tasks = false;
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $this->task_target_budget = filterCurrency($this->task_target_budget);
     $q = new w2p_Database_Query();
     $this->task_updated = $q->dbfnNowWithTZ();
     if ($this->task_id && $perms->checkModuleItem('tasks', 'edit', $this->task_id)) {
         // Load and globalize the old, not yet updated task object
         // e.g. we need some info later to calculate the shifting time for depending tasks
         // see function update_dep_dates
         global $oTsk;
         $oTsk = new CTask();
         $oTsk->load($this->task_id);
         if ($this->task_start_date == '') {
             $this->task_start_date = '0000-00-00 00:00:00';
         }
         if ($this->task_end_date == '') {
             $this->task_end_date = '0000-00-00 00:00:00';
         }
         if ($msg = parent::store()) {
             return $msg;
         }
         // if task_status changed, then update subtasks
         if ($this->task_status != $oTsk->task_status) {
             $this->updateSubTasksStatus($this->task_status);
         }
         // Moving this task to another project?
         if ($this->task_project != $oTsk->task_project) {
             $this->updateSubTasksProject($this->task_project);
         }
         if ($this->task_dynamic == 1) {
             $this->updateDynamics(true);
         }
         if ($msg = parent::store()) {
             return $msg;
         }
         // Milestone or task end date, or dynamic status has changed,
         // shift the dates of the tasks that depend on this task
         if ($this->task_end_date != $oTsk->task_end_date || $this->task_dynamic != $oTsk->task_dynamic || $this->task_milestone == '1') {
             $this->shiftDependentTasks();
         }
         if (!$this->task_parent) {
             $q->addTable('tasks');
             $q->addUpdate('task_parent', $this->task_id);
             $q->addUpdate('task_updated', "'" . $q->dbfnNowWithTZ() . "'", false, true);
             $q->addWhere('task_id = ' . (int) $this->task_id);
             $q->exec();
             $q->clear();
         }
         $stored = true;
     }
     if (0 == $this->task_id && $perms->checkModuleItem('tasks', 'add')) {
         $this->task_created = $q->dbfnNowWithTZ();
         if ($this->task_start_date == '') {
             $this->task_start_date = '0000-00-00 00:00:00';
         }
         if ($this->task_end_date == '') {
             $this->task_end_date = '0000-00-00 00:00:00';
         }
         if ($msg = parent::store()) {
             return $msg;
         }
         $q->clear();
         if (!$this->task_parent) {
             $q->addTable('tasks');
             $q->addUpdate('task_parent', $this->task_id);
             $q->addUpdate('task_updated', "'" . $q->dbfnNowWithTZ() . "'", false, true);
             $q->addWhere('task_id = ' . (int) $this->task_id);
             $q->exec();
             $q->clear();
         } else {
             // importing tasks do not update dynamics
             $importing_tasks = true;
         }
         $stored = true;
     }
     $last_task_data = $this->getLastTaskData($this->task_project);
     CProject::updateTaskCache($this->task_project, $last_task_data['task_id'], $last_task_data['last_date'], $this->getTaskCount($this->task_project));
     $this->pushDependencies($this->task_id, $this->task_end_date);
     //split out related departments and store them seperatly.
     $q->setDelete('task_departments');
     $q->addWhere('task_id=' . (int) $this->task_id);
     $q->exec();
     $q->clear();
     if (!empty($this->task_departments)) {
         $departments = explode(',', $this->task_departments);
         foreach ($departments as $department) {
             $q->addTable('task_departments');
             $q->addInsert('task_id', $this->task_id);
             $q->addInsert('department_id', $department);
             $q->exec();
             $q->clear();
         }
     }
     //split out related contacts and store them seperatly.
     $q->setDelete('task_contacts');
     $q->addWhere('task_id=' . (int) $this->task_id);
     $q->exec();
     $q->clear();
     if ($this->task_contacts) {
         foreach ($this->task_contacts as $contact) {
             if ($contact) {
                 $q->addTable('task_contacts');
                 $q->addInsert('task_id', $this->task_id);
                 $q->addInsert('contact_id', $contact);
                 $q->exec();
                 $q->clear();
             }
         }
     }
     // if is child update parent task
     if ($this->task_parent && $this->task_parent != $this->task_id) {
         if (!$importing_tasks) {
             $this->updateDynamics(true);
         }
         $pTask = new CTask();
         $pTask->load($this->task_parent);
         $pTask->updateDynamics();
         if ($oTsk->task_parent != $this->task_parent) {
             $old_parent = new CTask();
             $old_parent->load($oTsk->task_parent);
             $old_parent->updateDynamics();
         }
     }
     // update dependencies
     if (!empty($this->task_id)) {
         $this->updateDependencies($this->getDependencies(), $this->task_parent);
     }
     return $stored;
 }
コード例 #3
0
 public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $perms = $AppUI->acl();
     $stored = false;
     $this->w2PTrimAll();
     // ensure changes of state in checkboxes is captured
     $this->project_active = (int) $this->project_active;
     $this->project_private = (int) $this->project_private;
     $this->project_target_budget = filterCurrency($this->project_target_budget);
     $this->project_actual_budget = filterCurrency($this->project_actual_budget);
     // Make sure project_short_name is the right size (issue for languages with encoded characters)
     $this->project_short_name = mb_substr($this->project_short_name, 0, 10);
     if (empty($this->project_end_date)) {
         $this->project_end_date = null;
     }
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $this->project_id = (int) $this->project_id;
     // convert dates to SQL format first
     if ($this->project_start_date) {
         $date = new w2p_Utilities_Date($this->project_start_date);
         $this->project_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_end_date) {
         $date = new w2p_Utilities_Date($this->project_end_date);
         $date->setTime(23, 59, 59);
         $this->project_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_actual_end_date) {
         $date = new w2p_Utilities_Date($this->project_actual_end_date);
         $this->project_actual_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     // check project parents and reset them to self if they do not exist
     if (!$this->project_parent) {
         $this->project_parent = $this->project_id;
         $this->project_original_parent = $this->project_id;
     } else {
         $parent_project = new CProject();
         $parent_project->load($this->project_parent);
         $this->project_original_parent = $parent_project->project_original_parent;
     }
     if (!$this->project_original_parent) {
         $this->project_original_parent = $this->project_id;
     }
     /*
      * TODO: I don't like the duplication on each of these two branches, but I
      *   don't have a good idea on how to fix it at the moment...
      */
     $q = $this->_query;
     $this->project_updated = $q->dbfnNowWithTZ();
     if ($this->project_id && $perms->checkModuleItem('projects', 'edit', $this->project_id)) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->project_id && $perms->checkModuleItem('projects', 'add')) {
         $this->project_created = $q->dbfnNowWithTZ();
         if ($msg = parent::store()) {
             return $msg;
         }
         if (0 == $this->project_parent || 0 == $this->project_original_parent) {
             $this->project_parent = $this->project_id;
             $this->project_original_parent = $this->project_id;
             if ($msg = parent::store()) {
                 return $msg;
             }
         }
         $stored = true;
     }
     //split out related departments and store them seperatly.
     $q->setDelete('project_departments');
     $q->addWhere('project_id=' . (int) $this->project_id);
     $q->exec();
     $q->clear();
     if ($this->project_departments) {
         foreach ($this->project_departments as $department) {
             if ($department) {
                 $q->addTable('project_departments');
                 $q->addInsert('project_id', $this->project_id);
                 $q->addInsert('department_id', $department);
                 $q->exec();
                 $q->clear();
             }
         }
     }
     //split out related contacts and store them seperatly.
     $q->setDelete('project_contacts');
     $q->addWhere('project_id=' . (int) $this->project_id);
     $q->exec();
     $q->clear();
     if ($this->project_contacts) {
         foreach ($this->project_contacts as $contact) {
             if ($contact) {
                 $q->addTable('project_contacts');
                 $q->addInsert('project_id', $this->project_id);
                 $q->addInsert('contact_id', $contact);
                 $q->exec();
                 $q->clear();
             }
         }
     }
     if ($stored) {
         $custom_fields = new w2p_Core_CustomFields('projects', 'addedit', $this->project_id, 'edit');
         $custom_fields->bind($_POST);
         $sql = $custom_fields->store($this->project_id);
         // Store Custom Fields
         CTask::storeTokenTask($AppUI, $this->project_id);
     }
     return $stored;
 }
コード例 #4
0
 protected function hook_preStore()
 {
     $q = $this->_getQuery();
     $this->project_updated = $q->dbfnNowWithTZ();
     // ensure changes of state in checkboxes is captured
     $this->project_active = (int) $this->project_active;
     $this->project_private = (int) $this->project_private;
     $this->project_target_budget = filterCurrency($this->project_target_budget);
     $this->project_url = str_replace(array('"', '"', '<', '>'), '', $this->project_url);
     $this->project_demo_url = str_replace(array('"', '"', '<', '>'), '', $this->project_demo_url);
     $this->project_owner = (int) $this->project_owner ? $this->project_owner : $this->_AppUI->user_id;
     $this->project_creator = (int) $this->project_creator ? $this->project_creator : $this->_AppUI->user_id;
     $this->project_priority = (int) $this->project_priority;
     $this->project_type = (int) $this->project_type;
     $this->project_status = (int) $this->project_status;
     // Make sure project_short_name is the right size (issue for languages with encoded characters)
     if ('' == $this->project_short_name) {
         $this->project_short_name = mb_substr($this->project_name, 0, 10);
     }
     $this->project_short_name = mb_substr($this->project_short_name, 0, 10);
     if (empty($this->project_end_date)) {
         $this->project_end_date = null;
     }
     $this->project_id = (int) $this->project_id;
     // convert dates to SQL format first
     if ($this->project_start_date) {
         $date = new w2p_Utilities_Date($this->project_start_date);
         $this->project_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_end_date) {
         $date = new w2p_Utilities_Date($this->project_end_date);
         $this->project_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     // check project parents and reset them to self if they do not exist
     if (!$this->project_parent) {
         $this->project_parent = $this->project_id;
         $this->project_original_parent = $this->project_id;
     } else {
         $parent_project = new CProject();
         $parent_project->overrideDatabase($this->_query);
         $parent_project->load($this->project_parent);
         $this->project_original_parent = $parent_project->project_original_parent;
     }
     if (!$this->project_original_parent) {
         $this->project_original_parent = $this->project_id;
     }
     parent::hook_preStore();
 }