Esempio n. 1
0
 public function findAllInDatabase()
 {
     $criteria = new CDbCriteria();
     $criteria->addCondition('type.name=:resource_type');
     $criteria->params = array(':resource_type' => $this->type);
     if (is_null($this->devkey) || !isset($this->devkey)) {
         $criteria2 = $criteria;
     } else {
         $criteria2 = new CDbCriteria();
         $criteria2->condition = '
             SELECT * FROM Resource AS r
             INNER JOIN ResourceType as type ON r.type_id = type.id AND type.name = :resource_type
             INNER JOIN ClientApplication as client ON client.dev_key = :dev_key
             INNER JOIN Application as app ON app.resource_id = r.id AND app.client_application_id = client.id
         ';
         $criteria2->params = array('resource_type' => $this->type, 'dev_key' => $this->devkey);
     }
     return ARResource::model()->with('type')->findAll($criteria);
 }
 public function remove($object)
 {
     $transaction = ARResource::model()->getDbConnection()->beginTransaction();
     try {
         if (ARResource::model()->deleteByPk($object->id) == false) {
             throw new Exception('Could not remove object');
         }
         ResourceMetaData::model()->deleteAll('resource_id=:resid', array('resid' => $object->id));
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }