/**
  * Delete this object and reset all relationship. This function will not delete any of related objec
  *
  * @access public
  * @param void
  * @return boolean
  */
 function delete()
 {
     try {
         DB::execute("UPDATE " . ProjectMessages::instance()->getTableName(true) . " SET `milestone_id` = '0' WHERE `milestone_id` = " . DB::escape($this->getId()));
         DB::execute("UPDATE " . ProjectTaskLists::instance()->getTableName(true) . " SET `milestone_id` = '0' WHERE `milestone_id` = " . DB::escape($this->getId()));
         return parent::delete();
     } catch (Exception $e) {
         throw $e;
     }
     // try
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ProjectTaskLists 
  */
 function manager()
 {
     if (!$this->manager instanceof ProjectTaskLists) {
         $this->manager = ProjectTaskLists::instance();
     }
     return $this->manager;
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query arguments (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ProjectTaskLists')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ProjectTaskLists::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ProjectTaskLists::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
Ejemplo n.º 4
0
 /**
  * Add user
  *
  * @access public
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_user');
     $company = Companies::findById(get_id('company_id'));
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         $this->redirectTo('administration');
     }
     // if
     if (!User::canAdd(logged_user(), $company)) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $user = new User();
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         $user_data = array('password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $company->getTimezone());
         // array
     }
     // if
     $projects = $company->getProjects();
     $permissions = PermissionManager::getPermissionsText();
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('projects', $projects);
     tpl_assign('permissions', $permissions);
     tpl_assign('user_data', $user_data);
     if (is_array(array_var($_POST, 'user'))) {
         $user->setFromAttributes($user_data);
         $user->setCompanyId($company->getId());
         try {
             // Generate random password
             if (array_var($user_data, 'password_generator') == 'random') {
                 $password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13);
                 // Validate user input
             } else {
                 $password = array_var($user_data, 'password');
                 if (trim($password) == '') {
                     throw new Error(lang('password value required'));
                 }
                 // if
                 if ($password != array_var($user_data, 'password_a')) {
                     throw new Error(lang('passwords dont match'));
                 }
                 // if
             }
             // if
             $user->setPassword($password);
             if (config_option('check_email_unique', '1') == '1') {
                 if (!$user->validateUniquenessOf('email')) {
                     throw new Error(lang('email address is already used'));
                 }
             }
             DB::beginWork();
             $user->save();
             ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
             if (is_array($projects)) {
                 foreach ($projects as $project) {
                     if (array_var($user_data, 'project_permissions_' . $project->getId()) == 'checked') {
                         $relation = new ProjectUser();
                         $relation->setProjectId($project->getId());
                         $relation->setUserId($user->getId());
                         foreach ($permissions as $permission => $permission_text) {
                             $permission_value = array_var($user_data, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked';
                             $user->setProjectPermission($project, $permission, $permission_value);
                         }
                         // foreach
                         $relation->save();
                     }
                     // if
                 }
                 // foreach
             }
             // if
             DB::commit();
             // Send notification...
             try {
                 if (array_var($user_data, 'send_email_notification')) {
                     Notifier::newUserAccount($user, $password);
                 }
                 // if
             } catch (Exception $e) {
             }
             // try
             // Add task to Welcome project...
             try {
                 if (array_var($user_data, 'add welcome task')) {
                     $task_data = array('text' => lang('welcome task text', $user->getName(), get_url('account', 'edit')), 'due date' => DateTimeValueLib::now() + 7 * 24 * 60 * 60, 'assigned_to_company_id' => $user->getCompanyId(), 'assigned_to_user_id' => $user->getId());
                     $task_list = ProjectTaskLists::instance()->findById(2, true);
                     DB::beginWork();
                     $task = new ProjectTask();
                     $task->setFromAttributes($task_data);
                     $task_list->attachTask($task);
                     $task->save();
                     DB::commit();
                 }
                 // if
             } catch (Exception $e) {
                 DB::rollback();
             }
             // try
             flash_success(lang('success add user', $user->getDisplayName()));
             $projects = $company->getProjects();
             if (is_array($projects) || count($projects)) {
                 $this->redirectToUrl(get_url('account', 'update_permissions', $user->getId()));
                 // Continue to permissions page
             }
             // if
             $this->redirectToUrl($company->getViewUrl());
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }