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 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);
         }
     }
 }