public function executeApprove()
 {
     $approval = sfApprovalPeer::retrieveByUuid($this->getRequestParameter('uuid'));
     if (!$approval) {
         return 'NotFound';
     }
     $object = $approval->getRelatedObject();
     $this->setFlash('sf_approvable_object', $object);
     $class = get_class($object);
     $peerClass = get_class($object->getPeer());
     $destination = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . $class . '_destination', '@homepage');
     $approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . $class . '_approved_value', true);
     $columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . $class . '_column', 'is_approved');
     $method = 'set' . call_user_func(array($peerClass, 'translateFieldName'), $columnName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
     $ret = null;
     foreach (sfMixer::getCallables('sfApprovableActions:approve:pre') as $callable) {
         $ret = call_user_func($callable, $object);
     }
     if (!is_null($ret)) {
         return $ret;
     }
     $object->{$method}($approvedValue);
     $object->save();
     $approval->delete();
     foreach (sfMixer::getCallables('sfApprovableActions:approve:post') as $callable) {
         $ret = call_user_func($callable, $object);
     }
     if (!is_null($ret)) {
         return $ret;
     }
     $this->redirect($destination);
 }
 public function getApproval(BaseObject $object)
 {
     if ($object->isNew() === true || $object->isModified() === true || $object->isDeleted() === true) {
         throw new Exception('You can only approve an object which has already been saved');
     }
     $columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_column', 'is_approved');
     $approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_approved_value', true);
     $disabledApplications = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_disabled_applications');
     // Test if we should crated an approval - is the column value different to out required value?
     // If our object is already approved then we can delete other
     $columnGetter = 'get' . sfInflector::camelize($columnName);
     if ($approvedValue != $object->{$columnGetter}()) {
         return sfApprovalPeer::retrieveOrCreateByObject($object);
     } else {
         sfApprovalPeer::deleteByObject($object);
         return null;
     }
 }
Exemplo n.º 3
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = sfApprovalPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setApprovableModel($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setApprovableId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setUuid($arr[$keys[3]]);
     }
 }
Exemplo n.º 4
0
 public static function retrieveByUuid($uuid)
 {
     $c = new Criteria();
     $c->add(sfApprovalPeer::UUID, $uuid);
     return sfApprovalPeer::doSelectOne($c);
 }
} catch (Exception $err) {
    $t->pass('getApprovalUrl() on an unsaved class throws an exception');
}
try {
    $item1->getApproval();
    $t->fail('no code should be executed after throwing exception');
} catch (Exception $err) {
    $t->pass('getApproval() on an unsaved class throws an exception');
}
try {
    sfApprovalPeer::retrieveOrCreateByObject($item1);
    $t->fail('no code should be executed after throwing exception');
} catch (Exception $err) {
    $t->pass('sfApprovalPeer::retrieveOrCreateByObject() on an unsaved class throws an exception');
}
$item1->save();
$t->is($item1->getApproval(), null, 'getApproval() returns null for approved objects');
$t->is($item1->getApprovalUrl(), false, 'getApprovalUrl() returns false for approved objects');
$item1->{$approvable_setter}(!$approved_value);
$item1->save();
$t->isa_ok($approval = $item1->getApproval(), 'sfApproval', 'Unapproved getApproval() returns and sfApproval object');
$t->isa_ok($item1->getApprovalUrl(), 'string', 'Unapproved getApprovalUrl() returns a string');
$t->isa_ok(sfApprovalPeer::retrieveOrCreateByObject($item1), 'sfApproval', 'retrieveOrCreateByObject() returns an sfApproval object');
$t->isa_ok(sfApprovalPeer::retrieveByUuid($approval->getUuid()), 'sfApproval', 'sfApprovalPeer::retrieveByUuid() returns an instance of sfApproval');
$item1->delete();
try {
    $item1->getApprovalUrl();
    $t->fail('no code should be executed after throwing exception');
} catch (Exception $err) {
    $t->pass('getApprovalUrl() on an deleted class throws an exception');
}
Exemplo n.º 6
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(sfApprovalPeer::ID, $pks, Criteria::IN);
         $objs = sfApprovalPeer::doSelect($criteria, $con);
     }
     return $objs;
 }