예제 #1
0
 public function save(Entity $entity)
 {
     $result = parent::save($entity);
     $accountIdChanged = $entity->has('accountId') && $entity->get('accountId') != $entity->getFetched('accountId');
     $titleChanged = $entity->has('title') && $entity->get('title') != $entity->getFetched('title');
     if ($accountIdChanged) {
         $accountId = $entity->get('accountId');
         if (empty($accountId)) {
             $this->unrelate($entity, 'accounts', $entity->getFetched('accountId'));
             return $result;
         }
     }
     if ($titleChanged) {
         if (empty($accountId)) {
             $accountId = $entity->getFetched('accountId');
             if (empty($accountId)) {
                 return $result;
             }
         }
     }
     if ($accountIdChanged || $titleChanged) {
         $pdo = $this->getEntityManager()->getPDO();
         $sql = "\n\t\t\t\tSELECT id, role FROM account_contact\n\t\t\t\tWHERE \n\t\t\t\t\taccount_id = " . $pdo->quote($accountId) . " AND\n\t\t\t\t\tcontact_id = " . $pdo->quote($entity->id) . " AND\n\t\t\t\t\tdeleted = 0\t\t\t\t\t\n\t\t\t";
         $sth = $pdo->prepare($sql);
         if ($row = $sth->fetch()) {
             if ($titleChanged && $entity->get('title') != $row['role']) {
                 $this->updateRelation($entity, 'accounts', $accountId, array('role' => $entity->get('title')));
             }
         } else {
             $this->relate($entity, 'accounts', $accountId, array('role' => $entity->get('title')));
         }
     }
     return $result;
 }
예제 #2
0
 public function save(Entity $entity, array $options = array())
 {
     $isNew = $entity->isNew();
     $result = parent::save($entity, $options);
     if ($isNew) {
         if (!empty($entity->id) && $entity->has('contents')) {
             $contents = $entity->get('contents');
             $this->getFileManager()->putContents('data/upload/' . $entity->id, $contents);
         }
     }
     return $result;
 }