Example #1
0
 /**
  * (non-PHPdoc)
  * @see DetailsPageAbstract::saveItem()
  */
 public function saveItem($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $task = null;
         if (isset($param->CallbackParameter->id) && !($task = Task::get(trim($param->CallbackParameter->id))) instanceof Task) {
             throw new Exception('Invalid Task passed in!');
         }
         if (!isset($param->CallbackParameter->instructions) || ($instructions = trim($param->CallbackParameter->instructions)) === '') {
             throw new Exception('Instructions are required!');
         }
         if (!isset($param->CallbackParameter->customerId) || !($customer = Customer::get(trim($param->CallbackParameter->customerId))) instanceof Customer) {
             throw new Exception('Invalid Customer Passed in!');
         }
         $tech = isset($param->CallbackParameter->techId) ? UserAccount::get(trim($param->CallbackParameter->techId)) : null;
         $order = isset($param->CallbackParameter->orderId) ? Order::get(trim($param->CallbackParameter->orderId)) : null;
         $dueDate = new UDate(trim($param->CallbackParameter->dueDate));
         $status = isset($param->CallbackParameter->statusId) ? TaskStatus::get(trim($param->CallbackParameter->statusId)) : null;
         if (!$task instanceof Task) {
             $task = Task::create($customer, $dueDate, $instructions, $tech, $order);
         } else {
             $task->setCustomer($customer)->setDueDate($dueDate)->setInstructions($instructions)->setTechnician($tech)->setFromEntityId($order instanceof Order ? $order->getId() : '')->setFromEntityName($order instanceof Order ? get_class($order) : '')->setStatus($status)->save();
         }
         // 			$results['url'] = '/task/' . $task->getId() . '.html?' . $_SERVER['QUERY_STRING'];
         $results['item'] = $task->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see BPCPageAbstract::_preGetEndJs()
  */
 protected function _preGetEndJs()
 {
     parent::_preGetEndJs();
     $order = $tech = $customer = null;
     if (isset($_REQUEST['customerId']) && !($customer = Customer::get(trim($_REQUEST['customerId']))) instanceof Customer) {
         die('Invalid Customer provided!');
     }
     if (isset($_REQUEST['orderId']) && !($order = Order::get(trim($_REQUEST['orderId']))) instanceof Order) {
         die('Invalid Order provided!');
     }
     if (isset($_REQUEST['techId']) && !($tech = UserAccount::get(trim($_REQUEST['techId']))) instanceof UserAccount) {
         die('Invalid Technician provided!');
     }
     $statusIds = array();
     if (isset($_REQUEST['statusIds']) && ($statusIds = trim($_REQUEST['statusIds'])) !== '') {
         $statusIds = array_map(create_function('$a', 'return intval(trim($a));'), explode(',', $statusIds));
     }
     $allstatuses = isset($_REQUEST['allstatuses']) && intval(trim($_REQUEST['allstatuses'])) === 1;
     $preSetData = array('statuses' => array(), 'order' => $order instanceof Order ? $order->getJson() : array(), 'technician' => $tech instanceof UserAccount ? $tech->getJson() : array(), 'customer' => $customer instanceof Customer ? $customer->getJson() : array(), 'meId' => Core::getUser()->getId(), 'noDueDateStatusIds' => array());
     $statuses = array();
     foreach (TaskStatus::getAll() as $status) {
         $statuses[] = $statusJson = $status->getJson();
         if (($noDueDateChecking = in_array(intval($status->getId()), TaskStatus::getClosedStatusIds())) === true) {
             $preSetData['noDueDateStatusIds'][] = $status->getId();
         }
         if (count($statusIds) > 0) {
             if (in_array(intval($status->getId()), $statusIds)) {
                 $preSetData['statuses'][] = $statusJson;
             }
         } else {
             if ($allstatuses === false && !$noDueDateChecking) {
                 $preSetData['statuses'][] = $statusJson;
             }
         }
     }
     if (count($statusIds) > 0 && count($preSetData['statuses']) === 0) {
         die('Invalide Task Status provided.');
     }
     $js = "pageJs";
     $js .= ".setOpenInFancyBox(" . (isset($_REQUEST['blanklayout']) && intval(trim($_REQUEST['blanklayout'])) === 1 && (isset($_REQUEST['nosearch']) && intval($_REQUEST['nosearch']) === 1) ? 'false' : 'true') . ")";
     $js .= ".setStatuses(" . json_encode($statuses) . ")";
     $js .= ".setPreSetData(" . json_encode($preSetData) . ")";
     $js .= ";";
     return $js;
 }
Example #3
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::preSave()
  */
 public function preSave()
 {
     if (trim($this->getId()) === '') {
         if (!$this->status instanceof TaskStatus) {
             $this->setStatus(TaskStatus::get(TaskStatus::ID_NEW));
         }
         if (trim($this->getDueDate()) === trim(UDate::zeroDate())) {
             $this->setDueDate(UDate::now()->modify(self::DUE_DATE_PERIOD));
         }
     } else {
         $changed = array();
         $origTech = $origCustomer = $origOrder = $origStatus = null;
         $origTask = Task::get($this->getId());
         if (($customer = $this->getCustomer()) instanceof Customer && !($origCustomer = $origTask->getCustomer()) instanceof Customer || !$customer instanceof Customer && $origCustomer instanceof Customer || $customer instanceof Customer && $origCustomer instanceof Customer && $customer->getId() !== $origCustomer->getId()) {
             $changed[] = 'Customer Changed["' . ($origCustomer instanceof Customer ? $origCustomer->getName() : '') . '" => "' . ($customer instanceof Customer ? $customer->getName() : '') . '"]';
         }
         if (($tech = $this->getTechnician()) instanceof UserAccount && !($origTech = $origTask->getTechnician()) instanceof UserAccount || !$tech instanceof UserAccount && $origTech instanceof UserAccount || $tech instanceof UserAccount && $origTech instanceof UserAccount && $tech->getId() !== $origTech->getId()) {
             $changed[] = 'Technician Changed["' . ($origTech instanceof UserAccount ? $origTech->getPerson()->getFullName() : '') . '" => "' . ($tech instanceof UserAccount ? $tech->getPerson()->getFullName() : '') . '"]';
         }
         if (($order = $this->getFromEntity()) instanceof Order && !($origOrder = $origTask->getFromEntity()) instanceof Order || !$order instanceof Order && $origOrder instanceof Order || $order instanceof Order && $origOrder instanceof Order && $order->getId() !== $origOrder->getId()) {
             $changed[] = 'Order Changed["' . ($origOrder instanceof Order ? $origOrder->getOrderNo() : '') . '" => "' . ($order instanceof Order ? $order->getOrderNo() : '') . '"]';
         }
         if (($status = $this->getStatus()) instanceof TaskStatus && !($origStatus = $origTask->getStatus()) instanceof TaskStatus || !$status instanceof TaskStatus && $origStatus instanceof TaskStatus || $status instanceof TaskStatus && $origStatus instanceof TaskStatus && $status->getId() !== $origStatus->getId()) {
             $changed[] = 'Status Changed["' . ($origStatus instanceof TaskStatus ? $origStatus->getName() : '') . '" => "' . ($status instanceof TaskStatus ? $status->getName() : '') . '"]';
         }
         if (count($changed) > 0) {
             $this->addComment(implode(', ', $changed), Comments::TYPE_SYSTEM);
         }
     }
 }